over qubits $\sigma_{\alpha\beta}^{i}$ where $\alpha,\beta=0,1$ and
$i=0,1,2,3$.

$\mathcal{U}^{j_{1},\dots,j_{n}}_{i_{1},\dots,i_{n}}=\operatorname{Tr}[U(\sigma^{j_{1}}\otimes\dots\otimes\sigma^{j_{n}})U^{\dagger}(\sigma^{i_{1}}\otimes\dots\otimes\sigma^{i_{n}})].$
(C.7)

This unitary can then be contracted into a tensor network as described by [17]
to compute $Q(E|s)$.

If the unitary $U$ describes a stabilizer code on qubits, then it is a tensor
network code (TNC) for which the maximum likelihood decoder was proposed [32].
In that case, a tensor $T(L)_{g_{1},\dots,g_{n}}$, where $g_{i}=0,1,2,3$, is
used in [32] to track all the unitary product stabilizers that are also Pauli
operators. Then it is straightforward to enumerate all stabilizer equivalent
representations of some logical Pauli operator $L$ and construct the tensor
based on equation (2) in [32].

Let us assume that the augmented check matrix of an $[[n,k]]$ stabilizer code
(see Appendix D below) is known, then we enumerate all stabilizers generated
by adding the rows vectors $\vec{v}_{i}=(v_{i})^{j}=H_{ij}$ on the check
matrix

$\mathcal{S}=\\{\vec{v}_{b}=\sum_{i}\vec{v}_{i}b^{i}\>:\>\forall b^{i}\\}$
(C.8)

where $b_{i}$ are binary strings of length $n+k$ and $|\mathcal{S}|=2^{n+k}$.
Then for each $\vec{v}_{b}\in\mathcal{S}$ that corresponds to a particular
Pauli $L$ in the augmented section, we identify the corresponding pure
stabilizer section, which yields a $2n$-entry row vector. Then for each
$i=1,\dots,n$, we look at the 2-tuple given by $i$th and the $i+n$-th entry.
From it we generate a number $g_{i}$ using the mapping below

$\displaystyle(0,0)$ $\displaystyle\leftrightarrow g_{i}=0$
$\displaystyle(1,0)$ $\displaystyle\leftrightarrow g_{i}=1$
$\displaystyle(0,1)$ $\displaystyle\leftrightarrow g_{i}=3$
$\displaystyle(1,1)$ $\displaystyle\leftrightarrow g_{i}=2.$

These $g_{i}$ label the $n$ tensor indices of
$T(L)_{g_{1},g_{2},\dots,g_{n}}$. Then we set
$T(L)_{g_{1},g_{2},\dots,g_{n}}=1$. Overall, this sets $2^{n+k}$ elements of
the tensor $T(L)$ to 1 if the corresponding element is in $\mathcal{S}$. We
set the remaining elements to 0.

##  Appendix D Operator Matching for Stabilizer Codes

The total number of unitary stabilizers of a tensor grows exponentially with
system size, however they can be characterized from a few generators. This is
especially apparent for $[[n,k]]$ stabilizer codes where the number of the
stabilizers grows as $2^{n-k}$ while there are only $n-k$ generators.
Therefore, it is informative to track the stabilizer generators under tensor
gluing in addition to the graphical description. Here we provide an efficient
way of describing the operator matching process in the form of check matrix
operations so that we only track the stabilizer generators. A cursory version
is first discussed in [23] on qubits. Here we also generalize the procedure to
prime dimension qudits.

###  D.1 Conjoining Operations

Consider two qudit stabilizer codes with local dimension $D$. Write their
check matrices as $H_{1},H_{2}$, which have entries in the cyclic group
$\mathbb{Z}_{D}$. For the sake of clarity, we take $D$ to be a prime222222For
generalization to composite dimensions on $n$ qudits, one may have up to $2n$
stabilizer generators as opposed to $n$, but no other modifications are needed
[74].. The graphical tensor gluing operation can be rephrased as the
conjoining operation on check matrices,

$H=H_{1}\wedge_{J}H_{2}\sim H_{1}\wedge_{\\{e\\}}H_{2}$ (D.1)

where $J$ is a set of columns in the respective check matrices that correspond
to the set of qudits over which the tensors are glued. This operation is
exactly equivalent to operator matching/pushing, but is more succinct in the
language of matrix operations. Equivalently, we denote the conjoining by the
corresponding gluing edges $\\{e\\}$ in the tensor network. Overall, the
conjoining operation is a mapping that takes two check matrix inputs and
output a single check matrix that corresponds to the stabilizer code of a
glued tensor network. The specific construction of this mapping can be
translated into a sequence of operations of the check matrices that includes
(not necessarily in order) direct sum, row operations, row reductions, and
row/column deletions.

Any conjoining operation can be broken down into a single trace operation,
which glues one leg from two disconnected tensors, and a number of possible
subsequent self-trace operations, which corresponds to gluing one leg of the
tensor with another on the same tensor (or on the connected tensor network).
Therefore, it is sufficient to define these elementary operations separately.
If one of the matrices is trivial/empty, then the conjoining just correspond
to a number of self-traces. These operations are sufficient in creating a
check matrix description for any stabilizer tensor network.

Practically, when we apply this to study the gluing of stabilizer tensor
networks, it is convenient to treat each tensor as a $k=0$ code such that
their respective check matrix descriptions have full rank. In such cases, one
can easily verify from the operations below that the resulting check matrices
remain full rank after each trace.

Single Trace Operation: To perform a single trace, we identify the columns
corresponding to the qudit to be traced over. Without loss of generality,
suppose this is the first qudit of each code, which corresponds to the 1st and
$n+1$-st columns on both matrices.

If both codes correct any error on the first qudit, then the check matrices
can be written as

$H_{1}=\left(\begin{array}[]{cc|cc}1&v_{1}^{t}&0&u_{1}^{t}\\\
0&w_{1}^{t}&1&r_{1}^{t}\\\ 0&A_{1}&0&B_{1}\end{array}\right),\
H_{2}=\left(\begin{array}[]{cc|cc}1&v_{2}^{t}&0&u_{2}^{t}\\\
0&w_{2}^{t}&1&r_{2}^{t}\\\ 0&A_{2}&0&B_{2}\end{array}\right)$ (D.2)

after suitable row reductions.

In this notation, the left half of each check matrix represents $X$-type
operators and the right half $Z$-type operators. If a particular row in
$H_{1}$ whose entry in the 1st column is nonzero (e.g. first row on both
$H_{1},H_{2}$), we match it with the row in $H_{2}$ that has an non-zero entry
in its first column. For the $(n+1)$-st column, we match an operator to its
inverse. For instance, in the second rows of $H_{1},H_{2}$, we need to match 1
to $-1$ because from previous sections we know that $Z$ should be matched to
$Z^{-1}$. We then remove the $1$st and the $n+1$st entries on these matching
rows and then concatenate. This produces a row in the new check matrix $H$. In
this example, the matching rows
$(1~{}v_{1}^{t}|0~{}u_{1}^{t}),(1~{}v_{2}^{t}|0~{}u_{2}^{t})\rightarrow(v_{1}^{t}~{}v_{2}^{t}|u_{1}^{t}~{}u_{2}^{t})$;
$(0~{}w_{1}^{t}|1~{}r_{1}^{t}),(0~{}w_{2}^{t}|1~{}r_{2}^{t})\rightarrow(w_{1}^{t}~{}~{}-w_{2}^{t}|r_{1}^{t}~{}~{}-r^{t}_{2})$.
For rows whose entries on the 1st and the $(n+1)$-st columns are zero, then we
remove those entries and direct sum the remaining block matrices/rows.

