Skip to content

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.

Arrange d×dd \times d qubits in a square grid, for an odd number dd. 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 ZZZZZZZZ on its four corners, on squares of one colour,
  • an X check, the string XXXXXXXX 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-XX or all-ZZ, this is a CSS code.

Now count. A 3×33\times3 patch has 9 data qubits and 8 checks: four full squares and four half-squares. That leaves 9−8=19 - 8 = 1 logical qubit. In general there are d2d^2 data qubits and d2−1d^2 - 1 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 2d2−12d^2 - 1 physical qubits.

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 XX, and an X check fires when an odd number carry a ZZ.

SimulatorA surface code patch

This simulator needs JavaScript.

Work through these in order. The buttons in the “Try” row set up the first few for you.

  1. One X. A single XX in the middle fires the two Z checks that contain that qubit.
  2. Two neighbours. Add an XX 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.
  3. A longer chain. Switch to d=5d = 5 and build a path of XX 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.
  4. Off the edge. Put a single XX 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.
  5. A whole X check. Put XX 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.
  6. A full column. Put an XX 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.

Experiment 6 found the logical operators. A chain of XX 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 XX is a chain of XX‘s running from the top edge to the bottom edge.
  • Logical ZZ is a chain of ZZ‘s running from the left edge to the right edge. Switch the simulator to ZZ errors and fill a row to see it.

A column and a row cross at exactly one qubit, so logical XX and logical ZZ clash in one place and anticommute, as XX and ZZ 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 XX‘s from top to bottom is a logical XX, 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.

The shortest path across a d×dd\times d patch has dd qubits. So the smallest logical operator has weight dd, and the code is

[[ d2, 1, d ]].[[\,d^2,\ 1,\ d\,]].

It corrects any ⌊(d−1)/2⌋\lfloor (d-1)/2 \rfloor errors: one for d=3d = 3, two for d=5d = 5, three for d=7d = 7. To get more protection, make the patch bigger. Nothing else about the design changes: the checks are still on four neighbouring qubits.

Check

For a surface code patch of distance 7, how many data qubits are there and how many errors is it guaranteed to correct?

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 d=3d = 3, and put XX 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.

Check

On a distance-3 patch, XX errors hit two of the three qubits in one column. What does a decoder that chooses the smallest correction do?

Choosing corrections well is a problem in its own right. The lesson on decoding is about it, and lets you try it yourself.

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.

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.

RecallAnswer from memory, then check
LessonFinish this lesson