# Quantum Lego: Building Quantum Error Correction Codes from Tensor Networks

ChunJun Cao<EMAIL_ADDRESS>Joint Center for Quantum Information and
Computer Science, University of Maryland, College Park, MD, 20742, USA  Brad
Lackey<EMAIL_ADDRESS>Quantum Systems Group, Microsoft, Redmond,
WA 98052, USA

###### Abstract

We introduce a flexible and graphically intuitive framework that constructs
complex quantum error correction codes from simple codes or states,
generalizing code concatenation. More specifically, we represent the complex
code constructions as tensor networks built from the tensors of simple codes
or states in a modular fashion. Using a set of local moves known as operator
pushing, one can derive properties of the more complex codes, such as
transversal non-Clifford gates, by tracing the flow of operators in the
network. The framework endows a network geometry to any code it builds and is
valid for constructing stabilizer codes as well as non-stabilizer codes over
qubits and qudits. For a contractible tensor network, the sequence of
contractions also constructs a decoding/encoding circuit. To highlight the
framework’s range of capabilities and to provide a tutorial, we lay out some
examples where we glue together simple stabilizer codes to construct non-
trivial codes. These examples include the toric code and its variants, a
holographic code with transversal non-Clifford operators, a 3d stabilizer
code, and other stabilizer codes with interesting properties. Surprisingly, we
find that the surface code is equivalent to the 2d Bacon-Shor code after
“dualizing” its tensor network encoding map.

###### Contents

  1. I Introduction
  2. II General Formalism
    1. II.1 Overview
    2. II.2 Tensors as Quantum LEGO Blocks
    3. II.3 Conjoining the quantum lego blocks from tracing
      1. II.3.1 Stabilizer Codes
    4. II.4 Atomic Legos and expressivity
    5. II.5 Decoding and Error Correction
  3. III Examples
    1. III.1 Simple Codes
    2. III.2 Toric Code
    3. III.3 Surface code and variants
    4. III.4 Perfect Code in Flat Geometry
    5. III.5 Holographic code with transversal non-Clifford gate
    6. III.6 3d Code from the Steane code
  4. IV Discussion
    1. IV.1 Summary of Features
    2. IV.2 Future Directions
  5. A Properties of Isometry Tensors
  6. B Operator Matching and Unitary Stabilizers
    1. B.1 Unitary Stabilizer and Operator Pushing
    2. B.2 Operator Pushing in Connected Tensor Network
    3. B.3 Operator Pushing in Practice
  7. C General Network and decoding unitary
    1. C.1 General Methodology
    2. C.2 Construction of contractible tensor network codes
    3. C.3 Compatibility with Other known Decoding Methods on Tensor Networks
  8. D Operator Matching for Stabilizer Codes
    1. D.1 Conjoining Operations
    2. D.2 Channel-State Duality
    3. D.3 Tracing stabilizer codes: proof
  9. E Algorithm for tracking Stabilizers and logical operators
  10. F Atomic Lego Blocks
  11. G Details of Some Code Constructions
    1. G.1 Toric code
    2. G.2 Boundary conditions and defects
      1. G.2.1 XZZX code
      2. G.2.2 Toric Code with a Twist
    3. G.3 1d code
    4. G.4 2d Bacon-Shor Code
    5. G.5 3d code

##  I Introduction

Quantum error-correcting codes (QECCs) are critical ingredients for fault-
tolerant quantum computation. In light of developing future large scale
quantum computers, it is increasingly important to be able to design complex
QECCs over a large number of qubit/qudits. Naturally, this points to the need
for a simplifying framework that distills essential information from these
complex quantum many-body states that are difficult to intuit for designers.
Some pioneering examples have been explored in the context of quantum many-
body systems and topological quantum computation[1, 2, 3, 4, 5, 6, 7, 8].
These are often constructed over geometries that are sufficiently regular,
although some number of lattice defects have also been discussed [9, 10, 11,
12, 13].

On the other hand, tensor networks [14, 15, 16] are tools that efficiently
capture the features of complex quantum states. Therefore, they are natural
candidates for studying QECCs. Indeed, this connection has been explored by
[17] and more recently in the context of quantum gravity inspired by the
developments in AdS/CFT [18, 19, 20, 21, 22, 23]. More practical aspects of
these holographic codes in relation to quantum computing, many-body quantum
states, and quantum field theory have also been discussed in [24, 25, 26, 27,
28, 29, 30, 31, 16]. However, we argue that the underlying techniques implicit
in these constructions, particularly those of the HaPPY code [18], can be
extended far beyond the holographic contexts in which they are used. Some of
this have been discussed by [32, 33] in qubit stabilizer codes with certain
restrictions to tensor contractions.

In this paper, we generalize the guiding principles behind the aforementioned
works and propose a graphically intuitive and flexible framework for designing
quantum error-correcting codes. More concretely, the underlying idea is
analogous to playing with a lego set where one connects the “quantum lego
blocks” from smaller codes that have useful and straightforward properties to
create larger “quantum lego structures”, which are complex quantum error-
correcting codes111A paper [34] with similar idea but somewhat complementary
focus also appeared shortly after this work was released on arXiv. . This can
be understood as a generalization of code concatenation. The properties of the
larger codes can then be derived graphically following local operator flows
known as operator pushing. While the ideas of operator pushing and using
tensor network for code building are not new, the literature thus far have
been restricted to the case of contracting tensors in directions that are
isometric, which is a process that can be dualized to code concatenation. For
instance, the operator pushing in [18] relied on each tensor being an isometry
along the radial direction. In our work we lift this restriction and show that
operator pushing continues to hold in full generality, which now only relies
on the symmetries of the lego blocks and a generalized matching condition that
we derive. This significantly expands the previous capabilities of the code-
building methods based on tensor networks. For example, by combining the
tensors of codes along the directions that are non-isometric, one can easily
construct the toric code from the simplest qubit erasure correction codes,
which would not have been possible with the isometric restriction in place. In
fact, we show that a quantum lego set of simple building blocks is capable of
creating any code with our extension — this universality establishes the
framework as a powerful language.

This framework can be applied to study both stabilizer codes and non-
stabilizer codes on both qubits and qudits, but when specialized to stabilizer
codes, there is also a polynomial time algorithm (Appendix E) that determines
the corresponding stabilizer generators via operator pushing. Although we do
not provide a general decoding algorithm in this work, we emphasize that
(exact and efficient) tensor-network-inspired decoding algorithms for certain
known subclasses of these codes do exist. In addition, we find that for tensor
networks that are efficiently contractible, the sequence of contractions
explicitly constructs an encoding/decoding circuit.

To better understand its capability and to provide explicit tutorials, we
construct a few examples that include well-known existing codes as well as new
codes by connecting simple building blocks of stabilizer codes over a few
qubits. These code-building exercises not only can create new codes
geometrically, but also can recast existing codes that did not have obvious
geometric interpretations into the graphical language of tensor networks. On a
more practical level, because the rules for code building are based on
operator matching and are extremely simple, it provides a graphically
intuitive language for analyzing and deriving properties of a complex code.
Furthermore, their simplicity also accentuates the framework’s potential for
automated processes of code building, e.g. through machine learning, which are
more natural and scalable in the long run.

Because of the flexibility in choosing different tensors and how they can be
connected, the quantum lego framework can also customize known QECCs with
tailor-made properties. For instance, one can modify the toric code with ease
by altering the tensors in its network. This helps create variants, defects,
and other customizable boundary conditions that are more irregular and respond
to errors asymmetrically. It is particularly useful when one wishes to
preserve some overall properties of a code while accommodating certain
idiosyncrasies of the quantum hardware or personalized user requirements.

As a generalization of code concatenation expressible in a graphical form, we
hope it will be useful in devising decoding algorithms, deriving bounds for
fault-tolerant thresholds, and connecting tensor network properties, e.g.
contractibility, with decoding, circuit-building, and beyond. Because it has
potential in building non-trivial codes by combining smaller tensors with poor
error correction properties, we are also optimistic that this framework can be
used to construct interesting (potentially non-additive) codes that support
transversal non-Clifford operations from simple tensors on qubits and qudits.

In Sec II, we provide a general overview of the framework where we define the
quantum lego blocks in the form of tensors and discuss how they are joined. We
show that with the encoding tensors of trivial one qudit codes, 2-qudit
repetition codes and the tensors of the $|0\rangle$ state, any quantum code is
constructible. When specialized to manipulating stabilizer code legos, we
provide two new systematic results (Sec II.3.1) and a convenient method using
check matrix manipulations (Appendix D). We also show how decoding
circuits/recovery maps may be constructed via tensor contraction in this
framework and discuss connections with known error correction schemes.

In Sec III, we construct explicit examples, including three new quantum codes,
to highlight how they can be created and modified with relative ease using
this framework. We first present a few simple examples for intuition building
in Sec III.1. Then we show how the famous toric code can be constructed with a
straightforward arrangement by gluing tensors of the $[[4,2,2]]$ codes (Sec
III.2). It is followed by various modifications of the toric/surface code to
highlight its potential in customization (Sec III.3). Surprisingly, we show
that one can obtain the 2d Bacon-Shor codes from the 2d surface code tensor
networks by simply re-interpreting some of the physical legs as logical legs.
Therefore, this description unifies the two types of codes in a single
construction and provides a candidate tensor network for the quantum compass
model. By extension, it establishes a novel connection between the well-
studied $\mathbb{Z}_{2}$ gauge theory and a Hamiltonian with frustration which
can be difficult to analyze.

For the remainder of Section III, we use the quantum lego to construct a few
codes that, to the best of our knowledge, have not appeared in literature. In
Sec III.4 and III.5, we consider two codes that are inspired by discussions in
quantum gravity. The first is a code with a flat geometry built from perfect
tensors and the second is a holographic code that supports a transversal non-
Clifford operator. Both can be applied to magic state distillation. We finish
the section with a new 3d subsystem code built from the Steane codes that
supports localized stabilizers and fractal-like logical operators (Sec III.6),
which may be relevant from the point of view of topological quantum error
correction and fractons. Finally in Sec IV, we summarize key features of this
framework and possible future directions.

##  II General Formalism

###  II.1 Overview

The general idea behind the framework is to first convert simple, well-
understood building blocks, such as quantum codes or states over small number
of qubits, into tensors. Then one connects these tensors into a tensor network
(TN) to create more complex QECCs, not unlike building complex and versatile
structures using lego blocks. Using the graph associated with the TN and known
properties of the smaller code building blocks, one can then deduce certain
characteristics of the larger code using local moves, also known as operator
pushing, on the graph. The framework is not specific to stabilizer codes and
is valid for qubits as well as qudits. However, in this work, we provide
examples that are stabilizer codes as they have been more thoroughly studied.

More specifically, operator pushing allows one to construct the different
representations of logical operators. If the resulting code is also produced
by contracting stabilizer codes or states, then we also determine the
stabilizer generators of the larger code using a polynomial time algorithm. To
a lesser extent, this method provides us graphical clues to construct codes
with different network geometries and localized stabilizer generators.
Furthermore, if the tensor network is contractible, then the sequence of
contractions will also map to an encoding/decoding circuit for the code. On
syndrome decoding, one can employ a compatible scheme by [17, 32] for a
subclass of the tensor networks.

As we will soon explain, an isometric tensor can be written as an encoding map
for a QECC222In the error correction language, if a tensor is isometric along
certain contractions, it implies that the code it describes can correct any
erasure errors at those locations.. Therefore, a code-building process can be
mapped to code concatenation when we only restrict ourselves to contracting
tensors on legs that are isometric. Hence, the fully unrestricted network-
building exercise we introduce here is a natural graphical generalization of
code concatenation.

For the rest of this work, we will only focus on tensor networks with constant
uniform bond dimensions. Namely, the quantum lego blocks we use will be codes
over qudits of the same dimensionality. Although the formalism in principle
should allow us to build tensors that have varying bond dimensions on
different legs, e.g., code word stabilized codes [35], we will leave them to
future work.

###  II.2 Tensors as Quantum LEGO Blocks

Before we can build a tensor network, we first discuss the “tensors”. At its
heart, tensors have been used to describe quantum states and mappings as they
are simply the coefficients once a basis in the Hilbert space has been chosen.
For a review on the subject, please see [14, 15].

For concreteness, let us define an $[[n,k]]$ quantum code333We also allow the
case where $k=0$, encoding a single state, and do not decorate our notation
with the bond dimension $d$. as a mapping $V:\mathcal{H}_{d}^{\otimes
k}\rightarrow\mathcal{H}_{d}^{\otimes n}$, where
$\mathcal{H}_{d}=\mathbb{C}^{d}$. For typical encoding maps, $V$ is also an
isometry. One can easily convert it to a rank $n+k$ tensor
$V_{i_{1},\dots,i_{n+k}}$ by decomposing it over a basis

$V=\sum_{i_{j}}V_{i_{1}\dots i_{n+k}}|i_{k+1},\dots,i_{k+n}\rangle\langle
i_{1}\dots,i_{k}|.$ (II.1)

For each index $i_{j}$, one can assign a dangling edge. This tensor has a
graphical interpretation (Figure 1a), where the dangling legs with bond
dimension $d$ denote the total number of qubit/qudits the state or the mapping
is over. The tensor is also an isometric tensor if $V$ is an isometric map.
More detailed discussions of isometric tensors are found in Appendix A.

A careful reader will notice that the tensor $V_{i_{1},\dots i_{n+k}}$ by
itself does not specify whether it should be a mapping like (II.1) or a state
of the form

$|V\rangle=\sum_{i_{j}}V_{i_{1}\dots i_{n+k}}|i_{1},\dots,i_{n+k}\rangle$
(II.2)

unless we provide additional information about the basis over which we sums
over.

Figure 1: (a) A graphical representation of a tensor $V$ obtained from an
encoding map. We have coloured the “logical” legs orange while the physical
legs black. (b) Operator $O$ can be pushed through a tensor to $O^{\prime}$ as
long as $|V\rangle$ is a $+1$ eigenstate of $O^{-1}\otimes O^{\prime}$ (Lemma
B.1). The same pushing rule also tells us that as a code, $O^{\prime}$ acting
on the physical qubits performs a logical operation $Q(O)$ defined in Lemma
B.1 on the encoded qubits. If $O=I$ and $O^{\prime}$ is Pauli, then clearly
$O^{\prime}$ is a stabilizer.

For example, for an encoding isometry $V$ as in Figure 1a, one can divide the
dangling legs of the tensor $V_{i_{1}\dots}$, using the decomposition we are
given, into two types — the physical legs, which denotes the number of
physical qubits(qudits) over which the code is defined, and the logical legs,
which denotes the number of logical qubits(qudits) it encodes. One need not
insist over this particular interpretation, however. Depending on the user’s
preference, it can be equally useful to convert the tensor into a state
$|V\rangle$ over $n+k$ qubits(qudits) or a mapping from $k^{\prime}$ to
$n+k-k^{\prime}$ qubits(qudits). For concrete examples, see the perfect tensor
[18] and perfect code [36] where this inter-conversion is done for the
$[[5,1,3]]$ code.

