# 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. – Matthew Stypulkoski Jun 14 at 18:47
• This circuit before the measurements simplifies a lot. You should do that first. – AHusain Jun 14 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 ? – lufydad Jun 15 at 9:43
• @AHusain why do you mean by "You should do that first" ? – lufydad Jun 15 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;
creg c;

x q;
measure q -> c;
if(c==0) x q; # here where you can set it to trigger on c == 1
measure q -> c; This Circuit yields a 1 for q 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).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,c) to use the variable c, 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. – lufydad Jun 15 at 9:15
• @lufydad For the syntax with using qiskit, please look at the "conditional operations" section here – John Garmon Jun 15 at 17:46