PennyLane
Install
Install

Related materials

  • Related contentA Game of Surface Codes: Large-Scale Quantum Computing with Lattice Surgery
  • Related contentModeling the toric code on a quantum computer
  • Related contentStabilizer codes for quantum error correction

Contents

  1. Surface code quantum computing
  2. Universal quantum computing with Pauli product measurements
  3. Single-qubit measurements
  4. Arbitrary Pauli product measurements via lattice merging and splitting
  5. Y measurements
  6. Conclusion
  7. References
  8. About the author

Downloads

  • Download Python script
  • Download Notebook
  • View on GitHub
  1. Demos/
  2. Quantum Computing/
  3. Introducing lattice surgery

Introducing lattice surgery

Korbinian Kottmann

Korbinian Kottmann

Published: December 16, 2025. Last updated: December 16, 2025.

Lattice surgery is a way to perform fault-tolerant operations on two-dimensional quantum computer architectures with local physical connectivity. Its introduction improved spatial overheads in topological quantum error correction codes, such as surface codes, by replacing continuous code operations with discontinuous ones: lattice splitting and merging. In this demo, we are going to see how these operations enable parity measurements of arbitrary Pauli operators, which unlock universal fault-tolerant quantum computing.

demos/_static/hero_illustrations/pennylane-demo-lattice-surgery-hero.png

For self-consistency, we are going to briefly recap the basic concepts of the surface code and explain why Pauli product measurements are sufficient for universal computing. We are then going to explain how to perform such homological measurements using lattice splitting and merging.

Surface code quantum computing

Topological quantum error correction codes, like the surface code [1], protect quantum information stored in logical qubits by ensuring the underlying physical qubits are kept in the code space, defined by the \(+1\) eigenspace of a set of stabilizer measurements. A logical qubit is then represented by a patch of physical qubits, called data qubits, on a square lattice like so:

../../_images/surface_code_qubit1.png

Each intersection of a line corresponds to a data qubit. Here we have a code distance of \(d=5\), so \(5 \times 5\) data qubits in total. On yellow surfaces, we continually measure X stabilizers, which simply are the \(X_a X_b X_c X_d\) operators on the four data qubits of the corners. Similarly, Z stabilizers are measured on white surfaces. These stabilizer measurements are not performed directly on the data qubits, but via another kind of qubit that sits at the center of each square surface as well as the center of each arch (shown below). These extra qubits are sometimes called measurement qubits or syndrome qubits and the measurement is performed by entangling four data qubits with one syndrome qubit and measuring it (see Fig. 1 in [1]).

Note that this representation of a qubit is in the so-called rotated surface code due to its \(45^\circ\) rotation with respect to the original planar surface code. Here we indicate the underlying data and syndrome qubits with black and red dots, respectively. The vertical lines do not correspond to physical connections, but are a mere guide to the eye that differentiate X vertex and Z face syndromes. In principle, all nearest neighbor qubits are physically connected and can perform universal gates in a noisy fashion.

../../_images/surface_code_qubit2.png

One such \(d \times d\) patch represents a logical qubit. An important feature is that we have sides with X arches and Z arches, as this enables the error-corrected encoding of the qubit. Note that the edge with X arches is called a Z edge, because measuring along that edge corresponds to a logical Z operator (more on logical X and Z operators that define the qubit further below).

We are interested in performing logical operations like a CNOT gate between two such patches that represent a logical qubit, each. The most straight-forward way to compute a logical CNOT is by performing physical CNOT gates between the data qubits of each logical qubit patch, indicated here by the red line exemplarily for one pair:

../../_images/transversal_cnot.png

This is called a transversal operation because the logical operation just corresponds to performing the physical operation on each qubit. For a two-qubit gate, this is problematic on hardware with only local (physical) connectivity (like those built of superconducting qubits). In that case, we want to perform CNOT gates non-transversally to accomodate the connectivity constraints of such hardware platforms. In the early days, this was achieved via braiding [2], a concept commonly encountered in algebraic topology. In this setting, qubits are encoded by defects in the code, and operations via continuous deformations of the code. However, defect based qubits suffer from requiring significantly more physical qubits per logical qubit.

This is where lattice surgery [3] comes into play: It has been shown to enable error-corrected logical operations with significantly lower space overhead and comparable time requirements [4] [5] [6]. The fundamental operations in lattice surgery are discontinuous deformations of the lattice, in particular lattice merging and lattice splitting, common in geometric topology.

Universal quantum computing with Pauli product measurements