Indeed, these different manifestations of the same tensor can be interchanged
through the channel-state duality[37, 38]. For operations on the tensors, one
can remain agnostic about what each dangling leg represents until the final
step where we assign meaning to them. In this work, we will specify how we
interpret these tensor legs in the tensor network as we derive the code
properties444We can also choose $\\{|i\rangle\\}$ to be the computational
basis unless otherwise specified although this choice is more or less
irrelevant as we will never work with these tensor components directly in this
paper.. We will also make use of this flexibility to create new codes.

A tensor $V_{i_{1},\dots,i_{n+k}}$ can be expensive to describe as it has
exponentially many components. In this work, we are less interested in the
tensor itself, but rather its underlying structures. We describe such
structures by finding the unitary stabilizers of the state $|V\rangle$
described by the tensor. They encode the symmetries of the tensor.

######  Definition II.1.

For any state $|V\rangle\in\mathcal{H}$, a unitary $U$ that satisfies
$U|V\rangle=|V\rangle$ is called a unitary stabilizer of $|V\rangle$.
Additionally, if they also satisfy $\mathcal{H}=\mathcal{H}_{d}^{\otimes N}$
for some prime $d$ and $U=\bigotimes_{i}^{N}U_{i}$, then $U$ is also a unitary
product stabilizer (UPS).

For example, when $U$ is also an element of the Pauli group, then it is
nothing but a stabilizer of $|V\rangle$ in the usual sense.

The set of unitary stabilizers of a tensor/code is of particular interest to
us because they can be easily converted to logical operators of a code defined
by the same tensor $V$. More importantly, they tell us whether operators
acting on certain legs of the tensor can be “pushed” (Figure 1b) to some other
operators supported on (a subset of) the complementary legs 555More elaborate
examples how it is used in holographic codes is discussed in[18, 23].. See
Lemma B.1 and Appendix B for details. These pushing rules will allow us to
navigate the larger tensor network and will help us greatly when creating
codes with transversal operators.

It can be difficult to identify these unitary stabilizers for a general tensor
$V$ due to computational costs. However, the problem becomes far more
tractable if we take $V$ from relatively small or well-known quantum error
correction codes, as their unitary stabilizers are either known or are
relatively easy to find even by brute force. For stabilizer codes, it is
sufficient to simply work with its stabilizers and logical Pauli operators,
which are clearly unitary product stabilizers. Sometimes it is also beneficial
to keep track of its non-Clifford operators in addition to Pauli operators, as
we will see in later sections. Similarly, if there exist transversal single
qubit/qudit logical operators in any non-stabilizer code constructions, then
one can also convert them to UPS’s of the state $|V\rangle$ generated by its
encoding tensor. With non-stabilizer codes in mind, we also list a few
categories of such tensors that will be pertinent to our current discussion.

The first are isometries. These are tensors where certain subsystems of the
dual state $|V\rangle$ is maximally mixed. For instance, this is true for any
subset of the orange legs for $V$ in Figure 1 if it is an encoding isometry.
See Appendix A for further definitions and properties. For these tensors, it
was shown in [18] that any unitary operator $O$ incident on legs that are
maximally mixed can be pushed to an equivalent unitary operator acting on the
other edges. This thus ensures a class of unitary stabilizers through Lemma
B.1.

More generally, we may not care about being able to push all operators $O$,
but only particular operators, e.g. $YX$ and $TT$. In such cases, one has more
flexibility in code constructions. They admit unitary stabilizers that are
tensor products of particular incoming operators and outgoing ones. Some
examples are found in Sec III.2, III.6 and the double trace code in Sec III.1,
but these unitary stabilizers need not be Paulis.

Finally, it is often desirable to build codes where certain logical operators
are transversal. In this framework, transversality of (tensor product of)
single qubit (qudit) logical operators666By multi-qubit gates, we refer to
gates such as CNOT or Toffoli where they are non-trivial superpositions of
tensor product of single qubit gates.  can often be read off in a
straightforward manner provided we use tensors with suitable unitary product
stabilizers (UPS). These unitary stabilizers are simple tensor product of
operators acting on each tensor leg. Tensors of such properties can be
especially useful when constructing codes that have transversal non-Clifford
gates because one can easily read off transversality of, e.g. T-gates, of the
larger code via operator pushing once we understand the properties of the
individual quantum lego blocks. See examples in Sec III.1 and III.5.

Tensors created from stabilizer states are examples of these latter two cases,
although many also belong to the first category if they serve as isometric
encoding maps with $k>0$ or correct erasure errors. Examples of more general
tensors beyond tensors of stabilizer states have been discussed in the context
of TNs with global symmetries [39]. Such tensors are also in the intersection
of the second and the third category without additional constraints.

###  II.3 Conjoining the quantum lego blocks from tracing

With suitable tensors in hand, we can now combine the blocks together.
Graphically one can connect them by gluing some of the dangling legs.
Algebraically, this “tracing” corresponds to summing over the indices of the
legs that are glued. Equivalently, to create a connected edge, one can rewrite
the tensors as states and project two qubits(qudits) to be glued to a
maximally entangled state

$|\Phi^{+}\rangle=\sum_{i=0}^{d-1}|ii\rangle$ (II.3)

and rescale. Physically, it can be implemented via Bell measurements and post-
selections. Here $d$ is again the bond dimension. See Appendix B for details.
Such tracing operation eliminates some pairs of the physical/logical degrees
of freedom in the tensor components and creates a new state or mapping which
can define a quantum code.

Recall that unitary stabilizers contain crucial information about a tensor and
thus the code it defines, such as the logical operators and stabilizers, we
wish to understand how they transform under the gluing operation. Let us now
derive them for the larger tensor network from the unitary stabilizers of the
individual tensors following a sequence of local moves called operator
pushing. For the sake of simplicity and clarity, we will focus on a subset of
unitary stabilizers called unitary product stabilizers as they are good for
generating transversal operators. They will also be sufficient for
understanding all the examples we discuss in Sec III. For interested readers,
we give a more detailed account on pushing general unitary stabilizers in
Appendix B.

To begin, we insert a UPS of an individual tensor in the network (Figure 2a).
If such an operator only has non-trivial support over the dangling edges, then
the resulting operator acting on the dangling edges is a unitary stabilizer of
the larger tensor network. If such an operator has non-trivial support over a
connected edge $e$ in the form of $O_{e}\neq I$, we look for a matching
operator $Q_{e}$ such that

$\langle\Phi^{+}|O_{e}\otimes Q_{e}=\langle\Phi^{+}|.$ (II.4)

We call $(O_{e},Q_{e})$ a matching set. If multiple edges connect the same two
adjacent tensors, we find $\\{Q_{e}\\}$ for all such edges $e$. In other
words, $O_{e}$ is pushed to $Q_{e}$ over each connected edge $e$ (Figure
2b)777For Pauli operator over qubits, $Q_{e}$ and $O_{e}$ are identical up to
a phase, therefore the operator stays the same over a connected edge. However,
one should be more careful when pushing a general operator..

Then we push $\bigotimes_{e}Q_{e}$ through to the remaining legs of the
adjacent tensor and off of the connected edges $e$ using unitary product
stabilizers (UPS) of the adjacent tensors (Figure 2c). The algorithm succeeds
in finding a UPS of the larger tensor network if one can repeatedly perform
this operation until the support of the inserted UPS of a tensor can be
consistently “pushed” to only the dangling legs. The process terminates in
failure if a matching set can not be found in any of the connected edges or
$\bigotimes_{e}Q_{e}$ cannot be cleaned off of connected edges via operator
pushing. One can then repeat this exercise for other UPS insertions on the
same tensor as well as on other tensors. A local example is shown in Figure
2abc. We often drop the operator insertions to avoid clutter, but denote the
sequence of such operator pushings and matchings through a flow diagram
(Figure 2d). An alternative description of the same process is to insert a UPS
of each local tensor. If the operators inserted form matching sets on all
connected edges according to (II.4), then we keep the resulting operator
acting on the dangling edges as a UPS of the larger tensor network. We then
repeat this process until we have exhausted all combinations of local UPS
insertions.

Figure 2: Consider two tensors adjacent to each other in a larger tensor
network. (a) To find the UPS of a larger network, one inserts a UPS for a
local tensor (blue), and (b) pushes it to the matching operators $Q_{1},Q_{2}$
over connected edges. Then $Q_{1},Q_{2}$ are pushed to the remaining legs of
the adjacent tensor (pink) using the UPS of the pink tensor (c). (d) The whole
process may be denoted as an operator flow, where the sequence of matching and
pushing non-identity local operators are denoted by arrows along the edges.

This procedure acquires for us the unitary (product) stabilizers of this
larger tensor network. If we now designate the dangling legs of the tensor
network to be physical and logical legs, we can re-interpret the network as an
encoding map of a QECC. Using (B.0.1), we can then convert these unitary
stabilizers to logical operators (and stabilizers) of the quantum error
correction code.

A particularly instructive subclass of codes with such UPS pushing are
stabilizer codes, which we will discuss at length in the examples. The UPS we
track are the stabilizers and logical operators, which fully characterize a
given code. Occasionally we will also track non-Pauli operator in the interest
of producing transversal non-Clifford gates (Sec III.5). Because the number of
stabilizer generators scale linearly with system size, operator
matching/pushing can be tracked and performed more efficiently. As stabilizer
codes can be specified by their check matrices, we also provide an equivalent
description for the conjoining/tensor gluing over check matrices in Appendix
D. In addition to our graphical guideline for deriving its stabilizers, we
also provide an equivalent polynomial time algorithm based on check matrix
operations that identifies the stabilizer generators and logical operators of
the larger code (Appendix E). The latter description may be easier to
implement in a machine.

There is also incentive in creating TNs where consistent pushing can be easily
identified beyond the pushing and matching of UPS’s. (See Appendix B.2). For
instance, there are toy models of holography where “non-stabilizerness” is
crucial while transversality is less important [40]. Therefore, in those
cases, it is reasonable to consider general networks built from non-stabilizer
isometries without many UPS’s such that operator pushing can result in high
weight non-transversal logical operators that are superpositions of Pauli
operators. For general purpose tensor network computations, we also may not
care that a particular operator has to be a tensor product of operators acting
on each physical qudit. Instead, operators pushed through a network need not
be fully transversal as long as the overall weight allows for efficient
network contractions and computations of certain expectation values. For
example, they can be the tensor product of low weight operators.

####  II.3.1 Stabilizer Codes

Stabilizer codes are a special but popular type of quantum code. Here we prove
a few general statements on tracing that are also practically useful. Let us
call the corresponding tensor of a stabilizer state a stabilizer tensor. Since
any stabilizer encoding map can be converted to a stabilizer state using the
channel-state duality, it suffices to examine the tracing of stabilizer states
or tensors.

######  Theorem II.1.

Tracing stabilizer tensor(s) produce another stabilizer tensor.

The proof is obvious from the check matrix operations (Appendix D), where the
tracing produce check full rank matrices that can be used to describe the
corresponding stabilizer state, and hence its associated tensor. This is also
expected because tracing is a Clifford operation that does not increase
stabilizer rank. As a tensor can be used as an encoding map with a potentially
non-trivial kernel, it also describes a quantum code. Therefore, by iterating
the above procedure, we are assured a method for producing stabilizer codes
from quantum lego blocks that are themselves (smaller) stabilizer codes.

Calderbank-Shor-Steane (CSS) codes are a special class of stabilizer codes
where the stabilizer generators are Pauli strings that are tensor products of
$X$ and $I$ (or $Z$ and $I$) only. These CSS codes can be particularly
desirable because of the transveral properties of certain Clifford operations.
Let the tensor from a (self-dual) CSS code, including the case of $k=0$, be a
(self-dual) CSS tensor.

######  Theorem II.2.

Tracing (self-dual) CSS tensor(s) produce another (self-dual) CSS tensor.

Because tracing correspond to operator matching where the $X$ and $Z$ type
generators have to be matched to their own types, we can perform the matching
on the $X$ and $Z$ sections of the check matrix separately. The resulting code
is also a CSS code. If the initial codes are self-dual, then so will be the
resulting code. Therefore, one can easily construct CSS codes by gluing
together CSS tensors. Two such examples are shown in Sections III with the
toric code and the 3d code. A proof of the above theorems can be found in
Appendix D.3.

###  II.4 Atomic Legos and expressivity

A key question to ask is how general of a code can quantum legos construct.
For example, can one find a simple set “atomic codes” or elementary lego
blocks that can produce all QECCs using this framework?

######  Theorem II.3.

Any qudit quantum error correction code can be built from the following atomic
lego blocks

  * •

Encoding tensor of a 2-qudit repetition code (rank 3)

  * •

Encoding tensor of any 1-qudit code (rank 2)

  * •

Tensor of $|0\rangle$ (rank 1)

A detailed proof is given in Appendix F, but the intuition behind the above
statement is quite simple: a quantum gate can be seen as a tensor contraction.
For example, tracing a particular tensor leg with the encoding tensor of a
1-qudit code corresponds to applying a single qudit unitary to that leg or
qudit. Single-qudit measurements can be captured by a restricted form of
contracting the rank-1 $|0\rangle$ and rank-2 tensors. By contracting the
rank-3 encoding tensors with a rank-2 encoding tensor in a particular pattern,
one can also re-express it as implementing a two-qudit gate. Therefore, a
subset of the atomic lego contraction patterns map to a universal gate set. By
combining them sequentially, one can then construct a quantum circuit that can
be used to build up any state, and by extension, encoding map.

It immediately follows that if we restrict ourselves to the atomic legos that
correspond to Clifford operations, e.g., the encoding tensor of repetition
codes, rank 2 tensors from single qudit Clifford unitaries and rank 1 tensors
from $|0\rangle$, then one can construct any stabilizer state, and by channel-
state duality, the encoding tensor of any stabilizer code.

When tensors are restricted to the particular contractions patterns to form
gates, then we see that the framework is at least as expressive as the circuit
model. However, these tensor contractions are far more versatile in general,
as they can be grouped differently than the ones given above. More general
contraction patterns also need not be convertible to unitary time evolutions.

###  II.5 Decoding and Error Correction

For codes whose tensor networks can be efficiently evaluated through
sequential contraction of isometries, we can also construct its explicit local
unitary decoding/encoding circuit $U$ based on this contraction sequence.
Explicit examples of such contractible networks or codes include the MERA
[41], branching MERA [42, 43], holographic codes [18, 19, 24, 23], tree-tensor
network or concatenated codes [14, 15, 17]. However, it is also
straightforward to construct other different networks that have not been
discussed widely using Algorithm 1 in Appendix C.

To build the decoding circuit, one first lay down a wire for each dangling
physical leg in the tensor network. The contraction of a certain tensor acting
on a set of dangling physical legs maps to acting a unitary on the same set of
wires in the circuit picture. Thus, each step in the contraction sequence maps
to a time step in the quantum circuit (Figure 9).