Therefore, tracing the first qubit of these two codes correspond to the
following operation

$H=\left(\begin{array}[]{cc|cc}v_{1}^{t}&v_{2}^{t}&u_{1}^{t}&u_{2}^{t}\\\
w_{1}^{t}&-w_{2}^{t}&r_{1}^{t}&-r_{2}^{t}\\\ A_{1}&0&B_{1}&0\\\
0&A_{2}&0&B_{2}\\\ \end{array}\right).$ (D.3)

If, on the other hand, the check matrix does not correct a single erasure
error on a qudit to be traced, then we are not guaranteed to find a row with
matching entries at the $1$st and $(n+1)$-st columns when conjoining the two
matrices. In terms of the check matrix, it means that only one row in the row
reduced check matrix would contain non-zero entries in the 1st and the
$(n+1)$-st positions.

Suppose only one of the two tensors is erasure correcting on the qudit in the
tracing position. Without loss of generality, assume $H_{1}$ corrects erasure
error on the first qudit. Then

$H_{1}=\left(\begin{array}[]{cc|cc}1&v_{1}^{t}&0&u_{1}^{t}\\\
0&w_{1}^{t}&1&r_{1}^{t}\\\ 0&A_{1}&0&B_{1}\end{array}\right),\
H_{2}=\left(\begin{array}[]{cc|cc}i&v_{2}^{t}&j&u_{2}^{t}\\\
0&A_{2}&0&B_{2}\end{array}\right),$ (D.4)

where $(i,j)\neq(0,0)$232323While choosing the “generators”, we only require
that they generate the generalized Pauli group up to a phase.. We then perform
row operations on $H_{1}$ such that

$H_{1}\rightarrow\\\
\left(\begin{array}[]{cc|cc}i&iv_{1}^{t}-jw_{1}^{t}&-j&iu_{1}^{t}-jr_{1}^{t}\\\
0&w_{1}^{t}&1&r_{1}^{t}\\\ 0&A_{1}&0&B_{1}\end{array}\right)$ (D.5)

where $iv^{t}$ denotes scalar multiplication by $i\in\mathbb{Z}_{D}$. Then we
concatenate the rows that have matching 2-tuple at the $1$st and the $n+1$-st
columns e.g. $(i,j)$. We drop the rows with nonzero but non-matching 2-tuples.
If the 2-tuple is zero, then we direct sum the block matrices as before. The
single-traced check matrix one produces is

$H=\left(\begin{array}[]{cc|cc}iv_{1}^{t}-jw_{1}^{t}&v_{2}^{t}&iu_{1}^{t}-jr_{1}^{t}&u_{2}^{t}\\\
A_{1}&0&B_{1}&0\\\ 0&A_{2}&0&B_{2}\\\ \end{array}\right).$ (D.6)

If neither of the check matrices correct such located Pauli errors, then the
check matrices can be reduced to the form

$H_{1}=\left(\begin{array}[]{cc|cc}i_{1}&v_{1}^{t}&j_{1}&u_{1}^{t}\\\
0&A_{1}&0&B_{1}\end{array}\right),\
H_{2}=\left(\begin{array}[]{cc|cc}i_{2}&v_{2}^{t}&j_{2}&u_{2}^{t}\\\
0&A_{2}&0&B_{2}\end{array}\right),$ (D.7)

where we again assume $(i_{k},j_{k})\neq(0,0)$. If
$(i_{1},j_{1})=(i_{2},-j_{2})\cdot l$ for some $l\in\mathbb{Z}_{D}$, then we
concatenate the rows after removing the entries in the 2-tuples. If not, then
we drop both rows in making the new check matrix. More precisely, let
$f(i_{k},j_{k})$ be an indicator function such that $f=1$ if
$l(i_{1},j_{1})=(i_{2},-j_{2}),l\in\mathbb{Z}_{D}$ and $f=0$ if not. Since all
entries are in $\mathbb{Z}_{D}$, it takes at most $D$ operations to check if
the two 2-tuples are matching. The check matrix now reads

$H=\left(\begin{array}[]{cc|cc}fv_{1}^{t}&(fl)v_{2}^{t}&fu_{1}^{t}&(fl)u_{2}^{t}\\\
A_{1}&0&B_{1}&0\\\ 0&A_{2}&0&B_{2}\\\ \end{array}\right).$ (D.8)

One then performs a row reduction to produce the final check matrix.

Self-Trace Operation: Self-trace is very similar to single-trace in that they
are both just the matrix counterparts of operator matching. To perform a self-
trace, we identify the two qudits/columns to be traced over. Again, without
loss of generality, let us take them to be the first two columns in the $X$
and $Z$ sections of the the check matrix. If they satisfy the matching rules,
then we delete these columns from the check matrix. If there exist non-
matching rows, then those rows are also eliminated. Again, without loss of
generality, we trace the first two qudits that correspond to the first two
columns. If one traces over other qudits, then we can simply shuffle the
columns to the first two positions. Suppose the code detects any single qudit
errors on the qudits to be traced, then a check matrix can be arranged in the
following form

$H=\left(\begin{array}[]{ccc|ccc}1&0&v_{1}^{t}&0&0&u_{1}^{t}\\\
0&1&v_{2}^{t}&0&0&u_{2}^{t}\\\ 0&0&v_{3}^{t}&1&0&u_{3}^{t}\\\
0&0&v_{4}^{t}&0&1&u_{4}^{t}\\\ 0&0&A&0&0&B\end{array}\right).$ (D.9)

We perform row operations such that the first two entries of a row are equal
in the $X$ section or adds up to $D$ in the $Z$ section. Self-trace can be
easily performed by removing the first two columns and any rows whose entries
in the first two columns do not match.

$\displaystyle H$
$\displaystyle\xrightarrow{\mathrm{row~{}opt.}}\left(\begin{array}[]{ccc|ccc}1&1&v_{1}^{t}+v_{2}^{t}&0&0&u_{1}^{t}+u_{2}^{t}\\\
0&1&v_{2}^{t}&0&0&u_{2}^{t}\\\
0&0&v_{3}^{t}-v_{4}^{t}&1&-1&u_{3}^{t}-u_{4}^{t}\\\
0&0&v_{4}^{t}&0&1&u_{4}^{t}\\\ 0&0&A&0&0&B\end{array}\right)$ (D.15)
$\displaystyle\xrightarrow{\mathrm{self-
trace}}\left(\begin{array}[]{c|c}v^{t}_{1}+v_{2}^{t}&u_{1}^{t}+u_{2}^{t}\\\
v_{3}^{t}-v_{4}^{t}&u_{3}^{t}-u_{4}^{t}\\\ A&B\end{array}\right).$ (D.19)

If the code only corrects one located error on the 2 legs we plan to trace
together, then the check matrix takes on the form,

