Welcome

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!

The Basics

In [1]:
from pyquil import get_qc, Program
from pyquil.gates import H, CNOT, MEASURE
In [2]:
# Get a quantum virtual machine (simulator)
qvm = get_qc("2q-qvm")
In [3]:
# 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]

In [4]:
# Execute the program synchronously
qvm.run(p).readout_data.get("ro")
Out[4]:
array([[1, 1],
       [0, 0],
       [0, 0],
       [0, 0],
       [1, 1],
       [1, 1],
       [0, 0],
       [1, 1],
       [0, 0],
       [0, 0]])
In [5]:
# Alternately, asynchronous execution is supported
job = qvm.qam.execute(p)

# When ready, fetch job results
qvm.qam.get_result(job).readout_data.get("ro")
Out[5]:
array([[1, 1],
       [0, 0],
       [0, 0],
       [1, 1],
       [0, 0],
       [1, 1],
       [0, 0],
       [0, 0],
       [0, 0],
       [1, 1]])