Figure 3: (a) The contraction sequence for a portion of the tensor network
corresponds to (b) a unitary decoding circuit where each unitary gate can be
independently derived from the tensor/code of the same colour. The arrows
denote the encoded logical degrees of freedom999This is a notation similar to
say, the HaPPY pentagon code, where the arrow corresponds to the bulk degree
of freedom. From a tensor network perspective, the specific tensor that
describes the isometry, e.g. the blue tensor, will depend on the encoded
state. $|\psi_{1,2}\rangle$ are dummy states we use for notational clarity.
The actual encoded state need not be a product state. (c) The relevant tensors
are isometries in that the contraction of certain edges reduce them to
identity operators. A shorthand notation is used to avoid clutter.

The corresponding unitary gates are guaranteed to exist and can be explicitly
determined from each contracted tensor. One can also terminate the contraction
sequence and obtain a partial circuit if we only want to extract a subset of
the data qubits. For explicit examples see Sec 5.4 of [23]. Detailed
definition of the unitary gates and their existence is found in Appendix A.
Information regarding the contraction sequence and circuit building is found
in Appendix C.

When the tensor networks described above also have bond dimension 2, we have a
code on qubits whose encoding unitary $U$ is known. On the front of error
correction from syndrome measurements, one can easily deploy known decoding
algorithms for such codes by Ferris and Poulin [17]. In this case, the
encoding unitary compatible with [17] can be constructed as in (C.7). When
contracted with tensors representing errors and syndromes, it produces the
relevant conditional probability $Q(E|s)$ of error $E$ given syndrome $s$.
When the tensors in the network have bounded and small degrees such that they
are computationally tractable, then $Q(E|s)$ may also be efficiently
computable.

If the tensors further correspond to stabilizer codes, then one may also use
the maximum likelihood decoder introduced in [32, 33]. In particular, all bond
dimension 2 tensor networks generated by Algorithm 1 using stabilizer code
tensors will contain the tensor network codes (TNC) in [32] as a
subclass101010However, note that the algorithm does not cover all QECCs
produced by the quantum lego method, especially those that are not
contractions of isometries. PEPS, for example, are often difficult to
contract. Interestingly, certain systems with topological order, such as the
toric code, admit alternative descriptions in the form of exact MERA tensor
networks, which are efficiently contractible. . Therefore, we can apply the
efficient decoder in [32] for such kind of quantum lego codes. Note that the
tensor $T(L)$ in [32] is different from our tensor — the former is a bond
dimension 4 tensor that records the logical operator Pauli strings and
equivalent representations while the latter is a bond dimension 2 encoding
map. Nevertheless, it is straightforward to connect the two formalisms using
either encoding unitaries as shown in Appendix A of [32] or more directly by
enumerating the different representations of logical operators. For instance,
one can reproduce the tensors $T(L)$ by enumerating all Pauli string
representations of $L$ through row additions in the check matrices (See
Appendices D and C.3).

For some codes, although the exact contractions of individual isometries may
not possible, it may still be viable to contract groups of these tensors into
isometries or contract them approximately. In such cases, the above algorithm
still applies modulo the differences in grouping the tensors. For other tensor
networks that do not fall into the above subclasses and are not obviously
contractible in the same way, such as the codes in Sec III.2 and III.6,
decoding may still be devised on a case-by-case basis [44]. Here we do not
provide a comprehensive guideline for decoding in all such tensor networks
attainable using the quantum lego, however, these are interesting future
directions to be explored.

##  III Examples

Now with the quantum lego set in hand, we provide a few tutorials for building
“quantum lego structures” using the tensor network technique. In addition to
providing some hands-on exercises, we point out how such codes, some of which
are highly non-trivial, can be constructed and modified with ease in the
quantum lego framework. This suggests that the graphical framework can be a
more convenient and intuitive way of creating and understanding QECCs.

We first start with a couple of simple examples for intuition building, then
we build the toric code and the surface code to show that the technique is
capable of constructing codes with non-trivial properties. Then we construct a
few variants of surface codes, including the 2d Bacon-Shor code, using the
high level of flexibility and customizability of the quantum lego. In
particular, they can be useful in modifying known codes in a highly asymmetric
manner in which defects and local properties can be tailored to the needs of
the user. Finally, we construct and comment on a few potentially new codes
which may be of interest in quantum error correction and possibly quantum
gravity. We do not prove detailed code properties of these codes, but rather
give their constructions in our formalism and outline a few interesting
features that are relevant to our discussion. Further analysis of their
properties, variants, and viability as good quantum codes are left as future
work.

###  III.1 Simple Codes

Single-Trace 4-Qubit Code: The encoding isometry
$W_{[[4,2,2]]}:\mathcal{H}_{2}^{\otimes 2}\rightarrow\mathcal{H}_{2}^{\otimes
4}$ of a simple $[[4,2,2]]$ stabilizer code can be written as a rank 6 tensor
with bond dimension 2 (Figure 4a). Its stabilizer group is $\langle
XXXX,ZZZZ\rangle$. Logical $X$ and $Z$ operators are weight two products of
$X$ and $Z$ respectively. This allows us to determine a characterizing set of
unitary product stabilizers of the tensor. Some of them are shown in a
graphical language in Figure 17. The particular colour-coding of the tensor is
also useful in denoting its orientation — see Appendix G.1 for details.

Using these as building blocks, we perform a single trace between two such
tensors (Figure 4bc). One can treat the new tensor network as an encoding map
that maps 4 logical degrees of freedom (the 4 legs pointing up or down) to 6
physical degrees of freedom (the 6 in-plane legs). Because $k>0$ and each
$[[4,2,2]]$ code corrects one located error on any qubit, the resulting
6-qubit code has a distance no larger than 2.

Figure 4: (a) Encoding map of the $[[4,2,2]]$ code as a rank 6 tensor. We
naturally represent it as a 6 legged tensor where the in-plane legs correspond
to the 4 physical qubits and the other 2 legs correspond to logical degrees of
freedom. The colours are used to denote its orientation. (b) Generating a
stabilizer operator $ZZZZZZ$ from pushing. (c) Physical representation of
logical $\bar{X}_{1}\bar{I}_{2}\bar{I}_{3}\bar{I}_{4}$ by pushing $\bar{X}$ of
the left tensor across the connected edge to the right tensor using a
stabilizer (logical identity) of the right tensor. (d) The resulting
$[[6,2,2]]$ gauge code where the generators of the gauge group are $XX,ZZ$
operators that act on the endpoints of the coloured edges.

To characterize the new code, we find its UPS’s from operator pushing. Here
the relevant ones are the stabilizers (logical identity) and logical
operators. Some practical guidelines for gluing stabilizer codes can be found
in Appendix B.3. To determine the stabilizers of the larger code, we insert
the stabilizers of each tensor such that the operators acting on the
contracted edge satisfy (II.4). In this case, it translates into having two
Paulis of the same type acting on the one connected edge. Equivalently, one
can see it as inserting a stabilizer on the left tensor (without loss of
generality) and “pushing” the Pauli operator on the connected edge through the
right tensor by multiplying one of its stabilizers (Figure 4b). This produces
an operator that has Pauli $Z$s acting on all the dangling edges. As a result,
we can conclude that $ZZZZZZ$ is a stabilizer. A similar exercise can be
repeated for the all $X$ and all $Y$ stabilizers.

To produce logical operators of this code, one can repeat the above exercise
by inserting some combinations of UPS’s that correspond to logical and
stabilizer operators (Figure 4c). This produces a $[[6,4,2]]$ stabilizer code
where the 4 tensor legs pointing downward or upward correspond to the logical
degrees of freedom. If one takes the downward pointing legs to be gauge
qubits, then it is a $[[6,2,2]]$ gauge code where the generators of the gauge
group are given by Figure 4d. This is nothing but a 6 qubit implementation of
the generalized Bacon-Shor code [45, 46].

One can also grow the chain of tensors in Figure 4c by gluing another
$[[4,2,2]]$ tensor, say, onto the leg extending to the right. Such results in
an $[[8,6,2]]$ code. In general, for a chain generated by gluing $m-1$
$[[4,2,2]]$ tensors, we arrive at a $[[2m,2m-2,2]]$ code[47]. This particular
way of generating codes by gluing legs where at least one of them corrects an
erasure error is discussed in [32]. In this case, the logical legs represent
independent degrees of freedom.

This series of tracing can also be understood as code concatenation. For
instance, we can treat the right tensor in Figure 4bc as an (encoding)
isometry which maps one qubit to five others.

Double-Trace 4-Qubit Code:  However, the tensor tracing is not always
equivalent to code concatenation. This is especially apparent when we pass
physical qubits through a tensor that does not behave as an isometry. It
occurs when we are tracing edges whose erasures are not correctable. For
instance, we can trace two edges in the above example (Figure 5b). Repeating
the same operator-pushing exercise, we would find that the stabilizers are
generated by $XXXX$ and $ZZZZ$. However, now the dangling edges in the tensor
network that denote logical degrees of freedom are no longer independent,
i.e., the encoding map has a non-trivial kernel. This can be seen as the
$\bar{P}\bar{P}$ operator, where $P$ being a Pauli operator, is represented as
a stabilizer on the physical qubits. This serves as a constraint on the
apparent logical degrees of freedom. Therefore, after subtracting the number
of constraints from the apparent logical degrees of freedom, we are left with
two total encoded qubit degree of freedom in the tensor network. Because the
non-trivial constraint here posed by the loop introduces a new stabilizer this
procedure, it is not the same as concatenation.Indeed, one can verify either
graphically, or algebraically through the check matrices111111See Appendix
D.2.1 of [23]., that this tensor network reduces to the original 6-legged
encoding map (Figure 5b) after we mod out the kernel.

Figure 5: (a) Pushing $\bar{X}\bar{X}$ operators leads to a stabilizer because
the two traced legs are not correctable errors. (b) The double-trace tensor
network actually reduces to the original $[[4,2,2]]$ code where the two upward
(or downward) pointing logical legs are identified because of the stabilizer
constraint.

Steane Code from 4-Qubit Codes:  Thus far, we have kept two particular legs as
logical from the tensor of the $[[4,2,2]]$ code. However, as we have pointed
out in Sec II, their designation as logical degrees of freedom in the tensor
network is completely artificial. This freedom of choice can be seen as a
consequence of the Choi-Jamiolkowski isomorphism (See Appendix D.2).

In this example, staying completely agnostic about the meaning of each
dangling leg before tracing also allows us to construct codes with higher
distances using exactly the same tensor component. Let us illustrate a new
construction of the Steane code using these tensors from the 4 qubit codes.
Here we simply trace over the dangling edges that correspond to the “logical”
degrees of freedoms in the $[[4,2,2]]$ code (Figure 6a). The resulting tensor
network acts on 8 dangling legs (Figure 6b). Using operator pushing, we arrive
at an 8-qubit stabilizer state or a 7-qubit stabilizer code if we choose any
one leg to be the logical degree of freedom. One can easily check that this is
nothing but the $[[7,1,3]]$ Steane code (Figure 6c), where the stabilizer
generators are $XXXX$ and $ZZZZ$ that act on each vertex of the colored
faces121212Detailed derivation is left as an exercise for the reader..

Figure 6: (a) Tracing together the “logical” degrees of freedom in two
$[[4,2,2]]$ codes produces (b) an 8-legged tensor. Without loss of generality,
we choose leg number 8 to be a logical degree of freedom. Then it becomes an
encoding isometry of the Steane code [48] (c) where stabilizer generators are
$XXXX,ZZZZ$ acting on the 4 vertices of each of the coloured faces. Logical X
and Z operators are all X and all Z operators acting on all 7 vertices. (d)
Because the 15-qubit Reed-Muller code has a transversal T gate, we can easily
deduce from operator pushing that the code by tracing two such tensors would
also have a transversal non-Clifford gate. Here the red dots represent
dangling logical legs and $\bar{T}^{\dagger}\bar{T}$ can be pushed to the
boundary dangling legs where $T$ acts on the black solid lines and
$T^{\dagger}$ acts on the purple dashed lines.

Traced Reed-Muller Code with Transversal Non-Clifford Gate:  While it is also
straightforward to analyze the resulting stabilizer codes from tracing using
check matrices (Appendix D), the graphical analysis of certain operators in
the code has distinct advantages. One particular aspect is designing codes
that support certain types of transversal operators. Because tracing together
tensors that are stabilized by the tensor product of unitary operators also
lead to a new tensor of a similar property (Corollary B.1.1), this allows us
to produce, by simple observation, more complex codes with transversal non-
Clifford gates by picking and gluing the right kinds of tensors. For a
somewhat trivial example, we can trace together two identical $[[15,1,3]]$
codes [49, 50] with transversal $\bar{T}=T^{\otimes 5}$. For a non-Clifford
gate, we can push $\bar{T}$ from one logical leg and $\bar{T}^{\dagger}$ on
the other. This produces a transversal $\bar{T}\bar{T}^{\dagger}=T^{\otimes
14}\otimes(T^{\dagger})^{\otimes 14}$ (Figure 6d) such that $T$ and $T^{-1}$
act on the connected edge, as required by operator pushing (II.4). It is also
easy to build a code with the same physical operator but implements
$\bar{T}\bar{T}$ by attaching an extra $X$ gate on the logical leg on one of
the tensors131313In a way, this is similar to modifying the tensors in the
XZZX code except there we attach Hadamards. See Sec III.3 and Appendix G.2.1..
In the same way, it is easy to build other subsystem codes with transversal
$T$ operators. For example, we give a slightly more complex construction of a
holographic code that has a transversal $T$ gate in Sec III.5.

###  III.2 Toric Code

Using the $[[4,2,2]]$ tensor, one can also construct more geometric-looking
codes with highly non-trivial properties. One such example is the toric code
[1]. By connecting the tensors in a square lattice (Figure 7), we create a
PEPS-like tensor network where a physical qubit lies on each vertex141414The
form of the tensor network is similar to that of [51] but has additional
“logical legs” that are also dangling, which are necessary for us to indicate
that it is an encoding map. .

Figure 7: (a) One can recover the star $A_{s}$ and plaquette $B_{p}$ operators
by pushing the stabilizers of local tensor modules. (b) Similarly, one can
push through a combination of stabilizers and logical operators to obtain
closed contractible loops (stabilizers/logical identity) and uncontractible
loops (logical operators). The lattice of the tensor network is rotated by 45
degrees relative to the conventional toric code lattice. When the tensor
network is overlaid with the toric code lattice, we view the network from the
top down such that the logical legs point out of the page and the physical
legs point into the page. A vertex on the toric code lattice is coloured red
(or blue) if a $Z$ (or $X$) acts on the physical qubit.

The tensors that make up of the PEPS151515It can be easily converted into a
toric code ground state by contracting, say, $|0\rangle$s with the logical
inputs. This is also similar to [52] if the projection onto Bell pairs during
tensor gluing is enforced by a two-body Hamiltonian and treating the four
qubit code as a subsystem code. have two orientations, which are related to
each other by a $\pi/2$ rotation. To make it periodic, one can then identify
the sides of the network such that the unrotated lattice (right diagram in
Figure 7a) is periodic in the horizontal and vertical directions. We have
chosen the dangling leg pointing up as logical and the one pointing down as
physical. Note that because we are tracing over legs that are not correctable
erasure errors, the apparent logical degrees of freedom in the resulting
tensor network are not independent, not unlike the double trace example in Sec
III.1. As such, pushing some logical operators of local tensors result in
stabilizers, which serve as constraints, or a kernel in our logical space.
After subtracting the dimension of these constraints, we can reduce the
$2L^{2}$ number of apparent logical degrees of freedom into two. Similar to
the double trace example above (Figure 5), we see that the toric code
construction again contains a large number of loops and non-trivial
constraints from contracting tensors that are not acting as isometric encoding
maps. This is a more sophisticated example where the tensor network
construction is going beyond code concatenation. We further elaborate its
construction and degrees of freedom counting in Appendix G.1.