To achieve universal quantum computing, we need to be able to perform all Clifford gates, particularly CNOT gates. Furthermore, we need to be able to reliably inject states to enable magic state injection. This line of reasoning is a bottom-up way to show that lattice surgery enables universal quantum computing, which was done in its original introduction [3].

Let us alternatively take a top-down approach here and show that we can perform arbitrary Pauli product measurements (PPMs), because we know this enables universal quantum computing, as illustrated in, e.g., the Game of Surface Codes [5]. The gist of it is that Pauli product rotations (PPRs) like \(e^{-i \tfrac{\theta}{2} P}\), represented as

../../_images/PPR.png

for arbitrary Pauli words \(P\) with Clifford angles (multiples of \(\pi/2\)) and non-Clifford angles (odd multiples of \(\pi/4\)) reproduce the (Clifford + T) gate set, and thus allow for universal quantum computing. These PPRs can be directly executed using PPMs in the following way, so all we will need to show below is that the lattice surgery based quantum computer can perform arbitrary PPMs. Typically, this involves an auxiliary qubit in a specific state. Clifford angles that are odd multiples of \(\frac{\pi}{2}\) can be performed with an auxiliary qubit in \(|0\rangle\) like so:

../../_images/clifford_PPM.png

We use the color coding from [5], where orange boxes correspond to Clifford gates, gray boxes to Pauli operators (note that \(\exp\left(-i \tfrac{(2k+1)\pi}{2}P\right) \propto P\)), green boxes to non-Clifford gates, and blue boxes to measurements. Non-Clifford PPRs can be realized using a magic resource state in the following way:

../../_images/non_clifford_PPM.png

Here, we injected a magic state \(T|+\rangle = \tfrac{1}{\sqrt{2}} \left(|0\rangle + e^{-i \tfrac{1}{4}} |1\rangle\right)\) that was produced separately via magic state distillation. Note that Pauli operations that have angles that are multiples of \(\pi\) do not need to be executed on hardware, but can be tracked in software. In addition, we stress that there are different circuit identities to realize PPRs via PPMs. Here, we showed just the basic examples from [5]. For our purposes here it suffices to note that realizing PPRs via PPMs is possible, so the only thing left to show is how to perform arbitrary PPMs using lattice surgery.

Single-qubit measurements

Before we get to the meat of performing arbitrary PPMs with lattice surgery, let us recall how to perform single-qubit measurements (and thus single-qubit gates). In the orientation we previously used, logical operators \(Z_L\) and \(X_L\) of the logical qubit are defined by a horizontal line of \(Z\) and vertical line of \(X\) measurements on the data qubits:

../../_images/logical_X_Z.png

Note that these are not unique, but rather examples of the topological equivalence class of connected lines between the two Z and X edges, respectively. Any such operator represents the logical operators \(Z_L\) and \(X_L\). In particular, the edges also correspond to the logical operators, which leads to the somewhat confusing scenario where the edge with Z arches is called an X edge, and vice versa.

Because we only care about the homology of the measurement (i.e., that it in the same equivalence class of the corresponding X and Z edges), this is also called a homological measurement. It does not really matter which operator of the equivalence class we measure. We have access to any of them without extra effort because they are related to each other via stabilizer measurements, which we perform anyway during the continually performed error correction cycles. So for the following, we will just consider those that are convenient for illustrational purposes.

An important feature of the logical operators is that they are not stabilizers, but commute with all stabilizers to ensure that the logical operator does not move the state out of the code space (\(O_L S |\psi\rangle_L = S O_L |\psi\rangle_L\)). The commutation can be seen from the fact that the logical operator only ever overlaps with an even multiple of X or Z operators, and thus commutes with any other stabilizer.

We also note that the logical \(Y_L\) measurement is a topic on its own. In principle, one could measure \(Y_L\) by simultaneously measuring the logical \(X_L\) and \(Z_L\) with a physical \(Y\) measurement on the intersecting data qubit. However, this is not a properly defined logical operator anymore as it does not commute with the stabilizers, and thus moves the qubit out of the code space. Measuring (and applying, it’s the same really) logical \(Y_L\) operators is still possible, just a little more complicated as we will show further below.

Arbitrary Pauli product measurements via lattice merging and splitting

We now want to show how to perform the two fundamental operations of measuring \(Z_L \otimes Z_L\) and \(X_L \otimes X_L\) between two surface code qubits via lattice surgery. The operation is fairly simple in principle: merge the two patches, and split them again. We just need to make sure that the qubits are connected along the corresponding edges.

