Reproducibility and Seeds
Quantum measurement is intrinsically random — the Born rule gives probabilities, not outcomes — and on top of that, simulators sample those probabilities with a pseudo-random number generator. Two sources of nondeterminism (physical and computational) make raw runs irreproducible: run the same circuit twice and the histograms differ. For science and for debugging, that is unacceptable. The fix is seeding: fixing the PRNG so that "random" becomes deterministic and repeatable.
What is and is not random
It is worth separating the two kinds of variation:
- The distribution is exact. For a given circuit, the Born-rule probabilities are fully determined — there is nothing random about them. A state-vector simulator computes them analytically. This is why this platform's distribution grader compares exact probabilities, not sampled counts: the right answer is unambiguous.
- The samples are random. Drawing shots from that distribution is a random process. With shots a fifty-fifty outcome will not land on exactly 500/500; it fluctuates by — the shot noise that haunts every near-term experiment.
Seeding controls only the second kind. It cannot change the physics; it makes the sampling of the physics repeatable.
How a seed makes sampling deterministic
The simulator draws shots from a pseudo-random generator. A PRNG is a deterministic function of its seed: given the same seed it emits the same stream of numbers, so it produces the same sequence of sampled outcomes. Fix the seed and your histogram is bit-for-bit reproducible:
const c = circuit(2);
c.h(0);
c.measure();
// With shots = 1000 and seed = 42, the sampled counts are identical every run.
The grader for this lesson declares shots: 1000, seed: 42 precisely so the histogram you see is
the same one a teammate sees. Grading itself, however, still uses the exact probabilities — the
seed governs the display, not the verdict.
Reproducibility as an engineering contract
To reproduce a stochastic result exactly, four things must be pinned together:
- The circuit (from versioned generator code, last lesson).
- The shot count .
- The seed.
- The simulator / PRNG version — a different PRNG yields a different stream even from the same seed.
Record all four next to the result. With them, anyone can regenerate your histogram identically; without any one of them, "reproducible" quietly degrades to "statistically similar". This is the stochastic complement to the version-control discipline of the previous lesson: there we pinned the deterministic source; here we pin the randomness.
Seeds versus statistics
Seeding gives exact reproducibility but tests only one realisation of the randomness. To characterise an algorithm's typical behaviour — its variance, its tail outcomes — you instead run many shots, or many seeds, and report statistics with error bars. The two practices serve different goals: a fixed seed for reproducing and debugging a specific run, many seeds for estimating the distribution's spread. Mature quantum software uses both deliberately, and always states which it is doing.
Try it
Prepare the 2-qubit state with a single Hadamard on qubit 0, then measure all qubits. The grader checks the exact distribution (outcomes and each at probability ); the declared seed and shot count make the displayed histogram reproducible.
Sign in on the full site to ask questions and join the discussion.