# Get result measurement into a circuit with Qiskit

I'm trying to implement the three qubit bit flip code in Qiskit. Therefore, I need to get the result of a measure of two ancilla qubits, to deduce which gate I need to use do recover my logical qubit. I know how to get the result of a measure, at the end of a circuit with :

backend_sim = Aer.get_backend('qasm_simulator')
job_sim = execute(qc, backend_sim, shots=1000)
result_sim = job_sim.result()
counts = result_sim.get_counts(qc)
plot_histogram(counts)


But, I don't know how to get the result of a measure into the circuit. Sorry if my question is stupid, I'm a beginner on Qiskit.

• If I understand you correctly, you probably want something like this. These gates apply their usual actions if the value in the classical register is a certain value. NOTE: I think they only work in simulators though. Commented Jun 14, 2019 at 18:47
• This circuit before the measurements simplifies a lot. You should do that first. Commented Jun 14, 2019 at 22:13
• Thanks for the answer ! @MatthewStypulkoski I will try this. I think this will work. But do you know, why we can do these only with simulators ? Commented Jun 15, 2019 at 9:43
• @AHusain why do you mean by "You should do that first" ? Commented Jun 15, 2019 at 9:45

In Circuit Composer, you can use an if statement as shown below The circuit measures qubit 1 after a gate operation and, if it is 0, then applies an X gate to qubit 2:

OPENQASM 2.0;
include "qelib1.inc";

qreg q[3];
creg c[3];

x q[0];
measure q[0] -> c[0];
if(c==0) x q[1]; # here where you can set it to trigger on c == 1
measure q[1] -> c[1];


This Circuit yields a 1 for q[0] and a 0 for qubit 1 , because the X gate isn't applied due to the conditional. Hope this helps!

Edit: For syntax in qiskit, please look at the code below:

qc = QuantumCircuit(q, c)
qc.h(q)
qc.measure(q,c)
qc.x(q[0]).c_if(c, 0)
qc.measure(q,c)
qc.draw(output='mpl')


It appears that you should use .c_if at the end of a certain operation to use conditionals.

• Firstly thanks for answering my question. This work with Openqasm, but with Qiskit I try after measuring meas.measure(q[3],c[0]) to use the variable c[0], and it returns me the variable ClassicalRegister(2, 'c'). I didn't found any information about the value of the classical register in this variable. Commented Jun 15, 2019 at 9:15
• @lufydad For the syntax with using qiskit, please look at the "conditional operations" section here Commented Jun 15, 2019 at 17:46