In particular, for measuring \(X_L \otimes X_L\), we merge and split two qubits on their X edges. For simplicity, let us assume that the two qubits are already facing each other on their X edges with a column of unused data qubits separating them. In principle we can have a larger area separating them, we just need to be able to make the boundaries match. The lattice merging is started by preparing the intermediate data qubits in \(|0\rangle\).

../../_images/XX1.png

The actual merging is then done simply by including the intermediate X and Z stabilizers in the error correction cycles.

../../_images/XX2.png

Conveniently, the product of all stabilizers between the two logical \(X_L\) operators, indicated by the red dots below, corresponds to the eigenvalue of \(X_L \otimes X_L\).

../../_images/XX3.png

Now that we retrieved our measurement result \(X_L \otimes X_L\), we want to restore the two qubits, which is achieved by lattice splitting. This, on the other hand, is done by measuring the intermediate data qubits in the Z basis.

../../_images/XX4.png

In case the green Z measurement in the middle yields a negative sign, we need to assign it to one of the two logical \(Z_L\) operators, on top of the product of the sign of the original two \(Z_L\) operators we originally started from.

Measuring \(Z_L \otimes Z_L\) works in the same fashion, but with reversed roles: We connect the Z edges with each other, initialize in \(|+\rangle\) to merge, and measure in \(X\) to split again:

../../_images/ZZ.png

The rules for arbitrary products like, e.g., \(X_L \otimes Z_L\) are relatively simple: Merge and split the qubit patches on the corresponding edges and keep track of any signs you pick up on the way. The same goes for measuring more than two operators (see, e.g., Figure 41 in [5] for an example of measuring \(Y_L \otimes X_L \otimes Z_L \otimes X_L\)). Note that we can also rotate patches to get the correct orientation, as we will see below.

Y measurements

At this point we can measure arbitrary \(X_L\) and \(Z_L\) Pauli product measurements. The last missing ingredient for universality is measuring \(Y_L\) operators.

Introducing discontinuous operations on the surface code does not exclude the usage of continuous transformations of the code. In particular, we can always extend a qubit to a larger surface or move the edges of it. These are important operations if we want to include logical \(Y_L\) measurements.

The operations are very similar to the merging and splitting operations. To extend a qubit patch along its Z edge, we initialize the neighboring data qubits in \(|0\rangle\)

../../_images/extend1.png

and perform \(d\) cycles of error correction in this configuration.

../../_images/extend2.png

To remove part of the extended patch again, we perform \(Z\) measurements on the data qubits, effectively moving the qubit one patch size to the right:

../../_images/extend3.png

Recall from earlier that green and red lines merely indicate representatives of the logical \(Z_L\) and \(X_L\) operators, so moving the red line to the right is free within the error correction cycles.

Extending the qubit along the X edge works similarly, but moving vertically, initializing in \(|+\rangle\) and measuring \(X\) on the data qubits.

We can also move (or rotate?) the type of the edges within \(d\) error correction code cycles. This makes most sense on an already extended qubit because this way we do not change the code distance. As we can see, the bulk of the qubit is untouched and all that is changed is the set of stabilizers we measure on the boundaries (for \(d\) code cycles to take effect).

../../_images/corner_moving.png

Here we show an extended single-qubit patch and three example re-orientations of the type of edges. The smaller images are guides to the eye to indicate the settings, with X edges as solid lines and Z edges as dashed lines (i.e. the same as the logical measurements moved to the edges). Note that the important property is for neighboring X and Z edges to overlap on two data qubits for the corresponding stabilizers to commute. This is why the right patches introduce the triangle-shaped stabilizers of three \(Z\) operators.

Finally, to measure $Y$ we perform the following procedure:

../../_images/y_measurement.png

Here, one extends and orients a qubit such that it has both \(X\) and \(Z\) edges on the same side. At the same time, an auxiliary qubit is initialized in \(|0\rangle\) parallel to our extended qubit. This is intentionally done such that there is a mismatch between the boundary stabilizers which introduces a so-called twist defect, highlighted in purple. When we perform lattice merging between the two qubits, we obtain new stabilizers, some of which are mixed Z and X! This is because they still need to commute with all other stabilizers. That this is indeed the case can be shown by checking that \([ZZ, XY] = [XX, YZ,] = [XZ, ZX] = 0\) on top of the previously discussed \([XX, ZZ] = 0\):

../../_images/twist_boundaries.png

