# I am having problem in executing measurement based quantum computing circuit This is the circuit I want to implement. But I am unable to do this. basically How I can tell qiskit that "if the qubit is in |+> state then operate H gate on qubit 2 or if the qubit is in|-> state then apply ZH gate in the qubit 2

• Hi there, its generally preferred if questions are presented using LaTex/MathJax formatting rather than attaching photos. Jul 5 at 16:21

The c_if instruction can be used to make the result of a measurement saved to a classical register adjust whether a gate is or is not performed. Note that, since you do a Hadamard gate first in either scenario, the real dependence on measurement result is whether you also do a $$Z$$.

from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, Aer
from qiskit.quantum_info import random_statevector
from qiskit.visualization import plot_bloch_multivector
from qiskit.extensions import Initialize
instate = random_statevector(2)
qr = QuantumRegister(2)
cr = ClassicalRegister(1)
qc = QuantumCircuit(qr, cr)
qc.append(Initialize(instate), )
qc.h(1)
qc.cz(0, 1)
qc.h(0)
qc.measure(0, 0)
qc.h(0)
qc.h(1)
qc.z(1).c_if(cr, 1)


If you run this circuit, plot, and compare the second qubit's Bloch Sphere to the original random input, you will find them the same, as in this case below, where the measurement resulted in $$|-\rangle$$ and therefore applied the $$Z$$:

plot_bloch_multivector(instate) sim = Aer.get_backend('aer_simulator')
qc.save_statevector()
out_vector = sim.run(qc).result().get_statevector()
plot_bloch_multivector(out_vector) 