## Abstract

Topological error correction codes are promising candidates to protect quantum computations from the deteriorating effects of noise. While some codes provide high noise thresholds suitable for robust quantum memories, others allow straightforward gate implementation needed for data processing. To exploit the particular advantages of different topological codes for fault-tolerant quantum computation, it is necessary to be able to switch between them. Here we propose a practical solution, subsystem lattice surgery, which requires only two-body nearest-neighbor interactions in a fixed layout in addition to the indispensable error correction. This method can be used for the fault-tolerant transfer of quantum information between arbitrary topological subsystem codes in two dimensions and beyond. In particular, it can be employed to create a simple interface, a quantum bus, between noise resilient surface code memories and flexible color code processors.

## Introduction

Noise and decoherence can be considered as the major obstacles for large-scale quantum information processing. These problems can be overcome by fault-tolerant quantum computation^{1,2}, which holds the promise of protecting a quantum computer from decoherence for arbitrarily long times, provided the noise is below a certain threshold. Quantum error correction codes are indispensable for any fault-tolerant quantum computation scheme^{3}. Among these, stabilizer codes^{4}, building on classical coding theory, admit a particularly compact description. In particular, the subclass of topological stabilizer codes (TSCs)^{5} is promising since TSCs are scalable and permit a local description on regular *D*-dimensional lattices.

Two of the most prominent examples of TSCs in two dimensions are surface codes^{6,7} and color codes^{8}. While surface codes support adaption to biased noise^{9} and have better error thresholds than comparable color codes^{10}, they do not support a transversal phase gate. However, transversality is essential for any encoded quantum logic gate since it guarantees a straightforward implementation within a quantum error correction code. Gauge color codes, for example, were recently shown to support the transversal implementation of a universal set of gates in a three-dimensional (3D) layout^{11}. It is hence desirable to store quantum information in surface code quantum memories while performing computation on color codes in two (and three) dimensions^{12}.

Here we present a protocol that makes such hybrid computational architectures viable. We develop a simple, fault-tolerant conversion scheme between two-dimensional (2D) surface and color codes of arbitrary size. Our flexible algorithm for code switching is based on a formalization of lattice surgery^{13,14} in terms of operator quantum error correction^{15} and measurement-based quantum computation^{16}. This introduces the notion of subsystem lattice surgery (SLS), a procedure that can be understood as initializing and gauge fixing a single subsystem code. The required operations act locally on the boundaries, preserve the 2D structure, and are generators of a topological code. As all generators of the resulting code have constant size, errors on any of their components only affect a constant number of qubits, making the protocol inherently fault-tolerant. As we explicitly show, this generalizes the methodology of lattice surgery to any combination of 2D topological subsystem stabilizer codes, with color-to-surface code switching as an example of particular interest. While we restrict ourselves to 2D topological codes for the better part of this paper, we show that the essential ingredients of SLS carry over to higher-dimensional codes. In fact, the procedure works even for non-topological codes at the expense of locality. Therefore, our results represent a significant step toward a fault-tolerant interface between robust quantum memories and versatile quantum processors, independently of which topological codes will ultimately prove to be most effective. The method proposed here hence has the prospect of connecting different components of a future quantum computer in an elegant, practical, and simple fashion.

## Results

### Stabilizer formalism

We consider a system comprised of *n* qubits with Hilbert space $\mathcal{H}={\left({\mathbb{C}}^{2}\right)}^{\otimes n}$. The group of Pauli operators ${\mathcal{P}}_{n}$ on $\mathcal{H}$ is generated under multiplication by *n* independent Pauli operators and the imaginary unit *i*. We write ${\mathcal{P}}_{n}=\u27e8i,{X}_{1},{Z}_{1},...,{X}_{n},{Z}_{n}\u27e9,$ where *X*_{
j
}, *Z*_{
j
} are single-qubit Pauli operators acting on qubit *j*. An element $P\in {\mathcal{P}}_{n}$ has weight *w*(*P*) if it acts nontrivially on *w* qubits. We define the stabilizer group $\mathcal{S}=\u27e8{S}_{1},...,{S}_{s}\u27e9$ for *s* ≤ *n* as an Abelian subgroup of ${\mathcal{P}}_{n}$ such that the generators *S*_{
i
} are independent operators ∀*i* = 1, ..., *s* and $-\mathbb{1}\phantom{\rule{0.3em}{0ex}}\notin \phantom{\rule{0.3em}{0ex}}\mathcal{S}$. $\mathcal{S}$ defines a 2^{k}-dimensional codespace $\mathcal{C}=\mathrm{span}\left(\left\{\u2223\psi \u27e9\right\}\right)$ of codewords $\u2223\psi \u27e9\in \mathcal{H}$ through the condition $S\u2223\psi \u27e9=\u2223\psi \u27e9\phantom{\rule{0.3em}{0ex}}\forall S\in \mathcal{S}$, encoding *k* = *n* − *s* qubits. We denote the normalizer of $\mathcal{S}$ by $N\left(\mathcal{S}\right)$, which here is the subgroup of ${\mathcal{P}}_{n}$ that commutes with all elements of $\mathcal{S}$. That is, elements of $N\left(\mathcal{S}\right)$ map the codespace to itself. We write $\mathcal{L}=N\left(\mathcal{S}\right)\mathrm{\u2215}\mathcal{S}$ for the (quotient) group of logical operators which induces a tensor product structure on $\mathcal{C}$, i.e., $\mathcal{C}={\otimes}_{i=1}^{k}{\mathcal{H}}_{i}$. This construction implies that different logical Pauli operators are distinct, non-trivial classes of operators with an equivalence relation given by multiplication of stabilizers.

The distance of an error correction code is the smallest weight of an error $E\in {\mathcal{P}}_{n}$ such that *E* is undetectable. The code can correct any set of errors $\mathcal{E}={\left\{{E}_{a}\right\}}_{a}$ iff ${E}_{a}{E}_{b}\notin N\left(\mathcal{S}\right)-\u27e8i\u27e9\mathcal{S}$$\forall {E}_{a},{E}_{b}\in \mathcal{E}$. A stabilizer code defined through $\mathcal{S}$ has distance *d* iff $N\left(\mathcal{S}\right)-\u27e8i\u27e9\mathcal{S}$ contains no elements of weight less than *d*. Equivalently, any non-trivial element of $\mathcal{L}$ is supported on at least *d* qubits. By the above error-correction condition, an error with weight at most (*d*−1)/2 can be corrected while an error *E* with weight *d*/2 ≤ *w*(*E*) < *d* can only be detected. From a slightly different perspective, codewords are degenerate ground states of the Hamiltonian $H=-{\sum}_{i=1}^{s}{S}_{i}$. Adopting this viewpoint, correctable errors are local excitations in the eigenspace of *H* since they anticommute with at least one generator ${S}_{i}\in \mathcal{S}$, while logical operators map the degenerate ground space of *H* to itself.

### Subsystem stabilizer formalism

A subsystem structure can be induced on stabilizer codes by considering non-Abelian gauge symmetries^{15}. The group of gauge transformations is defined as $\mathcal{G}={\mathcal{L}}_{\mathrm{G}}\times \mathcal{S}\times \u27e8i\u27e9$ where $\mathcal{S}$ is a stabilizer group and ${\mathcal{L}}_{\mathrm{G}}$ is the group of operators in $N\left(\mathcal{S}\right)-\u27e8i\u27e9\mathcal{S}$ that are not in a non-trivial class of $\mathcal{L}=N\left(\mathcal{S}\right)\mathrm{\u2215}\mathcal{G}$. This imposes a subsystem structure on the codespace $\mathcal{C}={\mathcal{H}}_{\mathrm{L}}\otimes {\mathcal{H}}_{\mathrm{G}}$ where all operators in $\mathcal{G}$ act trivially on the logical subspace ${\mathcal{H}}_{\mathrm{L}}$^{17}. While logical operators in $\mathcal{L}$ define logical qubits in ${\mathcal{H}}_{\mathrm{L}}$, operators in ${\mathcal{L}}_{\mathrm{G}}$ define so-called gauge qubits in ${\mathcal{H}}_{\mathrm{G}}$. That is, operations in $\mathcal{L}$ and ${\mathcal{L}}_{\mathrm{G}}$ both come in pairs of (encoded) Pauli *X* and *Z* operators for each logical and gauge qubit, respectively. We recover the stabilizer formalism if $\mathcal{G}$ is Abelian, i.e., ${\mathcal{L}}_{\mathrm{G}}=\varnothing $. As before, a set of errors $\mathcal{E}={\left\{{E}_{a}\right\}}_{a}$ is correctable iff ${E}_{a}{E}_{b}\notin N\left(\mathcal{S}\right)-\mathcal{G}$$\forall {E}_{a},{E}_{b}\in \mathcal{E}$. Errors can again be considered as local excitations in the eigenspace of a Hamiltonian $H=-{\sum}_{i=1}^{g}{G}_{i},$ where *g* is the number of generators ${G}_{i}\in \mathcal{G}$.

### Topological stabilizer codes

Stabilizer codes $\mathcal{S}$ are called topological if generators ${S}_{i}\in \mathcal{S}$ have local support on a *D*-dimensional lattice. Here we focus on 2D rectangular lattices Λ = [1, *L*] × [$1$, *L*′] with linear dimensions *L* and *L*′ in the horizontal and vertical direction, respectively, where qubits are located on vertices (not necessarily all are occupied) but our discussion can be easily extended to arbitrary regular lattices. We call a generator ${S}_{i}\in \mathcal{S}$ local^{5} if it has support within a square containing at most *r*^{2} vertices for some constant *r*, called interaction range or diameter. Moreover, we require of a TSC that its distance *d* can be made arbitrarily large by increasing the lattice size. In other words, the generators *S*_{
i
} are not only local but also translationally invariant at a suitable scale^{18}. This definition of TSCs can be extended straightforwardly to topological subsystem stabilizer codes (TSSCs)^{19} where we impose locality on the generators of $\mathcal{G}$ instead of $\mathcal{S}$. Then, generators of $\mathcal{S}$ are not necessarily local.

### Logical string operators

An intriguing feature of 2D topological codes is that logical operators can be interpreted as moving point-like excitations around the lattice, i.e. logical operators form strings across the lattice. Specifically, for any 2D TSC or TSSC on a lattice with open boundaries there exists a quasi-1D string of tensor products of Pauli operators generating a logical Pauli operator whose support can be covered by a rectangle of size *r* × *L*′^{5}, i.e., a vertical strip of width at most *r*. If $\mathcal{S}$ obeys the locality condition, logical operators can be implemented row-by-row by applying Pauli operations along paths connecting two boundaries such that excitations emerge only at its endpoints. If $\mathcal{S}$ is not local, excitations might also emerge elsewhere since logical operators can anticommute with generators that act nontrivially on gauge qubits. Due to the translational invariance of generators with respect to the underlying lattice, one can always increase the code distance or choose the lattice such that there exists a logical Pauli operator whose support is covered by a vertical strip of maximal width *r* along the boundary (or at most a constant number of lattice sites away from it).

Since it is a general feature of topological codes to support logical string operators^{5}, we can generalize the method of lattice surgery^{13,14} to such codes. To this end, we consider any two TSCs or TSSCs ${\mathcal{G}}^{\mathrm{A}}$ and ${\mathcal{G}}^{\mathrm{B}}$ on two 2D lattices, e.g., Λ_{A} = [1, *L*_{A}]^{2} and Λ_{B} = [1, *L*_{B}]^{2}, with open boundaries that have distances *d*_{A} and *d*_{B}, respectively. We place the lattices such that their vertical boundaries are aligned. Let ${P}_{\mathrm{L}}^{\mathrm{A}}\in {\mathcal{L}}^{\mathrm{A}}$ and ${P}_{\mathrm{L}}^{\mathrm{B}}\in {\mathcal{L}}^{\mathrm{B}}$ be two logical operators defined along the aligned boundaries with maximal width *r*_{A} and *r*_{B}, respectively, where *r*_{
I
} is the interaction range of code *I* = A, B. The logical operators act nontrivially on a set of qubits, say *Q*_{A} and *Q*_{B}, respectively. Let *N*_{
I
} = $\u2223{Q}_{I}\u2223$ (for *I* = A, B) and *N* = max{*N*_{A}, *N*_{B}}. W.l.o.g. we assume *N*_{A} = *N*. We order the sets *Q*_{
I
} according to walks along paths^{5} on Λ_{
I
} running, e.g., from top to bottom such that we can implement ${P}_{\mathrm{L}}^{I}$ in a step-by-step fashion as described above. We write *Q*_{
I
} = {1, 2, ..., *N*_{
I
}} for such an ordering. For ease of notation, we denote qubits in the support of ${P}_{\mathrm{L}}^{I}$ by *i* = 1, ..., *N*_{
I
} since the association of qubits to the sets *Q*_{
I
} is clear from the context. Consequently, the logical operators take the form

for single-qubit Pauli operators ${P}_{\mathrm{L},i}^{I}$ acting on qubits *i* with *i* = 1, ..., *N*_{
I
}.

### Merging protocol and code splitting

Given the two codes ${\mathcal{G}}^{\mathrm{A}}$ and ${\mathcal{G}}^{\mathrm{B}}$ with respective logical Pauli operators ${P}_{\mathrm{L}}^{\mathrm{A}}$ and ${P}_{\mathrm{L}}^{\mathrm{B}}$ along boundaries, the goal is to achieve a mapping ${\mathcal{G}}^{\mathrm{A}}\times {\mathcal{G}}^{\mathrm{B}}\mapsto {\mathcal{G}}^{\mathrm{A}}\times {\mathcal{G}}^{\mathrm{B}}\times \u27e8{P}_{\mathrm{L}}^{\mathrm{A}}\otimes {P}_{\mathrm{L}}^{\mathrm{B}}\u27e9$ that projects onto an eigenstate of ${P}_{\mathrm{L}}^{\mathrm{A}}\otimes {P}_{\mathrm{L}}^{\mathrm{B}}$ (i.e., a Bell state). Therefore, we now define a fault-tolerant protocol that merges the two codes into one, similar to the method of lattice surgery, which has been developed for surface codes^{13} and extended to color codes^{14}. As we will see, the merged code can then be split to realize the mapping described above. The merging procedure has the following four steps.

(i) Including ancillas. We introduce a set *Q*_{C} of *N* − 1 ancillas initialized in the +1 eigenstates of their respective Pauli *X* operators. The ancillas are placed on newly added vertices along a column between boundaries (Fig. 1a) and we order the set *Q*_{C} accordingly from top to bottom, i.e., *Q*_{C} = {1, 2, ..., *N* − 1}. More formally, including ancillas in $\u2223+\u27e9$-states is equivalent to adding *N* − 1 single-qubit *X* stabilizers to ${\mathcal{G}}^{\mathrm{A}}\times {\mathcal{G}}^{\mathrm{B}}$. Note that this step is not strictly necessary but it has been included here to highlight the similarity to lattice surgery. Nonetheless, this step is useful if one operates solely on TSCs (rather than TSSCs), since this can allow reducing the interaction range of the resulting merged code (see Methods section for details).

(ii) Preparing lattices. Redundant vertices are added to the lattices Λ_{A} and Λ_{B} without adding corresponding new qubits. This corresponds to a relabeling that increases the interaction range on both lattices and the distance between ancillas by at most a constant *r*^{2}, where *r* = max{*r*_{A}, *r*_{B}}. This is done in such a way that horizontal strips of width (height) *r* contain the same number of qubits in *Q*_{A}, *Q*_{B}, and *Q*_{C} (Fig. 1b). Beyond the strip containing the last element of *Q*_{B} we only require the same number of qubits in *Q*_{A} and *Q*_{C}, except for the last strip, where *Q*_{C} contains one qubit less than *Q*_{A}. The lattices are then connected along their vertical boundary such that the resulting merged lattice Λ_{M} has linear dimension *L*_{A} + *L*_{B} + 1 along the horizontal direction. This step guarantees that the merged code remains topological according to the definition above. If a different definition of locality is adopted for topological codes, step (ii) can be replaced by a stretching of the lattices to ensure that the merged code is topological in the same sense as well.

(iii) Merging codes. After combining the underlying lattices, the codes are merged. To this end, one measures *N* merging operators, which are defined on the new lattice Λ_{M} as

where ${Z}_{i}^{\mathrm{C}}$ acts on ancilla *i* with *Z*_{0} ≡ $\mathbb{1}$ and *Z*_{
N
} ≡ $\mathbb{1}$. Since *N*_{A} ≥ *N*_{B}, we identify ${P}_{\mathrm{L},i}^{\mathrm{B}}\equiv \mathbb{1}$ for *i* > *N*_{B}.

(iv) Correcting errors. In order to retain full fault tolerance, *d*_{min} = min{*d*_{A}, *d*_{B}} rounds of error correction are required on the merged code. For this purpose, the structure of the merged code can be deduced from the SLS formalism that is introduced and analyzed in Methods section.

We now formulate the following theorem.

**Theorem 1.** For any two TSCs (or TSSCs) defined on regular 2D lattices with open boundaries, the procedure described in steps (i)–(iv) fault-tolerantly projects onto an eigenstate of ${P}_{\mathrm{L}}^{\mathrm{A}}{P}_{\mathrm{L}}^{\mathrm{B}}$. Moreover, all operations in steps (iii) and (iv) correspond to generators of a TSSC defined on the merged lattice with potentially increased interaction range and distance no less than the minimum distance of the merged codes.

For the proof of Theorem 1, we refer to Methods section, where the required SLS formalism is described in full detail. In this approach, the merged code is effectively treated as a subsystem code and the original codes ${\mathcal{G}}^{\mathrm{A}}$ and ${\mathcal{G}}^{\mathrm{B}}$ are recovered by gauge fixing. Note that in the merged code, some stabilizers at the boundary are merged while others can generate new gauge qubits. More details on the merged code structure in the most general case and in the case of a specific TSSC can be found in the Methods section. After the merging procedure described in steps (i)–(iv), the two individual codes can be recovered by measuring all ancillas in the *X*-basis. In this case the merged code is split and the two logical subspaces are left in a joint eigenstate of their respective Pauli operators. Here it is important to note that error correction has to be performed on the separate codes in order to retain full fault tolerance^{13}. Quantum information can then be teleported from one logical subspace to the other by measurement. This fault-tolerant way of transferring quantum states from one arbitrary TSC (or TSSC) to another provides a simple method that allows exploiting the advantages of different error correction codes. In particular, it can be used to realize an interface between a quantum memory (e.g., based on a surface code) and a quantum processor (using, for example, a color code). We will therefore now demonstrate our protocol for this crucial example of two TSCs.

### Color-to-surface code switching

The archetypical examples for TSCs are surface codes (SC) and color codes (CC). Surface codes^{6} are defined on 2-face-colorable regular lattices with qubits located on vertices. The two colors are identified with *X*- or *Z*-type generators ${S}_{p}^{X},{S}_{p}^{Z}\in {\mathcal{S}}^{\left(\mathrm{SC}\right)}$, respectively, acting as ${S}_{p}^{P}={\prod}_{v\in \mathcal{N}\left(p\right)}{P}_{v}$, where $\mathcal{N}\left(p\right)$ is the set of vertices adjacent to the plaquette *p* and *P* = *X*, *Z* (Fig. 2a). Horizontal and vertical boundaries cut through plaquettes and can be associated with their respective colors. The lattice is constructed such that opposite boundaries are identified with the same color. The number of logical qubits can be obtained by a simple counting argument. It is given by the difference between the number of physical qubits and the number of independent stabilizers. For the SC, the former is equal to the number of vertices *v*, while the latter equals the number of faces *f*. Since *v* − *f* = 1, we find that the SC encodes a single logical qubit. Logical operators for SCs are strings connecting boundaries of the same color that are separated by a boundary of a different color. Note that, for any choice of SC, one such logical operator is guaranteed to be aligned with the chosen (e.g., the vertical) boundary^{5}, but one may not be able to freely choose whether this logical operator is of *Z*- or *X*-type. 2D color codes^{8} are defined on 3-face-colorable regular lattices with qubits located on vertices. The generators of the corresponding stabilizer group ${\mathcal{S}}^{\left(\mathrm{CC}\right)}$ are pairs of operators ${S}_{p}^{X}$ and ${S}_{p}^{Z}$, i.e., two independent stabilizers per plaquette. The lattice is constructed such that we can use three colors to distinguish three types of boundaries and plaquettes. That is, any two adjacent plaquettes have different colors from each other and from their adjacent boundary (Fig. 2). In the CC, the number of physical qubits is equal to the number of vertices, but there are two independent stabilizers for each face. A quick count then reveals that the CC encodes one (*v* − 2*f* = 1) logical qubit. Logical operators for CCs are string operators along the lattice connecting three boundaries of different colors. This implies that there exists a string along the boundary of one type that effectively connects all three boundaries.

As an example for the application of our protocol let us consider the situation shown in Fig. 2a, where the outcome of a quantum computation, encoded in an arbitrary logical state $\u2223{\psi}_{\mathrm{L}}\u27e9=\alpha \u22230\u27e9+\beta \u22231\u27e9$ of a color code, is transferred to a quantum memory based on a surface code initialized in the state $\u2223{+}_{\mathrm{L}}\u27e9$. A circuit representation of this task is shown in Fig. 3. Since both initial codes in Fig. 2a have distance 3, we include two ancillas in the state $\u2223+\u27e9$, as instructed in step (i). Step (ii) of the protocol can be omitted since the lattices in this example already have the desired structure. As laid out in step (iii) and illustrated in Fig. 2b, one then measures joint *Z* stabilizers across the boundary, projecting the two surfaces onto a single, merged surface (M) corresponding to an eigenstate of ${Z}_{\mathrm{L}}^{\left(\mathrm{SC}\right)}{Z}_{\mathrm{L}}^{\left(\mathrm{CC}\right)}$. That is, the merging procedure projects onto a merged code that contains ${Z}_{\mathrm{L}}^{\left(\mathrm{SC}\right)}{Z}_{\mathrm{L}}^{\left(\mathrm{CC}\right)}$ as a stabilizer. The reduced 2D logical subspace can be represented by ${Z}_{\mathrm{L}}^{\left(\mathrm{M}\right)}={Z}_{\mathrm{L}}^{\left(\mathrm{CC}\right)}$ and a merged *X*_{L} operator along both surfaces, e.g., ${X}_{\mathrm{L}}^{\left(\mathrm{M}\right)}={X}^{\left(\mathrm{SC}\right)}\otimes {X}^{\left(\mathrm{CC}\right)}$. Since both color and surface codes are TSCs, the merged code can be understood as a TSC (as opposed to a TSSC) and merging operators coincide with merging stabilizers. Then, as instructed in Fig. 2b, *X*-type stabilizers have to be extended onto ancillas while *Z* stabilizers remain unaffected. For details on the distinction between TSSCs and TSCs, we refer to the SLS formalism introduced in the Methods. Having obtained this merged code of distance 3, three consecutive rounds of error correction ensure fault tolerance as suggested in step (iv). Note that the merging procedure increases the bias toward *X*-type errors since the minimum weight of logical *X* operators is increased. However, note that increasing the weight (and interaction range) of *X* stabilizers on the boundary can cause a temporarily worse error correction performance w.r.t. *Z* errors for the merged code than for the individual codes.

Irrespective of this we can then proceed by splitting the codes. To this end, we simply measure ancillas in the *X*-basis, while refraining from further measurement of the merging stabilizers. This procedure projects onto the separate surfaces while entangling the logical subspaces. After another three rounds of error correction to preserve fault tolerance, measuring ${X}_{\mathrm{L}}^{\left(\mathrm{CC}\right)}$ teleports the information according to the circuit displayed in Fig. 3.

## Discussion

We have introduced the method of subsystem lattice surgery (SLS) as a generalization of lattice surgery^{13,14} to any pair of 2D topological codes, exploiting their similarities^{20}. The applicability of our algorithm to all topological codes such that all topological features are preserved arises from their property to support logical string operators on the boundary^{5}. Therefore, the relevance of our algorithm remains unchanged even if other topological codes, such as the subsystem surface code^{21} (see also the Methods section) or Bacon-Shor code^{22,23,24}, are used as quantum memories or processors. Indeed, our method can even be generalized beyond 2D topological codes at the expense of the 2D layout or topological features (see Methods section for details).

In contrast to the method of code deformation^{18,25,26}, where a single underlying lattice is smoothly deformed everywhere through multiple rounds of local Clifford transformations, we combine two initially separate lattices through operations within constant distance of their boundaries. To the best of our knowledge, other established methods for code conversion^{27,28,29} have either been applied solely to specific codes, or have not been generalized to subsystem codes.

To highlight the usefulness of incorporating SLS into future quantum computers, let us briefly assess the current contenders for fault-tolerant quantum computation. At present, one of the most promising techniques is SC quantum computation supplemented by magic state injection^{30} in order to promote it to a universal quantum computer. However, the overhead on magic state distillation is large^{6,7} and it is expected that more effort will be directed towards identifying more resource-efficient techniques. At the same time, other approaches to universal fault-tolerant quantum computation are significantly constrained by no-go theorems that prohibit a universal set of transversal gates in a single stabilizer code^{31} and transversal non-Clifford gates in 2D topological codes^{32,33}. The former no-go theorem can be circumvented by gauge fixing^{11,34} or (subsystem) lattice surgery, and is hence no issue for our approach. The latter no-go theorem can be avoided in a 3D architecture or non-topological codes^{35,36,37}. One potential replacement for magic state distillation is hence the 3D gauge color code^{11,38} which successfully sidesteps both no-go theorems. Even though the resource requirement is similar to that of quantum computation with the surface code^{38}, 3D topological codes support other useful features such as single-shot error correction^{39}. As we show in the Methods section, SLS can also be employed to switch between codes of different dimensions, as well as between topological and non-topological codes. This facilitates the circumvention of both no-go theorems in an elegant fashion. At this point it should also be pointed out that many non-topological codes supporting transversal non-Clifford gates^{35,36,37} have lower resource requirements than comparable 3D topological codes or magic state distillation. However, while all 2D (and some 3D) TSSCs (including the merged code that appears during SLS) with local stabilizers feature error thresholds^{19,38}, the existence of error thresholds has not been proven for any of the mentioned non-topological codes. That is, in the case of non-topological codes it is not guaranteed that the storage time can be made arbitrarily large by enlarging the code distance. Codes have to be concatenated instead^{4}.

In any of these cases, quantum computers can only be expected to operate as well as their weakest link. Here, this applies to the error correction code used. The clear advantage of SLS in this context is that the weakest link (i.e., code) may be employed on-demand only and can otherwise be avoided. For instance, in a distributed architecture a code for the implementation of, e.g., a non-Clifford operation can be called only when required. In this scenario, SLS is particularly beneficial since non-Clifford operations could also unfavorably transform errors present in the system^{36}, while SLS does not carry such errors to other codes. SLS should thus not be seen as a stand-alone contender with other methods of realizing universal fault-tolerant quantum computation, but rather as a facilitator thereof, allowing to selectively combine and exploit the advantages of other methods. We hence expect lattice surgery to play a crucial role in future quantum computers, be it as an element of a quantum bus or for distributed quantum computing^{29}.

Our findings further motivate experimental efforts to develop architectures that are flexible enough to implement and connect surface and color codes and/or other codes. For instance, ion trap quantum computers^{40} may provide a platform soon capable of performing lattice surgery between two distinct codes. In this endeavor, the inherent flexibility attributed to multizone trap arrays^{41} may be beneficial. Moreover, topological codes and our approach to code switching are obvious choices for fault-tolerant quantum computation with architectures requiring nearest-neighbor interactions in fixed setups, such as superconducting qubits^{42} or nitrogen-vacancy diamond arrays^{43}. However, given the local structure of topological codes and the simplicity of our algorithm, the requirements for any architecture are comparatively low.

Despite the inherent fault tolerance of SLS, the codes on which it is performed are nonetheless subject to errors. Further investigations of error thresholds^{2,19} for (non-)topological codes and bench-marking^{44} are therefore required, in particular with regard to (subsystem) lattice surgery. Finally, our code switching method may find application in the design of adaptive error correction schemes^{45}.

## Methods

### Subsystem lattice surgery

In the main text, we have introduced a subsystem lattice surgery (SLS) protocol that is applicable to arbitrary 2D TSSCs, and we have shown how it can be used to teleport quantum information between surface and color codes. In this Methods section, we explain how lattice surgery can be understood entirely within the subsystem stabilizer formalism. To this end, we define SLS by the fault-tolerant mapping ${\mathcal{G}}^{\mathrm{A}}\times {\mathcal{G}}^{\mathrm{B}}\mapsto {\mathcal{G}}^{\mathrm{A}}\times {\mathcal{G}}^{\mathrm{B}}\times \u27e8{P}_{\mathrm{L}}^{\mathrm{A}}\otimes {P}_{\mathrm{L}}^{\mathrm{B}}\u27e9$, where the merging procedure as described in steps (i)–(iv) and formalized in Theorem 1 is an initialization of an intermediate, merged code ${\mathcal{G}}^{\mathrm{M}}$ and the splitting fixes gauge degrees-of-freedom to obtain ${\mathcal{G}}^{\mathrm{A}}\times {\mathcal{G}}^{\mathrm{B}}\times \u27e8{P}_{\mathrm{L}}^{\mathrm{A}}\otimes {P}_{\mathrm{L}}^{\mathrm{B}}\u27e9$ from ${\mathcal{G}}^{\mathrm{M}}$.

To see this, we again consider two “standard” TSSCs, ${\mathcal{G}}^{\mathrm{A}}$ and ${\mathcal{G}}^{\mathrm{B}}$. Note that we thereby exclude certain pathological “exotic” codes as will be explained in the proof of Lemma 1. Adopting the previous notation, we assume that the lattices have been chosen such that the logical operators ${P}_{\mathrm{L}}^{I}$ (*I* = A, B) along their boundaries have support on *N*_{A} and *N*_{B} qubits, respectively. For ease of presentation we further choose *N*_{A} = *N*_{B} = *N*. Now, let ${\mathcal{G}}^{I}$ with *I* = A, B be codes characterized by the tuples [[*n*_{
I
}, *k*_{
I
}, *g*_{
I
}, *d*_{
I
}]], where *n*_{
I
} are the numbers of physical qubits, *k*_{
I
} the numbers of logical qubits, *g*_{
I
} the numbers of gauge qubits, and *d*_{
I
} are the distances, respectively. We choose the generating set $\left\{{G}_{1}^{I},...,{G}_{{s}_{I}+2{g}_{I}}^{I}\right\}$ for code ${\mathcal{G}}^{I}$, where *s*_{
I
} = *n*_{
I
} − *k*_{
I
} − *g*_{
I
} is the number of independent stabilizer generators (or the number of stabilizer qubits in accordance with our previous terminology). The lattices are then aligned and prepared as in step (ii) of the algorithm described in the main text, but we omit including ancillas for now. We proceed by defining the merging operators

on the merged lattice Λ_{M}. From these merging operators, we then collect Δ*g* ≤ *N* − 1 (where the meaning of this notation becomes apparent in the following section) inequivalent ones (w.r.t. ${\mathcal{G}}^{\mathrm{A}}\times {\mathcal{G}}^{\mathrm{B}}\times \u27e8{P}_{\mathrm{L}}^{\mathrm{A}}\otimes {P}_{\mathrm{L}}^{\mathrm{B}}\u27e9$) in the set $\mathcal{W}={\left\{{G}_{i}^{\mathrm{M}}\right\}}_{i=1,...,\Delta g}$, and call the group generated by these operators $\mathcal{M}$. We refer to elements of $\mathcal{W}$ as merging generators. This allows us to define the subsystem code

Note that, technically, Eq. (4) specifies a subsystem stabilizer code only if the center of ${\mathcal{G}}^{\mathrm{M}}$ is non-empty, such that a stabilizer subgroup ${\mathcal{S}}^{\mathrm{M}}$ can be defined. That this is indeed the case follows from Lemma 2. As we will show next, the code ${\mathcal{G}}^{\mathrm{M}}$ has the structure of the merged code discussed in Theorem 1. The essential features of this structure can be captured in the following Lemma.

**Lemma 1.** The code ${\mathcal{G}}^{\mathrm{M}}$ defined in Eq. (4) is a TSSC on the merged lattice Λ_{M} with distance no less than *d*_{min} = min({*d*_{A}, *d*_{B}}). In addition, ${\mathcal{G}}^{\mathrm{M}}$ can be gauge fixed to ${\mathcal{G}}^{\mathrm{A}}\times {\mathcal{G}}^{\mathrm{B}}\times \u27e8{P}_{\mathrm{L}}^{\mathrm{A}}\otimes {P}_{\mathrm{L}}^{\mathrm{B}}\u27e9$, effectively splitting the code into ${\mathcal{G}}^{\mathrm{A}}$ and ${\mathcal{G}}^{\mathrm{B}}$.

*Proof*. First, let us show that ${\mathcal{G}}^{\mathrm{M}}$ obeys the locality condition for TSSCs. By definition, generators of the separated codes are also generators of the merged code. Their interaction range is increased by at most a constant along the vertical direction due to the relabeling in step (ii). Thereby, the interaction range of merging generators is also kept constant. The generators of the code ${\mathcal{G}}^{\mathrm{M}}$ are hence all local.

Second, we verify that the distance of the merged code is at least *d*_{min}. Since ${\mathcal{G}}^{\mathrm{A}}\times {\mathcal{G}}^{\mathrm{B}}\times \u27e8{P}_{\mathrm{L}}^{\mathrm{A}}\otimes {P}_{\mathrm{L}}^{\mathrm{B}}\u27e9$ is a subgroup of ${\mathcal{G}}^{\mathrm{M}}$, the normalizer $N\left({\mathcal{G}}^{\mathrm{M}}\right)$ is a subgroup of $N\left({\mathcal{G}}^{\mathrm{A}}\times {\mathcal{G}}^{\mathrm{B}}\times \u27e8{P}_{\mathrm{L}}^{\mathrm{A}}\otimes {P}_{\mathrm{L}}^{\mathrm{B}}\u27e9\right)$. Then, note that there exist stabilizers $S\in {\mathcal{S}}^{\mathrm{A}}\times {\mathcal{S}}^{\mathrm{B}}$ that anticommute with some ${G}^{\mathrm{M}}\in \mathcal{M}$. If that was not the case, all ${G}^{\mathrm{M}}{\mid}_{{Q}_{I}}$ would either be elements of the code ${\mathcal{G}}^{I}$ or undetectable errors. The latter option can be ruled out in accordance with the argument in the proof of Lemma 2. The former option, ${G}^{\mathrm{M}}{\mid}_{{Q}_{I}}\in {\mathcal{G}}^{I}$$\forall {G}^{\mathrm{M}}\in \mathcal{M}$, would imply that ${P}_{\mathrm{L}}^{I}$ is not a logical operator. In a quantum error correction code, such mutually anticommuting operators act either on the logical subspace or on gauge qubits. However, any stabilizer of the separate codes is also contained in ${\mathcal{G}}^{\mathrm{M}}$ according to the definition of the merged code in Eq. (4). Now recall that if ${\mathcal{G}}^{\mathrm{M}}$ is a subsystem stabilizer code, it can be decomposed as ${\mathcal{G}}^{\mathrm{M}}={\mathcal{L}}_{\mathrm{G}}^{\mathrm{M}}\times {\mathcal{S}}^{\mathrm{M}}\times \u27e8i\u27e9$, as explained in the main text. Therefore, the aforementioned anticommuting stabilizers *S* must act on gauge qubits and we can hence identify *S* as belonging to ${\mathcal{L}}_{\mathrm{G}}^{\mathrm{M}}$. Later, we will further elaborate on the structure of ${\mathcal{G}}^{\mathrm{M}}$. Since ${\mathcal{S}}^{\mathrm{A}}\times {\mathcal{S}}^{\mathrm{B}}$ contains elements that are not in the stabilizer of ${\mathcal{G}}^{\mathrm{M}}$ but not vice versa, ${\mathcal{S}}^{\mathrm{M}}$ must be a subgroup of ${\mathcal{S}}^{\mathrm{A}}\times {\mathcal{S}}^{\mathrm{B}}\times \u27e8{P}_{\mathrm{L}}^{\mathrm{A}}\otimes {P}_{\mathrm{L}}^{\mathrm{B}}\u27e9$. Consequently, any equivalence class of $N\left({\mathcal{G}}^{\mathrm{M}}\right)\mathrm{\u2215}{\mathcal{S}}^{\mathrm{M}}$ is contained in an equivalence class of $N\left({\mathcal{G}}^{\mathrm{A}}\times {\mathcal{G}}^{\mathrm{B}}\times \u27e8{P}_{\mathrm{L}}^{\mathrm{A}}\otimes {P}_{\mathrm{L}}^{\mathrm{B}}\u27e9\right)\mathrm{\u2215}\left({\mathcal{S}}^{\mathrm{A}}\times {\mathcal{S}}^{\mathrm{B}}\times \u27e8{P}_{\mathrm{L}}^{\mathrm{A}}\otimes {P}_{\mathrm{L}}^{\mathrm{B}}\u27e9\right)$.

The quotient group $N\left(\mathcal{G}\right)\mathrm{\u2215}\mathcal{S}$ defines so-called bare logical operators that do not act on gauge qubits. Generally, $N\left(\mathcal{G}\right)\u2215\u27e8i\u27e9\mathcal{S}$ contains all information about the logical operators but not about all undetectable errors. At the same time, undetectable errors are related to bare logical operators, since $N\left(\mathcal{S}\right)\u2215\mathcal{G}\simeq N\left(\mathcal{G}\right)\u2215\u27e8i\u27e9\mathcal{S}$ for any subsystem stabilizer code $\mathcal{G}$^{19}. To conclude then that the distance of ${\mathcal{G}}^{\mathrm{M}}$ is *d*_{min}, we have to verify that deformations (i.e., multiplications) of any non-trivial, logical operators $P\in N\left({\mathcal{G}}^{\mathrm{M}}\right)\mathrm{\u2215}{\mathcal{S}}^{\mathrm{M}}$ by operators in ${\mathcal{G}}^{\mathrm{M}}$ yield operators of weight at least *d*_{min}. Since any such *P* is also contained in ${\mathcal{L}}^{\mathrm{A}}\times {\mathcal{L}}^{\mathrm{B}}$ this is true for deformations by operators in ${\mathcal{G}}^{\mathrm{A}}\times {\mathcal{G}}^{\mathrm{B}}$. But we still need to confirm this for operators in ${\mathcal{G}}^{\mathrm{M}}-\left({\mathcal{G}}^{\mathrm{A}}\times {\mathcal{G}}^{\mathrm{B}}\right)$. Specifically, we have to consider deformations under ${\u27e8{G}_{i}^{\mathrm{M}}\u27e9}_{i=1,...,N}$. In principle, these merging operators can reduce the weight of operators *P* below *d*_{min}. However, this can only happen under rather exotic circumstances. That is, only for logical operators of the form *P* = *P*^{A} ⊗ *P*^{B}, where ${P}^{I}\in {\mathcal{L}}^{I}$ (*I* = A, B) and ${P}^{I}\nsim {P}_{\mathrm{L}}^{I}$ acts as ${P}_{\mathrm{L}}^{I}$ on a region *K*_{
I
} ⊂ *Q*_{
I
} such that for the complementary regions ${\stackrel{\u0304}{K}}_{I}$ (with ${\stackrel{\u0304}{K}}_{I}\cup {K}_{I}$ being the set of all qubits on lattice Λ_{
I
} and ${\stackrel{\u0304}{K}}_{I}\cap {K}_{I}={K}_{I}-{K}_{\u012a}$) the weights of these operators satisfy $0<w\left({P}^{\mathrm{A}}{\mid}_{{\stackrel{\u0304}{K}}_{\mathrm{A}}}\right)+w\left({P}^{\mathrm{B}}{\mid}_{{\stackrel{\u0304}{K}}_{\mathrm{B}}}\right)<{d}_{\mathrm{min}}$ independently of the system size. Here we make use of the fact that *Q*_{A} and *Q*_{B} have been labeled equally (cf. main text) and write with a slight abuse of notation ${\stackrel{\u0304}{K}}_{I}\cap {K}_{I}={K}_{I}-{K}_{\u012a}$ (where $\u012a=\mathrm{B}$ if *I* = A and vice versa). In the scenario described above, one could define the logical operator ${P}^{\mathrm{A}}\otimes {P}^{\mathrm{B}}\otimes {\prod}_{i\in {K}_{\mathrm{A}}\cap {K}_{\mathrm{B}}}{G}_{i}^{\mathrm{M}}$ with weight $0<w\left({P}^{\mathrm{A}}{\mid}_{{\stackrel{\u0304}{K}}_{\mathrm{A}}}\right)+w\left({P}^{\mathrm{B}}{\mid}_{{\stackrel{\u0304}{K}}_{\mathrm{B}}}\right)<{d}_{\mathrm{min}}$. At the same time, this also constricts ${P}_{\mathrm{L}}^{I}$ since *P*^{I} must be such that $w\left({P}^{I}\otimes {P}_{\mathrm{L}}^{I}\right)\ge {d}_{\mathrm{min}}$. Since this describes extremely restricted cases that (to the best of our knowledge) do not feature in any practical scenario, we will exclude codes with such properties from our construction.

Note that we can also exclude cases where $w\left({P}^{\mathrm{A}}{\mid}_{{\stackrel{\u0304}{K}}_{\mathrm{A}}}\right)+w\left({P}^{\mathrm{B}}{\mid}_{{\stackrel{\u0304}{K}}_{\mathrm{B}}}\right)=0$. In such cases at least two logical operators ${P}^{\mathrm{A}},{P}^{\mathrm{B}}\in {\mathcal{L}}^{\mathrm{A}}\times {\mathcal{L}}^{\mathrm{B}}$ with $\mathrm{supp}\left({P}^{I}\right)\subset \mathrm{supp}\left({P}_{\mathrm{L}}^{I}\right)$ (*I* = A, B) exist. However, we are only interested in projecting onto the joint eigenstate of any two logical operators ${P}_{\mathrm{L}}^{\mathrm{A}}$ and ${P}_{\mathrm{L}}^{\mathrm{B}}$ along the boundary. Therefore, we can always exclude the aforementioned case by choosing ${P}_{\mathrm{L}}^{\mathrm{A}}$ and ${P}_{\mathrm{L}}^{\mathrm{B}}$ such that there does not exist a logical operator that has support on a subset of *Q*_{
I
}. In the case of TSSC with non-local stabilizers, such logical operators may have support on disconnected regions of a lattice^{19}. Then, these regions have to be connected using local generators to obtain proper string operators. Then, any non-trivial logical operator of the merged code has support on at least *d*_{min} qubits. The distance of the merged code is hence at least *d*_{min}.

Third, the merged code is scalable since the separate codes are scalable. Thus, we can conclude that ${\mathcal{G}}^{\mathrm{M}}$ is indeed a TSSC. At last, note that fixing ${\mathcal{S}}^{\mathrm{M}}$ to ${\mathcal{S}}^{\mathrm{A}}\times {\mathcal{S}}^{\mathrm{B}}$ through a measurement of stabilizers $S\in {\mathcal{S}}^{\mathrm{A}}\times {\mathcal{S}}^{\mathrm{B}}$ anticommuting with at least one merging generator, the separate codes can be recovered while retaining the eigenstate of ${P}_{\mathrm{L}}^{\mathrm{A}}\otimes {P}_{\mathrm{L}}^{\mathrm{B}}$. This gauge fixing has to be accompanied by error correction to ensure full fault tolerance. Q.E.D.

To finally prove Theorem 1, we will now explain the connection between the merged code ${\mathcal{G}}^{\mathrm{M}}$ defined in Eq. (4) and the framework discussed in the main text. The merging procedure described in steps (ii)–(iv) can be understood as an initialization of the merged code. Specifically, measuring merging generators as in Eq. (3) (or similarly, Eq. (2)) initializes ${\mathcal{G}}^{\mathrm{M}}$ from the prepared codes ${\mathcal{G}}^{\mathrm{A}}\times {\mathcal{G}}^{\mathrm{B}}$. The parity of all random measurement outcomes yields the parity of ${P}_{\mathrm{L}}^{\mathrm{A}}\otimes {P}_{\mathrm{L}}^{\mathrm{B}}$ and error correction has to be performed thereafter in order to ensure correctness (see step (iv)). Fault tolerance is guaranteed since merging generators are constant-weight and errors can only propagate to a constant number of physical qubits. Since we have established in Lemma 1 that ${\mathcal{G}}^{\mathrm{M}}$ is indeed a TSSC with distance at least *d*_{min}, this concludes the proof of Theorem 1.

Altogether, by proving Theorem 1 and Lemma 1, we showed that SLS is fault-tolerant and well-defined through a merging, i.e., a mapping ${\mathcal{G}}^{\mathrm{A}}\times {\mathcal{G}}^{\mathrm{B}}\mapsto {\mathcal{G}}^{\mathrm{M}}$, followed by a splitting, i.e., a mapping ${\mathcal{G}}^{\mathrm{M}}\mapsto {\mathcal{G}}^{\mathrm{A}}\times {\mathcal{G}}^{\mathrm{B}}\times \u27e8{P}_{\mathrm{L}}^{\mathrm{A}}\otimes {P}_{\mathrm{L}}^{\mathrm{B}}\u27e9$.

Concluding this Methods section, we return to the discussion of the ancillas added during step (i) of the preparation. As already discussed in the main text, ancillas can be understood as additional stabilizer qubits included into the initial codes. In the merged code these become gauge qubits. The usefulness of ancillas arises when one considers TSCs as it is the case for the example discussed in the Results section. In that case the merged code can be understood as a TSC with stabilizers merged across the boundary. Here, introducing ancillas means that stabilizers of one surface are instead merged with stabilizers of ancillas, allowing for the possibility of reducing the interaction range of the merged code.

### Merged code structure

In this section, we provide a careful analysis of the merged code. In particular, we will discuss the structure of the subgroups ${\mathcal{S}}^{\mathrm{M}}$ and ${\mathcal{L}}_{\mathrm{G}}^{\mathrm{M}}$. Here we claim that ${\mathcal{G}}^{\mathrm{M}}$ is a [[*n*_{A} + *n*_{B}, *k*_{A} + *k*_{B} − 1, *g*_{A} + *g*_{B} + Δ*g*, *d*_{M}]] code with distance *d*_{M} ≥ *d*_{min}. That is, the distance *d*_{M} merged code has *n*_{A} + *n*_{B} physical qubits, *k*_{A} + *k*_{B} − 1 logical qubits, and *g*_{A} + *g*_{B} + Δ*g* gauge qubits, where Δ*g* is the number of merging generators (see Eq. (3)). To see this, we have to understand the structure of ${\mathcal{S}}^{\mathrm{M}}$ and ${\mathcal{G}}_{\mathrm{G}}^{\mathrm{M}}$ in comparison with the separate codes ${\mathcal{G}}^{\mathrm{A}}\times {\mathcal{G}}^{\mathrm{B}}$.

First, note that we can define Δ*g* new gauge qubits via their respective Pauli operators ${\u27e8{G}_{i}^{\mathrm{M}},{S}_{i}\u27e9}_{i=1,...,\Delta g}$ where *S*_{
i
} ∈ *S*^{A} × *S*^{B} ∀*i* such that $\left[{G}_{i}^{\mathrm{M}},{S}_{j}\right]=0$ for *i* ≠ *j*. That is, there exist Δ*g* independent stabilizers which are now included as gauge operators together with the same number of merging generators. As we will see, the existence of such stabilizers is guaranteed by the choice of logical operators ${P}_{\mathrm{L}}^{\mathrm{A}}$ and ${P}_{\mathrm{L}}^{\mathrm{B}}$ as explained in the proof of Lemma 1.

**Lemma 2.** For the operators ${P}_{\mathrm{L}}^{\mathrm{A}}$ and ${P}_{\mathrm{L}}^{\mathrm{B}}$ chosen above there exists a stabilizer ${S}_{i}\in {\mathcal{S}}^{\mathrm{A}}\times {\mathcal{S}}^{\mathrm{B}}$ for any merging generator ${G}_{i}^{\mathrm{M}}\in \mathcal{W}$ such that $\left\{{G}_{i}^{\mathrm{M}},{S}_{i}\right\}=0$ and $\left[{G}_{j}^{\mathrm{M}},{S}_{i}\right]=0$$\forall {G}_{j}^{\mathrm{M}}\in \mathcal{W}-\left\{{G}_{i}^{\mathrm{M}}\right\}$.

*Proof*. Suppose such a stabilizer does not exist. Then, there exists a $G\in \mathcal{M}$ that yields the same error syndrome as ${G}_{i}^{\mathrm{M}}$, i.e., $\u27e8\psi \u2223{G}_{i}^{\mathrm{M}}G\u2223\psi \u27e9=0$ for any codeword $\u2223\psi \u27e9\in {\mathcal{C}}^{\mathrm{A}}\times {\mathcal{C}}^{\mathrm{B}}$. Since ${G}_{i}^{\mathrm{M}}G\phantom{\rule{0.3em}{0ex}}\notin \phantom{\rule{0.3em}{0ex}}{\mathcal{G}}^{\mathrm{A}}\times {\mathcal{G}}^{\mathrm{B}}$, it is a non-trivial logical operator in ${\mathcal{L}}^{\mathrm{A}}\times {\mathcal{L}}^{\mathrm{B}}$. Combining this with the fact that $\mathcal{W}\subset {\left\{{G}_{j}^{\mathrm{M}}\right\}}_{j=1,...,N}$, the existence of the logical operator ${G}_{i}^{\mathrm{M}}G$ is not compatible with our construction of ${P}_{\mathrm{L}}^{I}$ as discussed in the proof of Lemma 1. That is, there exist no logical operators ${P}^{I}\in {\mathcal{L}}^{I}$ with $\mathrm{supp}\left({P}^{I}\right)\subset \mathrm{supp}\left({P}_{\mathrm{L}}^{I}\right)$ (*I* = A, B) for our choice of ${P}_{\mathrm{L}}^{I}$. Q.E.D.

We have hence defined Δ*g* new gauge qubits by $\mathcal{W}$ and the same number of independent stabilizers. As another consequence of Lemma 2, we can also define an additional stabilizer equivalent to ${P}_{\mathrm{L}}^{\mathrm{A}}\otimes {P}_{\mathrm{L}}^{\mathrm{B}}$. That is, the merged code has *s*_{A} + *s*_{B} − Δ*g *+ 1 independent stabilizers and thus, a necessarily non-empty center (but reduced logical subspace).

To complete our analysis of the merged code, we have to verify that ${\mathcal{G}}^{\mathrm{M}}$ still contains *g*_{A} + *g*_{B} gauge qubits besides new ones. Therefore, note that there might exist pairs of gauge operators $g,\stackrel{\u0303}{g}\in {\mathcal{L}}_{\mathrm{G}}^{\mathrm{A}}\times {\mathcal{L}}_{\mathrm{G}}^{\mathrm{B}}$ generating a gauge qubit, for which $\left\{g,{G}_{j}^{\mathrm{M}}\right\}=0$ with ${G}_{j}^{\mathrm{M}}\in \mathcal{W}$ ∀*j* ∈ *J* where *J* ⊆ {1, ..., Δ*g*}. While the associated gauge qubit in ${\mathcal{L}}_{\mathrm{G}}^{\mathrm{A}}\times {\mathcal{L}}_{\mathrm{G}}^{\mathrm{B}}$ was defined by $\u27e8\stackrel{\u0303}{g},g\u27e9$, in the merged code it is redefined to be generated by $\u27e8\stackrel{\u0303}{g},g\otimes {\prod}_{j\in J}{S}_{j}\u27e9$. Here, ${S}_{j}\in {\mathcal{L}}_{\mathrm{G}}^{\mathrm{M}}$ is associated with one of the Δ*g* new gauge qubits introduced above. W.l.o.g. we have assumed that $\left[\stackrel{\u0303}{g},{G}_{j}^{\mathrm{M}}\right]=0$ ∀*j* = 1, ..., Δ*g*. Otherwise, we would simply have to apply the same argument to $\stackrel{\u0303}{g}\in {\mathcal{L}}_{\mathrm{G}}^{\mathrm{A}}\times {\mathcal{L}}_{\mathrm{G}}^{\mathrm{B}}$ with $\left\{\stackrel{\u0303}{g},{G}_{j}^{\mathrm{M}}\right\}=0$ for some *j* ∈ *J*′ ⊆ {1, ..., Δ*g*}.

One can see that this code is indeed generated as indicated in Eq. (4). Hence, the distinction to the separated codes is that some stabilizers now act on gauge qubits which can be reversed by gauge fixing. Interestingly, applying this formalism to two Bacon-Shor codes^{22} on regular square lattices [1, *L*]^{2}, yields a merged, asymmetric Bacon-Shor code^{23} on a [1, 2*L*] × [1, *L*] lattice.

### Subsystem surface code lattice surgery

Here, we exemplify SLS by means of the subsystem surface code (SSC)^{21}. Therefore, consider two such codes ${\mathcal{G}}^{\mathrm{A}}$ and ${\mathcal{G}}^{\mathrm{B}}$ defined on regular square lattices [1, *L*]^{2} with qubits located on vertices. In Fig. 4a, we chose the smallest SSC with distance *d* = *L* = 3 defining a unit cell where the central vertex is unoccupied. The codes are generated by triangle and boundary operators, labeled ${G}_{i}^{I}$ and ${S}_{i}^{I}$, respectively, with *i* = 1, ..., 4 and *I* = A, B (Fig. 4a). Triangle operators ${\left\{{G}_{i}^{I}\right\}}_{i=1,...,4}$ act on qubits adjacent to a triangular plaquette *p* as ${G}_{i}^{I}={\prod}_{v\in \mathcal{N}\left(p\right)}{X}_{v}$ for *i* = 2, 3 and ${G}_{i}^{I}={\prod}_{v\in \mathcal{N}\left(p\right)}{Z}_{v}$ for *i* = 1, 4. Boundary operators ${\left\{{S}_{i}^{I}\right\}}_{i=1,...,4}$ are weight-two Pauli operators acting on every other pair of boundary qubits as either *X*-type or *Z*-type operators for *i* = 1, 4 and *i* = 2, 3, respectively. The stabilizer group is defined as

Henceforth, we write *A* ∝ *B* whenever we identify a group *A* with a generating set *B* up to phases. A single gauge qubit is defined up to irrelevant phases by

Logical operators ${X}_{\mathrm{L}}^{I}$ and ${Z}_{\mathrm{L}}^{I}$ are tensor products of single-qubit Pauli *X*- and *Z* operators, respectively, connecting two opposite boundaries as shown in Fig. 4a.

Now we initialize a merged code by measuring merging generators ${\left\{{G}_{i}^{\mathrm{M}}\right\}}_{i=1,2,3}$ as depicted in Fig. 4b. The merged code is left with 5 stabilizer qubits,

where we only kept stabilizers in ${\mathcal{S}}^{\mathrm{A}}\times {\mathcal{S}}^{\mathrm{B}}$ that commute with the merging generators. Consequently, we can identify 2 additional gauge qubits, i.e., 4 in total,

Here we included a semicolon between generators of independent gauge qubits and neglected additional phases. Evidently, this code has the structure predicted in the preceding Methods section and is indeed a TSSC with distance 3.

### Beyond 2D topological codes

Finally, let us discuss the applicability of SLS to higher-dimensional topological codes as well as to non-topological codes. As we shall argue, all of the above holds true in these cases. In short, this is because the essential feature of SLS is to project onto a joint eigenstate of two logical operators by measuring generators of a merged code. Such a merged code can always be formally defined, irrespective of whether or not the initial codes are topological.

Let us first consider topological codes in more than two dimensions. For instance, 3D topological codes (as opposed to 2D topological codes) can support membrane-like logical operators on their 2D boundary^{46,47}. Similarly, it can be expected that most topological codes in *D* dimensions can support logical operators that are associated with (*D* − 1)-dimensional extended objects on the boundary^{46}. With this assumption, it is straightforward to show that SLS can be applied in any dimension. This leaves us with the question of whether SLS can also be used to switch between dimensions. This is indeed the case, since, interestingly, 3D topological codes also support string-like logical operators^{33} which can be used to teleport information from a 2D topological code to a higher-dimensional one via SLS. In fact, at the expense of its 2D layout, a 2D code can even be wrapped along the surface of a 3D code to perform SLS between a string- and a membrane-like logical operator while preserving a 3D notion of locality.

Finally, let us consider the effects of relaxing the constraint of demanding topological features for the quantum error correction codes under scrutiny. For such codes there exists no notion of locality or scalability. Therefore, an underlying lattice of physical qubits cannot be defined in a meaningful way. However, when revising the arguments from Lemmas 1 and 2 in the spirit of non-topological codes, it turns out that one does not require any topological features to prove that the distance of the merged code is the minimum distance of the initial codes. Neither is it necessary to require locality or scalability to show that the merged code can be gauge-fixed to the original codes. The merged code as specified in Eq. (4) is always well-defined algebraically even without topological features. That is, at the expense of locality and/or scalability, Lemmas 1 and 2 hold and we can use SLS to switch between topological and non-topological codes. Nevertheless, one can expect that scalability in particular is a feature that is desirable for any code. Therefore, let us note that the merged code is scalable if the separate codes are scalable even if it is not topological otherwise. As an example of codes that are scalable but not topological consider the doubled codes^{36} which are also amenable for SLS.

### Data availability

Data sharing is not applicable to this article as no data sets were generated or analyzed during the current study.

## Additional Information

**Publisher's note:** Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

## References

- 1.
Nielsen, M. A. & Chuang, I. L.

*Quantum Computation and Quantum Information*(Cambridge University Press, Cambridge, 2000). - 2.
Preskill, J. Fault-tolerant quantum computation. in:

*Introduction to Quantum Computation and Information*(eds Lo, H.-K., Spiller, T. & Popescu, S.) (World-Scientific, Singapore, 1998). - 3.
Campbell, E. T., Terhal, B. M. & Vuillot, C. The steep road towards robust and universal quantum computation.

*Nature*,**549**, 172-179 (2017). - 4.
Gottesman, D.

*Stabilizer Codes and Quantum Error Correction*(California Insitute of Technology, Pasadena, 1997). - 5.
Bravyi, S. & Terhal, B. A no-go theorem for a two-dimensional self-correcting quantum memory based on stabilizer codes.

*New J. Phys.***11**, 043029 (2009). - 6.
Bravyi, S. B. & Kitaev, A. Y. Quantum codes on a lattice with boundary. Preprint at https://arxiv.org/abs/quant-ph/9811052 (1998).

- 7.
Fowler, A. G., Mariantoni, M., Martinis, J. M. & Cleland, A. N. Surface codes: towards practical large-scale quantum computation.

