Skip to content
Tushar Pandey

Step 8 of 8

Lattice surgery

Quantum Error Correction in Practice, part 2: Computing with logical qubits

Read

Two surface code patches sit side by side. Merge them along the edges that face each other, then split them again, and you have measured the product of their logical Z operators without reading either one. That is lattice surgery. The figure runs it on 21 simulated qubits.

Two patches and a seam

Each patch is the distance-3 patch from lesson 1: nine data qubits, four X checks and four Z checks. The left and right edges carry X checks, the top and bottom edges carry Z checks. XL runs along the top row, from one X edge to the other. ZL runs down a column, from one Z edge to the other. Multiply a column of Z by the patch's four Z checks and you get another column, so while those checks hold, any column is ZL.

Put patch B to the right of patch A, with a column of three fresh qubits, the seam, in between. A's right edge and B's left edge, both X edges, now face each other, and the columns that carry ZL run parallel to them.

Two surface code patches and the seam between them

The figure needs JavaScript. The text around it describes every stage.

Fig. 1Two distance-3 patches and the seam, simulated in your browser with a stabilizer tableau, one seeded shot at a time. Orange checks are X checks, blue are Z checks; a check that read -1 is red, one with no definite value is grey. The four seam Z checks whose product is the parity are outlined. ZL is drawn on the outer column of each patch. No noise is simulated, so every -1 is a measurement outcome, not an error. Use the arrow keys on the figure to step.

Merge

Prepare the seam in |+⟩ and measure the checks of one patch seven columns wide. The two facing X edge checks stop being checks. Six new ones appear across the seam: two X checks and four Z checks, two of them weight two on the top and bottom edges.

Multiply the four new Z checks. Every seam qubit appears twice and drops out, which leaves Z on A's right column times Z on B's left column. That is ZL(A) ZL(B), times A's own Z checks, which hold. Each of the four is random on its own, because each anticommutes with X on some seam qubit, and those were +1. Only the product carries information. The two new X checks are not random: each is an old edge check times X on two seam qubits, all +1.

Pick |+⟩ for both patches. The ZL lines are grey from the start: neither has a value. Step to Merge and they stay grey, but their product now has one, and each XL line turns grey too, because XL of one patch alone does not commute with the measurement.

Split

To split, measure each seam qubit in X. The seam Z checks end, but their product touches no seam qubit and keeps its value. The facing edge checks return: A's equals the merged X check on its side times the X outcomes of the two seam qubits it touched, and likewise for B. When that product is -1, Z on A's qubits 5 and 8, or on B's qubit 15, flips it back.

One correction is logical. XL(A), times X on the top seam qubit, times XL(B) commuted with every merged check and kept its value. After the split, XL(A) XL(B) carries the top seam outcome as a sign, so when it reads -1 you apply ZL to A. These Paulis are the frame. Hardware tracks them in software; the figure applies them.

What you are left with

After the frame every check holds again, and the pair is in an eigenstate of ZL(A) ZL(B) with the value the merge reported. Read both patches in Z and the product of the two outcomes is always that value; run 200 shots to see it. For |0⟩ and |1⟩ inputs the parity is fixed in advance and the merge confirms it.

For |+⟩|+⟩ the parity is +1 or -1 with even odds, and the two Z readouts then agree or disagree every time. Switch the readout to X and XL(A) XL(B) comes out +1 in every shot, because the measurement commuted with it. Correlated in Z and in X: a logical Bell pair, the state lesson 2 made with a transversal CNOT and lesson 4 spent on teleportation. Here it came from checks between neighbouring qubits, not from gates between matching qubits of two patches.

Why surgery matters

A transversal CNOT couples every qubit of one patch to its partner in the other. A planar chip with nearest-neighbour couplings has no such links between two patches side by side. Surgery needs only the local checks along a shared edge. Stack the patches instead, so their Z edges face, put the seam in |0⟩, and by the same argument the product of the new X checks gives XL XL, times X checks the patches already had. With both measurements you have a logical CNOT: take an ancilla patch in |+⟩, measure ZL ZL on control and ancilla, then XL XL on ancilla and target, read the ancilla in Z, and fix the frame from the three outcomes. That sequence is the standard construction; it is not simulated on this page.

The same idea, measuring logical operators by joining codes through new checks, is being generalised to qLDPC codes in current research.

End of the course

That was the last of the eight steps. To go further, the bivariate bicycle code explorer works with one family of qLDPC codes, a note on the threshold follows the crossings of the threshold lesson up to d = 21, and the research page describes current work on surgery for qLDPC codes.

Cite this lesson T. Pandey, "Lattice surgery", Quantum Error Correction in Practice (2026), https://pandey-tushar.com/qec-in-practice/lattice-surgery.html