1
$\begingroup$

I tried to implement three qubit bit flip code in qiskit and need to get the result of measurements and then apply recovery quantum operations conditioned on the measurement results. The following is a simplified version to initialize a circuit:

q= QuantumRegister(3)
c= ClassicalRegister(3)
qc= QuantumCircuit(q, c)
qc.measure(q,c)

I noticed that this question had a similar question and they transformed the statement

if(c[0]==0) qc.x(q[0])

into

qc.x(q[0]).c_if(c[0], 0)

However, I want to have multiple quantum operations conditioned on the if statement

if c[0]==1 and c[1]==1:
    qc.x(q[0])
    qc.x(q[1])

can this work with "c_if"?

$\endgroup$
  • $\begingroup$ I wonder what these if's physically mean. IMO quantum computer consists of qubits, gates that can be applied to qubits, and measurements; there is no external logic to branch a program on a measurement outcome. You can branch a program on a measurement outcome using controlled gates such as CNOT and additional qubit(s); is this how if's are implemented? $\endgroup$ – kludg Jan 2 at 8:21
  • $\begingroup$ I agreed. The "c_if" statement seems like a programming language and to implement it physically need controlled gates. I think qiskit provides this logic for simplicity. $\endgroup$ – Jacey Li Jan 2 at 11:57
3
$\begingroup$

AFAIK, what you want can't be run on the hardware right now. See this github issue.

However, you can do this in the simulators. If, for example, c[0] and c[1] make up a two-bit classical register c, you can do this:

qc.x(q[0]).c_if(c,3)
qc.x(q[1]).c_if(c,3)
$\endgroup$
  • $\begingroup$ Thank you. Does "c_if(c,3)" mean that both two bits in classical register are equal to 3? Can bits in classical register equal differently, such as "if(c[0]==0 and c[1]==1)"? $\endgroup$ – Jacey Li Jan 2 at 11:35
  • 1
    $\begingroup$ The value of the classical register c is interpreted as a number in binary. Thus, c_if(c,3) means c[0]==1 and c[1]==1. If you want c[0]==0 and c[1]==1, the condition is c_if(c,2). $\endgroup$ – dlyongemallo Jan 2 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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