To find the stabilizers of the larger tensor network, we insert the
stabilizers of a 6 legged tensor treating it as a $[[5,1,2]]$ code161616These
are stabilizers of a $[[5,1,2]]$ code because we take 5 of the legs to be
physical and the remaining one pointing up as logical. and pushing it around
the network using stabilizers of the neighbouring tensors. The resulting
stabilizer generators can be organized into the product of all X (or all Z)
acting on four corners of a square (Figure 7a). However, these are nothing but
the star and plaquette operators in the toric code. A similar exercise applies
for the logical operator, where a logical operator of a six-legged tensor is
injected through a logical dangling leg of the tensor network, and pushed
using logical or stabilizer operators (Figure 7b).

While this is clearly a tensor network construction of the toric code ground
space, it is also interesting that just by connecting these somewhat trivial
codes with low distances, and by pushing unitary stabilizers of individual
tensors, we can graphically reconstruct the relevant operators of the toric
code in a simple and intuitive manner. This example also highlights the
difference between the quantum lego method and the more generic tensor network
approaches to many-body quantum states — working with operator pushing is
easier than dealing with the tensor components directly when tackling specific
problems like code-building.

###  III.3 Surface code and variants

One can also construct different variants by taking a patch of the above
tensor network and impose different “boundary conditions” on the tensors. As
there is a wide variety of tensors that can be used to create distinct
boundary conditions, we here only list a few examples. For instance, the bare
boundary condition where we leave all boundary legs open creates a subsystem
code that also has weight-3 stabilizer generators along the boundary of the 2d
surface. This is not the typical surface code, as we have tripled the number
of boundary degrees of freedom. Another straightforward example is the
construction of the conventional surface code with the rough and smooth
boundaries by contracting with the “stopper” tensors, which are simply $X$ or
$Z$ eigenstates (Figure 8a).

Figure 8: (a) By contracting the dangling legs of a patch of the tensor
network with the X and Z eigenstates, one can confirm using operator pushing
that we recreate the 2d surface code with the correct number of qubits and the
different boundary conditions. The grey solid lines represent the contracted
in-plane edges. For each site/tensor marked by a black dot, there are also two
dangling legs pointing into and out of the page. These legs are not shown to
avoid clutter. (b) One can string together different repetition codes in a
tensor network (as denoted by the different colours) and connect some of them
to the dangling legs of the 2d tensor network with holes. Each coloured
boundary represents contraction with a boundary tensor of the same colour on
the right.

The stopper tensors are essentially disconnected nodes. For a boundary tensor
that has more connectivity, one can also connect the boundary dangling legs to
tensors obtained from different repetitions codes (Figure 8b). This creates
subsystem codes that have potentially different properties and defects. See
Appendix G.2 for more detailed constructions.

It is also straightforward to modify the bulk properties by using slightly
different tensors in the interior of the network as long as one preserves
certain operator pushing properties. Two such examples have been constructed
in detail in Appendix G. For instance, by replacing every other tensor with a
modified counterpart that differs by a local Hadamard, the resulting network
is nothing but an XZZX surface code [53, 54, 55] which has been shown to have
a better (symmetric) error threshold compared to the conventional surface code
(Figure 9). We assume the proper stopper tensors are contracted on the
boundary to produce the correct boundary stabilizers (e.g. Figure 19). A more
elaborate modification (Figure 20) introduces a defect by adding another
4-qubit code with stabilizer group $\langle XXIX,ZIZZ,YYYI\rangle$. This
produces the so-called triangle code [56].

Additionally, because what we call physical versus logical is artificial, one
can also build codes by converting some of the physical legs to logical ones
and vice versa. One extreme example is where all the bulk degrees of freedoms
are logical, which reduces the network into a 1d code (see Figure 21 in
Appendix G.3). When all bulk dangling legs are physical, we are left with a
stabilizer state on $2L^{2}$ qubits. It is also interesting to explore the
code properties of a tensor that is somewhere in between, where the choice of
logical vs physical legs can be somewhat non-uniform (Figure 9b). By assigning
the legs to inputs (or outputs) differently, one also creates new codes
distinct from the toric code using the same tensor network.

Figure 9: Local patches of the full tensor network that describes a surface
code variant: (a) Tensors with a white circuit differ from the original tensor
by a Hadamard acting on the downward pointing leg, this changes an all $Z$ or
all $X$ stabilizer to the form of $XZZX$ as needed. All other interpretations
of the network remains unchanged. (b) We have chosen, non-uniformly, to have
some legs (upward pointing) to be logical and some legs (downward pointing) to
be physical.

For an explicit example, by promoting the dangling physical legs to logical
legs in every other row in a surface code tensor network, one obtains the 2d
Bacon-Shor codes [57, 58]. A $3\times 4$ example is shown in Figure 10. The
gauge generators are weight 2 $XX$ or $ZZ$ acting on the qubits that reside on
the end points of the horizontal (blue) and vertical bonds (red) respectively.
A more detailed description and derivation is given in Appendix G.4.
Importantly, this surprising duality through our tensor network connects the
low energy subspace of two distinct systems — a topological quantum field
theory in the form of the surface code and the quantum compass model whose
ground space is frustrated. Therefore, it can provide exact analytical
insights for the low energy behaviour of such frustrated Hamiltonians through
well-known results in the surface code.

Figure 10: A $3\times 4$ Bacon-Shor code with distance 3 from the surface code
tensor network. Tensors every other row are coloured yellow, meaning that both
on-site dangling legs are logical (pointing out of the page) while the black
sites have one dangling leg pointing into the page (physical) while the other
out of the page (logical). The red and blue triangles are again stopper
tensors we used for the surface code, which are Z and X $+1$ eigenstates
respectively. The weight 2 shaded operators are gauge generators (blue: X
type, red: Z type) while some stabilizers are shaded in yellow (Z type) and
green (X type). They correspond to acting Pauli X or Zs on the physical qubits
(black). Blue and red edges in the right diagram mark the gauge generators. A
representative of the logical $X$ ($Z$) operator has $X$ ($Z$) acting on the
purple (orange) shaded qubits.

###  III.4 Perfect Code in Flat Geometry

Here, and the next section, we introduce two new codes that to the best of our
knowledge have not been discussed in previous literature. Other than their
connections to quantum gravity, both also have utility in quantum information.
For example, both can be used for magic state distillation: the first supports
a transversal $SH$ gate while the second supports a transversal $T$ gate.

The perfect tensor, or the associated $[[5,1,3]]$ code, has been used to
create holographic codes [18]. However, one can also construct codes that have
a flat geometry in a way similar to the toric code except that we are using
the $[[5,1,3]]$ instead of a $[[5,1,2]]$ code as base tensors. Such codes may
be relevant for the bulk entanglement gravity approaches [59, 21] where one
considers flat emergent geometries and gravity directly from the bulk, as
opposed to the usual holographic perspective.

Its tensor network construction is shown in Figure 11. One can build it using
Algorithm 1 from Appendix C.2, therefore the tensor network is also
efficiently contractible and admits a straightforward encoding/decoding
circuit. Despite having the same network architecture as that of the toric
code, its logical legs in this code are fully independent of each other. We
can also identify the support of a logical operator through operator pushing.
This codes does not have the same kind of localized stabilizer operators or
straightforward string-like logical operators because of the differences in
its base rank-6 tensor. The support of one such logical operator is shown in
Figure 11.

Figure 11: A tensor network with flat geometry created by connecting rank-6
perfect tensors (yellow). This creates a code where each logical degree of
freedom is localized to the “bulk” legs pointing up. The physical
representation and support of a logical operator can be found via pushing just
like the holographic code.

This is an example that is somewhat in between the holographic code and the
toric/surface code in that it introduces extra physical degrees of freedom in
the bulk like surface code, while the encoded degrees of freedom are still
localized to the bulk regions. It is clear that the same network architecture
can lead to codes with different properties because the tensors are different.

###  III.5 Holographic code with transversal non-Clifford gate

Recently, [31] pointed out that holographic stabilizer codes with good
complementary error correction properties can not support transversal non-
Clifford gates. While these complementary properties are desirable in
holography, they may not be strictly necessary for quantum error correction.
Continuing our earlier example using the $[[15,1,3]]$ Reed-Muller code,
consider a $\\{15,4\\}$ tessellation of the Poincaré disk. Because the base
tensor is a non-degenerate distance 3 code171717It can be checked that the
stabilizer weight is at least 4 for any non-identity element, therefore the
code is non-degenerate [60]., it is a 2-isometry in that any two legs of the
tensor is maximally mixed. Therefore, to produce a holographic code, one can
connect these tensors in the manner shown in Figure 12 using the methods
prescribed by [29]. The logical degrees of freedom in each tile are
independent of each other as their logical operators can be pushed to the
boundary181818Alternatively, one can apply thereom 1 of [32] because in
building the network we only need to contract pairs of edges where at least
one is a correctable erasure error.. This is not unlike the original HaPPY
code. However, we see that it is not a very good erasure correction code such
that a small number of erasures lead to a disconnected bulk entanglement
wedge.

Figure 12: A holographic Reed-Muller code with transversal non-Clifford gate.
The ellipsis represents the remaining boundary-facing legs that we drop to
avoid clutter. Dangling logical legs in the bulk are denoted as red or yellow
dots

Using features of the $[[15,1,3]]$ code outlined in Sec III.1, we can verify
that by pushing $\bar{T}^{\dagger}$ (or $\bar{T}$) through the logical legs
that are marked red (respectively, yellow), we produce a physical operator
that is a tensor product of $T$ and $T^{\dagger}$ on the boundary such that
operators on the internal edges match properly191919Similarly, by contracting
extra phase gates on the bulk/logical legs marked red, the same physical
operator implements the all $\bar{T}$ logical operation for a slightly
modified version of the code.. Therefore there is at least one transversal
logical non-Clifford operator consisting of the tensor products of $\bar{T}$
and $\bar{T}^{\dagger}$. Again we use overlines to indicate logical operation.
Although the transversal non-Clifford gate acts on all encoded qubits
simultaneously, the code may be useful for as a subsystem code that uses code
switching [61] or for magic state distillation [62, 63], especially in
manybody quantum states [64].

###  III.6 3d Code from the Steane code

Thus far we have focused on codes that are built on 2 dimensional geometries
such as flat or the 2d hyperbolic space. One can also construct 3d codes with
localized stabilizer generators using the Steane code by orienting the tensors
appropriately. This creates a cubic lattice tensor network where a physical
qubit is located on each vertex (Figure 13). Each Steane code tensor is
represented as a tensor with 6 contracted legs that connect the vertex to its
neighbours. The remaining 7th physical leg and the logical leg are located on
the vertices. They are not shown in the diagrams to avoid clutter. Instead, we
use the following notation: a vertex with coloured boundary circle denotes a
non-identity logical operator being pushed into the logical leg at that
vertex, while a black boundary indicates logical identity is pushed.
Similarly, vertices with coloured interior indicate non-trivial Paulis acting
on the dangling physical legs on-site while a black interior indicates the
identity operator acting on the physical qubits located at the vertices.

By pushing stabilizers of each Steane code tensor, one can show that there are
localized stabilizers consisting of weight 8 all $X$ or all $Z$ operators that
act on all corners of the coloured cubes (coloured red or blue in Figure 13)
in the lattice. The existence and form of other stabilizer generators will
heavily depend on the boundary condition, which is not unlike our earlier
construction of the toric/surface code.

Figure 13: A tree-like operator resulting from pushing logical operators in
the tensor network. Red denotes the pushing of Pauli $Z$s. We neglect some of
the dangling legs for tensors on the boundary of the cube because that depends
on how we choose the boundary condition. For example, the 3 dangling legs
bottom left corner are contracted with Z-type stopper tensors and two on the
nearby edges are contracted among themselves. Red arrow marks the path of
operator flow.

Potential logical operators can be generated by pushing a combination of
logical and stabilizer elements of the Steane code tensors, where some can
take on localized geometric shapes like boxes or quasilocal fractal structures
like trees. A couple of examples are shown in Figure 13 and Figure 25.

This 3d subsystem code is another non-trivial example for generalization
beyond concatenation, wherein lifting the isometry contraction allows us to
construct codes with spatially local stabilizers with the abundance of loops
in the network. As far as we know, this code has not been constructed in
literature. Further details of the construction and operator pushing can be
found in Appendix G.5.

Unlike the toric code example, we do not claim that the stabilizer group is
generated solely by stabilizers localized to the coloured boxes. It is also
unclear that how many logical degrees of freedom the code encodes or what
forms non-trivial logical operators should take. We will leave its analysis
with different boundary conditions to future work.

##  IV Discussion

Inspired by the work of [18], we proposed a graphical framework applicable to
any QECC, which constructs complex codes from simple ones using tensor
networks. While holographic codes were among its first concrete
implementations, we here have found that the fully extended framework which we
call quantum lego is far more capable and can generate a range of different
codes with different properties. In particular, it connects tensor network
geometry with error-correcting codes and can deduce properties of the larger
code from those of the simpler components using local moves like operator
pushing. Compared to past literature, we have generalized the idea in [18] to
all types of codes over qubits and qudits. More importantly, we lifted a
highly restrictive condition that only joins tensors in directions that are
isometric (or error correcting). Our work significantly extended the range of
constructible codes that can be studied with operator pushing and past
techniques. In doing so, we also provide a genuine generalization of code
concatenation and show that any quantum code can be constructed in such a
manner with simple atomic lego blocks. When applied to stabilizer codes, we
proved systematic statements on how the code transforms under tensor gluing
and how to efficiently capture it using a new type of operation over their
check matrices. Additionally, we have constructed new QECCs and brought about
novel insight for existing codes by applying the quantum lego language. We
find that the likes of toric code can be easily attained and modified using
this framework. We also identified a surprising duality which maps the 2d
Bacon-Shor code to the surface code, thus connecting the low energy subspace
of a well-known gapped local Hamiltonian to that of a frustrated system. We
note a few distinct advantages of this approach and then comment on some
potential future directions.

###  IV.1 Summary of Features

Geometry: All codes created in this manner have a natural association with
network geometries. While we are able to create codes whose geometry is
“regular” like those of the square lattice and of the hyperbolic plane, we are
also able to accommodate more flexible geometries that are more natural in
different hardwares. For instance, in addition to spatially local
constructions on lattices, one may imagine a network of ion traps that
correspond to graphs of clusters where there is all-to-all connectivity below
a certain scale but spatially local at a more coarse grained level (Figure
14).

Figure 14: A network architecture where the subgraph $G_{i}$ may have all-to-
all connectivity below a certain scale even though the connection is sparse
and local on a sufficiently coarse-grained level. Coloured edges represent
logical legs.

Alternatively, one could construct hybrid architectures by gluing together
networks of different geometries. These instances provide a fertile testing
ground for this framework. By reproducing known codes using this approach it
also enables us to interpret existing codes geometrically. For cases where the
code properties may be difficult to analyze otherwise, a graph geometry may
facilitate such an analysis.

Flexibility and Customizability: Distinct from highly idealized constructs, we
may also have varied demands for codes that serve different purposes. In
particular, they may have irregularities or defects in their geometries and
forms of logical operations. These somewhat specialized differences can
originate in both design and engineering of the quantum hardware. For
instance, in machines that rely on spatial locality, lattice defects and dead
qubits may also require that a flexible and customizable code be tailor-made
for these specific purposes. As we see in some of the earlier examples, the
tensor network approach allows local modifications of tensors which easily
creates variations of the base surface code. In other cases, one may require a
code that corrects error asymmetrically, e.g. correcting bit flip errors
better than phase errors in different parts of the machine. As shown in Sec
III.3 and Appendix G.2, tensor network approach may allow us to modify a base
code with the bulk of the desirable properties and create different variants
of the same code by taking out and putting in customized tensors at certain
locations.

Accessibility: Importantly, this framework works very minimally with the
specific expression of the tensors and requires little background on tensor
networks. At its core, this method of code-building is but a gluing and
operator pushing/matching exercise once the unitary stabilizers of each tensor
have been identified. In particular, the idea of operator pushing also
distinguishes this framework from generic tensor network approaches because we
only need to track a discrete set of elements by following the flow of (Pauli)
operators instead of dealing with the multi-component tensors numerically.
Just like how one can build lego houses without being able to manufacture the
lego blocks, the framework provides an intuitive and accessible approach that
allows users to generate interesting codes without heavy involvement or expert
knowledge in the area of tensor network or quantum error correction.
Furthermore, the simplicity in the stabilizer codes created using this method
may also allow us to automate the graphical code creation process using
techniques like machine learning.

Tensor Network, Codes, and Physics: This effort further strengthens the
connection between tensor networks and quantum error-correcting codes. As
such, tensor network can also serve as a bridge between QECCs and areas of
high energy physics (c.f. simulations of quantum field theories), condensed
matter physics and quantum gravity. In light of past productive connections
made between tensor network and these areas, further exploration can be
beneficial for both quantum information/computing and our understanding of
physics in the upcoming quantum information age. For instance, finding the
tensor network constructions of well-known gauge codes using the quantum lego
method may help us better understand the low energy behaviour of Hamiltonians
with frustration in the ground space. It is also curious whether the idea of
operator pushing can help facilitate certain numerical analyses when computing
correlations in the low energy states of quantum manybody systems.

###  IV.2 Future Directions

Framework Improvement: While we have summarized some critical properties and
constructions of the framework, many gaps of knowledge remain to be explored.
In particular, we need to understand the full range of capabilities and
limitations of this framework, as well as its connections with other
approaches for building QECCs. For instance, it is not clear how it can be
related to other graph-based quantum codes like quantum LDPC codes [65]. We
would also like to understand if tensor networks provide a graphical way that
simplifies the determination of code distances or related notions. Interesting
problems remain in decoding for tensor networks that may not be efficiently or
exactly contractible. Relatedly, we would like to explore more efficient ways
to perform active error correction from syndrome measurements using tensor
networks. Seeing how spatial locality may be important in QECC, we also like
to develop a more comprehensive guideline for creating codes that have mostly
spatially local stabilizer generators or other geometric features instead of
relying mostly on human intuitions.

Tensor Contraction, Decoding and Fault-tolerant Thresholds: A crucial part of
quantum error correction lies in the syndrome decoding algorithms. Although
the quantum lego is capable of creating codes in the form of tensor networks,
it remains unclear whether, or how, one can devise useful decoding algorithms
from it. However, because building a tensor network via tensor contraction can
be considered as a generalization of code concatenation for which decoding and
the derivation of threshold is better understood, it is interesting to
understand whether useful techniques for concatenated codes can be extended to
our quantum lego codes. If so, this may help us determine decoding algorithms
and bounds for fault-tolerant thresholds of the larger tensor network since
the properties of the individual tensors (smaller codes) are well-known.

We have also addressed decoding circuit and how it is related to the
contraction of tensors in certain networks. This connection offers us clues as
to how the decoding circuit transforms as one grows the tensor network (or
performs generalized code concatenation). However, it has not been made clear
when the encoding map has a non-trivial kernel, i.e. when the logical legs are
not independent. As many non-trivial codes, e.g. toric code, carry this
property, it is also crucial to extend the network-circuit connection to such
encoding maps.

Stabilizer Code Generation and Characterization: We have provided several
stabilizer QECCs created using tensor networks in this work. A few examples,
e.g. the 3d code and some surface code variants, are new and their code
properties have not yet been fully characterized. Therefore, we would like to
determine whether these codes or variations can have interesting properties,
such as having distance scaling favourably with system size or desirable
transversal operators. In particular, it will be fruitful to further explore
the connections between the 3d code and the Haah code [8] and fractons. We
would also like to generate other non-trivial stabilizer codes (or subsystem
codes) that have interesting network geometries and mostly local stabilizer
generators as way to circumvent some no-go theorems [66]. These might be 1d or
2d codes that have a few global/non-local stabilizer generators. We would also
like to better understand the connection between the surface code and the
Bacon-Shor code. Since one can be gradually deformed to the other by “bending”
some of the dangling legs, it is curious what type of codes one creates if we
only partially deform the surface code. Beyond the regular lattice geometries
like the examples in Sec III.2, one can also explore other more general
network geometries such as the one in Figure 14.

We also hope to reproduce other known families of codes of interest, such as
color codes, (generalized) Bacon-Shor codes, and LDPC codes. This helps us
glean further insights from their tensor networks, like distilling the
underlying principles that have led to their desirable properties and
generating variants or customized versions of such codes.

Non-additive Code and Transversal Gates: In Sec III, we have focused on
stabilizer codes generated by the tensor network framework. However, the
framework itself is also valid for generating non-additive codes as the same
tracing operation applies generically to any tensor and the operator matching
process holds for any tensor that admits a unitary (product) stabilizer. For
instance, one way to create larger non-stabilizer codes is to convert known
non-additive codes with transversal operators into tensors and then trace them
together.

We can also ask whether the tensor network language can help us construct non-
stabilizer quantum lego blocks in the first place. For example, one can find
small tensors that have desirable unitary product stabilizers and then convert
them into encoding isometries that describe non-additive codes. One approach
is to find states/tensors that are $+1$ eigenstates of operators of the form

$\\{\bar{O}\otimes O_{1}\otimes
O_{2}\otimes\dots\>:\>\bar{O}\in\mathcal{L}\\}$ (IV.1)

where we will take the first site of the tensor to be the intended data qubit
when the tensor is converted to an encoding isometry, and $\mathcal{L}$ is the
set of logical operators that we wish to be transversal. This is somewhat
similar to finding tensors that have global symmetries [67, 39, 68] if all of
$O_{i},\bar{O}$ are identical, which is a more restrictive condition than the
one we impose here. Although for larger codes the search can be exponentially
expensive, it should be possible for tensors of fewer dangling legs. Larger
codes can then be generated in the usual way by gluing together these smaller
components. Using operator pushing properties derived in Appendix B, we can
also ensure the larger code to have certain transversal operators.

On a differet note, while it is clear how one may generate transversal single
qubit (qudit) operators using operator pushing after gluing the tensors, it is
not clear how transversality may or may not be preserved after tracing for
multi-qubit gates such as CNOT or CCZ. Further work in this area is needed.

Asymmetric Error Correction and Customizability Sometimes certain errors are
more likely than others. Following the hints from examples in Figure 8b we
would like to understand how effective this framework can be in systematically
generating codes with asymmetric error correction properties. More generally,
we would like to understand how the flexibility in choosing different tensors
in a network can change the code properties locally and globally. Towards
building a framework that hopefully allows more user customizability in code
building, we wish to explore the extent to which the tensor network approach
can create useful tailor-made codes. Some would include modifying well-known
codes with good properties and connecting them with different tensors. Some
explicit directions are to understand the surface/toric code variants which we
have discussed in Sec III.3.

Approximate QECC, Random Tensor Network and Classical Codes It is also
possible to use the self-same technique to construct approximate QECCs — in
this case, one would replace some of the tensors with their “skewed”
counterparts as shown in [23]. Explicit models of approximate QECCs (AQECC) in
the form of tensor networks may also provide further insight in areas like
quantum gravity.

On a related note, random tensor networks of flexible geometry have been
discussed in [20]. While such codes may be more cumbersome to implement on a
quantum computer in the short term, they are powerful theoretical tools that
probe the general properties of (A)QECCs. It would be beneficial to further
pursue this direction and understand how random tensor networks (RTN) may help
with code building. Furthermore, construction of decoding unitaries of RTN
codes have not been fully understood. Therefore, it is also interesting to
establish connections between RTN and random unitary circuit models of quantum
codes [69] including systems that with random measurements [70, 71, 72].

While this framework is intended for building quantum codes, one can ask
whether it is also useful for classical error-correcting codes. Because its
graphical generalization of code concatenation, it may also be fruitful to
determine the necessary modifications for generating classical codes using
tensor networks.

Automated Code Generation and Machine Learning Thus far, we have applied the
quantum lego framework to generate new codes by hand. With reasonable amount
of effort, one can trace together these quantum codes and track their
properties. A lot of this was easily doable because of the abundant symmetries
in the tensors and the network geometry. However, as we move to larger codes
with fewer symmetries, it will become increasingly demanding to track the
different operator pushings by hand. However, because of the simple pushing
rules involved, and the limited number of ways a small tensor can be oriented,
such tasks of code generation can be delegated to a machine. Furthermore, it
should be computationally feasible and exciting to combine this code building
process with machine learning techniques to create codes that have certain
desirable features.

## Acknowledgements

We thank Victor Albert, Michael Beverland, Glen Evenbly, Michael Gullans,
Brian Swingle, and Eugene Tang for the helpful discussions and comments. C.C.
acknowledges the support by the U.S. Department of Defense and NIST through
the Hartree Postdoctoral Fellowship at QuICS, by the Simons Foundation as part
of the It From Qubit Collaboration, and by the DOE Office of Science, Office
of High Energy Physics, through the grant DE-SC0019380.

## References

  * [1] A.Y. Kitaev.  Proceedings of the 3rd International Conference of Quantum Communication and Measurement, Ed. O. Hirota, A. S. Holevo, and C. M. Caves.  Plenum, New York, 1997.
  * [2] S. B. Bravyi and A. Yu. Kitaev.  Quantum codes on a lattice with boundary.  arXiv e-prints, pages quant–ph/9811052, November 1998.
  * [3] Eric Dennis, Alexei Kitaev, Andrew Landahl, and John Preskill.  Topological quantum memory.  Journal of Mathematical Physics, 43(9):4452–4505, September 2002\.
  * [4] Alexei Kitaev.  Anyons in an exactly solved model and beyond.  Annals of Physics, 321(1):2–111, January 2006.
  * [5] Michael A. Levin and Xiao-Gang Wen.  String-net condensation: A physical mechanism for topological phases.  Phys. Rev. B, 71(4):045110, January 2005.
  * [6] H. Bombin and M. A. Martin-Delgado.  Topological Quantum Distillation.  Phys. Rev. Lett. , 97(18):180501, November 2006.
  * [7] H. Bombin.  An Introduction to Topological Quantum Codes.  arXiv e-prints, page arXiv:1311.0277, November 2013.
  * [8] Jeongwan Haah.  Local stabilizer codes in three dimensions without string logical operators.  Phys. Rev. A, 83(4):042330, April 2011.
  * [9] Robert Raussendorf and Jim Harrington.  Fault-Tolerant Quantum Computation with High Threshold in Two Dimensions.  Phys. Rev. Lett. , 98(19):190504, May 2007.
  * [10] Austin G. Fowler, Ashley M. Stephens, and Peter Groszkowski.  High-threshold universal quantum computation on the surface code.  Phys. Rev. A, 80(5):052312, November 2009.
  * [11] H. Bombin.  Topological Order with a Twist: Ising Anyons from an Abelian Model.  Phys. Rev. Lett. , 105(3):030403, July 2010.
  * [12] M. B. Hastings and A. Geller.  Reduced Space-Time and Time Costs Using Dislocation Codes and Arbitrary Ancillas.  arXiv e-prints, page arXiv:1408.3379, August 2014.
  * [13] Shota Nagayama, Austin G. Fowler, Dominic Horsman, Simon J. Devitt, and Rodney Van Meter.  Surface code error correction on a defective lattice.  New Journal of Physics, 19(2):023050, February 2017.
  * [14] Román Orús.  A practical introduction to tensor networks: Matrix product states and projected entangled pair states.  Annals of Physics, 349:117–158, October 2014.
  * [15] Román Orús.  Tensor networks for complex quantum systems.  Nature Reviews Physics, 1(9):538–550, August 2019.
  * [16] Alexander Jahn and Jens Eisert.  Holographic tensor network models and quantum error correction: A topical review.  arXiv e-prints, page arXiv:2102.02619, February 2021.
  * [17] Andrew J. Ferris and David Poulin.  Tensor Networks and Quantum Error Correction.  Phys. Rev. Lett. , 113(3):030501, July 2014.
  * [18] Fernando Pastawski, Beni Yoshida, Daniel Harlow, and John Preskill.  Holographic quantum error-correcting codes: toy models for the bulk/boundary correspondence.  Journal of High Energy Physics, 2015:149, June 2015.
  * [19] Zhao Yang, Patrick Hayden, and Xiao-Liang Qi.  Bidirectional holographic codes and sub-AdS locality.  Journal of High Energy Physics, 2016:175, January 2016.
  * [20] Patrick Hayden, Sepehr Nezami, Xiao-Liang Qi, Nathaniel Thomas, Michael Walter, and Zhao Yang.  Holographic duality from random tensor networks.  Journal of High Energy Physics, 2016(11):9, November 2016.
  * [21] ChunJun Cao and Sean M. Carroll.  Bulk entanglement gravity without a boundary: Towards finding Einstein’s equation in Hilbert space.  Phys. Rev. D, 97(8):086003, April 2018.
  * [22] William Donnelly, Donald Marolf, Ben Michel, and Jason Wien.  Living on the edge: a toy model for holographic reconstruction of algebras with centers.  Journal of High Energy Physics, 2017(4):93, April 2017.
  * [23] ChunJun Cao and Brad Lackey.  Approximate Bacon-Shor code and holography.  Journal of High Energy Physics, 2021(5):127, May 2021.
  * [24] Robert J. Harris, Nathan A. McMahon, Gavin K. Brennen, and Thomas M. Stace.  Calderbank-Steane-Shor Holographic Quantum Error Correcting Codes.  arXiv e-prints, page arXiv:1806.06472, June 2018.
  * [25] Robert J. Harris, Elliot Coupe, Nathan A. McMahon, Gavin K. Brennen, and Thomas M. Stace.  Decoding Holographic Codes with an Integer Optimisation Decoder.  arXiv e-prints, page arXiv:2008.10206, August 2020.
  * [26] Alexander Jahn, Marek Gluza, Fernando Pastawski, and Jens Eisert.  Holography and criticality in matchgate tensor networks.  arXiv e-prints, page arXiv:1711.03109, November 2017.
  * [27] A. Jahn, M. Gluza, F. Pastawski, and J. Eisert.  Majorana dimers and holographic quantum error-correcting codes.  Physical Review Research, 1(3):033079, November 2019.
  * [28] Alexander Jahn, Zoltán Zimborás, and Jens Eisert.  Central charges of aperiodic holographic tensor-network models.  Phys. Rev. A, 102(4):042407, October 2020.
  * [29] ChunJun Cao, Jason Pollack, and Yixu Wang.  Hyper-Invariant MERA: Approximate Holographic Error Correction Codes with Power-Law Correlations.  arXiv e-prints, page arXiv:2103.08631, March 2021.
  * [30] Alexander Jahn, Zoltán Zimborás, and Jens Eisert.  Tensor network models of AdS/qCFT.  arXiv e-prints, page arXiv:2004.04173, April 2020.
  * [31] Sam Cree, Kfir Dolev, Vladimir Calvera, and Dominic J. Williamson.  Fault-tolerant logical gates in holographic stabilizer codes are severely restricted.  arXiv e-prints, page arXiv:2103.13404, March 2021.
  * [32] Terry Farrelly, Robert J. Harris, Nathan A. McMahon, and Thomas M. Stace.  Tensor-network codes.  arXiv e-prints, page arXiv:2009.10329, September 2020.
  * [33] Terry Farrelly, Robert J. Harris, Nathan A. McMahon, and Thomas M. Stace.  Parallel decoding of multiple logical qubits in tensor-network codes.  arXiv e-prints, page arXiv:2012.07317, December 2020.
  * [34] Terry Farrelly, David K. Tuckett, and Thomas M. Stace.  Local tensor-network codes.  arXiv e-prints, page arXiv:2109.11996, September 2021.
  * [35] Andrew Cross, Graeme Smith, John A. Smolin, and Bei Zeng.  Codeword Stabilized Quantum Codes.  arXiv e-prints, page arXiv:0708.1021, August 2007.
  * [36] Raymond Laflamme, Cesar Miquel, Juan Pablo Paz, and Wojciech Hubert Zurek.  Perfect quantum error correction code.  2 1996.
  * [37] Man-Duen Choi.  Completely positive linear maps on complex matrices.  Linear Algebra and its Applications, 10(3):285–290, 1975.
  * [38] A. Jamiołkowski.  Linear transformations which preserve trace and positive semidefiniteness of operators.  Reports on Mathematical Physics, 3(4):275–278, 1972.
  * [39] Sukhwinder Singh, Robert N. C. Pfeifer, and Guifré Vidal.  Tensor network decompositions in the presence of a global symmetry.  Phys. Rev. A, 82(5):050301, November 2010.
  * [40] Christopher David White, ChunJun Cao, and Brian Swingle.  Conformal field theories are magical.  Phys. Rev. B, 103(7):075145, February 2021.
  * [41] G. Vidal.  Class of Quantum Many-Body States That Can Be Efficiently Simulated.  prl, 101(11):110501, September 2008.
  * [42] G. Evenbly and G. Vidal.  Class of Highly Entangled Many-Body States that can be Efficiently Simulated.  Phys. Rev. Lett. , 112(24):240502, June 2014.
  * [43] Andrew J. Ferris and David Poulin.  Branching MERA codes: a natural extension of polar codes.  arXiv e-prints, page arXiv:1312.4575, December 2013.
  * [44] Miguel Aguado and Guifré Vidal.  Entanglement Renormalization and Topological Order.  Phys. Rev. Lett. , 100(7):070404, February 2008.
  * [45] Sergey Bravyi.  Subsystem codes with spatially local generators.  Phys. Rev. A, 83(1):012320, January 2011.
  * [46] Zhang Jiang and Eleanor G. Rieffel.  Non-commuting two-local Hamiltonians for quantum error suppression.  arXiv e-prints, page arXiv:1511.01997, November 2015.
  * [47] Philippe Faist, Sepehr Nezami, Victor V. Albert, Grant Salton, Fernando Pastawski, Patrick Hayden, and John Preskill.  Continuous Symmetries and Approximate Quantum Error Correction.  Physical Review X, 10(4):041018, October 2020.
  * [48] Andrew Steane.  Multiple-Particle Interference and Quantum Error Correction.  Proceedings of the Royal Society of London Series A, 452(1954):2551–2577, November 1996.
  * [49] E. Knill, R. Laflamme, and W. Zurek.  Threshold Accuracy for Quantum Computation.  arXiv e-prints, pages quant–ph/9610011, October 1996.
  * [50] Jonas T. Anderson, Guillaume Duclos-Cianci, and David Poulin.  Fault-Tolerant Conversion between the Steane and Reed-Muller Quantum Codes.  Phys. Rev. Lett. , 113(8):080501, August 2014.
  * [51] F. Verstraete, M. M. Wolf, D. Perez-Garcia, and J. I. Cirac.  Criticality, the Area Law, and the Computational Power of Projected Entangled Pair States.  Phys. Rev. Lett. , 96(22):220601, June 2006.
  * [52] Courtney G. Brell, Steven T. Flammia, Stephen D. Bartlett, and Andrew C. Doherty.  Toric codes and quantum doubles from two-body Hamiltonians.  New Journal of Physics, 13(5):053039, May 2011.
  * [53] Xiao-Gang Wen.  Quantum Orders in an Exact Soluble Model.  Phys. Rev. Lett. , 90(1):016803, January 2003.
  * [54] Alastair Kay.  Capabilities of a Perturbed Toric Code as a Quantum Memory.  Phys. Rev. Lett. , 107(27):270502, December 2011.
  * [55] J. Pablo Bonilla Ataides, David K. Tuckett, Stephen D. Bartlett, Steven T. Flammia, and Benjamin J. Brown.  The XZZX surface code.  Nature Communications, 12:2172, January 2021.
  * [56] Theodore J. Yoder and Isaac H. Kim.  The surface code with a twist.  arXiv e-prints, page arXiv:1612.04795, December 2016.
  * [57] Peter W. Shor.  Scheme for reducing decoherence in quantum computer memory.  Phys. Rev. A, 52:R2493–R2496, Oct 1995.
  * [58] Dave Bacon.  Operator quantum error-correcting subsystems for self-correcting quantum memories.  pra, 73(1):012340, January 2006.
  * [59] ChunJun Cao, Sean M. Carroll, and Spyridon Michalakis.  Space from Hilbert space: Recovering geometry from bulk entanglement.  Phys. Rev. D, 95(2):024031, January 2017.
  * [60] Narayanan Rengaswamy, Robert Calderbank, Michael Newman, and Henry D. Pfister.  On Optimality of CSS Codes for Transversal $T$.  arXiv e-prints, page arXiv:1910.09333, October 2019.
  * [61] Adam Paetznick and Ben W. Reichardt.  Universal Fault-Tolerant Quantum Computation with Only Transversal Gates and Error Correction.  Phys. Rev. Lett. , 111(9):090505, August 2013.
  * [62] Sergey Bravyi and Alexei Kitaev.  Universal quantum computation with ideal clifford gates and noisy ancillas.  Physical Review A, 71(2), Feb 2005.
  * [63] Sergey Bravyi and Jeongwan Haah.  Magic-state distillation with low overhead.  Phys. Rev. A, 86(5):052329, November 2012.
  * [64] Ning Bao, ChunJun Cao, and Vincent Paul Su.  Magic State Distillation from Entangled States.  arXiv e-prints, page arXiv:2106.12591, June 2021.
  * [65] Matthew B. Hastings, Jeongwan Haah, and Ryan O’Donnell.  Fiber Bundle Codes: Breaking the $N^{1/2}\operatorname{polylog}(N)$ Barrier for Quantum LDPC Codes.  arXiv e-prints, page arXiv:2009.03921, September 2020.
  * [66] Sergey Bravyi and Barbara Terhal.  A no-go theorem for a two-dimensional self-correcting quantum memory based on stabilizer codes.  New Journal of Physics, 11(4):043029, April 2009.
  * [67] Norbert Schuch, Ignacio Cirac, and David Pérez-García.  PEPS as ground states: Degeneracy and topology.  Annals of Physics, 325(10):2153–2192, October 2010.
  * [68] Patrick Hayden, Sepehr Nezami, Sandu Popescu, and Grant Salton.  Error Correction of Quantum Reference Frame Information.  arXiv e-prints, page arXiv:1709.04471, September 2017.
  * [69] Michael J. Gullans, Stefan Krastanov, David A. Huse, Liang Jiang, and Steven T. Flammia.  Quantum coding with low-depth random circuits.  arXiv e-prints, page arXiv:2010.09775, October 2020.
  * [70] Soonwon Choi, Yimu Bao, Xiao-Liang Qi, and Ehud Altman.  Quantum Error Correction in Scrambling Dynamics and Measurement-Induced Phase Transition.  Phys. Rev. Lett. , 125(3):030505, July 2020.
  * [71] Michael J. Gullans and David A. Huse.  Dynamical Purification Phase Transition Induced by Quantum Measurements.  Physical Review X, 10(4):041020, October 2020.
  * [72] Yaodong Li and Matthew P. A. Fisher.  Statistical mechanics of quantum error correcting codes.  Phys. Rev. B, 103(10):104306, March 2021.
  * [73] Daniel Harlow.  The Ryu–Takayanagi Formula from Quantum Error Correction.  Commun. Math. Phys., 354(3):865–912, 2017.
  * [74] Vlad Gheorghiu.  Standard form of qudit stabilizer groups.  Physics Letters A, 378(5-6):505–509, January 2014.
  * [75] A. Yu. Kitaev.  Fault-tolerant quantum computation by anyons.  Annals of Physics, 303(1):2–30, January 2003.
  * [76] Muyuan Li, Daniel Miller, Michael Newman, Yukai Wu, and Kenneth R. Brown.  2D Compass Codes.  Physical Review X, 9(2):021041, April 2019.

##  Appendix A Properties of Isometry Tensors

######  Definition A.1.

A tensor of degree (or rank) $N$ is an $\ell$-isometry if contracting $N-\ell$
legs with its conjugate transpose reduces to the identity $I^{\otimes\ell}$.

Note that this contraction is performed over specific $N-\ell$ input
legs202020See Figure 1 of [29] for an explicit tensor contraction diagram.. By
definition, for a tensor of degree $N$, we have $\ell\leq N/2$. We call an
isometry permutation invariant if such properties hold for the contraction of
any $N-\ell$ legs. For example, the perfect tensor is a permutation invariant
3-isometry and the $[[4,2,2]]$ tensor over 4 legs, after fixing the logical
states, is a permutation invariant 1-isometry. However, many isometries are
not permutation invariant. One such example is a generic isometry used in
MERA, where it contracts to identity only in a particular direction. A unitary
is a special case of isometry where $N=2\ell$.

######  Lemma A.1.

Consider the state $|\psi_{W}\rangle$ dual to an $\ell$ isometry
$W:\mathcal{H}_{B}\rightarrow\mathcal{H}_{A}$ with bond dimension $\chi$ such
that $\log_{\chi}\dim\mathcal{H}_{B}=\ell$

$|\psi_{W}\rangle_{AC}=\frac{1}{\sqrt{\chi^{\ell}}}W_{AB}\sum_{i=1}^{\chi^{\ell}}|ii\rangle_{BC},$
(A.1)

the $\ell$-site subsystem $C$ is maximally mixed.

######  Proof.

$\displaystyle\rho_{A}$
$\displaystyle=\operatorname{Tr}_{C}[|\psi_{W}\rangle\langle\psi_{W}|]$
$\displaystyle=\frac{1}{\sqrt{\chi^{\ell}}}\sum_{i,j,k=1}^{\chi^{\ell}}W_{AB}|i\rangle\langle
k|i\rangle\langle j|k\rangle\langle j|W_{AB}^{\dagger}$
$\displaystyle=\frac{1}{\sqrt{\chi^{\ell}}}\sum_{k=1}^{\chi^{\ell}}W|k\rangle\langle
k|W^{\dagger}$
$\displaystyle=\frac{1}{\sqrt{\chi^{\ell}}}\sum_{k=1}^{\chi^{\ell}}|\phi_{k}\rangle\langle\phi_{k}|$

where $|\phi_{k}\rangle=W|k\rangle$. Because $W$ is an isometry and
$\\{|k\rangle\\}$ is an orthonormal basis, $\\{|\phi_{k}\rangle\\}$ is also an
orthonormal basis. Given that the Schimidt coefficients are equal and have
rank $\chi^{\ell}$, the subsystem $C$ must be maximally mixed. ∎

######  Lemma A.2.

An $\ell$ isometry can encode $k\leq\ell$ logical qubits and corrects
$\ell-k\geq 0$ number of erasures.

######  Proof.

For the $\ell$-isometry, we first distinguish the $\ell$ legs such that
contraction of their complement yields identity. Then we choose $k\leq\ell$
legs and designate them as logical degrees of freedom. In the dual state
$|\psi_{W}\rangle_{AC}$ defined in Lemma A.1, let us label the $k$ logical
legs as $R_{k}$ and the remaining $\ell-k$ legs as $R_{\ell-k}$ such that
$R_{k}\cup R_{\ell-k}=C$. Now we compute the mutual information between
$R_{k}$ and $A$, where $R_{k}$ now serves as a reference system isomorphic to
the code subspace. As long as the mutual information $I(R_{k}:A)$ is
$2|R|=2k$, we have proved the above statement because all encoded information
is contained in $A$ and erasure of $R_{\ell-k}$ is in principle correctable.
It is clear that $S(R_{k})=S(R_{k}^{c})=k$ by Lemma A.1. Similarly,
$S(A)=\ell,S(R_{\ell-k})=S(R_{k}A)=\ell-k$, because the state is pure. Then

$I(A:R_{k})=S(A)+S(R_{k})-S(AR_{k})=\ell+k-(\ell-k)=2k,$ (A.2)

while

$I(R_{\ell-k}:R_{l})=S(R_{\ell-k})+S(R_{k})-S(A)=\ell-k+k-\ell=0.$ (A.3)

Indeed $A$ has full access to the encoded information while $R_{\ell-k}$ has
none. Therefore erasure of $R_{\ell-k}$ is correctable. ∎

######  Lemma A.3.

An $\ell$-isometric tensor as an encoding isometry that encodes $k\leq\ell$
qubits into $n$ physical qubits admits an $n-(\ell-k)$ local decoding unitary
that decodes the $k$ data bits of logical information. If one fixes the
encoded state and treats the resulting rank $n$ tensor as an $\ell-k$
isometry, then the same unitary transforms the isometry into
$(\ell-k)$-identity, the fixed encoded state, and a tensor product of ancilla
bits.

