I know it's possible to create custom controlled gates from a circuit, for example,

qc_gate = QuantumCircuit(2)

gate = qc_gate.to_gate().control(2)

However, since initialization is not considered a gate operation, one cannot do

qc_gate = QuantumCircuit(2)

gate = qc_gate.to_gate().control(2)

but instead, one can do

qc_gate = QuantumCircuit(2)

gate = qc_gate.to_instruction()

This, however, does not allow for control qubits. Is there any way to get around this, to create a quantum instruction that is applied in terms of a set of control qubits?


2 Answers 2


You can use QuantumCircuit.isometry instead of QuantumCircuit.initialize for state preparation. Like Initialize, Isometry is not a gate so you can't call control() method. But it doesn't use resets internally. So you can use it as follows:

state = [0.5, 0.5, 0.5, 0.5]

qc_iso = QuantumCircuit(2)
qc_iso.isometry(state, [0, 1], [])
controlled_gate = UnitaryGate(Operator(qc_iso)).control()


Qiskit 0.35 introduced a new class StatePreparation. This class allows us to prepare a state in the same fashion as Initialize without the reset being automatically applied. So, creating a controlled initialization is now as simple as:

controlled_gate = StatePreparation(state).control()

As far as I know, you cannot do that, but depending on what you want to do, there is a way around.

Using the $\texttt{transpile}$ function, you can turn an instruction in the beginning of your circuit into a unitary. Here's an example:

>>> qc_gate = QuantumCircuit(2)
>>> qc_gate.initialize([0,1,0,0])
>>> qc=transpile(qc_gate,basis_gates=["u1","u2","u3","cx"],optimization_level=1)
>>> print(qc_gate)
q_0: ┤0                     ├
     │  Initialize(0,1,0,0) │
q_1: ┤1                     ├
>>> print(qc)
q_0: ┤ U2(0,0) ├┤ X ├┤ U2(0,0) ├┤ X ├
q_1: ─────────────■───────────────■──

and you can then use $\texttt{qc.to_instruction().control(2)}$


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.