|q⟩ Bad Qubits

beginner · Physics · Math Foundations: Calculus, Probability & Statistics

Sampling Error

Every quantum experiment involves finite statistics: you run a circuit nn times (called shots or runs), count how many times a particular outcome appears, and report that count divided by nn as your estimated probability. Understanding how much to trust that estimate is the subject of sampling error.

The estimated probability and why it fluctuates

Suppose the true, underlying probability of outcome "1" is pp (unknown). Each shot is an independent Bernoulli trial that returns 1 with probability pp and 0 with probability 1p1 - p.

If you observe kk ones in nn shots, the natural estimate is

p^=kn.\hat{p} = \frac{k}{n}.

Because kk is a random variable, p^\hat{p} is also random — it will differ slightly each time you repeat the nn-shot experiment. The count kk follows a binomial distribution with parameters nn and pp:

E[k]=np,Var(k)=np(1p).\operatorname{E}[k] = np, \qquad \operatorname{Var}(k) = np(1-p).

Dividing by nn to form p^=k/n\hat{p} = k/n simply scales both the mean and the variance:

E[p^]=p,Var(p^)=p(1p)n.\operatorname{E}[\hat{p}] = p, \qquad \operatorname{Var}(\hat{p}) = \frac{p(1-p)}{n}.

The first line says p^\hat{p} is an unbiased estimator of pp: on average it gets the right answer. The second line says the spread around pp shrinks as nn grows — exactly the law of large numbers in action.

Standard error: the key formula

The standard error (SE) of p^\hat{p} is the standard deviation of the sampling distribution:

σp^=p(1p)n.\sigma_{\hat{p}} = \sqrt{\frac{p(1-p)}{n}}.

In practice pp itself is unknown, so we substitute the estimate p^\hat{p}:

σ^p^=p^(1p^)n.\widehat{\sigma}_{\hat{p}} = \sqrt{\frac{\hat{p}(1-\hat{p})}{n}}.

This is the number you quote when someone asks "how precisely do you know your probability?"

How the formula behaves

Two features are worth internalising:

Scaling with shots. The SE shrinks as 1/n1/\sqrt{n}. Halving the error requires four times as many shots; cutting it by ten requires one hundred times as many. This square-root growth is a fundamental statistical fact and places a practical limit on how quickly you can pin down a quantum probability.

Maximum at p=1/2p = 1/2. The numerator p(1p)p(1-p) is a downward-opening parabola maximised at p=1/2p = 1/2, where it equals 1/41/4. At that point

σp^=12n.\sigma_{\hat{p}} = \frac{1}{2\sqrt{n}}.

So a balanced coin-flip outcome is the hardest to pin down; extreme probabilities near 0 or 1 have smaller sampling error because nearly every shot gives the same result.

A worked example

You run a quantum circuit n=100n = 100 times and record k=40k = 40 "one" outcomes. The estimated probability is p^=40/100=0.40\hat{p} = 40/100 = 0.40. The estimated standard error is

= \sqrt{0.0024} \approx 0.049.$$ You would report $p \approx 0.40 \pm 0.05$ — a roughly 5 % uncertainty. To reduce that to 1 % you would need approximately $0.24 / (0.01)^2 = 2400$ shots. ## Why this matters in quantum computing Quantum computers are inherently probabilistic: most algorithms — Shor's, Grover's, variational algorithms — produce outputs that must be **sampled** from a probability distribution. The precision of any experimentally measured quantity (an expectation value, a probability, an energy estimate) is limited by the number of circuit evaluations. Understanding sampling error lets you budget your shot count before running expensive experiments on real hardware. <Callout type="tip"> A quick sanity check: the standard error must lie in the range $[0, 0.5/\sqrt{n}]$. If your calculation produces a number outside this range, check whether you divided by $n$ inside the square root, not outside it. </Callout> ## Try it This is a numerical exercise — your code should `return` a number, not a circuit. You observe $k = 40$ successes in $n = 100$ shots. Return the standard error $\widehat{\sigma}_{\hat{p}} = \sqrt{\hat{p}(1-\hat{p})/n}$. <RunnableExample />

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