# How to separate initializing qubits from runing algorithm several times

I have read several papers about quantum computing. It looks like any algorithm consists of several phases. For example in Grover algorithm initially qubits must be initialized from reset state $$|0\rangle$$ and sent through Hadamard gate. After that computer must do several runs (shots?) via oracle and amplifier.

Question: schemas of Grover algorithm contain single diagram schema from left to right.How does a quantum computer knows where is initialization phase and where is oracle with amplifier? I mean if I run multiple times same schema then it starts from schema most left gates from initialization phase which I guess must be skipped during oracle-amplifier repetitions?

I guess initialization must be executed once only and after that repeat runs/shots as many times as needed, is this correct or not? How to declare this in schema? Or how to separate initialization phase from repetitive steps in Qiskit language? I looked at many Qiskit programs and do not see any algorithm separator from init steps to algorithm steps.

What did I miss? Are my assumptions incorrect?

When you consider a quantum circuit, it is often (if not always) assumed that the circuit starts in the state where all the qubits are in state $$|0\rangle$$. The "initialization part" is simply the first gates you apply in an algorithm, it does not play any particular role.

In Qiskit, using the initialize function simply adds gates that will create the desired state starting from the all-$$|0\rangle$$ state. So if you're running multiple shots of the algorithm, the workflow goes as follow:

1. Set the starting state to the all-$$|0\rangle$$ state

2. a. Apply the initialization gates

b. Apply the remaining of the algorithm

3. Measure and retrieve the result

4. Repeat

Note that you always reset to state to $$|0\rangle$$ before another shot, which is why the "initialization part" is just yet another part of the algorithm. You cannot execute the initialization step once and for all for all your shots, since you modify the state of your qubits when running your algorithms, which is why you have to redo it every time: in order to have a clean state to run the algorithm on.

• Sorry, I still do not understand. Or maybe I am wrong with terminology calling "shot" something which is not a really "shot" but part of algorithm circle. Can You please look at picture Grover algorithm. This picture I found in one article explaining Grover algorithm. This picture shows "repeate 3 times" oracle+amplifier. How to do that in quantum computer? Should I draw schema 3 times? Or what? I need a cicle here. What if algorithm is even more complex and I need repeate 1000 times?
– nckm
Oct 18, 2021 at 10:11
• @nckm In the Qiskit's terminology, a "shot" is simply an execution of the algorithm. Running 1024 shots is going through the workflow I've described 1024 times, noting down the result you got each time. Is there something else that you don't understand? Oct 18, 2021 at 10:43
• @nckm Oh ok! I was misunderstanding what you meant. This is just an artifact to help drawing the circuit. The way to do that on a quantum computer is simply to repeat the gates. If you want to get the final circuit, you simply have to unroll the repetition step by concatenating the Oracle+Amplifier gates to itself as many times as required. Oct 18, 2021 at 10:54
• Thanks for explaining this. But to be honest this is not what I expected to hear. My understanding is that gates are very expensive parts. I have FPGA development experience and in FPGA world logic elements in chip are also very expensive, but logic can have loopbacks, so cycles can be implemented. Unrolling circuit cycle in quantum computing probably should be very-very expensive. Seem in real world that way circuits would require thousands gates and thousands cycles.
– nckm
Oct 18, 2021 at 11:09
• @nckm You're right about that! This is why there is some research trying to determine what it the circuit depth of some algorithms (see here for instance: quantumcomputing.stackexchange.com/questions/21518/…). On the particular case of computing the power of a gate (which is the case here), there may be some optimization (for instance in Shor's) but there is none in general (see here: quantumcomputing.stackexchange.com/questions/11414/…) Oct 18, 2021 at 11:20