Skip to content

Instantly share code, notes, and snippets.

@jeffrafter
Created July 1, 2017 15:24
Show Gist options
  • Save jeffrafter/c35286bbcf0c08376de935dac47f3c87 to your computer and use it in GitHub Desktop.
Save jeffrafter/c35286bbcf0c08376de935dac47f3c87 to your computer and use it in GitHub Desktop.
Flip a coin on Forest Quantum Virtual Machine
import pyquil.quil as pq
import pyquil.api as api
from pyquil.gates import *
coin_flip = pq.Program().inst(H(0)).measure(0, 0)
num_flips = 5
qvm = api.SyncConnection()
flips = qvm.run(coin_flip, [0], num_flips)
# Should see [[0], [1], [0], [1], [0]] (the results will change!)
print(flips)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment