The toric code of Module 7 lives on a torus. A real chip is flat. You cannot wrap a 2D grid of qubits around a doughnut without long wires. The fix is to cut the torus open and give the lattice boundaries. Each boundary type lets one kind of anyon disappear into it. A logical operator is then a string that runs from one boundary to the opposite one, rather than a loop.

This module builds the two standard flat versions: the planar code and the rotated surface code . The rotated code is the one used in the Google, IBM and other surface-code experiments. We then go down to the circuit level. How is a weight-4 check measured with CNOTs? In which order should the CNOTs act? Why does the wrong order quietly cut the distance roughly in half?

Learning goals. After this module you should be able to

  1. explain rough and smooth boundaries and why a string ending on a boundary has a single defect;
  2. derive the parameters of the planar and rotated surface codes, and write down the rotated code with its logical operators;
  3. draw the syndrome extraction circuits for X-type and Z-type checks and explain them with Pauli propagation through CNOTs;
  4. explain hook errors and choose a CNOT order that keeps the full distance.

1. Boundaries

Start from the toric code’s chain picture. A Z error string flips the stars (X-checks) at its two endpoints. On the torus there is nowhere for an endpoint to go, so defects are always created in pairs. Now remove the periodic identification and stop the lattice at an edge. There are two natural ways to do it.

  • Smooth boundary. The lattice ends in a row of vertices. Stars on that row lose one edge and become weight-3 X-checks. Plaquettes stay complete.
  • Rough boundary. The lattice ends in a row of dangling edges that stick out with no vertex at the far end. Plaquettes along that side lose an edge and become weight-3 Z-checks. Stars stay complete.

The key effect: a Z string can end on a rough boundary without creating a defect there. The dangling edge has only one endpoint inside the lattice, so a Z error on it flips only one star. Dually, an X string, which lives on the dual lattice, can end on a smooth boundary without a defect. Following Fowler et al., we often name boundaries by which checks are cut: the rough boundary carries the truncated Z-type checks, so we call it a Z-boundary. The smooth boundary carries truncated X-type checks, so it is an X-boundary.

Convention check

Which boundary is “rough” depends on whether X-checks sit on vertices (this course, Kitaev) or on faces (Pesah, for example). The statement that does not depend on the picture is: runs between the two boundaries that carry the cut Z-type checks, and runs between the two boundaries that carry the cut X-type checks.

2. The planar code

Definition 8.1 (Planar surface code).

Take a grid of sites , .

  • Data qubits sit at sites with even.
  • X-checks (stars) sit at sites with even and odd.
  • Z-checks (plaquettes) sit at sites with odd and even.

Each check acts on the data qubits among its four grid neighbours , that lie inside the grid.

In the edge picture of Module 7, X-check sites are vertices. Data qubits at (even, even) sites are horizontal edges and those at (odd, odd) are vertical edges. The left and right columns of horizontal edges dangle. So the left and right sides are rough and the top and bottom are smooth.

rough (Z-bdry) rough (Z-bdry) smooth (X-boundary) smooth (X-boundary) ZL: rough to rough XL: smooth to smooth data qubit (edge) vertex: X-star L = 3: 13 qubits, 6 stars, 6 plaquettes, k = 1, d = 3
Theorem 8.1 (Parameters of the planar code).

The planar code is an code. It has X-checks and Z-checks, all independent. With one ancilla per check, it uses physical qubits.

We checked this by computer. For the construction gives , , and minimum logical weights in both bases. Two smaller facts are worth seeing explicitly:

  • At , a Z error on the left-boundary qubit flips one star, while a Z error on the bulk qubit flips two. Single defects are possible only at the matching boundary.
  • The planar code has data qubits and checks, so qubits with ancillas. This is Fowler et al.’s standard example.

Compared with the toric code we lost one logical qubit: instead of . In exchange the layout is flat, and only the boundary checks have lower weight.

3. The rotated surface code

The planar code spends many qubits along its boundaries. Rotate the lattice by 45 degrees, keep only the central diamond, and add weight-2 checks along the new boundaries. The result is the rotated surface code. It has the same distance with about half as many data qubits (Bombin and Martin-Delgado, 2007). In this picture, data qubits sit on the vertices of a grid and checks sit on the faces, coloured like a checkerboard.

Definition 8.2 (Rotated surface code).

Place data qubits on a grid, row and column from to , with index . Each unit square with top-left qubit , , carries a weight-4 check: X-type if is even, Z-type if is odd. Along the boundary, add weight-2 checks on every second pair of neighbouring boundary qubits: X-type on the top and bottom edges and Z-type on the left and right edges, continuing the checkerboard pattern.

0 1 2 3 4 5 6 7 8 X Z Z X X X Z Z X-type check Z-type check data qubit q = 3r + c bulk: weight 4 boundary: weight 2 X-type on top and bottom, Z-type on left and right

For the eight generators are

You can check commutation by eye. Every X-type and Z-type check overlap on 0 or 2 qubits. For example, and share , and and share .

Proposition 8.1 (Parameters of the rotated code).

The rotated surface code is a code for odd . It has X-type and Z-type checks, all independent. With one ancilla per check it uses physical qubits. The logical operators can be chosen as

runs left to right, between the boundaries carrying weight-2 Z-checks. runs top to bottom, between the boundaries carrying weight-2 X-checks. They share exactly qubit , so they anticommute.

ZL = Z0 Z1 Z2 (row 0) XL = X0 X3 X6 (column 0) they share qubit 0 ZL joins the two Z-type boundaries (left, right); XL joins the two X-type boundaries (top, bottom).

Numerically: for the construction gives , and independent checks, , and total qubits. Brute force over and confirms and . The minimum-weight logicals are not unique. At there are 8 weight-3 X-logicals, for instance , and also the zig-zag , and 8 weight-3 Z-logicals. Each is a string from one boundary to the opposite one.

distanceplanar data / totalrotated data / total
313 / 259 / 17
541 / 8125 / 49
785 / 16949 / 97

The 17-qubit layout (often called Surface-17) is the usual first target in experiments. Google’s Willow experiment ran a rotated code on 101 qubits: 49 data, 48 measure, and 4 extra qubits for leakage removal.

Example 8.1 (Syndrome table of the d = 3 rotated code).

Order the Z-checks as . They detect X errors. Order the X-checks as . They detect Z errors. Single-qubit errors give (computed):

qubit 012345678
001010001000011011001001010001000001
100010100010100011000100000101010100

Some syndromes repeat: and both give . This is not a failure of the code. is itself a stabilizer (the top boundary check), so correcting with leaves , which does nothing. The same holds for , for and for . This is degeneracy (Module 3). Since every repeated syndrome belongs to such a pair, a lookup table that maps each syndrome to one of its errors corrects every single-qubit X, Y or Z error.

4. Measuring a check: syndrome extraction circuits

A check like cannot be measured by measuring the four qubits one at a time. That would collapse the encoded superposition and destroy the logical information. Instead, the parity is copied onto an ancilla (measure qubit) and only the ancilla is measured.

a b c d anc |0> M Z check: measures Za Zb Zc Zd a b c d anc |0> H H M X check: measures Xa Xb Xc Xd

To see why this works, we need the propagation rules for Paulis through a CNOT (from Module 5):

CNOT copies X forward from control to target, and Z backward from target to control. We also need and .

Proposition 8.2 (What the circuits measure).

With the ancilla prepared in , the Z-check circuit (four CNOTs with data as controls, ancilla as target, then measure the ancilla in the Z basis) measures . The X-check circuit ( on the ancilla, four CNOTs with the ancilla as control, , measure) measures . In both cases the data qubits are left in the corresponding eigenstate.

One full syndrome extraction round has four steps: reset all ancillas, apply Hadamards on the X-type ancillas, run four CNOT layers, then apply Hadamards again and measure. The Z-type ancillas idle during the Hadamard steps, so both kinds stay in lockstep. Fowler et al. count this as an 8-step “surface code cycle”.

