2
$\begingroup$

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') 

enter image description here 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?

$\endgroup$

1 Answer 1

2
$\begingroup$

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, [0]) print(circuit) circuit.decompose().decompose().decompose().decompose().decompose().draw('mpl') 1 Qubit

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')

2 Qubits

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.

$\endgroup$
3
  • $\begingroup$ Thank you @KMagdy for this kind help. $\endgroup$
    – Manu
    Commented Apr 13, 2022 at 2:43
  • $\begingroup$ 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. $\endgroup$
    – Manu
    Commented Apr 13, 2022 at 4:44
  • $\begingroup$ 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 $\endgroup$
    – kibrahim
    Commented Apr 15, 2022 at 7:35

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.