# State Initialization of quantum circuit

I am trying to understand how to initialize a quantum circuit with classical input. By browsing on the internet, I came to the conclusion that there are some fixed circuits which can be used to initialize data to a quantum circuit, but could not understand the logic of creating them. I also could find a good practical example. There is one paper related to initialization but it is very difficult to understand for me - https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=1629135&casa_token=gBxw0KycKhIAAAAA:TTnN57HZI_jbB2XDjcIOoayRKrwwkPbUfpRROiU3_Dq9GMaZ8v0m4OQ_hs9DYdthPeQ_uCuTxQ

Also, tried one qiskit code as below:

from qiskit import QuantumCircuit, IBMQ
import numpy as np
num_qubits = 3
vector = [0.5,0.8660254,0.5,0.77432, 0.45, 0.6654,.5, .9987]
initial_state = vector/np.linalg.norm(vector)
circuit = QuantumCircuit(num_qubits,num_qubits)
circuit.initialize(initial_state, [0,1,2])
print(circuit)
circuit.decompose().decompose().decompose().decompose().decompose().draw('mpl') Not sure, how these values of vector are put into the quantum circuit and why the vector is normalized ? Please guide me to some link where I can understand this topic or explain me this topic with an example?

I would suggest that you try first with a simpler circuit to understand how the initialization is happening, so if we simplify your circuit first where we try to initialize a circuit with 1 qubit to $$|1\rangle$$  from qiskit import QuantumCircuit, IBMQ import numpy as np num_qubits = 1 vector=[0,1] initial_state = vector/np.linalg.norm(vector) print(initial_state) circuit = QuantumCircuit(num_qubits,num_qubits) circuit.initialize(initial_state, ) print(circuit) circuit.decompose().decompose().decompose().decompose().decompose().draw('mpl') This is basically doing 180 degrees rotation on the bloch sphere to go from $$|0\rangle$$ to $$|1\rangle$$. now if we change the initialized vector to different values, you will notice that that the resulting circuit basically does a rotation with a different angle each time to achieve the required initial state.

Now if we add 1 more qubit:

 from qiskit import QuantumCircuit, IBMQ import numpy as np num_qubits = 2 vector=[0.5,0.5,0.5,0.5] initial_state = vector/np.linalg.norm(vector) print(initial_state) circuit = QuantumCircuit(num_qubits,num_qubits) circuit.initialize(initial_state, [0,1]) print(circuit) circuit.decompose().decompose().decompose().decompose().decompose().draw('mpl') This circuit performs a series of rotations and cnots on the qubits to reach equal probabilities of achieving $$|00\rangle$$ , $$|01\rangle$$ , $$|10\rangle$$ and $$|11\rangle$$

The example you have is for 3 qubits but it is basically the same idea trying to reach the initial state using rotations and cnot gates.

Now if we go back to your questions. the initial vector you have in the example is not normalized  vector = [0.5,0.8660254,0.5,0.77432, 0.45, 0.6654,.5, .9987]  so first it is normalized using  initial_state = vector/np.linalg.norm(vector) 

The resulting initial state vector [0.25846679 0.44767761 0.25846679 0.40027201 0.23262011 0.3439676 0.25846679 0.51626157] means that the probability of having
$$|000\rangle$$ is (0.25846679)^2 and $$|001\rangle$$ is (0.44767761)^2 and so on until we reach $$|111\rangle$$.

I hope this clarifies your questions.

• Thank you @KMagdy for this kind help.
– Manu
Apr 13, 2022 at 2:43
• Hi @KMagdy. I tested your code by giving 4 values to a 2 qubit circuit and I am able to receive back the same data by measuring. I am highly thankful to you for this help. But I am still able to understand the analogy between number of rotation gates, their values, number of CNOT gates and Input vector.
– Manu
Apr 13, 2022 at 4:44
• I think you will then need to understand what the initialize function is doing , you can start by checking Initialize function , it mentions that the preparation is done on those 2 classes qiskit.extensions.StatePreparation , qiskit.extensions.Initialize Apr 15, 2022 at 7:35