Last active
November 29, 2019 04:05
-
-
Save ryan-lam/46bba4ae3e267e9565cff2f9d73ca78b to your computer and use it in GitHub Desktop.
Part 4 Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pyquil import Program, get_qc, list_quantum_computers | |
| from pyquil.gates import * | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| p = Program() | |
| ro = p.declare('ro', 'BIT', 2) | |
| p += X(0) | |
| p += Y(0) | |
| p += H(0) | |
| p += CNOT(0, 1) | |
| p += MEASURE(1, ro[1]) | |
| p += MEASURE(0, ro[0]) | |
| # print(p) #This line is optional | |
| qc = get_qc('9q-square-noisy-qvm') | |
| cp = qc.compile(p) | |
| results = [] | |
| for i in range(100): | |
| results.append(qc.run(cp).tolist()) | |
| print(results) | |
| unique = [] | |
| for x in results: | |
| if x not in unique: | |
| unique.append(x) | |
| tally = [] | |
| for i in range(len(unique)): | |
| print(str(unique[i]) + " = " + str(results.count(unique[i])) + " (" +str(((results.count(unique[i]))/len(results))*100) + " %)") | |
| tally.append(results.count(unique[i])/100) | |
| y_pos = np.arange(len(unique)) | |
| plt.bar(y_pos, tally, width=0.2, align='center', alpha=0.5) | |
| plt.xticks(y_pos, unique) | |
| plt.ylabel('Percentage') | |
| plt.title('States') | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment