The surface code
The codes so far correct one error. To run a long computation we need codes that correct many, and we need them to suit real devices. On a superconducting chip, for instance, the qubits sit in a flat layer and each one can interact only with its nearest neighbours. The Steane code asks for checks on qubits that are not neighbours in any flat arrangement, and making it stronger makes this worse.
The surface code was designed around those constraints. It grew out of Alexei Kitaev’s work in the late 1990s, and it is the code behind several of the largest experiments of recent years.
The layout
Section titled “The layout”Arrange qubits in a square grid, for an odd number . These are the data qubits. Now colour the squares between them like a chessboard. Each square has four data qubits at its corners, and each square is one generator of the code:
- a Z check, the string on its four corners, on squares of one colour,
- an X check, the string on its four corners, on squares of the other colour.
Around the outside, half-squares hold checks on just two qubits: X checks along the top and bottom edges, Z checks along the left and right edges.
Do these commute? A Z check and an X check on adjacent squares share an edge, which is two qubits. Two clashes is even, so they commute. Squares that touch only at a corner have the same colour and so the same type. Everything commutes, and since every generator is all- or all-, this is a CSS code.
Now count. A patch has 9 data qubits and 8 checks: four full squares and four half-squares. That leaves logical qubit. In general there are data qubits and checks. One patch holds one logical qubit, however large it is. What the extra qubits buy is distance.
No check involves more than four qubits, and those four are neighbours. On hardware, an extra measurement qubit sits in the middle of each square and is used as the ancilla for that square’s check, with the circuits you built in earlier lessons. Counting those, a patch uses physical qubits.
Errors are chains
Section titled “Errors are chains”In the simulator, circles are data qubits. Orange squares are Z checks and blue squares are X checks. Click a qubit to put an error on it. Remember which check sees what: a Z check fires when an odd number of its qubits carry an , and an X check fires when an odd number carry a .
This simulator needs JavaScript.
Work through these in order. The buttons in the “Try” row set up the first few for you.
- One X. A single in the middle fires the two Z checks that contain that qubit.
- Two neighbours. Add an on the qubit to its right. The Z check that contains both now sees two errors and goes quiet. Only the checks at the two ends fire.
- A longer chain. Switch to and build a path of errors several qubits long. However long it is, only its ends are visible. The checks do not see errors. They see the endpoints of chains of errors.
- Off the edge. Put a single on a qubit in the top row. Only one check fires. The other end of this chain has fallen off the top edge, where no Z check is waiting to catch it.
- A whole X check. Put on all four corners of a blue square. Nothing fires, and the simulator reports that nothing is wrong. This pattern is a generator, and generators do nothing to encoded states.
- A full column. Put an on every qubit of one column, from the top edge to the bottom. Both ends have fallen off the patch. Nothing fires, and this time something is wrong.
Logical operators cross the patch
Section titled “Logical operators cross the patch”Experiment 6 found the logical operators. A chain of errors is invisible wherever it passes through the interior, and its ends are invisible if they lie on the top and bottom edges. So:
- Logical is a chain of ‘s running from the top edge to the bottom edge.
- Logical is a chain of ‘s running from the left edge to the right edge. Switch the simulator to errors and fill a row to see it.
A column and a row cross at exactly one qubit, so logical and logical clash in one place and anticommute, as and must.
The chain need not be straight. Multiplying a logical operator by a check bends it around that square without changing what it does to the encoded qubit. Any path of ‘s from top to bottom is a logical , and all of them are equivalent. What matters is not the exact shape of a chain but whether it gets across. Properties that survive this kind of bending are called topological, and the surface code is the best-known topological code.
Distance
Section titled “Distance”The shortest path across a patch has qubits. So the smallest logical operator has weight , and the code is
It corrects any errors: one for , two for , three for . To get more protection, make the patch bigger. Nothing else about the design changes: the checks are still on four neighbouring qubits.
For a surface code patch of distance 7, how many data qubits are there and how many errors is it guaranteed to correct?
There are data qubits, plus 48 measurement qubits on hardware. The distance is 7, and a distance-7 code corrects errors.
How correction fails
Section titled “How correction fails”Correction means choosing a set of flips that silences the checks. If the flips and the real errors together make something harmless, a product of checks, all is well. If together they make a chain right across the patch, the correction has completed a logical operator, and the data is wrong although every check is quiet.
Clear the simulator, set , and put errors on the top two qubits of the middle column. One check fires. The smallest correction that silences it is a single flip on a qubit in the bottom row. Together with the two real errors, that makes a chain from the top edge to the bottom edge.
On a distance-3 patch, errors hit two of the three qubits in one column. What does a decoder that chooses the smallest correction do?
Two errors in a column of three look, from the syndrome, exactly like one error in the bottom row, and one error is the likelier story. Distance 3 guarantees correction of one error only. With the same two errors would be handled correctly, and it takes three in a column to fool the decoder.
Choosing corrections well is a problem in its own right. The lesson on decoding is about it, and lets you try it yourself.
Running the code
Section titled “Running the code”A surface code is not corrected once. It runs in cycles: every check is measured, then every check is measured again, for as long as the logical qubit must live. On superconducting hardware a cycle takes around a microsecond. Errors arrive continually, and a classical computer watches the stream of syndromes and keeps track of what correction is owed.
Corrections do not even need to be applied as gates. Since they are Pauli operators, it is enough to record them and reinterpret later measurement results accordingly.
Why hardware likes it
Section titled “Why hardware likes it”It is local and flat. Every check involves four neighbouring qubits in a plane. No long-range connections are needed.
It tolerates noisy parts. The surface code works as long as the error rate of each physical operation is below a threshold of very roughly 1%, the exact figure depending on the noise assumed. That is far more forgiving than concatenated codes like the Steane code, and it is within reach of today’s best devices. The next lesson explains what a threshold is.
It has been shown to work. In an experiment published in 2024, a team at Google ran patches of distance 3, 5 and 7 and found that the logical error rate roughly halved with each step up in distance. Bigger was better, which is the signature of operating below threshold.
Its weakness is cost. One patch holds a single logical qubit, and a useful distance may need hundreds or thousands of physical qubits per patch. Other code families, known as quantum LDPC codes, store many more logical qubits in the same number of physical ones. They need connections between distant qubits, which some kinds of hardware can provide and others cannot. Which approach wins is an open question.
The claim that a code “works below a threshold” has been made twice now without explanation. It rests on a deeper question: the circuits that measure the checks are built from the same faulty gates as everything else, so why do they not make matters worse? That is the subject of fault tolerance.
Remember it
Section titled “Remember it”What are the checks of the surface code?
Four-qubit and checks on alternating squares of a grid of data qubits, like a chessboard, with two-qubit checks along the edges.
What are the parameters of a surface code patch?
: one logical qubit, however large the patch.
What do the checks of the surface code reveal about a chain of errors?
Only its endpoints. A chain is invisible along its length, and an end that reaches a suitable edge of the patch is invisible too.
What are the logical operators of a surface code patch?
Chains that cross the whole patch: 's from one pair of opposite edges, 's between the other pair. They cross at one qubit, so they anticommute.
Give two reasons the surface code suits real hardware.
Every check involves only four neighbouring qubits on a flat grid, and its threshold is high, very roughly 1%.