Learning goals. After this module you should be able to
compute the logical error rate of a classical repetition code and say when encoding helps;
explain why no-cloning, measurement back-action and continuous errors seem to rule out quantum error correction, and why they do not;
show that correcting the Pauli errors , , is enough to correct any single-qubit error (“error digitization”);
encode, diagnose and correct the three-qubit bit-flip and phase-flip codes using parity measurements;
describe Shor’s code and identify its logical operators;
state the Knill-Laflamme condition and check it on a small example.
Throughout the course qubits inside a code are numbered , and a Pauli string such as means on three qubits (identities are implicit). We use the Hermitian , so that .
1. The classical starting point: repetition and majority vote
Suppose you want to store one bit in a memory where every bit is flipped independently with probability while you are not looking. The oldest trick is to store several copies.
Definition 1.1 (Repetition code).
The -bit repetition code encodes and . These two strings are the codewords (or logical and ). The decoder reads all bits and outputs the majority value.
With and independent flips, majority vote fails exactly when two or three bits flip:
This is smaller than the unencoded error rate precisely when . For general odd the decoder fails when more than bits flip,
for example . The table shows what this buys.
Three lessons from this simple computation run through the whole course.
There is a threshold. Below , adding more bits drives the logical error rate to zero exponentially fast in ; above it, more bits make things worse. Quantum codes will also have a threshold, though a much smaller one (around for the surface code, see Module 11).
The distance sets the exponent. The repetition code of Definition 1.1 has distance: it takes flips to turn one codeword into the other. A distance- code can only fail if at least errors occur, so .
You do not need to read the data. Instead of reading every bit, we could measure only the parities, , and so on, of neighbouring bits. A flipped bit lights up the two parity checks on either side of it, and the pattern of lit checks (the syndrome) says where the error is, without ever revealing whether the stored value is or .
Figure 1.1. Circles are data bits, squares are parity checks of neighbouring bits. A single flip on b3 (highlighted) lights the two checks next to it; the syndrome 0110 locates the error without reading the stored value.
The third lesson is the one that will survive the trip to quantum mechanics. Quantum codes are built entirely out of parity-type measurements. (Practice: Problem 1.1.)
2. Why the quantum case looks hopeless
A qubit stores a state with continuous complex amplitudes. Four features of quantum mechanics seem to block the repetition idea.
(i) You cannot copy. The quantum analogue of would be , and that is forbidden.
Theorem 1.1 (No-cloning).
There is no unitary and fixed blank state such that for every single-qubit state .
Proof
Suppose such a exists. Then and . By linearity, for ,
whereas cloning demands . The two agree only if , that is, only for the two basis states.
(ii) Measurement disturbs. Reading the qubits to take a majority vote collapses the superposition and destroys and .
(iii) Errors are continuous. A qubit can be rotated by a tiny angle instead of being flipped. There seem to be infinitely many errors to correct, and correcting an infinitesimal one seems to require infinite precision.
(iv) There is more than one kind of error. Besides bit flips there are phase flips, which have no classical analogue and which no classical code protects against.
The rest of this module disposes of all four objections. The answers are: (i) we encode by entangling, not copying; (ii) we measure only parities, which carry no information about ; (iii) measuring a parity digitizes a continuous error into a discrete Pauli error; (iv) we combine a bit-flip code and a phase-flip code.
3. Error digitization: Paulis are enough
The four matrices form a basis of all complex matrices. Concretely, any matrix can be written
and in general the coefficient of in is . Tensor products of Paulis form a basis of matrices in the same way.
Now let a qubit interact with its environment (anything we do not control). Whatever the unitary is, we can expand its action on the qubit in this basis:
where the are unnormalized, not necessarily orthogonal environment states. For qubits the same expansion runs over all Pauli strings.
Proposition 1.1 (Error digitization).
Suppose a code can correct each error in a set of Pauli strings, by a procedure that first measures which error occurred and then undoes it. Then the same procedure corrects every error of the form , and every interaction with an environment whose expansion only involves the .
The reason is linearity together with the fact that the diagnosis is a measurement. If the code is designed so that the states for different “syndrome classes” lie in mutually orthogonal subspaces, then measuring which subspace the state is in projects the superposition onto a single term , which we then undo. A continuous error becomes, after the measurement, a discrete one. Section 4 shows this in action (Example 1.1), and Theorem 1.2 in Section 7 gives the precise condition.
Problem 1.2 works through such an expansion in detail. So from now on we only need to worry about the Pauli errors (bit flip), (phase flip) and (both). In the course’s noise models (see Module 9) a qubit suffers , or each with probability ; this is the depolarizing channel.
4. The three-qubit bit-flip code
Encoding without cloning
The quantum repetition code maps
using two CNOT gates from the data qubit onto two fresh qubits in (left part of the figure below). This is not a copy: is an entangled state, unlike , and the encoding is linear, so Theorem 1.1 is not violated (see also Problem 1.3). The codewords are and ; the two-dimensional space they span is the codespace.
Diagnosing errors by parity checks
A bit flip on one qubit moves the state out of the codespace into one of three orthogonal “error spaces”:
To tell these apart we measure the two parity checks and . Each has eigenvalue on states where the two qubits agree and where they disagree. Every codeword is a eigenvector of both, and each error space is a joint eigenspace with a distinct pair of signs. We record a outcome as syndrome bit (the course-wide convention: bit of the syndrome is iff anticommutes with check ).
error
syndrome
correction
none
none
The crucial point is what the measurement does not learn. The outcome of is the same for and , hence the same for every superposition . Measuring it collapses nothing about and . Measuring the single qubits and separately would give the same parity, but it would also reveal the logical value and destroy the superposition: we must measure the product without measuring its factors.
The syndrome extraction circuit
Parities are measured with an ancilla qubit. Prepare the ancilla in and apply CNOTs from qubits 1 and 2 onto it: the ancilla ends in for each computational-basis component, and since this value is the same in every component of an encoded state, the ancilla does not become entangled with the logical information. Measuring the ancilla in the basis returns the syndrome bit.
q1q2: |0>q3: |0>a1: |0>a2: |0>encodenoiseMMs1s2Figure 1.2. Encoding (two CNOTs), noise, then syndrome extraction: ancilla a1 collects the parity of q1 and q2 (the check Z1Z2), ancilla a2 the parity of q2 and q3 (Z2Z3). Measuring the ancillas gives the syndrome bits s1, s2.
We checked this circuit in Stim: with no error the ancillas read , and with an on qubit 1, 2 or 3 they read , , , independently of the encoded logical state.
Continuous errors collapse
Here is error digitization in its simplest form.
Example 1.1 (A small rotation becomes a discrete flip).
Let the error be a small rotation of qubit 1 about the axis,
Applied to the encoded state it gives , a superposition of a codeword and an error-space state. Measuring the two parity checks yields
syndrome with probability , leaving exactly (nothing to do);
syndrome with probability , leaving exactly (up to a global phase), which we fix by applying .
Either way the logical state is restored perfectly. The tiny rotation was not “partially corrected”; the measurement forced it to become either no error or a full bit flip. The same happens for a superposition of errors such as : the syndrome is with probability and with probability , and each outcome is corrected.
What the bit-flip code cannot do
The bit-flip code is blind to phase flips. A on any qubit commutes with both checks, so it produces the trivial syndrome, and it acts on the encoded state as
a flip of the logical phase. A single physical error is a logical error: against noise this code has distance .
5. The three-qubit phase-flip code
Phase flips become bit flips in the Hadamard basis, because and . So we simply run the bit-flip code in that basis. Write and encode
with the bit-flip encoder followed by on all three qubits. A error swaps on one qubit, and the checks and locate it with the same table as before: , , . In circuits, an -type parity is measured with an ancilla prepared in , CNOTs from the ancilla (control) onto the data (targets), and an -basis measurement of the ancilla.
Notice the roles of the operators. maps to , so it acts as the logical; a single acts as the logical (). The price of protecting against is that a single error is now a logical error. Neither three-qubit code handles both error types. (Practice: Problem 1.4.)
6. Shor’s nine-qubit code
Shor’s idea (1995) was to concatenate the two codes: first encode against phase flips, then encode each of the three resulting qubits against bit flips. The codewords are
Think of the nine qubits as three blocks of three.
block 1block 2block 3123456789ZZ checks inside blocksX1 X2 X3 X4 X5 X6X4 X5 X6 X7 X8 X9Figure 1.3. Shor's code. Solid links: the six ZZ checks inside blocks detect bit flips. Dashed brackets: the two weight-six X checks compare the relative sign (+ or -) of neighbouring blocks and detect phase flips.
Bit flips. Inside each block the state is , a bit-flip codeword. The six checks
locate any single error exactly as in Section 4.
Phase flips. A on any qubit of a block flips that block’s sign, . The operator measures a block’s sign (it has eigenvalue on ), so the two weight-six checks
compare the signs of blocks 1 and 2, and of blocks 2 and 3. That is the phase-flip code acting on the blocks. A on block 1 gives syndrome on these two checks, block 2 gives , block 3 gives .
errors trigger both kinds of checks and are corrected by correcting the part and the part. By error digitization (Proposition 1.1), correcting , , on every qubit means Shor’s code corrects any error on any single qubit.
A new phenomenon: degeneracy., and produce the same syndrome, so the decoder cannot tell them apart. It does not need to: is itself one of the products of checks that fix every codeword, so and the correction undoes either. Of the 27 single-qubit Pauli errors, only 21 distinct syndromes occur, and errors that share a syndrome always differ by such a harmless operator. Codes with this property are called degenerate; it has no classical counterpart and will matter a great deal for decoding (Module 10).
Logical operators and distance. Two operators of weight three act on the codewords as logical gates:
Note the swap: the physical -string is the logical , and vice versa, because the outer code is the phase-flip code. Both operators commute with all eight checks, so they cause no syndrome at all. The smallest weight of such an undetectable logical operator is the distance: a brute-force search confirms , so Shor’s code is a code (9 physical qubits, 1 logical qubit, distance 3).
How it fails. Two bit flips in one block, say , have the same syndrome as . The decoder applies , leaving : a logical phase error. Similarly, phase flips in two different blocks lead to . Under depolarizing noise with probability per qubit and perfect syndrome measurement, Preskill bounds the probability of such failures by about , so encoding beats an unprotected qubit when . Problem 1.5 traces these failure modes by hand. The real threshold, once the syndrome-measuring circuits themselves are noisy, is much lower; see Module 9 and Module 11.
7. When can a set of errors be corrected?
All three codes so far follow the same pattern: errors move the codespace into orthogonal error spaces, a measurement identifies the space, and a unitary moves it back. Knill and Laflamme turned this into a precise criterion. Let be the projector onto the codespace .
Theorem 1.2 (Knill-Laflamme condition).
A code with projector can correct every error in the set (that is, there is a recovery operation that undoes any of them on every code state) if and only if
for some Hermitian matrix of numbers that does not depend on the code state.
In words, Eq. asks two things for every pair of correctable errors:
orthogonality: errors that must be told apart send codewords to orthogonal states, for ;
no information leak: the overlap is the same for every codeword, so the environment learns nothing about which logical state was stored.
When (distinct errors send the codespace to mutually orthogonal spaces) the code is nondegenerate for that error set; Shor’s code with the errors , shows that can have off-diagonal entries, which is degeneracy again. Because Eq. is linear in each , if it holds for it holds for every linear combination of them. This is the precise form of error digitization (Proposition 1.1).
Example 1.2 (Checking the condition on the bit-flip code).
Take the bit-flip code, , and the error set .
: , so and .
: is or with . Each maps and to strings with one or two s, which are orthogonal to the codespace, so .
So and the condition holds. Now add to the set. Then , which is not a multiple of : the error distinguishes from , and the condition fails. Likewise adding the two-qubit error fails, because swaps and . We confirmed all three statements numerically.
The Knill-Laflamme condition also explains what the distance means. If a code has distance , every Pauli error of weight less than is either detectable or harmless, and the condition holds for all errors of weight at most (since has weight at most ). So:
a distance- code corrects any errors;
it detects any errors;
it corrects erasures (errors at known locations).
The bit-flip computation in Example 1.2 is the prototype; Problem 1.6 separates detection from correction and Problem 1.7 simulates the bit-flip code in Stim. Module 3 restates all of this in the language of stabilizer groups, where the condition becomes a simple commutation test.
8. What lies beyond the Pauli model
Two caveats are worth keeping in mind from the start.
Correlations. The analysis above assumes errors on different qubits are independent. Correlated errors, such as a single coherent rotation of many qubits at once or a cosmic-ray burst that hits a whole chip, can defeat a code whose distance was designed for independent errors (McEwen et al., Nature Physics 18, 107 (2022), arXiv:2104.05219).
Leakage. Physical qubits such as superconducting transmons have more than two levels. An excitation into is not a Pauli error at all and needs dedicated “leakage reduction” circuitry.
Neither caveat breaks the theory; they shape how experiments are engineered. For the rest of the course we work with Pauli errors, which, by digitization, is the essential case.
Summary
Classical repetition with majority vote turns an error rate into . Parity checks find errors without reading the data.
No-cloning, measurement back-action, continuous errors and phase errors look fatal, but are answered by entangling encodings, parity measurements, error digitization and combining codes.
The bit-flip code with checks , corrects one error; the phase-flip code with checks , corrects one error.
Shor’s code concatenates the two and corrects an arbitrary single-qubit error. It is degenerate, and its logical operators , have weight .
The Knill-Laflamme condition characterizes correctable error sets.
Next, Module 2 builds the algebra (Pauli groups and stabilizer groups) that turns these examples into a systematic theory.
Further reading
J. Preskill, Lecture Notes for Physics 219, Chapter 7: Quantum Error Correction, Sections 7.1-7.4 (Shor code, error digitization, Knill-Laflamme conditions).
P. W. Shor, “Scheme for reducing decoherence in quantum computer memory”, Phys. Rev. A 52, R2493 (1995).
E. Knill and R. Laflamme, “Theory of quantum error-correcting codes”, Phys. Rev. A 55, 900 (1997), arXiv:quant-ph/9604034.
V. V. Albert, Modern quantum error correction with four qubits (Boulder School lecture notes, 2023), Sections 0.2-0.4.
A. Fowler, Quantum error correction I: what are quantum errors? (Google Quantum AI lecture slides).
M. A. Nielsen and I. L. Chuang, Quantum Computation and Quantum Information, Chapter 10.