Quantum demos

Eight small demos about how qubits work and what they mean for secret messages. Each part of the first seven takes a few minutes. Intercepts, the last, is a code-breaking game that takes longer.

The demos

A short guide

Quantum basics

Bits and qubits

A bit is 0 or 1. A qubit also has two basic states, written |0⟩ and |1⟩. The bar and the angle bracket only mark a qubit state, so |0⟩ reads as "the state 0". A qubit can also be in a mix of the two, called a superposition. Think of the qubit as an arrow in a ball, called the Bloch sphere: |0⟩ points up, |1⟩ points down, and every other direction is a superposition. Bloch sphere golf lets you move this arrow.

With two qubits, one label holds both: |01⟩ means the first qubit is 0 and the second is 1.

A qubit state is α|0⟩ + β|1⟩, where the amplitudes α and β are complex numbers with |α|² + |β|² = 1. Up to a global phase, each state is one point on the Bloch sphere. Bloch sphere golf shows that point as you apply gates.

Measurement

When you measure a qubit, you get 0 or 1, never a mix. The direction of the arrow sets the chance of each result. After the measurement, the qubit stays at the result you got. So one measurement cannot show you the whole arrow. The Measure button in Bloch sphere golf lets you see this.

A measurement asks the arrow one question: up or down? You can also turn the qubit first and so ask along a different line through the ball, such as left or right. Ask the same way twice and you get the same answer. Ask along a line at right angles to the arrow, and the result is a fair coin flip. A line in between gives an uneven coin. Either way, the arrow moves to match the result.

A measurement in the 0 and 1 basis gives 0 with probability |α|² and 1 with probability |β|². This is the Born rule. The state is then |0⟩ or |1⟩, to match the result.

Phase and interference

Two arrows can give the same chances and still point different ways around the middle of the ball. That difference is the phase. A measurement cannot see the phase, but a later gate can turn it into a difference in the chances. Parts of a state add up or cancel out, the way waves do. This is interference. Quantum algorithms use it to make right answers more likely and wrong answers less likely. The Hidden sign puzzle in the circuit puzzle is about a phase you cannot see in the chances. The bomb tester uses interference to find a bomb without setting it off.

|+⟩ = (|0⟩ + |1⟩) / √2 and |−⟩ = (|0⟩ − |1⟩) / √2 both give P(0) = ½. But H|+⟩ = |0⟩ and H|−⟩ = |1⟩: the relative phase decides the result. Amplitudes add as complex numbers, so they can cancel. The circuit puzzle shows each amplitude as a dial. The bomb tester shows what a measurement does to that cancellation.

Gates

A gate changes the state of one or more qubits. On one qubit, each gate turns the ball. H, the Hadamard gate, turns a sure 0 into a fair coin. X flips 0 and 1, and S and T spin the arrow around the middle. Each gate has a reverse gate that undoes it, so no gate loses information.

A gate is a unitary matrix U, so U†U = I and U† undoes U. Every one-qubit gate is a rotation of the Bloch sphere, up to a global phase. H and T together approximate any one-qubit gate, and with CNOT they make a universal set.

Entanglement

Two qubits can be linked, or entangled, so that their results are tied together even when the qubits are far apart. In a Bell pair, the simplest linked pair, each qubit by itself is a fair coin. When both are measured along the same line, as in these demos, their results always match. The link does not carry a message: each side sees only coin flips until the two sides compare their results. In the CHSH game, linked qubits win more rounds than any plan made ahead of time. The same page has a three-player game that linked qubits win every time. Teleportation uses a link to move a qubit’s state, and to send two bits on one qubit.

The Bell state (|00⟩ + |11⟩) / √2 is not a product of two one-qubit states. Its correlations break the CHSH inequality: the best quantum strategy wins cos²(π/8) ≈ 85.4% of rounds, and the best classical strategy wins 75%. By the no-signaling theorem, each side's results do not depend on the other side's choice of angle. The CHSH game lets you set the angles. That page also has the GHZ game, which a three-qubit state wins with certainty against a classical 75%. Teleportation and superdense coding show what an ebit buys when classical bits or a qubit also travel.

No copies

Nobody can make a copy of an unknown qubit, and reading a qubit along the wrong line changes it. Quantum key distribution uses this. A spy who reads the qubits on their way leaves errors, and the two sides find those errors when they compare a few bits. Eavesdropper lets you play the spy, and then attack a real laser that sends some photons in pairs. Last, it builds a key from linked pairs, which catch a spy with the CHSH game.

The no-cloning theorem: no unitary takes |ψ⟩|0⟩ to |ψ⟩|ψ⟩ for every |ψ⟩. In BB84, a spy who measures a fraction f of the qubits in random bases causes an error rate of f/4 in the kept bits. Eavesdropper runs 1,000 rounds to show it, then adds photon-number splitting and decoy states, and Ekert’s protocol, where a CHSH test on Bell pairs exposes the spy.

Noise and error correction

Qubits are fragile, and noise changes them at random. You cannot fix this with copies, and you cannot read a qubit to check it. Instead, one message is spread over many qubits, and checks ask only whether qubits match. Keep it alive lets you repair a message that you cannot see.

A code stores one logical qubit in many physical qubits. Its stabilizer measurements locate errors and reveal nothing about the logical state. The code helps only below a threshold error rate. Keep it alive runs the three-qubit repetition code, then the surface code that real machines use.

How the simulation works

The demos follow their qubits with exact math, one gate at a time, in your browser. When a demo measures, it picks each result with the chance that the math gives. One part of Keep it alive runs the surface code, a large grid of qubits that real machines use to fix errors. It has too many qubits for this exact math, so it follows only the errors.

A state on n qubits is a vector of 2n complex amplitudes, one for each basis state. A gate is a unitary matrix that acts on that vector. A measurement gives one basis state, with a probability equal to the squared magnitude of its amplitude (the Born rule).

The golf, circuit, bomb tester, teleportation, error correction, and CHSH demos apply each gate to the full state vector in plain JavaScript, with no external library, and sample measurements from the exact probabilities. Eavesdropper uses only the four BB84 states, so it applies the measurement rule for those states directly. Its photon-number splitting part samples photon counts from a Poisson distribution, and its Ekert part runs each pair as a two-qubit state vector. The surface code part of Keep it alive has too many qubits for a state vector, so it follows Pauli errors through the circuit. Part 2 of Intercepts runs its Grover search as a state vector, and samples its period finder from the exact distribution.

Use the switch at the bottom of the screen to read each page simply or with the math.