*Phys. Rev. A***86**, 032324 (2012). - 8.
Bombín, H. & Martín-Delgado, M. A. Topological quantum distillation.

*Phys. Rev. Lett.***97**, 180501 (2006). - 9.
Fujii, K. & Tokunaga, Y. Error and loss tolerances of surface codes with general lattice structures.

*Phys. Rev. A***86**, 020303(R) (2012). - 10.
Wang, D. S., Fowler, A. G. & Hollenberg, L. C. L. Surface code quantum computing with error rates over 1%.

*Phys. Rev. A***83**, 020302(R) (2011). - 11.
Bombín, H. Gauge color codes: optimal transversal gates and gauge fixing in topological stabilizer codes.

*New J. Phys.***17**, 083002 (2015). - 12.
Bombín, H. Dimensional jump in quantum error correction.

*New J. Phys.***18**, 043038 (2016). - 13.
Horsman, C., Fowler, A. G., Devitt, S. & Van Meter, R. Surface code quantum computing by lattice surgery.

*New J. Phys.***14**, 123011 (2012). - 14.
Landahl A. J. & Ryan-Anderson, C. Quantum computing by color-code lattice surgery. Preprint at https://arxiv.org/abs/1407.5103 (2014).

- 15.
Poulin, D. Stabilizer formalism for operator quantum error correction.

*Phys. Rev. Lett.***95**, 230504 (2005). - 16.
Raussendorf, R. & Briegel, H. J. A one-way quantum computer.

*Phys. Rev. Lett.***86**, 5188 (2001). - 17.
Zanardi, P., Lidar, D. & Lloyd, S. Quantum tensor product structures are observable induced.

*Phys. Rev. Lett.***92**, 060402 (2004). - 18.
Bombín, H. Structure of 2D topological stabilizer codes.

*Commun. Math. Phys.***327**, 387 (2014). - 19.
Bombín, H. Topological subsystem codes.

*Phys. Rev. A***81**, 032301 (2010). - 20.
Bombín, H., Duclos-Cianci, G. & Poulin, D. Universal topological phase of two-dimensional stabilizer codes.

*New J. Phys.***14**, 073048 (2012). - 21.
Bravyi, S., Duclos-Cianci, G., Poulin, D. & Suchara, M. Subsystem surface codes with three-qubit check operators.

*Quant. Inf. Comput.***13**, 0963 (2013). - 22.
Bacon, D. Operator quantum error-correcting subsystems for self-correcting quantum memories.

*Phys. Rev. A***73**, 012340 (2006). - 23.
Brooks, P. & Preskill, J. Fault-tolerant quantum computation with asymmetric Bacon-Shor codes.

*Phys. Rev. A***87**, 032310 (2013). - 24.
Yoder, T. J. Universal fault-tolerant quantum computation with Bacon-Shor codes. Preprint at https://arxiv.org/abs/1705.01686 (2017).

- 25.
Bombín, H. & Martín-Delgado, M. A. Quantum measurements and gates by code deformation.

*J. Phys. A: Math. Theor.***42**, 095302 (2009). - 26.
Kubica, A., Yoshida, B. & Pastawski, F. Unfolding the color code.

*New J. Phys.***17**, 083026 (2015). - 27.
Anderson, J. T., Duclos-Cianci, G. & Poulin, D. Fault-tolerant conversion between the steane and reed-muller quantum codes.

*Phys. Rev. Lett.***113**, 080501 (2014). - 28.
Hwang, Y., Choi, B.-S., Ko, Y.-C. & Heo, J. Fault-tolerant conversion between stabilizer codes by Clifford operations. Preprint at https://arxiv.org/abs/1511.02596 (2015).

- 29.
Nagayama, S.

*Distributed Quantum Computing Utilizing Multiple Codes on Imperfect Hardware*(Graduate School of Media and Governance, Keio University, Fujisawa, 2017). - 30.
Bravyi, S. & Kitaev, A. Universal quantum computation with ideal Clifford gates and noisy ancillas.

*Phys. Rev. A***71**, 022316 (2005). - 31.
Eastin, B. & Knill, E. Restrictions on transversal encoded quantum gate sets.

*Phys. Rev. Lett.***102**, 110502 (2009). - 32.
Bravyi, S. & König, R. Classification of topologically protected gates for local stabilizer codes.

*Phys. Rev. Lett.***110**, 170503 (2013). - 33.
Pastawski, F. & Yoshida, B. Fault-tolerant logical gates in quantum error-correcting codes.

*Phys. Rev. A***91**, 012305 (2015). - 34.
Paetznick, A. & Reichardt, B. W. Universal fault-tolerant quantum computation with only transversal gates and error correction.

*Phys. Rev. Lett.***111**, 090505 (2013). - 35.
Jochym-Oonnor, T. & Bartlett, S. D. Stacked codes: universal fault-tolerant quantum computation in a two-dimensional layout.

*Phys. Rev. A***93**, 022323 (2016). - 36.
Bravyi, S. & Cross, A. Doubled color codes. Preprint at https://arxiv.org/abs/1509.03239 (2015).

- 37.
Jones, C., Brooks, P. & Harrington, J. Gauge color codes in two dimensions.

*Phys. Rev. A***93**, 052332 (2016). - 38.
Brown, B. J., Nickerson, N. H. & Browne, D. E. Fault-tolerant error correction with the gauge color code.

*Nat. Commun.***7**, 12302 (2016). - 39.
Bombín, H. Single-shot fault-tolerant quantum error correction.

*Phys. Rev. X***5**, 031043 (2015). - 40.
Nigg, D. et al. Quantum computations on a topologically encoded qubit.

*Science***345**, 302 (2014). - 41.
Bowler, R. et al. Coherent diabatic ion transport and separation in a multizone trap array.

*Phys. Rev. Lett.***109**, 080502 (2012). - 42.
Barends, R. et al. Superconducting quantum circuits at the surface code threshold for fault tolerance.

*Nature***508**, 500 (2014). - 43.
Yao, N. Y. et al. Scalable architecture for a room temperature solid-state quantum information processor.

*Nat. Commun.***3**, 800 (2012). - 44.
Delfosse, N., Iyer, P. & Poulin, D. A linear-time benchmarking tool for generalized surface codes. Preprint at https://arxiv.org/abs/1611.04256 (2016).

- 45.
Orsucci, D., Tiersch, M. & Briegel, H. J. Estimation of coherent error sources from stabilizer measurements.

*Phys. Rev. A***93**, 042303 (2016). - 46.
Bombín, H. & Martín-Delgado, M. A. Exact topological quantum order in

*D*= 3 and beyond: Branyons and brane-net condensates.*Phys. Rev. B***75**, 075103 (2007). - 47.
Bombín, H., Chhajlany, R. W., Horodecki, M. & Martín-Delgado, M. A. Self-correcting quantum computers.

*New J. Phys.***15**, 055023 (2013).

## Acknowledgements

We are grateful to Rainer Blatt, Nicolas Delfosse, Vedran Dunjko, Alexander Erhard, Esteban A. Martinez, and Philipp Schindler for valuable discussions and comments. We acknowledge support from the Austrian Science Fund (FWF) through the DK-ALM: W1259-N27, the SFB FoQuS: F4012, the START project Y879-N27, and the Templeton World Charity Foundation Grant No. TWCF0078/AB46.

## Author information

### Affiliations

#### Institute for Theoretical Physics, University of Innsbruck, Technikerstr. 21a, 6020, Innsbruck, Austria

- Hendrik Poulsen Nautrup
- , Nicolai Friis
- & Hans J. Briegel

#### Institute for Quantum Optics and Quantum Information, Austrian Academy of Sciences, Boltzmanngasse 3, 1090, Vienna, Austria

- Nicolai Friis

### Authors

### Search for Hendrik Poulsen Nautrup in:

### Search for Nicolai Friis in:

### Search for Hans J. Briegel in:

### Contributions

H.P.N. has devised the code switching protocol, proven Theorem 1 and composed the manuscript. N.F. has contributed to the conceptual development of the project and helped writing the manuscript. H.J.B. has supervised the project. All authors have discussed the results.

### Competing interests

The authors declare no competing financial interests.

### Corresponding author

Correspondence to Hendrik Poulsen Nautrup.

## Electronic supplementary material

## Comments

By submitting a comment you agree to abide by our Terms and Community Guidelines. If you find something abusive or that does not comply with our terms or guidelines please flag it as inappropriate.

**Open Access** This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license, and indicate if changes were made. The images or other third party material in this article are included in the article’s Creative Commons license, unless indicated otherwise in a credit line to the material. If material is not included in the article’s Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/.