######  Proof.

Suppose $W$ is an $\ell$-isometry with total degree $N=n+k$. Let

$|\tilde{\psi}\rangle_{AC}=W_{AR}(|\Phi^{+}\rangle^{\otimes(\ell-k)})_{R_{\ell-k}C}|\psi\rangle_{R_{k}}=\tilde{W}_{(AC)R_{k}}|\psi\rangle_{R_{k}},$
(A.4)

where $R_{k}\cup R_{\ell-k}=R$ and $R_{\ell-k}\cong C$.

$|\Phi^{+}\rangle=\frac{1}{\sqrt{\chi}}\sum_{i=1}^{\chi}|ii\rangle.$ (A.5)

is a maximally entangled (Bell) state between two isomorphic Hilbert spaces
$R_{\ell-k}$ and $C$. $|\psi\rangle$ denotes the logical information we
encode. By doing so, we can re-express $W$ as an encoding isometry $\tilde{W}$
that encodes $k$ data qubits (qudits) in $R_{k}$ to $n$ physical qubits
(qudits) in $A\cup C$. The state $|\tilde{\psi}\rangle$ is an encoded state
and $A$ is the $n-(\ell-k)$ qubit/qudit subsystem whose complement is
maximally mixed. By Lemma A.2, it contains the entire encoded information.
Thus there exists a unitary decoder $U_{A}$ that acts only on $A$ and recovers
the $k$ data bits of encoded information on $A_{1}\subset A$ [73]. Thus
$U_{A}$ is at most $n-(\ell-k)$-local.

$U_{A}|\tilde{\psi}\rangle=|\psi\rangle_{A_{1}}|\chi\rangle_{(A-A_{1})C}.$
(A.6)

Having extracted the information we wanted, we now focus on $|\chi\rangle$
where we know that $C$ of $\ell-k$ qubits/qudits is maximally entangled with
$A-A_{1}$ of $n-\ell\geq\ell-k$ qubits/qudits by Lemma A.2. Therefore, there
must exist Schmidt decomposition

$|\chi\rangle=\frac{1}{\sqrt{D}}\sum_{i=1}^{D}|\phi_{i}\rangle_{C}|\mu_{i}\rangle_{A-A_{1}}$
(A.7)

where $D=2^{\ell-k}$ and $\\{|\phi_{i}\rangle\\}$,
$\\{|\mu_{i}\rangle_{A-R_{k}}\\}$ are orthonormal. Furthermore, there must be
a unitary $U^{\prime}_{A-A_{1}}$ on $A-A_{1}$ such that

$\displaystyle U^{\prime}_{A-A_{1}}|\chi\rangle_{(A-A_{1})C}$
$\displaystyle=(|\Phi^{+}\rangle^{\otimes\ell-k})_{C^{\prime}C}(|0\rangle^{\otimes(n+k-2\ell)})_{A-A_{1}-C^{\prime}},$
(A.8)

where $C^{\prime}\subset A-A_{1}$ and $\dim C^{\prime}=\dim C$. Therefore,
there exists an $n-(\ell-k)$-local decoding unitary
$U_{D}=U^{\prime}_{A-A_{1}}U_{A}$ with support on $A$ such that

$U_{D}|\tilde{\psi}\rangle=|\psi\rangle|\Phi^{+}\rangle^{\otimes(\ell-k)}|0\rangle^{\otimes(n+k-2\ell)}.$
(A.9)

When $|\tilde{\psi}\rangle$ is converted to an isometric mapping between $A$
and $C$, one distills the channel dual to the tensor product of Bell pairs
$|\Phi^{+}\rangle^{\ell-k}$ instead. Indeed, they are the identity operator
$I^{\otimes(\ell-k)}$. ∎

##  Appendix B Operator Matching and Unitary Stabilizers

###  B.1 Unitary Stabilizer and Operator Pushing

As we have discussed in Sec III, the process of finding unitary product
stabilizers can be construed as a form of operator flow in the tensor network
known as operator pushing.

Suppose one has a linear map $V:\mathcal{H}_{A}\rightarrow\mathcal{H}_{B}$
from a tensor, through channel-state duality, we can turn it into a state by
acting it on a maximally entangled state
$|\Phi^{+}\rangle\in\mathcal{H}_{A}\otimes\mathcal{H}_{A^{*}}$ such that

$|\psi_{V}\rangle_{BA^{*}}=V|\Phi^{+}\rangle,$ (B.1)

where

$|\Phi^{+}\rangle=\frac{1}{\sqrt{|A|}}\sum_{i=0}^{|A|}|ii\rangle_{AA^{*}}.$
(B.2)

Here $\\{|i\rangle\\}$ is a complete orthonormal basis for
$\mathcal{H}_{A}\cong\mathcal{H}_{A^{*}}$; $|A|$ is the dimension of the
Hilbert space $\mathcal{H}_{A}$.

######  Lemma B.1.

A linear map $V$ admits operator pushing $VO=O^{\prime}V$ if and only if the
dual state $|\psi_{V}\rangle$ is a $+1$ eigenstate of $O^{\prime}\otimes Q$
where $Q$ satisfies $O_{A}\otimes
Q_{A^{*}}|\Phi^{+}\rangle_{AA^{*}}=|\Phi^{+}\rangle_{AA^{*}}$.

######  Proof.

In the forward direction, assume operator $O,O^{\prime}$ can be pushed across
$V$, then

$\displaystyle|\psi_{V}\rangle$
$\displaystyle=V|\Phi^{+}\rangle=V(O_{A}\otimes Q_{A^{*}})|\Phi^{+}\rangle$
(B.3) $\displaystyle=O^{\prime}_{B}\otimes
Q_{A^{*}}V|\Phi^{+}\rangle=O^{\prime}\otimes Q|\psi_{V}\rangle.$ (B.4)

Conversely, assume $O^{\prime}\otimes Q$ “stabilizes” $|\psi_{V}\rangle$

$\displaystyle O^{\prime}_{B}Q_{A^{*}}|\psi_{V}\rangle$
$\displaystyle=(O^{\prime}V)_{BA}Q_{A^{*}}|\Phi^{+}\rangle$ (B.5)
$\displaystyle=(O^{\prime}V)_{BA}O_{A}^{-1}(O_{A}Q_{A^{*}}|\Phi^{+}\rangle)$
(B.6) $\displaystyle=O^{\prime}_{B}VO_{A}^{-1}|\Phi^{+}\rangle$ (B.7)

This implies that $O^{\prime}_{B}VO^{-1}_{A}=V$, or after multiplying both
sides by $O_{A}$, $O^{\prime}_{B}V=VO_{A}$. ∎

Therefore, understanding operator pushing in a linear map is the same as
understanding the unitary stabilizers of the dual state. The set of such
unitary stabilizers is similar to having symmetries to the tensor/state. See
[39] for example. This, of course, applies to our current discussion in the
form of encoding isometries. In particular, for tensors with special
symmetries, it may be possible to construct transversal logical gates that are
non-Clifford using such techniques. However, one must take care in selecting
the correct operator $Q$ when we dualize between a mapping and a state. In
particular, $Q$ and $O$ are equal (up to sign) when they are Pauli operators
over qubits. However, even for Pauli operators in higher dimensions, one needs
to take care in setting $X\rightarrow X$ and $Z\rightarrow Z^{-1}$ etc when
reading off $Q$ from $O$.

######  Corollary B.0.1.

Suppose a tensor $V$ admits a unitary stabilizer $O\otimes O^{\prime}$ such
that $O,O^{\prime}$ only act on the degrees of freedom that we have chosen to
be the logical legs and physical legs respectively, then $O^{\prime}$ is a
representation of a logical operator $\bar{Q}$ for the code defined by $V$
when we interpret it as an encoding map. Here $Q$ satisfies $Q\otimes
O|\Phi^{+}\rangle_{AA*}=|\Phi^{+}\rangle_{AA*}$.

######  Proof.

From the above lemma we know that $VQ_{B}=O^{\prime}_{A}V$. Thus logical
operator $Q$ acting on the encoded information in $\mathcal{H}_{B}$ is
realized by $O^{\prime}_{A}$ with support on the physical Hilbert space
$\mathcal{H}_{A}$. ∎

If $Q=I$ and $O^{\prime}$ is a Pauli operator, then the it produces a
stabilizer. Note that the uniqueness of $Q$ will depend on whether the
encoding map $V$ has a non-trivial kernel. For example, the $ZZZZ$ operator in
double trace tensor network of two $[[4,2,2]]$ codes corresponds to both
$\bar{Z}\bar{Z}$ and the logical identity. However, in a single $[[4,2,2]]$
code, $ZZZZ$ can only correspond to the logical identity212121It seems likely
that $Q$ is unique when V is an encoding isometry, i.e. its kernel is
trivial..

We have provided rules on how to keep track of the form of operators when they
are being pushed. However, sometimes we only wish to track the support of
these operators during pushing, and not their specific forms. For such
purposes, a flow diagram is often used where arrows are drawn over edges on
which the operators are supported and the direction of the arrows indicate the
direction of operator pushing. Sometimes when the operators are simple enough,
we also use different colours to denote the type of operators being pushed
through (Figures 7,13,20).

###  B.2 Operator Pushing in Connected Tensor Network

When we start tracing different tensors together, we wish to understand how
their respective unitary stabilizers transform under such operations. This
allows us to push operators through tensor networks to find new unitary
stabilizers of the larger network.

First we make a few comments about tracing.

######  Lemma B.2.

Let $T_{i_{1}\dots i_{p}},R_{j_{1}\dots j_{q}}$ be the tensors of the
corresponding states

$\displaystyle|T\rangle=\sum_{i_{k},k=1,\dots,p}T_{i_{1}\dots
i_{p}}|i_{1},\dots,i_{p}\rangle$ (B.8)
$\displaystyle|R\rangle=\sum_{j_{k},k=1,\dots q}R_{j_{1}\dots
j_{q}}|j_{1},\dots,j_{q}\rangle$ (B.9)

where $i_{k},j_{k}$ run from $1$ to $\chi$.

Then tracing two edges of the tensors

$\sum_{l=1}^{\chi}T_{i_{1}\dots l\dots i_{p}}R_{j_{1}\dots l\dots j_{q}}$
(B.10)

corresponds to

$\langle\Phi^{+}|T\rangle|R\rangle$ (B.11)

where

$|\Phi^{+}\rangle=\sum_{l=1}^{\chi}|ll\rangle$ (B.12)

is an unnormalized Bell state on the two edges/qudits to be traced.

######  Proof.

Without loss of generality, let us trace the first edge of the two tensors

$\displaystyle\langle\Phi^{+}|TR\rangle$
$\displaystyle=\sum_{i_{k},j_{s}}T_{i_{1}\dots i_{p}}R_{j_{1}\dots
j_{q}}\delta_{i_{1}l}\delta_{j_{1}l}|i_{2},\dots,i_{p},j_{2},\dots,j_{q}\rangle$
(B.13) $\displaystyle=\sum_{i_{k},j_{s};k,s\neq 1}\sum_{l}T_{l\dots
i_{p}}R_{l\dots j_{q}}|i_{2},\dots,i_{p},j_{2},\dots,j_{q}\rangle$ (B.14)
$\displaystyle=\sum_{i_{k},j_{s};k,s\neq 1}H_{i_{2}\dots i_{p},j_{2}\dots
j_{q}}|i_{2},\dots,i_{p},j_{2},\dots,j_{q}\rangle,$ (B.15)

where it is clear that

$H_{i_{2}\dots i_{p},j_{2}\dots j_{q}}=\sum_{l}T_{l\dots i_{p}}R_{l\dots
j_{q}}$ (B.16)

is created by tracing the two tensors on the correct legs. ∎

######  Theorem B.1.

Consider a unitary stabilizer $S_{A_{1}}\otimes O_{A_{2}}\otimes
S^{\prime}_{B_{1}}\otimes O^{\prime}_{B_{2}}$ of a state
$|\psi\rangle\in\mathcal{H}_{A_{1}}\otimes\mathcal{H}_{A_{2}}\otimes\mathcal{H}_{B_{1}}\otimes\mathcal{H}_{B_{2}}$
such that $\mathcal{H}_{A_{2}}\cong\mathcal{H}_{B_{2}}$, and a maximally
entangled state

$|\Phi^{+}\rangle_{A_{2}B_{2}}=\sum_{i=1}^{|A_{2}|}|ii\rangle_{A_{2}B_{2}}.$
(B.17)

If $\langle\Phi^{+}|O_{A_{2}}O^{\prime}_{B_{2}}=\langle\Phi^{+}|$, then the
state $\langle\Phi^{+}|\psi\rangle$, after tracing the two edges corresponding
to subsystems $A_{2},B_{2}$, is stabilized by unitary $S_{A_{1}}\otimes
S^{\prime}_{B_{1}}$.

######  Proof.

$\displaystyle\langle\Phi^{+}|\psi\rangle$
$\displaystyle=\langle\Phi^{+}|S_{A_{1}}\otimes O_{A_{2}}\otimes
S^{\prime}_{B_{1}}\otimes O^{\prime}_{B_{2}}|\psi\rangle$ (B.18)
$\displaystyle=S_{A_{1}}\otimes
S_{B_{1}}^{\prime}(\langle\Phi^{+}|O_{A_{2}}\otimes
O^{\prime}_{B_{2}})|\psi\rangle$ (B.19) $\displaystyle=S_{A_{1}}\otimes
S_{B_{1}}^{\prime}\langle\Phi^{+}|\psi\rangle$ (B.20)

Therefore $S_{A_{1}}\otimes S^{\prime}_{B_{1}}$ is a unitary stabilizer of the
traced state. ∎

When
$|\psi\rangle=|\phi\rangle_{A_{1}A_{2}}\otimes|\phi^{\prime}\rangle_{B_{1}B_{2}}$,
then this corresponds to tracing two tensors together with a single trace.
Alternatively, if $|\psi\rangle$ is entangled, then it corresponds to a self-
trace.

######  Corollary B.1.1.

If the unitary stabilizers $S_{A_{1}}\otimes
O_{A_{2}},S^{\prime}_{B_{1}}\otimes O^{\prime}_{B_{2}}$ consist of tensor
products of unitary operators acting on each qudit, then so is the resulting
unitary stabilizer after tracing $A_{2},B_{2}$.

We drop the proof as it is obvious. As a consequence, it allows us to
construct transversal operators through operator pushing/matching. For
instance, let there be a logical operator that acts transversally on its
qudits and acts with $O_{A_{2}}$ on a particular leg. One can generate a new
code by tracing subsystem $B_{2}$ of a different tensor in the form of
$|\psi^{\prime}\rangle$ or its dual isometries with $A_{2}$. As long as
$|\psi^{\prime}\rangle$ is stabilized by $S^{\prime}_{B_{1}}\otimes
O^{\prime}_{B_{2}}$, where $S^{\prime}$ is the tensor product of local
operators on each qudit, and that
$\langle\Phi^{+}|O_{A_{2}}O_{B_{2}}=\langle\Phi^{+}|$, then the resulting
logical operator of new code from tracing (or equivalently, operator pushing)
remains transversal.

For the special case where $O,O^{\prime}$ are generalized Pauli operators, the
pair of matched operators on $A_{2},B_{2}$ can take the form of $XX,ZZ^{-1}$.
When $d=2$ and Pauli operators are over qubits, this is simply matching the
same Pauli operators (up to a phase factor) over a trace, hence the form of
operator pushing in [18]. However, this matching extends beyond just Pauli
operators. For example, $TT^{-1}$ is also a valid operator matching which is
important for determining the existence of transversal non-Clifford operators
in such tensor network constructions. More general operator matching rules can
be derived by solving for all possible unitaries $O_{A},O_{B}$ such that
$O_{A}O_{B}|\Phi^{+}\rangle=|\Phi^{+}\rangle$.

Nevertheless, when we push operators through the network, they only remain
tensor products when pushing is done by UPS’s. More generally, one can also
push non-product operators that are unitary stabilizers. The resulting
operator from such pushing need not be transversal. While this may not be as
desirable in our conventional practices of code building, it is not a problem
for general tensor network toy models of holography.

Suppose we are pushing a non-product operator $O$ through $l$ number of
connected edges to adjacent tensors. Let us first decompose $O$ in the Pauli
basis

$\mathcal{O}=\sum_{i_{1},\dots,i_{l}}c_{i_{1},\dots,i_{l}}P_{i_{1}}\otimes\dots\otimes
P_{i_{l}}.$ (B.21)

If the tensors connected to these edges can correct these erasure errors,
i.e., they collectively act as an isometry such that these $l$ legs are
maximally entangled with other degrees of freedoms on the adjacent tensors
(e.g. pink tensors in Figure 15), then any Pauli operators can be pushed
through. Operationally, we can simply apply operator pushing term by term for
$\mathcal{O}$ similar to the UPS case and resum them once all terms have been
pushed through.Suppose each term $P_{i_{1}}\otimes\dots\otimes P_{i_{l}}$
pushes to an operator $O^{\prime}_{i_{1},\dots,i_{l}}$ supported on a set of
legs on the adjacent tensors which in general need not be a product operator,
then the final operator we obtain through pushing $\mathcal{O}$ is

$\mathcal{O}^{\prime}=\sum_{i_{1},\dots,i_{l}}c_{i_{1},\dots,i_{l}}O^{\prime}_{i_{1},\dots,i_{l}}.$
(B.22)

See Sec 3.2 of [23] for an explicit example of operator pushing.

If the adjacent tensors do not correct erasure errors on these legs, i.e., not
all operators can be pushed through, then we first identify the set of unitary
stabilizers these adjacent tensors do have, which act non-trvially as a set of
$\\{Q^{m}=Q^{m}_{1}\otimes\dots\otimes Q^{m}_{l}\>:\>m\in M\\}$ on the $l$
connected edges. We use $M$ to label the set of all such operators acting on
the connected edges. Then we find their corresponding matching operators
$\\{O^{m}=O^{m}_{1}\otimes\dots\otimes O^{m}_{l}\>:\>m\in M\\}$ for each $l$
and $m\in M$ such that,

$\displaystyle(\langle\Phi^{+}|)^{\otimes l}(O^{m}\otimes Q^{m})$
$\displaystyle=$ $\displaystyle(\langle\Phi^{+}|O^{m}_{1}\otimes
Q^{m}_{1})\otimes\dots\otimes(\langle\Phi^{+}|O^{m}_{l}\otimes Q^{m}_{l})$
$\displaystyle=$ $\displaystyle(\langle\Phi^{+}|)^{\otimes l}.$

If $O$ can be expanded in terms of $\\{O^{m}\\}$, then we again repeat the
same term by term pushing above and add up the pushed operators in the end.

A more intuitive way to think about this is to treat the collection of
adjacent tensors as a mapping $W$. If $W$ admits a suitable unitary stabilizer
then one can push $\mathcal{O}$ to the right as $\mathcal{O}^{\prime}$ (Figure
15).

Figure 15: A non-product operator $\mathcal{O}$ can be pushed to the right
through the adjacent operators (pink) by treating them collectively as a
single tensor $W$ with suitable unitary stabilizers.

###  B.3 Operator Pushing in Practice

Here we summarize a few practical tips for operator pushing.

Assume that we start with a number of uncontracted tensors generated by
stabilizer states and designate a set of physical and logical legs. From their
unitary stabilizers, we can determine the logical operators and stabilizers
using Lemma B.1 and Corollary B.0.1. Then we contract these tensors into a
network of our choice.

From Theorem B.1, we know that by inserting a stabilizer of a tensor and push
it around with stabilizers of nearby tensors, we will produce a stabilizer of
the final tensor network. This is always true and we can rely on such methods
to characterize stabilizer groups of such QECCs.

If, on the other hand, we have pushed through a logical operator of a tensor,
one can push it around using both stabilizers and logical operators and other
nearby tensors. The nature of the resulting operators will now depend on the
tensor network itself.

If we have contracted the tensors in a way such that these connected edges can
be treated as correctable erasure errors in the adjacent tensors, then their
logical legs represent independent degrees of freedom. More precisely, the
logical legs remain independent degrees of freedom if tensors are contracted
in a way described in Theorem 1 of [32] or equivalently by Algorithm 1 in
Appendix 1. In this case, such kind of operators pushing produce logical
operators on the larger tensor network. If we further restrict ourselves to
bond dimension 2, then we reproduce the tensor network code (TNC) proposed by
[32].

However, if the above is false, then sometimes pushing of logical operators
can also produce stabilizer elements. If that happens, then the logical legs
in the tensor network are not independent encoded qubits/qudits. Some obvious
examples are given in Sec III.2 and Sec III.6. In that case, naive counting of
the apparent number of logical legs does not correspond to the number of
encoded qubits/qudits.

There are also cases in which we are not as interested in producing stabilizer
codes. This is particularly important for toy models of holography where non-
stabilizerness is crucial. In these scenarios, we are often interested in the
support of logical operators but less so about its specific form or (the lack
of) transversality. Therefore, a tensor network constructed through
contracting general isometries not dual to stabilizer states is also useful.
We can understand such codes created by Algorithm 1 as generalizations of
[32], where the tensors of individual stabilizer encoding maps are replaced by
non-stabilizer higher dimensional counterparts. In all of these codes, one can
easily derive the support logical operators by following the flow of operator
pushing.Such tensor networks are also efficiently contractible and are thus
desirable for numerical computations. Contractibility is nice because we can
give a procedure that constructs the explicit decoding circuit for each such
network. For a simple illustration see Figure 9.

##  Appendix C General Network and decoding unitary

Some of the tensor networks are efficiently contractible through isometries.
In these tensor networks, it is much easier to compute the expectation values
of certain operators through tensor contractions. In this section, we describe
how tensor contraction steps can be mapped to a decoding unitary circuit of
the tensor network quantum code. We also give a construction for the type of
networks that are guaranteed to have such explicit encoding/decoding circuits.
For all our discussions, we assume the bond dimension to be constant through
out the network.

###  C.1 General Methodology

Here we focus on tensor networks that can be locally efficiently contracted
through isometries[29]. Common examples include [41, 42, 18, 44]. In such
tensor networks, when the network is contracted with its conjugate transpose,
one can contract the individual tensors sequentially to identity operators.
Such properties facilitates the computation of local observables as they only
depend on a relatively small part of the entire network. For example, in MERA,
computing the expectation value of a local operator would only involve
contracting tensors its causal cone.

Suppose we are given one such tensor network $G_{0}$ and a contraction
sequence $S_{G}=\\{\eta_{i}:G_{i}\rightarrow G_{i+1}\\}$ through the
contraction of isometries. One can think of each step of the contraction as a
mapping from the initial graph $G_{i}$ before contraction and the final graph
$G_{i+1}$ after. A more concrete expression of this sequence is found in
Figure 9c. When the tensor network acts as an encoding map, we assume the
logical dangling legs network are never touched during the contraction
sequence. For concreteness, one can fix these logical legs to certain states
so that the overall network represents an encoded state. The contraction
sequence does not depend on what states they are fixed to.

Explicitly, such networks can be written as

$V=\prod_{i=0}^{N}W_{i}.$ (C.1)

Each $W_{i}$ is a set of isometries that one can contract in a step of the
sequence. In general it may also be written as a tensor product of isometries

$W_{i}=\bigotimes_{\alpha_{i}}W_{i}^{\alpha_{i}},$ (C.2)

where $W_{i}^{\alpha}$ correspond to the individual isometric tensors that
appear in the tensor network. To construct the circuit, we begin with a number
of wires equal to the total number of physical degrees of freedom in the
tensor network.

Then for each contraction of an isometry into identity, it involves an
isometric tensor acting on a particular set of wires that are either dangling
(non-logical) legs or contracted legs. Let us treat such an isometry tensor as
an encoding map where the dangling wires are physical qubits the user has
control and the other contracted wires are erasure errors. Using lemma A.3, we
can find a decoding unitary that decodes the encoded information by acting
only on the uncontracted legs. This unitary converts each ($\ell$) isometry
tensor $W_{i}^{\alpha_{i}}$ to the tensor product of ($k\leq\ell$) decoded
data qubits (qudits), an ancillary all $|0\rangle$ state, and the identity
operator that acts on the remaining ($\ell-k$) physical degrees of freedom.
Let $U_{i}^{\alpha_{i}}$ be the decoding unitary that corresponds to isometry
$W_{i}^{\alpha_{i}}$. At the $0$-th step

$\displaystyle\bigotimes_{\alpha_{0}}U_{0}^{\alpha_{0}}W_{0}W_{1}\dots
W_{N}\bigotimes_{i=0}^{N}|\psi_{i}\rangle=$
$\displaystyle|\psi_{0}\rangle|\Omega_{0}\rangle\mathbb{I}(W_{1}\dots
W_{N})\bigotimes_{i=1}^{N}|\psi_{i}\rangle,$ (C.3)

where, respectively, $|\psi_{0}\rangle,|\Omega_{0}\rangle$ are the decoded
information and the ancillary all 0 state from isometries contractible at step
0 of the sequence. For the sake of clarity in the presentation, we fix the
encoded states to be a product state. If the encoded state is entangled, then
we recover the a mixed state. Proceeding similarly for $i\geq 1$, we then
obtain the decoding circuit

$\underbrace{(\bigotimes_{\alpha_{N}}U_{N}^{\alpha_{N}})\dots(\bigotimes_{\alpha_{0}}U_{0}^{\alpha_{0}})}_{\rm
unitary~{}decoding~{}circuit}\overbrace{V|\Psi\rangle}^{\rm
encoded~{}state}=\bigotimes_{i=0}^{N}\underbrace{|\psi_{i}\rangle}_{\rm
decoded~{}info}|\Omega_{i}\rangle,$ (C.4)

where $\bigotimes_{i}|\Omega_{i}\rangle=|0\rangle\otimes|0\rangle\otimes\dots$
are ancillary states.

Graphically we place the corresponding the decoding unitary
$U_{i}^{\alpha_{i}}$ of a tensor on the same set of wires in the quantum
circuit. For the wires that contract to identity in the tensor network, they
will continue on to a later time in the circuit. The other wires will
terminate on either an ancilla or a decoded state in the circuit. See Figure 9
for an example. Note that for small enough isometry tensors, we assume that
these decoding unitaries can be independently derived and are thus known.

Readers may recall that in MERA one can convert the tensor network with
isometries into a unitary quantum circuit where the isometries are replaced
with a unitary with a fixed ancilla output. A similar process takes place here
except one also recovers a non-trivial $|\Psi\rangle$ in addition to the
ancillary $|0\rangle$s.

Another point to note is that the contraction sequence given a tensor network
may not be unique. Different sequences thus give rise to different
realizations of the decoding process. For encoding, one can run the circuit
backwards.

Sometimes, the tensor network may only be approximately contractible, i.e.,
the tensors contract to identity up to a small error[23]. In such cases, the
quantum circuit from exact contraction sequence can still be useful, which
encodes/decodes the logical information at the expense of small errors.

###  C.2 Construction of contractible tensor network codes

Here we give a general construction of tensor networks that are contractible
in the above description. As such, it always admits an explicit
encoding/decoding circuit construction from the contraction sequence above.
Algorithm 1 is sufficient for producing a network that is locally
contractible, and thus resulting in a local decoding quantum circuit.

initialization: start with an $\ell_{0}$-isometry with no more than $\ell_{0}$
logical legs;

for  _$0 <i<$cut-off_ do

Begin with the $\ell_{i-1}$-isometry tensor network with $k_{i-1}$ logical
legs and $n_{i-1}$ total non-logical external legs

Select another $r_{i}$-isometry and designate $\kappa_{i}<r_{i}$ logical legs
and total $m_{i}$ non-logical external legs

Contract no more than $c_{i}=r_{i}-\kappa_{i}$ legs with the non-logical
external legs of the $\ell_{i-1}$-isometry

Produce a new network which is a $\ell_{i}$-isometry with
$k_{i}=k_{i-1}+\kappa_{i}$ logical legs and $n_{i}=n_{i-1}+m_{i}-2c_{i}$ non-
logical external legs

end for

Algorithm 1 Tensor Network Building Algorithm

For isometries that are obtained from stabilizer codes with bond dimension 2,
this is simply an iterative procedure that applies Theorem 1 of [32]
repeatedly provided we pre-assign logical and physical legs to the tensors
before contraction and then never contract the logical legs in the individual
tensors. Codes generated that way are known as tensor network codes (TNC). If
we permit the contraction of logical legs, as in the example shown in Figure
6a, then the procedure also produces non-TNCs.

###  C.3 Compatibility with Other known Decoding Methods on Tensor Networks

Let us refer to the codes built by the current framework as quantum lego codes
(QLC). There are several subclasses of QLC whose decoding have been discussed.
Therefore, one can reuse some of these methods when we fall into one of these
classes. For instance,

$\mathrm{QLC}\supset\mathrm{QbQLC}\supset\mathrm{TNC}\supset\mathrm{HSbC},$
(C.5)

where HsBC stands for holographic stabilizer codes of which HaPPY code is a
member.

The approach by Ferris and Poulin (FP) [17] is based on qubit code decoding
unitaries which map operators to operators. Let us refer to QLCs over qubits
whose encoding/decoding unitaries are known as qubit QLCs (QbQLC). More
precisely, let $U$ be an encoding unitary that maps a pre-encoded state on $n$
qubits to an encoded state on $n$ qubits.

$|\tilde{\psi}\rangle=U|\psi\rangle_{k}|0\rangle^{\otimes{n-k}}$ (C.6)

where $|\psi\rangle_{k}$ is an encoded message over $k$ data qubits. This
unitary is known for tensor networks described in the previous section.

However, it is not exactly the unitary used by [17] to compute the conditional
probability distributions $Q(E|s)$ of error $E$ given syndrome $s$, which is a
tensor network of bond dimension 4. To do so, we introduce the FP-compatible
encoding unitary $\mathcal{U}$ by contracting with tensors of Pauli operators