Skip to content

Instantly share code, notes, and snippets.

@ryan-lam
Last active November 29, 2019 04:06
Show Gist options
  • Select an option

  • Save ryan-lam/c33785bbc42929e90e960b9ae0c84e18 to your computer and use it in GitHub Desktop.

Select an option

Save ryan-lam/c33785bbc42929e90e960b9ae0c84e18 to your computer and use it in GitHub Desktop.
Part 3 Code
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) #Uncomment this line
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment