1
$\begingroup$

I am implementing classical control of gates multiple times. There is no issue if the gate is a local gate, such as an $X$ gate. However, it seems that if I append the control multi-qubits gates more than once, the control classical registers will all become the latest one, as shown in the circuit diagram below. Although I append the first gate with c_if(0, 1), after append c_if(1, 1), the control classical register of the first gate changed from c_0 to c_1. May I ask how to solve this issue?

qc = QuantumCircuit(3, 6)
gate = UnitaryGate(identity_matrix)

qc.append(gate, [0, 1, 2]).c_if(0, 1)
qc.append(gate, [0, 1, 2]).c_if(1, 1)

Implementation of classical control of multi-qubit gates

$\endgroup$

1 Answer 1

1
$\begingroup$

It looks like a bug. You can report it here.

You can avoid this issue by using IfElseOp which is a more flexible replacement for c_if.

with qc.if_test((0, 1)):
    qc.append(gate, [0, 1, 2])

with qc.if_test((1, 1)):
    qc.append(gate, [0, 1, 2])

enter image description here

$\endgroup$
2
  • $\begingroup$ Thank you for your answer! It has been very helpful. However, may I ask how you change the appearance of your control gates? It looks much nicer than the default appearance in qiskit. Thank you! $\endgroup$
    – JiQing
    Jan 17 at 17:23
  • 1
    $\begingroup$ I'm using qc.draw('mpl', style='textbook') to draw a circuit $\endgroup$ Jan 18 at 5:30

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.