$\displaystyle H$
$\displaystyle=\left(\begin{array}[]{ccc|ccc}i&0&v_{1}^{t}&j&0&u_{1}^{t}\\\
\eta_{2}m&1&v_{2}^{t}&\eta_{2}n&0&u_{2}^{t}\\\
\eta_{3}m&0&v_{3}^{t}&\eta_{3}n&1&u_{3}^{t}\\\ 0&0&A&0&0&B\end{array}\right)$
(D.24)

for some $(i,j)\neq(0,0)$, where $\eta_{2},\eta_{3}\in\mathbb{Z}_{D}$,
$(i,j)\neq l(m,n)$ for any $l\in\mathbb{Z}_{D}$. If $\eta_{2}=\eta_{3}=0$,
then

$\displaystyle H$
$\displaystyle=\left(\begin{array}[]{ccc|ccc}i&0&v_{1}^{t}&j&0&u_{1}^{t}\\\
0&1&v_{2}^{t}&0&0&u_{2}^{t}\\\ 0&0&v_{3}^{t}&0&1&u_{3}^{t}\\\
0&0&A&0&0&B\end{array}\right)$ (D.29)
$\displaystyle\rightarrow\left(\begin{array}[]{ccc|ccc}i&i&v_{1}^{t}+iv_{2}^{t}-jv_{3}^{t}&j&-j&u_{1}^{t}+iu_{2}^{t}-ju_{3}^{t}\\\
0&1&v_{2}^{t}&0&0&u_{2}^{t}\\\ 0&0&v_{3}^{t}&0&1&u_{3}^{t}\\\
0&0&A&0&0&B\end{array}\right)$ (D.34)
$\displaystyle\rightarrow\left(\begin{array}[]{c|c}v_{1}^{t}+iv_{2}^{t}-jv_{3}^{t}&u_{1}^{t}+iu_{2}^{t}-ju_{3}^{t}\\\
A&B\end{array}\right).$ (D.37)

As before, it must be possible to reduce all other entries in the 1st and the
$(n+1)$-st columns to zero. If there exists another element whose 2-tuple is
linearly independent of the $(i,j)$, then together with $(i,j)$ they must
generate the full Pauli group to be phase factors. This then reduces to the
first case where the traced qudit is a correctable erasure error. If certain
rows in these columns can not be made to match, we also eliminate the
corresponding rows.

If $\eta_{2}\neq\eta_{3}$, then we can rearrange the check matrix into one of
the following form via row operations.

$\displaystyle H$
$\displaystyle=\left(\begin{array}[]{ccc|ccc}1&l^{\prime}&r_{1}^{t}&0&0&w_{1}^{t}\\\
0&k^{\prime}&r_{2}^{t}&1&0&w_{2}^{t}\\\
0&j^{\prime}&r_{3}^{t}&0&1&w_{3}^{t}\\\ 0&0&A&0&0&B\end{array}\right)$ (D.42)

or

$\displaystyle H$
$\displaystyle=\left(\begin{array}[]{ccc|ccc}1&0&r_{1}^{t}&0&l^{\prime}&w_{1}^{t}\\\
0&1&r_{2}^{t}&0&j^{\prime}&w_{2}^{t}\\\
0&0&r_{3}^{t}&1&k^{\prime}&w_{3}^{t}\\\ 0&0&A&0&0&B\end{array}\right)$ (D.47)

for some arbitrary $l^{\prime},j^{\prime},k^{\prime}\in\mathbb{Z}_{D}$ and
vectors $w,r$. Because the two above matrices are equivalent up to swapping
the second columns in the left and right sections followed by row swaps, we
will consider the first matrix without loss of generality.

$\displaystyle H$
$\displaystyle\rightarrow\left(\begin{array}[]{ccc|ccc}1&l^{\prime}&r_{1}^{t}&0&0&w_{1}^{t}\\\
0&k^{\prime}-j^{\prime}&r_{2}^{t}-r_{3}^{t}&1&-1&w_{2}^{t}-w_{3}^{t}\\\
0&j^{\prime}&r_{3}^{t}&0&1&w_{3}^{t}\\\ 0&0&A&0&0&B\end{array}\right)$ (D.52)

can produce at least one matching operator by adding the first two rows after
multiplying them by constants $a=(j^{\prime}-k^{\prime})$ and
$b=(l^{\prime}-1)$ respectively. Namely, the row

$(a,al^{\prime}+b(k^{\prime}-j^{\prime}),ar_{1}^{t}+b(r_{2}^{t}-r_{3}^{t})|b,-b,aw_{1}^{t}+b(w^{t}_{2}-w_{3}^{t}))$
(D.53)

corresponds to a stabilizer generator. For some values of
$j^{\prime},k^{\prime},l^{\prime}$, we also obtain other matching rows.
However, these must be a linear combination of other rows.

Note that the resulting matrix must be full rank after row elimination. The
top 3 rows are linearly independent from the remaining rows. If $r,w$ are all
parallel to some vectors in $A,B$, then one must find 3 linearly independent
vectors that only have non-zero entries on the 2 columns. This is impossible,
so at least one of $r_{i},w_{i}$ is linearly independent of the vectors in
$A,B$. The matching solution above have support in all 3 such vectors, so it
must not be parallel to row vectors in $A,B$ unless (a)
$r_{2}-r_{3}=0,w_{2}-w_{3}=0$ for any $a,b$ or (b) at least one of $a,b$ is
zero.

In case (a), the first and second row of (D.52) only lead to commuting
operators if $l^{\prime}\neq 0$. This means that a suitable multiple of the
first row is matching, hence the final check matrix will also include vector
$r_{1},w_{1}$. If it were non-zero, then we are done. If it is zero, then the
operator on the first row does not commute with the one on the third, which is
a contradiction. Therefore $(r_{2},w_{2})-(r_{3},w_{3})\neq 0$ and it must be
a linearly independent vector. (D.53) has non-trivial support on all three
such row vectors unless at least one of $a,b=0$.

For case (b1), suppose $a=j^{\prime}-k^{\prime}=0,b\neq 0$. If one of
$(r_{2},w_{2}),(r_{3},w_{3})$ is linearly independent then we are done. If
only $(r_{1},w_{1})$ is the requisite linearly independent vector, then
$r_{2},w_{2},r_{3},w_{3}=0$. If $l^{\prime}\neq 0$, then some multiple of the
first row produces a matching operator, and we are done. If $l^{\prime}=0$,
then it does not commute with the stabilizer on the second row, which is a
contradiction. If $b=0$ (case b2), $l^{\prime}=1$, the first row is matching.
Again, we are done if $(r_{1},w_{1})$ is linearly independent. If not, then
$(r_{1},w_{1})=0$ and the first row does not commute with the third. If
$a=b=0$ (case b3), both the first and second rows are matching operators. The
second row already produces a linearly independent vector.

Finally, if neither qudits are correctable erasures, we again need to check
whether the two 2-tuples $(i_{1},j_{1})$ and $(i_{2},j_{2})$ match using the
function $f$ such that $f=1$ if $l(i_{1},j_{1})=(i_{2},-j_{2})$ and $f=0$ if
no such $l\in\mathbb{Z}_{D}$ exists. In the latter case, we simply remove the
first two rows, then follow by removing the first two columns of the $X$ and
$Z$ sections of the check matrix. More succinctly, summarize the operations as

