cs.thefarshad
hard

Quantum Error Correction

Decoherence threatens every qubit — the 3-qubit bit-flip code shows how redundancy and syndrome measurement fight back.

Real qubits are fragile. Stray fields, heat, and unwanted interactions cause decoherence and noise, randomly disturbing the delicate amplitudes. Worse, the obvious classical fix — “just copy the bit three times and take a majority vote” — is blocked by the no-cloning theorem and by the fact that measuring a qubit destroys its superposition. Quantum error correction has to detect and repair errors without ever reading α\alpha or β\beta.

The 3-qubit bit-flip code is the simplest example. Step through it below: encode one logical qubit into three, let noise flip one of them, measure the syndrome to locate the flip, and apply a correction.

bit flip on:
qubit 0
ok
qubit 1
ok
qubit 2
ok
syndrome:s₀₁ (q0⊕q1) = s₁₂ (q1⊕q2) =
logical state: 0.819|0⟩ + 0.574|1⟩ → encoded as 0.819|000⟩ + 0.574|111⟩

Encode: α|0⟩ + β|1⟩ → α|000⟩ + β|111⟩ using two CNOTs. The three qubits now agree.

Encoding

We spread one logical qubit across three physical qubits using two CNOTs:

α0+β1    α000+β111\alpha|0\rangle + \beta|1\rangle \;\longrightarrow\; \alpha|000\rangle + \beta|111\rangle

This is not cloning — there is still only one quantum state, now entangled across three qubits. The amplitudes α,β\alpha, \beta are never duplicated; only the classical pattern (all-zeros vs. all-ones) is made redundant.

Detecting the error

Suppose noise flips qubit 11, turning the state into α010+β101\alpha|010\rangle + \beta|101\rangle. We must find the culprit without learning α\alpha or β\beta. The trick is to measure parities rather than the qubits themselves:

  • s01s_{01} = parity of qubits 00 and 11 (do they match?)
  • s12s_{12} = parity of qubits 11 and 22

These two bits form the syndrome. They reveal whether neighbors disagree, but reveal nothing about the encoded amplitudes — so the superposition survives the measurement. The mapping is unambiguous:

s01s_{01}s12s_{12}flipped qubit
00none
10qubit 0
11qubit 1
01qubit 2

Correcting it

Once the syndrome names the offending qubit, applying an XX gate flips it back, restoring α000+β111\alpha|000\rangle + \beta|111\rangle and therefore the logical state. The correction is itself a quantum operation, so the protected superposition is recovered exactly — no information was lost. Try the none option in the visualizer to confirm that a clean round produces syndrome 0000 and leaves the state untouched.

Limits and the bigger picture

This code only fixes a single bit flip; two simultaneous flips would fool the majority and produce a logical error. It also does nothing about phase flips (the ZZ-type error). The famous 9-qubit Shor code stacks a bit-flip code and a phase-flip code to correct any single-qubit error, and modern surface codes extend the idea to large 2D lattices. The strategy is always the same: redundancy plus syndrome measurements that diagnose errors without disturbing the data — the foundation of fault-tolerant quantum computing.

The Shor code (9 qubits)

The 3-qubit code above fixes a bit flip (XX) but is blind to a phase flip (ZZ). The fix for phase flips is elegant: a phase flip in the standard basis is a bit flip in the Hadamard basis. So the phase-flip code is just the bit-flip code conjugated by Hadamards — encode with HH on every qubit, and a ZZ error becomes an XX error that the same parity machinery catches:

Z=HXHZ = H X H

Peter Shor’s 9-qubit code concatenates the two: it nests a bit-flip code inside a phase-flip code, encoding one logical qubit into 99 physical qubits arranged as 3 blocks of 3.

0L=122(000+111)3,1L=122(000111)3|0\rangle_L = \tfrac{1}{2\sqrt2}\big(|000\rangle + |111\rangle\big)^{\otimes 3}, \qquad |1\rangle_L = \tfrac{1}{2\sqrt2}\big(|000\rangle - |111\rangle\big)^{\otimes 3}

Two layers of syndrome measurement then cooperate:

  • Inner (bit-flip) syndrome — within each block of 3, the same parity checks as before locate a single XX error and fix it with an XX.
  • Outer (phase-flip) syndrome — a ZZ on any qubit in a block flips that block’s sign (000+111000111|000\rangle + |111\rangle \to |000\rangle - |111\rangle). Comparing the signs across the three blocks locates which block carries the phase error and fixes it with a ZZ.

Because any single-qubit error is a combination of XX, ZZ, and Y=iXZY = iXZ, correcting bit flips and phase flips independently corrects every single-qubit error — even a small continuous rotation, which the syndrome measurement discretizes into one of these cases. Inject a bit flip, a phase flip, or both on any qubit and step through detection and correction:

error on qubit:
block 0|000⟩+|111⟩
q0
ok
q1
ok
q2
ok
block 1|000⟩+|111⟩
q3
ok
q4
ok
q5
ok
block 2|000⟩+|111⟩
q6
ok
q7
ok
q8
ok
syndromes:inner (bit): outer (phase):

Encode 1 logical qubit into 9: three blocks, each (|000⟩±|111⟩). The inner layer guards bit flips, the outer layer guards phase flips.

Takeaways

  • Qubits suffer decoherence; no-cloning and measurement collapse rule out naive copying, so QEC must repair errors blindly.
  • The 3-qubit code encodes α0+β1\alpha|0\rangle + \beta|1\rangle as α000+β111\alpha|000\rangle + \beta|111\rangle and corrects one bit flip.
  • Syndrome parity measurements locate the error without revealing α,β\alpha,\beta; an XX gate then fixes it. Bigger codes handle phase and multi-qubit errors.

References