# Applying conditional X-gate in Qiskit

I have problem with implementation of the circuit below. How can I write down the conditional X-gate in the following circuit? This can be done in qiskit with c_if operation.

To construct the circuit that you are interested in in OPENQASM, you can do it as follow:

OPENQASM 2.0;
include "qelib1.inc";

qreg q;
creg cw;
creg cw2;

z q;
h q;
h q;
h q;
z q;
barrier q,q;
measure q -> cw;
barrier q,q;
if (cw==1) x q;
barrier q,q;
measure q -> cw2;


The result circuit is: Also look at this question and answer: Composing teleportation circuit in Qiskit Circuit Composer

Update: You can also run this with Qiskit as:

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from numpy import pi

qreg_q = QuantumRegister(2, 'q')
creg_cw = ClassicalRegister(1, 'cw')
creg_cw2 = ClassicalRegister(1, 'cw2')
circuit = QuantumCircuit(qreg_q, creg_cw, creg_cw2)

circuit.z(qreg_q)
circuit.h(qreg_q)
circuit.h(qreg_q)
circuit.h(qreg_q)
circuit.z(qreg_q)
circuit.barrier(qreg_q, qreg_q)
circuit.measure(qreg_q, creg_cw)
circuit.barrier(qreg_q, qreg_q)
circuit.x(qreg_q).c_if(creg_cw, 1)
circuit.barrier(qreg_q, qreg_q)
circuit.measure(qreg_q, creg_cw2)

circuit.draw('mpl', style={'name': 'iqx'})


It should be noted that if you compose your circuit in OPENQASM, there is an option that would allow you to convert it to Qiskit code. Look for this tab in circuit composer: • Can you provide the equivalent quantum composer code? Thank you Nov 4 '20 at 19:02