- Demos/
- Quantum Computing/
Intoducing lattice surgery
Intoducing lattice surgery
Published: October 27, 2025. Last updated: October 27, 2025.
Lattice surgery is a way to fault-tolerantly perform operations on two-dimensional topological QEC codes such as the surface code. These concepts can be generalized to other codes such as color codes or folded surface codes. In this demo we are going to introduce the basic operations in lattice surgery and see how they enable fault tolerant quantum computing on the surface code. We note that some of these routines may already be superseded by more efficient alternatives, but shall suffice for the educational purpose of this demo.
Surface code quantum computing
Topological quantum error correction codes like the surface code [1] protect quantum information of 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:
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 (not shown here, see below). These extra qubits are sometimes called measurement qubits or syndrome qubits and the measurement is performed by entangling the data qubits with the syndrome qubit and measuring it in the corresponding basis (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 noisy (Clifford + T) gates.
One such \(d \times d\) patch represents a logical qubit. An important feature is that it has two X and two Z edges, as this enables the error-corrected encoding of the qubit (more on logical operators 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:
This is called a transversal operation, which is problematic as it requires non-local physical connections between data qubits. Most quantum hardware architectures only allow for nearest neighbor interactions, and thus do not allow for transversal gate operations. Instead, we want to perform CNOT gates non-transversally. 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, as it has been shown to enable error-corrected logical operations with significantly lower space resources with 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, and, in particular, CNOT gates. Further, we need to be able to reliably inject states to enable magic state injection. This is a bottom-up way to show that lattice surgery enables universal quantum computing and done so 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
for arbitrary Pauli words \(P\)
with Clifford and non-Clifford angles \(\theta \in \{k \tfrac{\pi}{4} | k \in \mathbb{Z} \}\) cover 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 need to show 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:
We use the color coding from [5], where orange boxes correspond to Clifford gates, gray boxes to Pauli operators (as \(e^{-i \tfrac{(2k+1)\pi}{2}P} \propto P\)), and green boxes to non-Clifford gates. Non-clifford PPRs can be realized using a magic resource state like so:
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. Further, we stress that there are different circuit identities to realize PPRs via PPMs, with the ones shown here just the basic examples taken 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 recal how to perform single qubit measurements (and thus single qubit gates). 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 like so:
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\). Because we only care about the homology of the measurement (i.e., that it connects the two kinds of edges), which is why this is also called homological measurement. It does not really matter which operator of the equivalence class we measure, and in principle we have access to any of them without extra effort because they are related to each other via stabilizer measurements, which we anyway perform 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. Stabilizers are topologically trivial (loops), whereas logical operators are topologically non-trivial (cycles). This differentiation is only possible due to the distinctive Z and X boundaries, which enable the definition of the logical operators without being stabilizers themselves.
We also note that 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, same 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 facing each other with the correct edges, and use the correct state preparation and measurements for the merging and splitting operations, respectively.
Let us walk through the process of measuring \(X_L \otimes X_L\) first. Assuming we already have the two qubits facing each other with their smooth Z edges, we can start by preparing the intermediate data qubits in \(|0\rangle\).
Note that here we left just a single column of data qubits between the two patches, but in principle we can have a larger area, as long as we can make the boundaries match. The actual merging is then done by simply by including the intermediate X and Z stabilizers in the error correction cycles.
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\). In case any of the two \(X_L\) operators were carrying a sign, we need to make sure to include those in the product.
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.
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 face rough X edges towards each other, initialize in \(|+\rangle\) to merge and measure in \(X\) to split again:
measurements\(Y_L\) measurements
Introducing discontinuous operations on the surface code does not exclude that we can still use the 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 on the smooth Z edge, we initialize the neighboring data qubits in \(|0\rangle\)
and perform \(d\) cycles of error correction:
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:
(Recall from earlier that green and red lines mreely indicate representatives of the logical \(Z_L\) and \(X_L\) operators, so moving the red line to the right is free with the error correction cycles)
Extending the qubit on the rough \(X\) edge works similarly, but moving vertically, initializing in \(|+\rangle\) and measuing \(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.
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 dotted lines.
import pennylane as qml
Universal Gate set in the surface code using lattice surgery
asd
text
Conclusion
text
References
Disclaimer
This demo is a Frankenstein of the two seminal papers on surface code quantum computing [1] and [3]. First two sections follow closely the intro sections of reference [1], and the final section is inspired by [3].
About the author
Korbinian Kottmann
Quantum simulation & open source software
Total running time of the script: (0 minutes 0.009 seconds)