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)

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.

enter image description here

  • $\begingroup$ 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. $\endgroup$ Jun 14, 2019 at 18:47
  • $\begingroup$ This circuit before the measurements simplifies a lot. You should do that first. $\endgroup$
    – AHusain
    Jun 14, 2019 at 22:13
  • $\begingroup$ 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 ? $\endgroup$
    – lufydad
    Jun 15, 2019 at 9:43
  • $\begingroup$ @AHusain why do you mean by "You should do that first" ? $\endgroup$
    – lufydad
    Jun 15, 2019 at 9:45

1 Answer 1


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:

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];

enter image description here

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.x(q[0]).c_if(c, 0)

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

  • $\begingroup$ 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. $\endgroup$
    – lufydad
    Jun 15, 2019 at 9:15
  • $\begingroup$ @lufydad For the syntax with using qiskit, please look at the "conditional operations" section here $\endgroup$ Jun 15, 2019 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.