$\displaystyle
H=\left(\begin{array}[]{ccc|ccc}i_{1}&0&v_{1}^{t}&j_{1}&0&u_{1}^{t}\\\
0&i_{2}&v_{2}^{t}&0&j_{2}&u_{2}^{t}\\\ 0&0&A&0&0&B\end{array}\right)$ (D.57)
$\displaystyle\rightarrow\left(\begin{array}[]{ccc|ccc}li_{1}&i_{2}&lv_{1}^{t}+v_{2}^{t}&lj_{1}&j_{2}&lu_{1}^{t}+u_{2}^{t}\\\
0&i_{2}&v_{2}^{t}&0&j_{2}&u_{2}^{t}\\\ 0&0&A&0&0&B\end{array}\right)$ (D.61)
$\displaystyle\rightarrow\left(\begin{array}[]{c|c}flv_{1}^{t}+fv_{2}^{t}&flu_{1}^{t}+fu_{2}^{t}\\\
A&B\end{array}\right).$ (D.64)

To obtain the valid forms of check matrices, one perform row reduction to all
$H$s we analyzed above and eliminate any zero rows. This is to eliminate extra
row vectors that are linearly dependent of other row vectors.

###  D.2 Channel-State Duality

Specifying the stabilizers is helpful, but often not enough for a multi-qudit
logical subspace. To keep track of the logical operators under tensor gluing,
we simply augment the above check matrices with their logical operators as
well. In the tensor network language, we are simply turning these encoding
maps into stabilizer states by demoting the logical legs to physical legs.

We first augment the logical operators. For each logical $\bar{X}_{i}$ with
physical representation $O^{i}_{x}$, we write
$S^{i}_{\bar{X}}=O^{i}_{x}\otimes I_{1}\otimes\dots\otimes X_{i}\otimes
I_{i+1}\dots$. Similarly, for logical $\bar{Z}=O_{z}$, we construct
$S_{\bar{Z}}=O_{z}^{i}\otimes I_{1}\otimes\dots\otimes
Z^{\dagger}_{i}\otimes\dots$. Suppose the original stabilizer group of the
code is $\mathcal{S}_{H}$; we then construct a new stabilizer group from each
of the augmented logical operators $S_{\bar{X}}^{i},S_{\bar{Z}}^{i}$ and all
augmented stabilizers $S_{h}\otimes I_{1}\otimes I_{2}\otimes\dots$, where
$S_{h}\in\mathcal{S}_{H}$ are the $n-k$ generators of the original stabilizer
group.

$\mathcal{S}_{H_{A}}=\langle S_{h}\otimes
I\otimes\dots,S_{\bar{X}}^{i},S_{\bar{Z}}^{i}\>:\>\forall 1\leq i\leq
k\rangle$ (D.65)

It is straightforward to check that $\mathcal{S}_{H_{A}}$ has $n+k$ generators
and now identifies a stabilizer state over $n+k$ qudits. Then we have
converted the encoding isometry of an $[[n,k]]$ stabilizer code into an
$[[n+k,0]]$ stabilizer state in a way similar to [18] where one converts the
perfect code into the perfect tensor.

More explicitly, let the original check matrix of the code be
$H=(H_{X}|H_{Z})$. Then the new check matrix of the $[[n+k,0]]$ code/state is

$H_{A}=~{}\blockarray{c|c|c|c}\block{(c|c|c|c)}\block*{c|c|c|c}\block*{c|c|c|c}H_{X}&0H_{Z}0\\\
\BAhhline{--|--}\block*{c|c|c|c}P_{LX}&L_{X}Q_{LX}0\\\ P_{LZ}0Q_{LZ}L_{Z}\\\ $

where $P_{LX,LZ},Q_{LX,LZ}$ record the respective $X$ and $Z$ matrix entries
of the original logical operators over the $n$ original physical qudits.
$L_{X,Z}$ are row vectors with $1$ nonzero entry and $k-1$ zero entries which
correspond to the specific logical $X$ or $Z$ operator we have dualized.

The conjoining operations described in the previous section can then be
applied to the augmented check matrix. Note that it is perfectly valid to
treat the tensor network as a stabilizer state and perform contractions on any
tensor legs as needed. Once the gluing/conjoining operations are finished, one
can then pick out the qudits of interest to be logical and physical legs. This
is done by selecting the corresponding columns and then reversing the above
“tensorization” procedures. As such, one can turn relevant stabilizer elements
back into logical operators.

However, if one only performs contractions on the physical legs and do not
contract any of the logical edges, then it is also convenient to keep track of
the original logical edges in the second and the fourth sections of the matrix
separately. They remain the logical degrees of freedom after the conjoining
operations, and one can revert them back into logical operators using the
reverse procedure described above. In particular, if a corresponding logical
operator has non-trivial entries in $L_{X,Z}$ but trivial entries in $P,Q$
after row reducing $H_{A}$, then it implies that certain apparent logical legs
in the tensor networks do not encode independent degrees of freedom. These
rows in the check matrix $H_{A}$ then become constraints that mark which
logical legs are inter-dependent. Some explicit examples of this is found in
Sec III.

###  D.3 Tracing stabilizer codes: proof

In this section we provide a quick proof for Theorems II.1 and II.2. The
theorem statements are produced here for the readers’ convenience.

######  Theorem.

Tracing stabilizer tensor(s) produce another stabilizer tensor.

######  Proof.

For any stabilizer code, consider its encoding stabilizer tensor. Recall that
any tracing/conjoining can be written as a sequence of single-trace and self-
trace operations. To prove the above statement, it suffices to show that self-
traces of any stabilizer tensor remains a stabilizer tensor. This is because
for any single-trace operation, we can consider instead the two disconnected
tensors as a single larger tensor whereby single trace is now given by a self-
trace.

Now any stabilizer tensor of rank $n$ can be used to describe a stabilizer
state that admits a rank $n$ check matrix $H$. Note that from the procedures
in Appendix D.1 by taking the case of $k=0$, self-trace on this check matrix
always produces another check matrix with rank $n-2$, which corresponds to
another stabilizer state. Therefore, self-traces of any stabilizer tensor
remains a stabilizer tensor. Using the tensors to represent encoding maps,
then traces or self-traces of stabilizer codes remain a stabilizer code. ∎

######  Theorem.

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

######  Proof.

Similar to the proof above, we treat the CSS tensor as a state and examine how
its check matrix transforms under self-trace. Recall that for an $n$-qudit CSS
code, its check matrix can be written in a form

$\begin{pmatrix}H_{X}&\mathbf{0}\\\ \mathbf{0}&H_{Z}\end{pmatrix}$ (D.66)

where $H_{X},H_{Z},\mathbf{0}$ are block matrices with $n$ columns. If the
state, and hence the associated tensor, is self-dual, then $H_{X}=H_{Z}$. Now
to perform a self-trace, we perform row reduction and the subsequent matching
separately on $H_{X}$ and $H_{Z}$. The conjoining operations requires that for
each row we only need to match the two row entries in $H_{X}$ (or $H_{Z}$)
separately. As the matching in $H_{X}$ and $H_{Z}$ are completely independent,
this preserves the block structure in the new check matrix