5. Scheduling the CNOTs and hook errors

Each data qubit belongs to up to four checks, and each check needs four CNOTs. To finish in four layers, every layer must use each qubit at most once. Let the corners of a check be TL, TR, BL, BR (top-left, top-right, bottom-left, bottom-right). Two orders are natural:

  • Z order: TL, TR, BL, BR (the path traces a “Z”);
  • N order: TL, BL, TR, BR (the path traces an “N”).

The schedule must also measure the stabilizers correctly when X-checks and Z-checks share qubits, and it must not create harmful hook errors. For the layout in Definition 8.2, the two standard choices pass the first test. Using the same order for all X-checks and the same order for all Z-checks, we tried all four combinations in Stim. Each is collision-free and gives deterministic detectors. The second test is where they differ.

Definition 8.3 (Hook error).

A hook error is a single fault on an ancilla, partway through its CNOT sequence, that spreads to two or more data qubits. If an X error hits an X-check ancilla (the control) after the second CNOT, it is copied onto the targets of CNOTs 3 and 4. A single fault thus becomes on the last two data qubits the check touches. Likewise, a Z error on a Z-check ancilla (the target) after the second CNOT is copied backward onto the last two controls as .

Stim propagation confirms this. An X on the X-check ancilla after CNOT 2 becomes on the data. A Z on the Z-check ancilla after CNOT 2 becomes . After CNOT 1, the X fault becomes , which equals times the check, so it is effectively a single-qubit error. Two data errors from one fault is the worst a single ancilla fault can do.

A weight-2 error from one fault is harmless as long as it does not line up with a logical operator. It is dangerous when it does. is a vertical string, so an hook on a vertical pair of qubits does two steps of the work of a logical error for the price of one fault.

1 2 3 4 X Z order: hook on BL-BR (horizontal) 1 2 3 4 X N order: hook on TR-BR (vertical) XL runs vertically good: Z order bad: N order
Remark 8.1 (The hook rule).

To keep the full circuit-level distance, the last two qubits touched by each check must form a pair perpendicular to the logical operator built from that check’s error type. In the layout of Definition 8.2 ( vertical, horizontal), X-checks should use the Z order (the last pair is horizontal) and Z-checks the N order (the last pair is vertical).

This is a design rule, not a theorem. We checked it with a Stim simulation of a -round memory experiment under uniform circuit-level noise of strength : a bit flip after every reset and before every measurement, two-qubit depolarizing noise after every CNOT, and single-qubit depolarizing noise after every Hadamard and on every idle qubit in every layer (including data qubits while the ancillas are reset and measured). The table gives the smallest number of faults that produce an undetected logical error, using graph-like errors. The memory-Z experiment is sensitive to X errors and the memory-X experiment to Z errors.

X-check order / Z-check ordermemory-Z distancememory-X distance
3Z / N (correct)33
3Z / Z32
3N / N23
3N / Z22
5Z / N (correct)55
5Z / Z53
5N / N35
5N / Z33
7Z / N (correct)77
7Z / Z74
7N / N47
7N / Z44

A wrong order reduces the distance in the affected basis to : a chain of hooks spans the patch. This is not just a lower number in a table. At , 5 rounds and physical error rate , decoding with PyMatching on shots gave a memory-X logical error rate per shot of with the correct Z/N order. With Z/Z it was , about three times worse, while the memory-Z rate stayed at . (N/Z, wrong in both bases, lowers both distances.)

These absolute rates depend on the noise model, so do not compare them directly with Module 10. Stim’s built-in surface_code:rotated_memory_z generator with the same for its four standard noise parameters puts no noise on idle qubits during the CNOT layers. For , 5 rounds, we measured with it (504 failures in shots), several times lower than our . The ratio between a good and a bad schedule is the point here, not the absolute number.

A silent bug

Every ordering in the table is a valid, collision-free circuit with deterministic detectors. Nothing crashes. If you only ever simulate memory-Z, the Z/Z ordering looks perfect. Always test both bases when you write a surface code circuit generator.

