|q⟩ Bad Qubits

beginner · Programming · Measurement & Probability in Code

Estimating Probabilities Accurately

Every quantum measurement yields a single classical outcome — you never directly observe a probability. Instead, you run the same circuit many times (called shots) and count how often each outcome appears. The fraction of runs that produced outcome bb is your estimate p^b\hat{p}_b of the true probability pb=bψ2p_b = |\langle b|\psi\rangle|^2 given by the Born rule.

From counts to error bars

Because each shot is an independent draw from a Bernoulli distribution with parameter pp, the standard error of the proportion estimator over NN shots is

SE=p(1p)N.\mathrm{SE} = \sqrt{\frac{p(1-p)}{N}}.

This is the typical deviation you expect between your estimate p^\hat{p} and the true value pp. The worst case is p=0.5p = 0.5 (maximum uncertainty), where

SEmax=12N.\mathrm{SE}_{\max} = \frac{1}{2\sqrt{N}}.

To cut the error in half you need four times as many shots: precision scales as 1/N1/\sqrt{N}. This square-root law governs any sampling experiment, classical or quantum.

Practical consequences

When you run a quantum circuit on real hardware or a simulator, the number of shots sets a hard floor on how precisely you can know any output probability. For a lesson's grader based on analytic probabilities (exact formulas), this limitation disappears — but for real devices it is unavoidable. As a rule of thumb, choose NN large enough that SE\mathrm{SE} \ll the smallest probability difference you need to resolve.

Try it

Solve for the minimum number of shots NN that guarantees SE0.01\mathrm{SE} \leq 0.01 for any 50/50 distribution, then return that integer.

Run your code to see the quantum state.

Sign in on the full site to ask questions and join the discussion.