$\begin{pmatrix}H^{\prime}_{X}&\mathbf{0}\\\
\mathbf{0}&H^{\prime}_{Z}\end{pmatrix}.$ (D.67)

Hence the state or the $k=0$ code remains CSS. By definition it maps to a CSS
tensor.

If the tensor is self-dual CSS, then one only need to perform the matching or
self-trace on $H_{X}$ to produce $H_{X}^{\prime}$ because identical procedures
apply to $H_{Z}=H_{X}$, which will yield $H_{Z}^{\prime}=H_{X}^{\prime}$.
Hence the resulting tensor is a self-dual CSS tensor. ∎

##  Appendix E Algorithm for tracking Stabilizers and logical operators

Here we consider the algorithm of tracking the new stabilizer generators under
conjoining or tensor gluing. To start, we assume that each bond/edge of a
tensor has the same dimension $D$. For clarity, we will again assume that $D$
is a prime, even though for non-prime $D$ a similar argument holds.

It is often helpful to identify the stabilizer generators of a stabilizer
code. In addition, we want to identify, for instance, the minimal weight
logical operators and stabilizers, for instance. To facilitate such analysis,
it is often convenient to first produce the check matrix of the overall
stabilizer code generated from the tensor network. One can then perform
whatever tools available to stabilizer codes to the check matrix to further
ascertain its properties.

The algorithm is simple: we assume that we are given the check matrices of
each tensor prior to gluing, and then connect the edges one-by-one. This
corresponds performing the conjoining operations on the relevant check
matrices. We keep conjoining until all intended edges of the tensor network
have been connected.

More precisely, let us start with a number of tensors from which we want to
generate a new tensor network with internal (glued) edges $E$.

initialization;

for  _each edge $e\in E$_ do

Identify the corresponding columns in relevant check matrices

Swap columns to the left

Convert the matrices into reduced row echelon forms

Produce a new check matrix $H$ through conjoining

Row reduce $H$ and remove all zero rows

end for

Algorithm 2 Check Matrix Building Algorithm

Algorithmic Complexity:

Let the total number of dangling legs from the initial set of tensor modules
be $N$. This includes the physical as well as the logical edges. Here we give
an upper bound on its (time) complexity.

One can encapsulate the union of all uncontracted tensors prior to tracing as
a single check matrix of size at most $N\times 2N$. Then each tensor
contraction simply corresponds to a self-trace operation on this matrix. This
requires moving the columns around, which can be achieved in $O(1)$ time
through swapping, and Gaussian elimination to prepare the matrix for self-
trace. If the traced qudits are correctable erasures, then one only require
again $O(1)$ operations to arrange the rows and columns in a desirable form.
If, on the other hand, they are not, then one has to check whether the
appropriate entries are matching. For a finite field of order $D$, it takes at
most $D$ iterations. After $O(1)$ operations to eliminate the proper rows and
columns, one again performs Gaussian elimination, which is $O(N^{3})$
time242424As we are operating on a finite field, we need not be concerned
about the bit complexity for integer values.. Therefore, each tracing
procedure is of order $O(N^{3}+D)$.

Any subsequent self-tracings will operate on a check matrix that has size
$n\leq N$, depending on the number of constraints and trivial rows the tracing
produces. Because each dangling leg can be glued only once, and there are
total of $N$ dangling legs, one can perform such tracing at most $N/2$ times.
Then for any tensor network stabilizer codes built this way, the algorithm
that produces the final code is at most $O(N^{4}+ND)$.

##  Appendix F Atomic Lego Blocks

Here we show that atomic legos of rank-3, rank-2 and rank-1 outlined in
Theorem II.3 are sufficient in producing all quantum states, and by extension,
encoding maps.

######  Proof.

We first show that any quantum state over qudits can be constructed using
these basic components. Let $|\psi\rangle$ be some state over $n$ qudits
constructed from these atomic legos represented as a tensor network with $n$
dangling legs. For example, one can choose $|\psi\rangle=|0\rangle^{\otimes
n}$ which is a trivial tensor network with $n$ rank-1 tensors. The encoding
tensor of any 1-qudit code is a rank-2 tensor that corresponds to a single-
qudit unitary. Therefore, subsequent contractions of any such rank-2 tensor on
any leg of $|\psi\rangle$ acts as a single-qudit unitary gate. In the same
way, contraction of any dangling leg of $|\psi\rangle$ with the rank-1
$|0\rangle$ tensor acts as a projective measurement in the $Z$-basis with
eigenvalue $+1$. More generally, by contracting the $|0\rangle$ tensor with an
additional rank-2 tensor, then with $|\psi\rangle$, we can also perform
projective measurements in any basis. We notice that if we can construct an
additional suitable two qubit gate to act on $|\psi\rangle$, then these
tensors form a universal gate set and thus one can in principle produce any
target quantum state.

Figure 16: The triangular tensors are the encoding tensors of the repetition
code and $H$ is the tensor that corresponds to the Hadamard or Fourier gate.
Right figure represents the generalized controlled phase gate, which reduces
to the CZ gate on qubits.

For the remaining two-qubit gate, we construct the controlled phase gate,

$\sum_{j=0}^{d}|j\rangle\langle j|\otimes Z^{j}$ (F.1)

which can be converted to a $\rm{CSUM}$ gate by Hadamard (or Fourier)
conjugation on the second qudit [74]. Here
$Z=\sum_{j}\omega^{j}\>|j\rangle\langle j|$ is the generalized Pauli-$Z$
operator on qudits with $\omega=\exp(i2\pi/d)$. The addition of this gate will
render our gate set universal. This gate can be synthesized via the tensor
contraction in Figure 16 using the encoding tensor of the repetition code and
a Hadamard. Indeed, let the repetition code encoding map be
$\sum_{i}|ii\rangle\langle i|$, then the gate represented by tensor in Figure
16 can be written as

$\displaystyle\Big{(}\sum_{i,j=0}^{d-1}|i\rangle\langle
ii|_{AB}\otimes|j\rangle\langle jj|_{CD}\Big{)}|H\rangle_{AC}$
$\displaystyle=$ $\displaystyle\Big{(}\sum_{i,j=0}^{d-1}|i\rangle\langle
ii|_{AB}\otimes|j\rangle\langle
jj|_{CD}\Big{)}\Big{(}\sum_{k,l=0}^{d-1}\omega^{kl}|k\rangle_{A}|l\rangle_{C}\Big{)}$
$\displaystyle=$ $\displaystyle\sum_{i,j=0}^{d-1}\omega^{ij}\,|i\rangle\langle
i|\otimes|j\rangle\langle j|=\sum_{i=0}^{d-1}|i\rangle\langle i|\otimes Z^{i}$

where $|H\rangle$ is the Hadamard state. We have labelled the relevant Hilbert
space factors to avoid confusion.

As for quantum channels in the form of isometric encoding maps, one can first
convert it into a quantum state and then build up its corresponding tensor
network. Because the same tensor network represents the desired encoding map,
the same atomic legos are sufficient for expressing any such encoding map. ∎

##  Appendix G Details of Some Code Constructions

###  G.1 Toric code

