This is a Binder repository containing tutorial notebooks for learning about pyQuil and the rest of the Forest SDK (quilc and the QVM). The table of contents for the repository can be found at the bottom of this notebook. If you'd like to add a notebook, or change an existing one, make a pull request to the rigetti/forest-tutorials repository!
from pyquil import get_qc, Program
from pyquil.gates import H, CNOT, MEASURE
# Get a quantum virtual machine (simulator)
qvm = get_qc("2q-qvm")
# Build a program
p = Program()
p += H(0)
p += CNOT(0, 1)
ro = p.declare("ro", "BIT", 2)
p += MEASURE(0, ro[0])
p += MEASURE(1, ro[1])
p.wrap_in_numshots_loop(10)
print(p)
H 0 CNOT 0 1 DECLARE ro BIT[2] MEASURE 0 ro[0] MEASURE 1 ro[1]
# Execute the program synchronously
qvm.run(p).readout_data.get("ro")
array([[1, 1], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0]])
# Alternately, asynchronous execution is supported
job = qvm.qam.execute(p)
# When ready, fetch job results
qvm.qam.get_result(job).readout_data.get("ro")
array([[1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [1, 1]])