# How can you extract all the state probabilities in e.g. Grover's search?

In the Qiskit tutorial for e.g. Grover's algortihm, there is a 3-qubit implementation on a real quantum computer https://qiskit.org/textbook/ch-algorithms/grover.html#3.1.2-Experiment-with-Real-Devices--

Since we have 3 qubits, there are 2^3=8 states. How does a practical implementation of the search come about to reconstruct all the probabilities for the 8 states when there are only 3 qubits to measure on? What is the cost of doing this, and how is it implemented for a much larger qubit case (say 50, where we have 2^50 states where we can encode information onto)?

Welcome to QCSE!

Indeed, as you mentioned - A closed qunatum system of $$3$$ qubits has a state space spanned by $$2^3 = 8$$ computational basis states. During the computation the quantum statevector of the system can be in many linear combinations of these states. However, upon measurement in the computational basis - The statevector of the system collapses into one of the basis states and we get only one result - which has to be one of the computational basis states.

The graph posted above is showing the distribution of the results being measured. For example, if the program ran for $$1000$$ "shots" so the results above implies that $$000$$ has been measured $$245$$ times, $$001$$ has been measured $$111$$ times, $$010$$ has been measured $$63$$ times, and so on..

The default "shots" value in qiskit is $$1024$$, so I guess what we see is the distribution of the $$1024$$ results being measured. You can set any desired amount of shots using the backend.run(qc, shots = XX) or execute(qc, shots = XX) commands.

I would like to emphasize that quantum programs don't "reconstruct probabilities" - All we can do is maniuplating the statevector of the system throughout the computation and get a single result for each run ("shot") upon measurement.

Having said that, when using classical simulators only, we can keep track on the statevector of the system - which can be seen as a list of probability amplitudes for each computational basis state. The probability to measure each basis state is the magnitude squared of its probability amplitude. For example let $$|\psi\rangle = \alpha_{00}|00\rangle + \alpha_{01}|01\rangle + \alpha_{10}|10\rangle + \alpha_{11}|11\rangle$$ be the statevector of the system at a given instant. Then the probability to measure $$|00\rangle$$ is $$|\alpha_{00}|^2$$, the probability to measure $$|01\rangle$$ is $$|\alpha_{01}|^2$$, and so on. That's the closest thing to "extract state probabailites" being asked upon in the title - and again, it's not possible in a real quantum computer because the only information we can extract from a quantum system is a result of a measurement.

Indeed, for a system with $$50$$ qubits the state space is spanned by $$2^{50}$$ computational basis states - but it works exactly the same as in the case of $$3$$ qubits being explained above.

• So clear, thanks! I forgot that we get either 0 or 1 in all 3 states when we measure each, and the histogram is simply a recording of these ordered events. Commented Aug 26, 2022 at 13:37
• You mean in all 3 qubits, not states.