Suppose we have a 4-qubit quantum state state which is a Statevector object:

>>> type(state)

I would like to initialize a 6-qubit QuantumCircuit, such that registers 0, 1, 3, 4 are initialized in state, something like this:

qc = QuantumCircuit(6)
qc.initialize(state, [0, 1, 3, 4])

Now, the initialize method takes a list of complex amplitudes as an input. However, is there a way to feed it state directly, without converting it into a list?


1 Answer 1


You can do this with QuantumCircuit.prepare_state or QuantumCircuit.initialize.

I'll show a simple example.

from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector

state = Statevector.from_label("+-rl")
qc = QuantumCircuit(4)
qc.prepare_state(state, [0, 1, 2, 3])

Here I've constructed my Statevector object using Statevector.from_label but you should be able to construct it however you like and plug it into QuantumCircuit.prepare_state.

QuantumCircuit.initialize resets all qubits to the $|0\rangle$ state before state preparation.

QuantumCircuit.prepare_state does not add resets.

  • $\begingroup$ It looks like we can use state directly, whether it is prepare_state or initialize, but why does it matter if initialize resets all states to $|0 \rangle$ before preparation? $\endgroup$
    – Bard
    Oct 20, 2023 at 17:11
  • $\begingroup$ Yes, indeed you can do it with qiskit.initialize. Adding resets to reset each qubit to the $|0\rangle$ state is in general a non-unitary operation. This is what QuantumCircuit.initialize does. If you use QuantumCircuit.prepare_state the entire circuit is unitary. $\endgroup$
    – Callum
    Oct 20, 2023 at 21:48
  • $\begingroup$ I'm not quite clear on what you're asking. You can pass a Statevector object directly into QuantumCircuit.initialize. You don't have to pass a list of amplitudes. $\endgroup$
    – Callum
    Oct 20, 2023 at 21:57

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.