6. Running the code: initialization and readout

A memory experiment is the basic benchmark: store a logical state for rounds and read it out.

  • Prepare . Reset every data qubit to . All Z-checks then start at for sure. The X-checks give random outcomes in the first round, and these outcomes fix the state’s X-check signs, which are tracked from then on. The result is a valid eigenstate. To prepare , reset to instead.
  • Run rounds of syndrome extraction.
  • Read out . Measure every data qubit in the Z basis and take the parity of the outcomes along a string, for example qubits . One data qubit is not enough. Unlike the repetition code, the logical value is a parity of qubits. The same data outcomes also give one final value of every Z-check, which is used for decoding.

Turning these measurement records into something a decoder can use is the subject of Module 9.

7. Beyond memory: computing with patches

A surface code patch stores one qubit. For computation the standard approach is lattice surgery (Horsman, Fowler, Devitt and Van Meter, 2012). Two patches placed side by side are temporarily merged by measuring new checks along their shared boundary. The product of the new check outcomes gives a joint logical measurement such as or . Splitting the patches again completes the operation. Joint Pauli measurements plus single-patch operations implement the Clifford group. Non-Clifford gates such as require magic states prepared by state injection and distillation. Older proposals instead move holes (“defects”) in a large lattice around each other (braiding, as in Fowler et al. 2012). Neutral atoms and ions can physically move qubits, which also allows transversal CNOTs between patches. Litinski’s A Game of Surface Codes is a readable guide to the lattice-surgery picture.

Summary

  • Cutting the torus open creates boundaries. A rough (Z-)boundary absorbs Z strings and a smooth (X-)boundary absorbs X strings, so a single defect can appear next to a boundary.
  • The planar code (Definition 8.1) is , with independent checks and qubits including ancillas (Theorem 8.1).
  • The rotated code (Definition 8.2) is with checks and qubits (Proposition 8.1). joins the Z-type boundaries and joins the X-type boundaries. At every single-qubit error can be corrected from the syndrome (Example 8.1).
  • Checks are measured by copying parities onto ancillas with CNOTs (Proposition 8.2). CNOTs copy X forward and Z backward.
  • A fault on an ancilla can spread to two data qubits (Definition 8.3). Ordering the CNOTs so that the last pair is perpendicular to the matching logical (Remark 8.1) preserves distance . The wrong order gives .

Further reading

  • S. B. Bravyi, A. Yu. Kitaev, Quantum codes on a lattice with boundary, arXiv:quant-ph/9811052. The planar code.
  • A. G. Fowler, M. Mariantoni, J. M. Martinis, A. N. Cleland, Surface codes: Towards practical large-scale quantum computation, Phys. Rev. A 86, 032324 (2012), arXiv:1208.0928. Circuits, the surface code cycle, X/Z boundaries.
  • H. Bombin, M. A. Martin-Delgado, Optimal resources for topological two-dimensional stabilizer codes: Comparative study, Phys. Rev. A 76, 012305 (2007), arXiv:quant-ph/0703272. The rotated layout.
  • Y. Tomita, K. M. Svore, Low-distance surface codes under realistic quantum noise, Phys. Rev. A 90, 062320 (2014), arXiv:1404.3747. The 17-qubit code and CNOT ordering.
  • C. Horsman, A. G. Fowler, S. Devitt, R. Van Meter, Surface code quantum computing by lattice surgery, New J. Phys. 14, 123011 (2012), arXiv:1111.4022.
  • D. Litinski, A Game of Surface Codes: Large-Scale Quantum Computing with Lattice Surgery, Quantum 3, 128 (2019), arXiv:1808.02892.
  • Google Quantum AI, Quantum error correction below the surface code threshold, Nature 638, 920 (2025), arXiv:2408.13687.
  • Google Quantum AI / Coursera, Quantum error correction IV slides (rotated code, CNOT order and hook errors) and the Surface code in Stim lab.

Homework

Homework 8: Planar and Rotated Surface Codes