Some of the new stabilizers are trivial in the sense that they are simply the product of the already-measured stabilizers from each of the qubits. The non-trivial new ones are highlighted in red and correspond to the measurement of \(Y \otimes Z\) of the joint state \(|\psi\rangle \otimes |0\rangle\) between the qubit and the auxiliary qubit in \(|0\rangle\), effectively measuring \(\langle Y \rangle = \langle \psi | Y |\psi \rangle = \langle \psi 0 | Y \otimes Z |\psi 0 \rangle\). A more intuitive way to view this is that we simultaneously measured the X and Z edge of our extended qubit, yielding the \(Y \propto X Z\) measurement (modulo some global phase). This is exactly the perspective in the game of surface codes [5].

Measuring \(Y_L\) inside a Pauli product measurement, e.g. \(Y_L \otimes Z_L\) works in the same fashion as above with lattice merging and splitting while making sure a twist defect is introduced. This corresponds to having the first qubit facing the other with both X and Z edges.

More details on twist-based lattice surgery can be found in [7].

Conclusion

Lattice surgery is enabling error-corrected quantum computing on planar codes with local connectivity as it allows for non-transversal gates. We introduced its basics exemplified on the surface code and by realizing arbitrary Pauli product measurements. These are performed by merging and splitting qubits in such a way that the logical operators “topologically” align. In this process of merging and splitting, we only ever change which stabilizers we measure, but we never perform a strict projective measurement of the logical operator. In a sense, we are reading out parity information from the stabilizer measurements in a non-perturbative way. The parity on the other hand provides us only with the topological information of what the logical string is connecting, which is why this process is called homological measurement.

Note that the introduction of the higher weight twist-defect stabilizer with 5 Pauli operators breaks the nearest-neighbor connectivity the surface code requires. This leads to deeper physical CNOT circuits for syndrome extraction, and thus leads to a higher error probability. This is why twist-free alternatives are being proposed at higher resource costs (time or space) [6].

References

[1] (1,2)

Austin G. Fowler, Matteo Mariantoni, John M. Martinis, Andrew N. Cleland, “Surface codes: Towards practical large-scale quantum computation”, arXiv:1208.0928, 2012

[2]

Robert Raussendorf, Jim Harrington, Kovid Goyal, “Topological fault-tolerance in cluster state quantum computation”, arXiv:quant-ph/0703143, 2007

[3] (1,2)

Dominic Horsman, Austin G. Fowler, Simon Devitt, Rodney Van Meter, “Surface code quantum computing by lattice surgery”, arXiv:1111.4022, 2011

[4]

Austin G. Fowler, Craig Gidney “Low overhead quantum computation using lattice surgery” arXiv:1808.06709, 2018.

[5] (1,2,3,4,5,6)

Daniel Litinski “A Game of Surface Codes: Large-Scale Quantum Computing with Lattice Surgery” arXiv:1808.02892, 2018.

[6] (1,2)

Christopher Chamberland, Earl T. Campbell “Universal quantum computing with twist-free and temporally encoded lattice surgery”, arXiv:2109.02746, 2021

[7]

Daniel Litinski, Felix von Oppen “Lattice Surgery with a Twist: Simplifying Clifford Gates of Surface Codes”, arXiv:1709.02318, 2017

About the author

Korbinian Kottmann
Korbinian Kottmann

Korbinian Kottmann

Quantum compilation & open source software

Share demo

Ask a question on the forum

Related Demos

A Game of Surface Codes: Large-Scale Quantum Computing with Lattice Surgery

Modeling the toric code on a quantum computer

Stabilizer codes for quantum error correction

Measurement-based quantum computation

How to optimize a QML model using JAX and Optax

How to optimize a QML model using JAX and JAXopt

Estimating observables with classical shadows in the Pauli basis

Loom x Catalyst: designing, orchestrating, and automating quantum error correction experiments

Quantum gradients with backpropagation

How to optimize a QML model using Catalyst and quantum just-in-time (QJIT) compilation

PennyLane

PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Built by researchers, for research. Created with ❤️ by Xanadu.

Research

  • Research
  • Performance
  • Hardware & Simulators
  • Demos
  • Quantum Compilation
  • Quantum Datasets

Education

  • Teach
  • Learn
  • Codebook
  • Coding Challenges
  • Videos
  • Glossary

Software

  • Install PennyLane
  • Features
  • Documentation
  • Catalyst Compilation Docs
  • Development Guide
  • API
  • GitHub
Stay updated with our newsletter

© Copyright 2025 | Xanadu | All rights reserved

TensorFlow, the TensorFlow logo and any related marks are trademarks of Google Inc.

Privacy Policy|Terms of Service|Cookie Policy|Code of Conduct