Starting with the $[[4,2,2]]$ code tensors, we can understand them as 6 qubit
stabilizer states whose generators are given in Figure 17. If we promote one
of the legs (upward pointing) to be a logical degree of freedom, then the same
tensor also represents a $[[5,1,2]]$ code where stabilizers that act non-
trivially on the same leg now can be converted to logical operators.
Similarly, it serves as an encoding map for the $[[4,2,2]]$ code where one
promotes both the upward and downward pointing legs to logical degrees of
freedom. The colours of the tensors are chosen such that a logical $Z$ ($X$)
operator acting on the downward pointing logical leg is represented by
weight-2 $ZZ$ ($XX$) operator acting on physical in-plane edges that are two
sides of an angle coloured in red (blue).

Figure 17: Some unitary product stabilizers of the rank-6 tensor derived from
the $[[4,2,2]]$ encoding map. Identifying the two legs pointing up and down as
the logical legs, these diagrams also produce the different representations of
the logical operators
$\bar{Z}\bar{I},\bar{X}\bar{I},\bar{I}\bar{Z},\bar{I}\bar{X}$ for the
$[[4,2,2]]$ code.

Now, it is tempting to simply contract these tensors into a grid of square
lattices. However, to create a code with localized stabilizer generators, we
need to choose the orientation of the tensors such that stabilizers pushed
into a local tensor can flow through the tensor work in a small enough closed
loop. Additionally, they need to act non-trivially on the physical qubits
which are dangling legs. The simplest configuration was given in Figure 7
where there are small closed loops of $X$ or $Z$ types — loops that have red
triangles facing inward correspond to $Z$ type loops where pushing of the
local Z stabilizer results in a weight 4 $ZZZZ$ stabilizer of the contracted
tensor network. Similarly, if the inward facing triangles are blue, it results
in the $X$ type stabilizers. Because by contracting CSS codes together, we end
up with another CSS code, it is sufficient for us to check stabilizers that
are purely $Z$ type or $X$ type. For any given type, the only remaining local
stabilizer of a tensor that does not result in a closed loop when pushing
operators is the weight for $XXXX,ZZZZ$ stabilizer that act on the 4 in-plane
legs of the tensor. This operator leaves the physical leg untouched and
continues to push any operators in one loop to another that is diagonally
adjacent. However, because it is simply the product of the two stabilizers
shown in Figure 17, pushing using this stabilizer is equivalent to multiplying
two of the adjacent star or plaquette operators. Therefore, for a tensor
network with toroidal boundary condition, it does not produce any new
stabilizers that have not been generated by the star or plaquette operators.

One can confirm that there are two actual logical degrees of freedom after
imposing the independent constraints from pushing logical operators that
result in stabilizers. We first note that the toric code has $2L^{2}$ physical
qubits and $2L^{2}-2$ stabilizer generators from the plaquette and star
operators [75].

We now wish to know how many independent constraints one can produce by
pushing only logical operators, i.e., the pushing of these logical operators
end up being a stabilizer element. The set of constraints are said to be
independent if the logical operators pushed in one set of constraint cannot be
obtained by multiplying the logical operators pushed in the other constraints.

In the case of the toric code tensor network, this is actually identical to
counting the stabilizer generators of the toric code. We note that the tensor
network has a symmetry such that the network remains invariant by exchanging
$Z\leftrightarrow X$ and all the downward pointing physical and the upward
pointing logical legs. For example, pushing $\bar{Z}\bar{Z}\bar{Z}\bar{Z}$
into the 4 logical legs around a closed loop with blue inward facing triangles
result in the identity operator will now map to operator pushing that produces
the $XXXX$ stabilizer under this transformation. Therefore, by identifying
each such weight 4 logical operator with a stabilizer generator, the number of
independent logical constraints must also be $2L^{2}-2$. Thus we arrive at the
two remaining true logical degrees of freedom despite having $2L^{2}$ apparent
logical legs in the tensor network.

From the above duality, we can also conclude that if we were to treat this
tensor network as a $4L^{2}$ stabilizer state, i.e. all dangling legs are
physical legs, then it is the unique ground state of two copies of the toric
code Hamiltonian with four additional global string-like coupling terms. More
explicitly, the stabilizer Hamiltonian is

$\hat{H}_{\rm state}=\hat{H}^{\rm toric}_{A}\otimes
I_{B}+I_{A}\otimes\hat{H}_{B}^{\rm toric}+\hat{H}_{AB}^{\rm strings},$ (G.1)

where $A$ and $B$ label the two copies of the local toric code Hamiltonians
$\hat{H}^{\rm toric}$. The local terms from the first two contributions in
$\hat{H}_{\rm state}$ provide $4L^{2}-4$ local stabilizer generators. The
remaining four non-local generators are given by $\hat{H}^{\rm strings}_{AB}$.
From the toric code tensor network, they are precisely generated by pushing
what was logical operators into strings that wrap around the torus (Figure
7b). Therefore, in the above stabilizer Hamiltonian, the last coupling term is
the sum of two X-type and two Z-type non-contractible Pauli string operators,

$\hat{H}_{AB}^{\rm strings}=\sum_{i=1,2}L_{A}^{X}(i)\otimes
L_{B}^{X}(i)+L_{A}^{Z}(i)\otimes L_{B}^{Z}(i).$ (G.2)

Each $L(i)$ is the conventional non-contractible string-like logical operator
in the usual toric code construction where it wraps around the $i$-th
direction of the torus. The superscript denotes the type of the logical
operator while the subscript denotes on which copy of the toric code it acts.

###  G.2 Boundary conditions and defects

We have seen in the previous example that by imposing the periodic boundary
condition on the tensor network, we construct the toric code. One can
similarly impose other boundary conditions. One possibility is to simply leave
the dangling legs on the boundary open for patches shown in Figure 7. We call
this the bare boundary condition. This builds a subsystem code that is similar
to the surface code in the bulk, in that it has similar stabilizer elements
acting on stars and plaquettes, but is somewhat similar to the Bacon-Shor code
on the boundary, where one can identify weight 2 $X$\- or $Z$-type gauge
operators. The logical (string) operators that connect different parts of the
boundary can also be deformed to an operator that acts purely on the boundary
degrees of freedom. An example of such a code is shown in Figure 21.

Alternatively, one can contract the dangling legs in the bare tensor network
with “stopper tensors” which are simply eigenstates of Pauli operators. An
example is shown in Figure 8a, which reproduces the surface code.

However, because of the flexiblity in a tensor network, we can choose other
types of “boundary tensors” to contract with the bare network. This allows us
to tune the boundary condition by using a combination of such different
tensors according to our needs, which hopefully creates new codes with
interesting properties.

For a straightforward example, another type of tensor one can contract with
the boundary is given in Figure 8b. These tensors can be easily created by
gluing together repetition codes (Figure 18). In the example shown, the tensor
is created by gluing 2 qubit repetition codes that are stabilized by the $ZZ$
operator. The resulting tensor is represented as the blue loop tensor in
Figure 8b. By exchanging $X\leftrightarrow Z$, one can also generate the
tensor with a red loop. Their colours denote the type of the global stabilizer
(X or Z). One can check that they simply correspond to GHZ states in different
local bases.

