Project: A Random-Circuit Sampler
A random-circuit sampler is a program that generates a circuit whose gate sequence is chosen (pseudo-)randomly and then measures all qubits to collect an output probability distribution. Sampling from random circuits sits at the heart of Google's 2019 quantum supremacy experiment and is the basis for the quantum volume benchmark used to compare processors.
Why random circuits matter
For an ideal quantum computer, a depth- random circuit over qubits generates a distribution over the bitstrings that converges toward the Porter-Thomas distribution — the distribution you would expect if you chose a Haar-random unitary and measured it. The key property is that the output probabilities are highly non-uniform: a few bitstrings receive much more weight than the uniform baseline, and many receive less. A classical simulator cannot reproduce this pattern efficiently for large and , which is the core claim behind quantum advantage.
More concretely, if is the probability of bitstring under an ideal random circuit, then the average collision probability satisfies
which exceeds the uniform value by a factor of roughly . This "anti-concentration" threshold is a signature that the circuit has reached sufficient depth.
Anatomy of a random circuit
A typical random circuit layer looks like this:
- Single-qubit gates — choose a random gate from a fixed set (for example ) for each qubit. These spread amplitude across basis states.
- Two-qubit entangling gates — apply CX or CZ between randomly chosen pairs. These create correlations between qubits that a product-state simulator cannot capture.
- Measurement — read out all qubits to obtain a bitstring sample.
Repeating steps 1-2 for layers before measuring gives a circuit of depth . For the distribution to anti-concentrate, only needs to grow like , which is surprisingly shallow.
A minimal example: 3 qubits
Consider a simple 3-qubit circuit:
Starting from :
After (qubit 0 is most significant), the controlled-NOT entangles qubits 0 and 1 by permuting the basis states — every amplitude keeps its original magnitude, so the marginal probabilities remain equal. The gate on qubit 2 multiplies the amplitude of every state with qubit 2 in by , creating a relative phase between the and components, but again without changing any . Both operations therefore leave the measurement probability of each of the 8 bitstrings equal at . The entanglement and phase are nonetheless physically significant: the phase is detectable via interference in a more complex circuit, and the entanglement means the joint state of qubits 0 and 1 cannot be written as a product state. Real random-circuit samplers use many alternating layers of single-qubit gates and entangling gates precisely so that the interference effects accumulate over depth and eventually break uniformity toward the Porter-Thomas distribution.
Analyzing the output
Once you have a distribution , useful statistics include:
- Heavy outputs — bitstrings with above the median. A high heavy-output probability indicates the device is operating close to ideal.
- Linear XEB fidelity — defined as , where the expectation is over sampled bitstrings weighted by the ideal probability. For a noiseless device ; for a fully depolarised device .
- Collision probability — can be estimated from samples and compared to the uniform baseline .
Try it
Build the 3-qubit circuit described above: Hadamard every qubit, entangle with a CNOT, add a phase with , then measure. The grader checks the output probability distribution against the reference solution.
After running, inspect the histogram. The 8 bitstrings will all appear with equal height (probability each) — because the CX and S operations in this shallow, single-layer circuit preserve the uniform probability distribution created by . The entanglement and relative phase are still physically present in the amplitudes; they would produce interference (and non-uniform probabilities) if additional gate layers were added. This is precisely why real random-circuit samplers require many alternating layers: depth is needed for the circuit to reach the non-uniform Porter-Thomas regime that random-circuit sampling benchmarks test.
Sign in on the full site to ask questions and join the discussion.