|q⟩ Bad Qubits

beginner · Programming · Mini-Projects: Coin Flips, RNG & Bell Tests

Project: A Simple Bell Test

The Bell test is one of the most striking experiments in physics: it shows that two entangled qubits cannot be described as two independent classical bits. In this project you will build the simplest entangled state — a Bell pair — and read off the correlation between the two qubits by sampling the measurement outcomes.

The Bell state Φ+|\Phi^+\rangle

Start both qubits in 00|00\rangle. Apply a Hadamard to the first qubit:

HI00=12(0+1)0=12(00+10).H \otimes I \,|00\rangle = \tfrac{1}{\sqrt{2}}\bigl(|0\rangle + |1\rangle\bigr) \otimes |0\rangle = \tfrac{1}{\sqrt{2}}\bigl(|00\rangle + |10\rangle\bigr).

Now apply a CNOT with qubit 0 as the control and qubit 1 as the target. The CNOT flips the target whenever the control is 1|1\rangle:

CNOT12(00+10)=12(00+11)=Φ+.\text{CNOT}\,\tfrac{1}{\sqrt{2}}\bigl(|00\rangle + |10\rangle\bigr) = \tfrac{1}{\sqrt{2}}\bigl(|00\rangle + |11\rangle\bigr) = |\Phi^+\rangle.

This is one of the four Bell states, the maximally entangled two-qubit states. It cannot be factored as a product of two single-qubit states — that is the definition of entanglement.

What sampling reveals

Measuring both qubits in the computational basis collapses the state to either 00|00\rangle or 11|11\rangle, each with probability 12\tfrac{1}{2} (by the Born rule applied to the amplitudes 12\tfrac{1}{\sqrt{2}}). The outcomes 01|01\rangle and 10|10\rangle never appear. This perfect correlation — the two bits always agree — is the signature of entanglement and is what a real Bell test verifies.

Estimating the correlation

In practice a Bell test works by running the circuit many times (many shots), recording the pairs of outcomes, and computing a correlation coefficient. For Φ+|\Phi^+\rangle measured in the ZZ-basis, every shot gives matching bits, so the correlation between qubit 0 and qubit 1 is +1+1. The simulator gives you the exact probabilities, which correspond to the infinite-shot limit.

Try it

Build the circuit that prepares Φ+|\Phi^+\rangle and measures both qubits. Look at the Probabilities tab: you should see exactly two equal bars for outcomes 00 and 11, and nothing for 01 or 10.

Run your code to see the quantum state.

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