A subset of their legs can then be contracted with the dangling boundary legs
of the bare tensor network while leaving the rest dangling. This helps create
different boundary conditions while maintaining the “bulk properties” of the
surface code. One can also understand this as a form of code concatenation,
where we have encoded a subset of the boundary qubits with larger repetition
codes.

Figure 18: (a) Tensors that correspond to a 2-qubit repetition code or a 3
qubit stabilizer state stabilized by the generators shown. (b) By gluing the
horizontal legs of these tensors, one can create larger tensors with more legs
whose stabilizers can be determined through operator pushing.

####  G.2.1 XZZX code

In addition to the boundary, one can also make modifications to tensors in the
“bulk”. It is known that the XZZX code [54] is related to the surface code via
local transformations. A tensor network construction reflects these changes.
To do so, we simply modify every other tensor and pass their physical leg
through a Hadamard gate (Figure 19a). These tensors can be contracted into a
network (Figure 19b). In this example, we have contracted the boundary legs
with “$X$ stopper” tensors which are simply $|+\rangle$. However, like our
earlier example with the surface code, this is one of many different boundary
tensors one can contract. The stopper tensors produce $ZX$ generators for
alternating segments on the boundary. Then, pushing $X$-type stabilizers
through the original tensors on one of these segments will result in an $XX$
stabilizer. However, because the $X$ on modified tensors is pushed through an
extra Hadamard, a $Z$ operator comes out of the modified tensors. Similarly,
for stabilizer operators pushed around a closed loop, the Hadamards attached
to the modified tensors now flips two of the $X$s to $Z$s and vice versa. This
creates the same $XZZX$ operator for every square in interior of the network.

Figure 19: (a) The locally modified tensor by a Hadamard. (b) A sample XZZX
code tensor network where the boundary is contracted with X stopper tensors.
Some stabilizer generators are marked using operator pushing.

####  G.2.2 Toric Code with a Twist

One can also use twist defects to perform the full local Clifford operations.
Such defects also break the CSS nature of the surface code. One planar
construction is known as the triangle code with a central twist defect [56].
We here present a tensor network that reproduces such triangle codes by using
the $[[4,2,2]]$ code tensor, the Hadamard gate and a 4-qubit code tensor
(Figure 20). The same tensor network can be easily extended to larger codes,
but here we have chosen to reproduce the distance 5 code defined in [56] for
the sake of simplicity.

As in the surface code, we take the tensor legs pointing inwards as logical
legs and the ones pointing out as physical legs. This is indeed simply a
variant of the surface code with a defect introduced by the orange tensor
(Figure 20a). Then, stabilizers can be generated through operator pushing. One
such example is shown in Figure 20c, where the generator acting on the square
containing the orange tensor now support mixed type of Paulis. Similarly, for
the plaquettes containing the Hadamard tensor, their corresponding stabilizer
generator is also mixed, of the form $XXZZ$.

Figure 20: (a) The 4-qubit code tensor. (b) Stabilizer generators of the
4-qubit code. (c) The tensor network that corresponds to a ditance 5 triangle
code. White squares marked with “H” are the $2\times 2$ matrix representation
of the Hadamard gate. The orientation of the orange tensor is the same in all
subfigures.

Although the tensor network appears 3-dimensional, the geometry is fully
planar in the form of a triangle [56].

###  G.3 1d code

Once we have the 2d code with bare boundary condition, it is also easy to
determine the relevant operators of a dual 1d code. We first identify the
logical operators and stabilizers that act on the boundary (Figure 21a). One
can find that stabilizers are generated by the all $X$ and $Z$ Pauli strings
that act solely on the boundary degrees of freedom (circles). The logical
operators of the 2d code are given by different string operators that connect
different segments of the boundary. One can identify several other such string
operators from the 2d subsystem code then push them to the boundary through
stabilizer multiplication. Their representations for such a 2d code is shown
in (Figure 21).

To obtain a “dual 1d code”, we promote all bulk physical degrees of freedom to
logical legs. We are then left with a set of qubits on the 1 dimensional
boundary. For the example given, it is a $[[20,18,2]]$ code with two global
stabilizer generators of all $X$ and all $Z$. One set of logical operators of
an encoded qubit is shown as green and yellow strings in Figure 21a. The other
eight are shown as coloured strings in Figure 21bc. By exchanging $X$ and $Z$
for the first nine sets of logical operators, we obtain the other 9
independent sets. Together they characterize the 18 logical qubits of this
code.

Note that it is somewhat inaccurate to call this a 1d code as the stabilizer
Hamiltonian constructed from its generators is not one that contains spatially
local interaction terms. However, by fixing a suitable gauge, one can reduce
the code to a $[[20,2,2]]$ stabilizer code that contains only 2-spatially-
local stabilizer generators plus the two global all $X$ and all $Z$
generators.

This code is somewhat reminiscent of the holographic code in that it maps the
bulk logical degrees of freedom to the boundary physical qubits. However,
because of constraints and degrees of freedom counting, the “bulk” qubits are
delocalized compared to the independent encoded qubits that are localized to
the bulk AdS-sized regions (Figure 12). Note that its logical operators have a
nested, multi-scale structure such that the support of certain logical
operators is contained in the support of other logical operators. This is also
somewhat similar to the hyperbolic holographic code.

Figure 21: Starting from a 2d code with bare boundary condition, the boundary
degrees of freedom we wish to preserve is denoted by circles whereas the bulk
degrees of freedom are solid disks. If we promote all bulk degrees of freedom
to logical legs, we then produce the encoding map of a 1d code. (a) One set of
the logical (string) operators for the 2d code is given by all $Z$ (red) or
all $X$ (blue) acting on the shaded qubits. Their equivalent boundary
counterparts are given in yellow and green respectively. (b,c) Other logical
operators for this example. Blue and green strings denotes the tensor product
of Pauli $X$ acting on the shaded qubits while yellow and red indicate the
product of $Z$ on the shaded qubits. For the 2d code, these strings can also
be deformed to act on physical qubits in the bulk. For the dual 1d codes, they
only act on the boundary in the way shown.

Indeed, by switching all the bulk legs to logical degrees of freedom in the
tensor network of the 2d code, we have converted into a 1d code which has a
pseudo-holographic mapping in the form of the tensor network. Note that there
are more apparent logical legs than there are actual logical degrees of
freedom because of the constraints similar to what we have seen in the toric
code example. In any case, the tensor network here serves as a natural
connection between two distinct codes (1d vs 2d). We see that they are “dual”
to each other by simply flipping some kets to bras (and vice versa) in the
encoding map using a tensor network prescription.

In a similar fashion, we can consider other 2d codes with defects and non-
trivial boundaries. By taking all the bulk legs to be logical legs, we can
create their dual 1d codes with different properties which are manifestly
related to the 2d codes through channel-state duality. For instance, one can
repeat this exercise for the boundary that is contracted with repetition codes
(Figure 8b).

###  G.4 2d Bacon-Shor Code

Starting from the tensor network of the surface code, we can also “re-
interpret” the dangling legs differently. One such option which preserves some
degree of translation symmetry is to re-assign the physical dangling legs to
be logical legs every other row. This is explicitly shown in Figure 22, where
we again keep the logical dangling legs pointing upwards while the physical
dangling legs pointing down. We can also interpret this tensor network as
constructed from alternating $[[5,1,2]]$ and $[[4,2,2]]$ codes without
changing the interpretations of the dangling legs.

