# Set the initial state of the QuantumCircuit using the Statevector object

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

>>> type(state)
qiskit.quantum_info.states.statevector.Statevector


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?

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.

• 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?
– Bard
Oct 20 at 17:11
• 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. Oct 20 at 21:48
• 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. Oct 20 at 21:57