# Hello, World! from pyquil.quil import Program from pyquil.gates import H, CNOT from pyquil.api import SyncConnection # construct a Bell State program p = Program() p.inst(H(0)) p.inst(CNOT(0, 1)) # run the program on a QVM qvm = SyncConnection() result = qvm.wavefunction(p) # pyquil init needed
# of the currently built up reversed_prog because # of the reversal of the steps in the final reversed program. reversed_prog = reversed_step_prog + reversed_prog # Add Hadamard gates to remove superposition reversed_prog = pq.Program().inst(list(map(H, qubits))) + reversed_prog # Correct the overall phase reversed_prog = pq.Program().inst(RZ(-2 * phases[0], qubits[0])) \ .inst(PHASE(2 * phases[0], qubits[0])) + reversed_prog # Apply all gates in reverse return reversed_prog if __name__ == "__main__": print("Example list: -3.2+1j, -7, -0.293j, 1, 0, 0") v = input("Input a comma separated list of complex numbers:\n") if isinstance(v, int): v = [v] else: v = list(v) p = create_arbitrary_state(v) qvm = SyncConnection() wf, _ = qvm.wavefunction(p) print("Normalized Vector: ", list(v / np.linalg.norm(v))) print("Generated Wavefunction: ", wf) if input("Show Program? (y/n): ") == 'y': print("----------Quil Code Used----------") print(p.out())
from pyquil.quil import Program from pyquil.gates import H, X, CNOT, MEASURE from pyquil.api import SyncConnection # Reference: https://arxiv.org/pdf/1302.4310.pdf p = Program() p.inst("""DEFGATE CH(%theta): 1, 0, 0, 0 0, 1, 0, 0 0, 0, cos(2*%theta), sin(2*%theta) 0, 0, sin(2*%theta), cos(-2*%theta)""") p.inst(H(3)) p.inst(CNOT(3, 2)) p.inst(CNOT(2, 1)) p.inst("CH(pi/8) 1 0") p.inst("CH(pi/16) 2 0") p.inst(H(1)) p.inst(H(2)) p.inst(X(0)) p.inst(MEASURE(0)) p.inst(MEASURE(1)) p.inst(MEASURE(2)) # run the program on a QVM qvm = SyncConnection() wvf, _ = qvm.wavefunction(p) print(wvf)