2
$\begingroup$

If I want to condition adding a gate to a circuit in qiskit, I understand how to use c_if() to condition on one classical register, but is there a way to condition it on the measurement of two or more classical registers? Say I have

q = QuantumRegister(5)
c1 = ClassicalRegister(1)
c2 = ClassicalRegister(1)

qc = QuantumCircuit(q,c1)
qc.add_register(c2)

So there are two classical registers and 5 qubits. Then say

circuit.measure(q[1],c1)
circuit.measure(q[3],c2)

Is there a way for me to do something like qc.x(q[4]).c_if((c1,1) AND (c2,3))?

$\endgroup$

1 Answer 1

1
$\begingroup$

First of all, c_if is the old way for applying an operation conditioning on the value of a classical register. Instead, you should use if_test[1] which is much more flexible.

Logical operators such as and &&, or ||, not ! are part of OpenQASM 3.0 standard[2]. And according to the feature support table[3], they are already supported in IBM Quantum hardware. However, they are not supported in Qiskit yet.

In your case, you can't use AND operator in Qiskit but you can nest two if_test operations as follows:

with circuit.if_test((c1,1)):
    with circuit.if_test((c2,3)):
        circ.x(4)
$\endgroup$

Your Answer

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

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