pyquil
pyquil copied to clipboard
How to apply controlled if gate using pyquil and measure intermediate state in program
I am working on porting some sample programs from qiskit to pyquil
I have a couple of questions
-
I haven't been able to found any equivalent of this statement in pyquil
qc.h(q[0]).c_if(c,0)
here we are applying hadamart on qubit(0) when our classical bit is 0 (controlled_if) -
I need to measure the qubit before and after
qc.h(q[0]).c_if(c,0)
, so am i doing it right in my pyquil implementation or i need to change something there.
Here is my qiskit program
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
q = QuantumRegister(1,"q")
c = ClassicalRegister(1,"c")
qc = QuantumCircuit(q,c)
qc.h(q[0])
qc.measure(q,c)
qc.h(q[0]).c_if(c,0)
qc.measure(q[0],c)
qc.draw(output="mpl")
Here is my pyquil program
from pyquil.quilbase import Declare, MemoryReference
from pyquil import Program, get_qc
from pyquil.gates import *
p = Program()
p += H(0)
ro = p.declare('ro', 'BIT', 1)
p += MEASURE(0, ro[0])
# apply hadamard on qubit(0) if classical bit is 0 // qc.h(q[0]).c_if(c,0)
p += MEASURE(0, ro[0])
qc = get_qc('1q-qvm')
executable = qc.compile(p)
result = qc.run(executable)