Figure 22: The tensor network of a 2d Bacon-Shor code. (a) shows the operator
pushing that lead to the X (blue) and Z (red) type gauge operators by pushing
logical and stabilizer operators. If we only push stabilizers of the local
tensors, this results in a stabilizer generator (X type: green) and (Z type:
yellow) in (b). (b) and (c) shows the operator pushing that correspond to the
logical operator that has high weight. These X and Z type logical operators,
shaded in purple and orange respectively, act on a column or a row.

Again, the physical qubits lie on the sites of an $M\times N$ lattice. By
checking the stabilizer and the logical (gauge) operators through operator
pushing, we can verify that it is nothing but the 2d Bacon-Shor code. Although
it encodes large a number of qubits as a stabilizer code, we generally only
keep the one with the largest distance while demoting the rest of the encoded
qubits to gauge qubits. For $M=N$, this yields a $[[M^{2},1,M]]$ gauge code.
An example for $M=3,N=4$ is constructed in Figure 10. The tensors where we
have both legs pointing up are coloured in yellow. Such tensors do not have a
dangling physical leg, and therefore there is no physical qubit residing on
those sites. Repeating the operator pushing exercises outlined in Figure 22,
we recover the generators of the gauge group, consisting of weight-2 $ZZ$
(acting on the two boundary sites of the vertical red edges) and weight-2 $XX$
operators (acting on the two sites adjacent to each horizontal blue edge). The
$X$ logical operator (purple) is a weight $M$ Pauli X string acting on the
shaded qubits while the logical $Z$ (orange) acts on a row of $N$ qubits with
weight-$N$ Z strings.

This is an “in-between” example where some of the dangling legs in the bulk
have been reassigned (c.f. Figure 9b). Note that the apparent logical degrees
of freedom (i.e. the upward pointing dangling legs) are again inter-dependent,
not unlike what we encountered for the surface code tensor network. However,
it is somewhat surprising that by simply “dualizing” the encoding map of the
surface code one obtains a degenerate subsystem code related to the quantum
compass model. While it is known that one can interpolate between the surface
code and the Bacon-Shor code in the 2d compass code via gauge fixing[76], it
appears distinct from this tensor network description.

###  G.5 3d code

We start with the $[[7,1,3]]$ Steane code as basic components in the tensor
network. Each code can be represented as an 8-legged tensor (Figure 6b) among
which 7 of them represent physical qubits and 1 represents the encoded qubit.
For clarity, we represent such a tensor by Figure 23, where we orient 6 of the
legs such that they are mutually perpendicular when embeded in 3-dimensional
Euclidean space. The remaining 7th physical qubit and the logical leg are
localized at the origin, where we drop them in the figure to avoid clutter.
This is a CSS code, and all stabilizers that contain only Z (or X) are given
by Figure 23, where a red dot indicates a Pauli Z operator acting on the
corresponding physical qubit. If the interior of the circle located at the
center is coloured, then we mean that a Z (or X) operator is inserted at the
physical leg located at the origin.

Figure 23: Graphical representation of the stabilizer elements that only
contain $Z$ or $I$ operators. An identical set applies when we switch $Z$ to
$X$. Disks coloured red denote Pauli $Z$s acting on the corresponding qubits.

We then contract these tensors in a cubic lattice. They are oriented
appropriately such that we end up with localized stabilizer elements (Figure
24). The tensor in the center of the network has the same orientation as the
ones in Fig 23 such that the stabilizers in the top row of Fig 23 subtend the
4 corners of the adjacent coloured cubes. Starting with the central vertex, we
move along the adjacent squares on the same horizontal plane in the
counterclockwise direction. One such paths is marked by green arrows in Figure
24. When we reach the next vertex in the square, we rotate the tensor by 90
degrees counterclockwise relative to the previous tensor along the path. The
tensor immediately above (or below) the central tensor is oriented such that
it is a reflected version of the central tensor about the horizontal plane
between them. The rest of the lattice can be generated similarly by
translation and rotation.

Figure 24: A tensor network that mimics a 3d cubic lattice. It represents a
code where a physical qubit rests on each lattice site in the bulk. There is
one logical and one physical dangling leg on each vertex. They are not shown
to avoid clutter. The tensor with a yellow curly arrow hovering above is
rotated relative to the central tensor by 90 degrees counterclockwise. The
specific boundary conditions has to be treated separately by contracting the
dangling legs for tensors on the boundary. We show an example for such
contraction for the three tensors in the lower left corner. This results in
$ZZ$ stabilizers that act on an edge. Localized stabilizers can be generated
by pushing/matching the stabilizers of each Steane code tensor that act on the
appropriate corners (red arrows). The pushing is consistent because Pauli $Z$s
(or Xs) on the contracted edges match and we are left with a stabilizer that
acts with the same Pauli operator on all corners of a coloured cube.

This creates a tensor network that has localized stabilizer elements which are
$ZZZZZZZZ$ (or $XXXXXXXX$) that act on all 8 physical qubits that are located
on the corners of the coloured cubes through operator pushing. One such
example is shown by following the red arrows in (Figure 24). Again, the
interior of a vertex is coloured red if a Pauli Z operator is acting on the
dangling physical leg on the vertex, which we do not draw in the figure.

These cubes are positioned in the alternating manner as shown in Figure 24.
Whether these stabilizers end up generating the entire stabilizer group of the
final code will also largely depend on how we treat the boundary conditions,
not unlike the surface code example we have discussed. They can be contracted
differently according to our needs. As it is becoming somewhat cumbersome to
track by hand, we leave the detailed analysis of this code to future work.

In a similar way, one can examine the logical operators graphically. Because
logical X and Z operators are simply the tensor product of 7 Xs or Zs, such a
logical $Z$ (or $X$) operator is supported on the uncoloured qubits in Figure
23. Therefore, pushing of logical operators propagate along straight lines and
acts on the physical qubits the line passes through. Alternatively, it can
reach a corner and propagate in the other 2 directions orthogonal to the
incoming direction. An easy way to keep track of these paths is that they
traverse through the edges of the uncoloured boxes. For straight lines this is
relatively trivial because every edge is adjacent to an uncolored box.
However, if we use the corner terms, then they move along the corner of the
transparent boxes.

Figure 25: Pushing logical $\bar{Z}$ operators and stabilizers of the Steane
tensor produces a box-like operator flow, which is nothing but an all $Z$
stabilizer acting on the dangling physical legs located at the eight corners
of a red-coloured cube.

If we generate an operator flow using a combination of the Steane code logical
and stabilizer operators, we can produce logical operators and possibly
stabilizers with different geometric shapes. For example, one such operator is
shown in Figure 13, which takes on the form of a tree. Various other patterns
can also be generated on a larger lattice. Similar to the toric code tensor
network, there is a large degree of interdependence among the apparent logical
degrees of freedom in the tensor network because some combination of the
logical and stabilizer operator pushing produce a stabilizer. This introduces
a constraint in the apparent “logical subspace” (Figure 25).