I'm using qiskit for simulation. Suppose, I have 6 qubits with indices [0, 1, 2, 3, 4, 5] and I have an operator $U$ of size $4 \times 4$, such that it operates on 2 qubits.

How can we use qiskit to create a multi-control-multi-target gate such that, for example, the control qubit index is [1] and target qubit indices are [3, 4]? Or control indices are [0, 1] and target indices are [3, 4] or any other variation.


1 Answer 1


We can create a quantum gate from any unitary operator $U$ using UnitaryGate class. And we can add any number of controls to any gate using control() method.

As an example, let's create a $4 \times 4$ unitary:

from qiskit.quantum_info import random_unitary

U = random_unitary(4)

Now, let's apply this operator to qubits $3$ and $4$ controlled by qubits $0$ and $1$.

from qiskit.circuit import QuantumCircuit
from qiskit.circuit.library import UnitaryGate

circ = QuantumCircuit(6)
circ.append(UnitaryGate(U).control(2), [0, 1, 3, 4])

The result:

enter image description here


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.