Union-Find Decoders For Homological Product Codes

Homological product codes are a class of codes that can have improved distance while retaining relatively low stabilizer weight. We show how to build union-find decoders for these codes, using a union-find decoder for one of the codes in the product and a brute force decoder for the other code. We apply this construction to the specific case of the product of a surface code with a small code such as a $[[4,2,2]]$ code, which we call an augmented surface code. The distance of the augmented surface code is the product of the distance of the surface code with that of the small code, and the union-find decoder, with slight modifications, can decode errors up to half the distance. We present numerical simulations, showing that while the threshold of these augmented codes is lower than that of the surface code, the low noise performance is improved.

Homological product codes are a class of codes that can have improved distance while retaining relatively low stabilizer weight. We show how to build union-find decoders for these codes, using a union-find decoder for one of the codes in the product and a brute force decoder for the other code. We apply this construction to the specific case of the product of a surface code with a small code such as a [ [4,2,2]] code, which we call a augmented surface code. The distance of the augmented surface code is the product of the distance of the surface code with that of the small code, and the union-find decoder, with slight modifications, can decode errors up to half the distance. We present numerical simulations, showing that while the threshold of these augmented codes is lower than that of the surface code, the low noise performance is improved.
The homological product provides a general tool to construct a new CSS quantum code out of two smaller CSS quantum codes. The resulting codes are called homological product codes [1,2]. One application of this product has been to construct quantum codes with linear distance and rate and with stabilizers whose weight scales only as the square-root of the number of qubits [2]. Other applications include weight balancing [3,4] and the construction of some novel code families [5]. A special case of the homological product is the hypergraph product [6], which has been applied to construct quantum LDPC codes of linear rate and square-root distance. These hypergraph product codes have efficient decoders [7]. However, until recently, no efficient decoders have been proposed for homological product codes; while this paper was in preparation a decoder for a certain class of such codes was proposed in [8].
In this paper, we give a general construction of an efficient decoder for another class of homological product codes. The decoder is a generalization of the union-find decoder [9]. We assume that one of the codes in the product, which we call the large code has a union-find decoder, while we assume that the other code, which we call the fixed code, is of some fixed O(1) size so that we can use a brute force decoder on that code. From these two ingredients, we construct a decoder on the product code. (As a technical point, to do this in general, we must assume that the fixed code has no redundancies in its checks, as explained later.) Importantly, the decoder on the product code is only a constant factor slower than the decoder on the large code and so it runs in close to linear time when the large code is a surface code.
We apply this decoder then to the product of the surface code with various small codes (the product was proposed in [2] and the anyons of the theory were studied in [10]), and give numerical results.
First let us review the union-find algorithm and also let us say what we mean by a union-find decoder in general: if the large code is not a surface code, what properties should the decoder have in order for it to be called a union-find decoder? For us, a union find decoder for an LDPC code works as follows: it takes as input some syndrome (and possibly also some list of erased qubits). It constructs a set of clusters, where each cluster contains a set of qubits and and a set of checks. These clusters are constructed using some local operations (i.e., local with respect to the distance defined by the checks of the code) in an initialization phase; for example, in the original union-find decoder with no erasures, then each cluster contains one syndrome error.
Then it runs through an iterative process: for each cluster it checks whether the cluster is valid. A cluster is valid if there is some error pattern on the bits in the cluster which produces exactly the observed errors on the checks in that cluster and produces no other errors; let us call that error pattern a valid error pattern. The decoder then grows any clusters which are invalid, merging them with other clusters if they intersect, and again checks validity, continuing in this fashion until all clusters are valid. Then, it constructs some valid error pattern for each cluster (arbitrarily, without regard to minimizing weight), which we call the decoding of that cluster, and it returns the sum of all those error patterns as the decoding of the input syndrome.
The paper is organized as follows. In Section 1, we review the homological product construction in general. We also give as an example the special case of the homological product of the surface code with a [ [4,2,2]] code. Interestingly, other authors have considered concatenating a surface code with the [ [4,2,2]] code [11]. We leave the question of a detailed performance comparison between these two classes of codes (homological product vs. concatenated) for future work, but we note that the homological product gives lower weight stabilizers than concatenation does.
In Section 2, we give the decoding algorithm that we use for various products of surfaces codes with small codes. In particular, we give routines to test validity of clusters, to decode clusters, and to grow clusters, and we present numerical simulations of this algorithm for a variety of different codes. The correctness of the test for validity and decoder in this section will follow from the general theory given in in Section 3 where we consider more general products, where the large code need not be a surface code and also where the fixed code may have some redundancies in its stabilizers.
Finally, in Section 4, we prove distance properties of the homological product under certain general assumptions on the large code; while in some cases [2], the distance of the homological product code can be smaller than the product of the distance of the two codes used as input to the product, if one of the codes is a "topological code" (in a sense explained later), the distance of the product is equal to the product of the distances. Further, in Section 2, we prove that if the fixed code has distance 2, then our algorithm decodes up to half the distance of the product, and a modification of our algorithm decodes up to half the distance of the product for arbitrary distance of the fixed code.

Review of Homological Product
In this section, we review the homological product. The product we use is a "multiple sector" product rather than the "single sector" product used in [2]. Throughout this paper, we consider CSS codes over qubits, meaning that all the vector spaces that we define are over Z 2 ; this means that we may ignore signs throughout.

Homology and cohomology
We consider only Z 2 -linear chain complexes and When no confusion is possible, we will omit the subscript i.
In the present work, all the spaces C i will be finite dimensional. Vectors of C i are called i-chains. We assume that a basis is fixed for each space C i and we refer to the basis elements as i-cells. A i-chain can be interpreted equivalently as a binary vector or as a subset of i-cells. As a consequence, we can talk about the boundary of a cell or a set of cells.
Two subsets of the chain space play a central role in homology: the cycles space ker ∂ i denoted Z i , and the space of boundaries or trivial cycles Im ∂ i+1 that we denote B i . The quotient H i = Z i /B i is the homology group. In our setting, it is a Z 2 -linear space.
We can obtain a new chain complex by replacing each boundary map ∂ i by its transposed map ∂ i . Identifying each space C i with its dual, we obtain the complex The map ∂ i will be called the coboundary map and the space Z i = ker ∂ i is the space of cocycles and B i = Im ∂ i−1 is the coboundary space. The cohomology group is defined to the be quotient

General Products
The product takes as input two codes. We describe both codes in terms of chain complexes.
The large code will be defined by some chain complex B defined by a sequence of vector spaces B j indexed by some integer j and a boundary map ∂ B from B j to B j−1 such that ∂ 2 B = 0. For some given q, we associate the qubits of the large code with q-cells, and we associate X-and Z-checks of the code with (q − 1)-cells and (q + 1)-cells, respectively, with the boundary operator ∂ defining the checks of the code in the usual way (original references include [12,13,14]; see [2] for a review). For use later, use L to denote the collection of all cells. The chain complex defining the large code may be obtained from some cellulation of a manifold, in which case we call it a topological code, but it need not be.
The fixed code C is defined by some chain complex C, with three vector spaces C 0 , C 1 , C 2 , with boundary operator ∂ C which is a map from C 2 to C 1 and from C 1 to C 0 such that ∂ 2 C = 0. Qubits are associated with 1-cells of C and X-checks and Z-checks are associated with C 0 and C 2 respectively. Assume that C is an [[n C , k C , d C ]] code with n X distinct X checks and n Z distinct Z checks. Assume further that there are no redundancies in the stabilizers of C (i.e., no nontrivial product of stabilizers is the identity), so n X + n Z + k C = n C . Hence, the zeroth and second homology of C vanish.
The homological product code is given by taking the product of the complex defining the large code with the complex defining C, and then defining a code from that complex. The product complex, which we denote A, has spaces A 0 , A 1 , . . ., with and the product complex has boundary operator Note that if the code is over qudits rather than qubits, there is a slightly more complicated sign structure for the boundary operator.
In the homological product code, qubits are identified with basis vectors of the space A q+1 , i.e., Thus, for every (q + 1)-cell of L, there are n X qubits, for every q-cell of L there are n C qubits, and for every (q − 1)-cell of L there are n Z qubits.
Logical Z operators of the product are given by (q + 1)-th homology classes (a particular choice of logical operator corresponds to a representative) and logical X operators are given by (q + 1)-th cohomology classes.
For a surface code on a square lattice, the number of 2-cells is roughly n B /2 and similarly for the number of 0-cells. So, in this case n ≈ n B (n X + n Z ) 2 + n B n C .
X-stabilizers of the product code are associated with basis vectors of A q = so that for every (q −2)-cell there are n Z different stabilizers, for every (q −1)-cell there are k C different stabilizers and for every q-cell that are n X different stabilizers. Note that in many cases (for example, the surface code with q = 1 or some LDPC codes), the first term (B q−2 ⊗ C 2 ) is absent.
The "cells" of the product complex will be basis vectors of spaces A q , and a cell e of the product complex will be associated with some cell f of L if the basis vector corresponding to e is some product of the basis vector corresponding to f with some basis vector of a cell in the fixed code. Given any vector v in this space A q , and any (q − 1)-cell e ∈ L, we define the vector of coefficients of v on e on that cell in the obvious way: it is given by the n C distinct coefficients of v for cells of the product complex which are associated to e.

Simple Example
As an example of this formalism, we give perhaps the simplest augmented surface code, the homological product of a surface code on a square lattice with a [ [4,2,2]] code with checks XXXX and ZZZZ. Figure 1 shows the layout of the qubits are checks of the augmented surface code.
This code has 4 qubits per edge, one qubit per vertex, and one qubit per plaquette. It has one X stabilizer on each edge e given by where X a e for a = 1, . . . , 4 are Pauli operators on the four qubits on edge e, the product is over plaquettes p such that e is in the boundary of p, and X p is a Pauli operator on the qubit on plaquette p. This stabilizer is weight 6. It has four X stabilizers on each vertex v given by (for a = 1, . . . , 4) where X v is a Pauli operator on the qubit on vertex v. This stabilizer is weight 5. There is also one Z stabilizer on each edge e given by and four Z stabilizera on each plaquette p given by For any cellulation, the code has twice as many logical qubits as the surface code does. Based a m × m square lattice of a torus one can define a [[2m 2 , 2, m]] toric code. Its product with [[4, 2, 2]] code provides a [[10m 2 , 4, 2m]] which uses more physical qubits but encodes twice has many logical qubits with a doubled minimum distance (Section 4). Overall, this strategy leads to a significant reduction of the qubit overhead required to achieve a given minimum distance as shown in Figure 2.

Decoding Augmented Surface Codes
We now give our decoding algorithm for the case where the large code is a surface code and the fixed code has no redundancies in its checks. Since we consider CSS codes, we consider just the correction of Z-error using X-type measurements. By duality, X-type errors can be corrected with the same procedure. So, for us, the error patterns will be on 2-cells of the product complex and the syndrome of an error will be the set of 1-cells on its boundary.

Error and syndrome
To define the surface code, consider a finite cellulation (V, E, F ) of a closed surface with vertex set V , edge set E and face set F . The chain complex B of the surface code is the chain complex of the cellulation defined over the spaces The n X rows of H X correspond to the X type stabilizer generators and n Z rows of H Z define the Z type stabilizer generators of C. Equivalently, the code C can be described by the chain complex The matrices H X and H T Z are the matrices of the boundary maps C 1 → C 0 and C 2 → C 1 respectively.
Qubits of the augmented surface code are placed on the 2-cells of the homological product A = B⊗C.  (1) is obtained by applying the boundary map of the product complex: One can write this syndrome using the standard form with s(v) ∈ C 1 and s(e) ∈ C 0 . The first and third terms of (2) contribute to the vectors s(v) and the second and fourth terms contribute to s(e).

Generalization of the Union-Find decoder
In order to design a decoder for augmented surface codes, we use a decoder D X : C 0 → C 1 and a decoder D T Z : C 1 → C 2 for the linear codes with parity check matrices H X and H T Z respectively. For a small CSS code, these two decoders can be given as a lookup table. We can assume that they provide a minimum weight correction. Pick a family x 1 , . . . , x k C ∈ C 1 representing k C independent X logical operators of the fixed CSS code C and let z 1 , . . . , z k C ∈ C 1 be independent Z logical operators of C such that (x i |z j ) = δ i,j (mod 2).
The union-find decoder will grow connected clusters in the surface until all the clusters can be erased and corrected independently given the syndrome s. Such a cluster is said to be a valid cluster.
To determine if a cluster κ is valid, we compute the validity vector A cluster is valid iff its validity vector is trivial. In Section 3.1, we will prove that a valid cluster contains a valid error pattern.

Algorithm 1 Union-Find decoder for augmented surface codes
Require: The syndrome s(x) as in (3)  Computex(e) = D X (s(e)).

6:
Add u ⊗ s(e) and v ⊗ s(e) to s. 7: Union-Find growth: 8: Initialize clusters with a single vertex κ v = {v}. 9: Merge clusters connected by an edge of E. 10: While there exists at least one invalid cluster do:

11:
Select an invalid cluster κ with minimum boundary.

13:
Update the validity vector of κ. 14: Set E to be the set of all edges fully covered by the grown clusters. 15: Peeling: 16: Construct a spanning forest F of the subgraph E of the surface. 17: While F = ∅ do:

18:
Select an edge e = {u, v} of F such that u is a leaf.

20:
Add u ⊗ s(u) and v ⊗ s(u) to s.

24:
Add u ⊗ z i and v ⊗ z i to s.
Algorithm 1 works in four steps. First, we eliminate the components of the syndrome on edges. A syndrome component e ⊗ s(e) ∈ B 1 ⊗ C 0 is killed (moved to the endpoints of e) by adding an Z error on the 2-cell e ⊗ D X (s(e)) ∈ B 1 ⊗ C 1 . We will treat this edge set E ⊂ E as an erasure in the surface.
The second step is a growth step similar to the union-find decoder. On can erase and decode a cluster iff it is valid. We apply the same growth procedure as in the union-find decoder with erasure E and with the validity function defined above based on the syndrome values s(v) on nodes.
Once valid clusters are grown, they are erased and the peeling decoder [15] is used to identify a correction that explains the syndrome inside each cluster. This peeling step applies a correction on the edges of a spanning tree of each cluster. Over an edge e = {u, v}, two types of correction are applied. (i) A correction e ⊗ s(u) moves the local syndrome s(u) from u to v. (ii) A correction of the form e ⊗ z i to used to cancel the validity vector in node u. As a result, after peeling, each node v of the cluster, except the root v 0 , supports a trivial syndrome v ⊗ s(v) with s(v) = 0. Moreover, the validity vector of each node of the cluster is trivial because the cluster is valid.
Finally, the residual syndrome v 0 ⊗ s(v 0 ) on each cluster root v 0 is eliminated using the decoder D T Z by applying a correction v 0 ⊗ D T Z (s(v 0 )). This local decoder can be applied because s(v 0 ) is a Z stabilizer of C. Indeed, we will show that s(v 0 ) is orthogonal with X stabilizers and X logical operators of C. The root v 0 satisfies val(v 0 ) = 0, which means that s(v 0 ) is orthogonal with all the X logical operators of C. Moreover, since the cluster is valid before peeling, the restriction of the syndrome to the cluster, is 1-boundary in A and this property is preserved after peeling. As a consequence One can slightly improve the performance of Algorithm 1 by modifying the growth procedure. This variant of the decoder is described in Appendix A.

Numerical results
In this section, we report the result of numerical simulation of augmented toric codes. We consider the product of a rotated toric code with different CSS codes. We only simulate the correction of Z-error since the codes considered are self-orthogonal. To sample from Z-errors, we start from the trivial 2-chain and we flip each bit of each vector x(v), x(e) and x(f ) independently with probability p. For simplicity, we do not consider the case of erasure errors. We assume perfect syndrome extraction circuit. Our numerical simulations are based on the variant of Algorithm 1 proposed in Appendix A.
In Figure 2 we observed that augmented topological codes can achieve the same distance as traditional topological codes with a reduced qubit overhead. To illustrate further the advantage of augmented codes, we compare numerically the performance of toric codes and their product with a [[4, 2, 2]] code. In both cases, the correction is performed using a union-find decoder. Denote by TC(m) the toric code defined on the m × m lattice. In Figure 3, we compare the product TC(m) ⊗ [ [4,2,2]] with all the toric codes TC( ) achieving a smaller or equal qubit overhead. Our numerical results show that augmented toric codes with m ≥ 3 outperform toric codes in the regime of low error rate. As an example, the augmented toric code TC(6) ⊗ [ [4,2,2]] consumes 90 physical qubits per logical qubit and it achieves a lower logical error rate than the toric code TC(9) which has comparable overhead. The origin of the superiority of augmented toric codes is their increased minimum distance which reaches 12 for the code TC(6) ⊗ [ [4,2,2]], whereas the traditional toric code is limited to distance 9 for the same overhead. As a result the gap between the two family of codes increases when we consider better qubits.

Distance
The results of Section 4 show that the distance of an augmented surface code equals the product of the distances of the large and fixed codes. Here we show that Lemma 1. If the fixed code has distance 2, then the union-find decoder (in its simplest form where we do not have separate clusters for each logical operator) decodes errors with weight less than half the distance. (It is already known [9] that for the unaugmented surface code, the union-find decoder has this property.) ] with toric codes with smaller or equal overhead for m = 3, 4, 5, 6. Toric codes are decoder is the standard union-find decoder and Algorithm 2 is used to decode augmented toric codes. Augmented toric codes achieve a better logical error rate than toric codes in the regime of low physical error rate. The overhead reported in these plots is the number of physical qubit per logical qubit.

Further, a modification of the algorithm (detailed in the proof of this lemma and not studied elsewhere in the paper) decodes errors with weight less than half the first for any distance of the fixed code.
Proof. First consider the case where the fixed code has distance 2. Suppose an error of weight w occurs. Let there be m edges in E before edge cancellation; these edges have at least one error on them. So, the sum over diameters of clusters in E is bounded by m.
After edge cancellation, there may be some edges that have an error on them but are not in E. Call this set of edges H, for "hidden". There must be at least 2 errors on each of these edges and so the number of such edges is at most (w − m)/2. Now consider the growth process of clusters. (This step of the proof is almost exactly the same as the proof [9] that the union-find decoder decodes up to half the distance for a surface code.) If a cluster is not valid, then there must be some edge in H leaving the cluster. A single step of the growth will cover half of one of the edges in H, and will increase the sum of cluster diameters by at most 1 (it is possible that it joins two clusters and so greatly increases the largest cluster diameter). Suppose the growth process terminates after t steps, at which point it has covered at least t/2 edges in H (hence, t ≤ w − m) and the sum of cluster diameters is bounded by m + t ≤ w. It is possible at this point that not all edges in H are covered: there may be paths in H going from a cluster to itself, and the length of these paths is then bounded by (w − m)/2 − t/2 = (w − m − t)/2. So, the sum of the cluster diameters plus the sum of the length in these paths is bounded by m + t + (w − m − t)/2 ≤ w. So, the algorithm replaces the actual error with clusters of erasures plus possibly some operator which commutes with the stabilizers (i.e., due to paths in H which are not covered), with these errors supported on sets of diameter at most w. If w is smaller than the surface code distance, it decodes correctly. Remark: we see that the worst case is when all edges in H are covered. Now consider the case where the fixed code has distance d > 2. We modify the algorithm as follows. Each edge is broken into d subedges. Note that d may be odd. Rather than keeping a set of half edges, we keep a set of these subedges. Let w(e) denote the error weight on each edge, so that w = e w(e).
We first perform the edge cancellation step. Let c(e) denote the weight of the correction applied on edge e if that correction weight is ≤ d/2; if the correction weight is > d/2 then c(e) = d/2. If an error of weight w(e) occurs, with w(e) ≥ d/2, then c(e) ≥ d − w(e). We use a minimum weight decoder so that c(e) ≤ w(e). If we fix an error on an edge e with a correction of some weight c(e), we add the c(e) closest subedges to each vertex attached to that edge to the subedge set, so that the total number of subedges on that edge in the subedge set is 2c(e). Thus, in the case that the distance is 2, any correction means adding both half edges, but for larger distance, it is possible that only part of each edge is added.
We grow so that subedges are added starting closest to the vertex and moving outwards. Note that if d is odd, it is possible that two clusters are separated by an odd number (for example, 1) subedge; to deal with this, we add subedges to clusters sequentially, rather than in parallel, or, alternatively, one may further subdivide each subedge into two subsubedges to run growth in parallel.
Let s(e) denote the total number of subedges on edge e which are in the subedge set. Thus, initially s(e) = 2c(e), but s(e) may increase as the algorithm runs. The sum of cluster diameters initially is After applying edge cancellation, the error applied on each edge may be a nontrivial logical operator. Let L denote the set of such edges with a nontrivial logical operator, and for an edge e ∈ L, let h(e) = d − s(e) denote the "hidden weight" on that edge. Let H denote the set of edges e with h(e) > 0: these are edges in L on which not all subedges are in the subedge set. Let the total hidden weight h = e∈H h(e).
Before any growth, immediately after edge cancellation, the hidden weight is bounded by h 0 ≡ e s.t. w(e)≥d/2 (d − 2c(e)). This hidden weight h reduces as a result of the growth process. If a cluster is not valid, then there must be some edge in H leaving the cluster. So, a single step of step of growth (growing on any single subedge) will reduce the hidden weight by at least 1 and will increase the sum of cluster diameters by at most 2/d. So, if the algorithm terminates after t steps, the sum of cluster diameters is upper bounded by (2/d)( e c(e) + t), and t ≤ h 0 . There may possibly be some hidden weight that remains at the end of the algorithm: this is due to edges with hidden weight d forming paths from a cluster to itself. Thus, the sum of cluster diameters plus the length of these paths is bounded by (

Union-Find Decoder in General
We now consider how to construct a decoder for a more general choices of large and fixed codes. As before, we assume that the large code has a union-find decoder, and we construct a union-find decoder for the homological product.
The initialization and growth aspects of the decoder can be chosen in various ways (for example, growing each cluster by a minimal amount). What we will be concerned with is the routines for testing if a cluster is valid and for decoding a valid cluster. We will assume that those two routines exist for any cluster of the large code, and we will construct them for the product code for any choice of fixed code in Section 3.1, Section 3.2, subject only to the requirement that the fixed code have no redundancies in its stabilizers.

Syndrome Validation
We consider the question: given some set of qubits and some observed syndrome on some set of X checks, is there a Z error pattern on those qubits which can give rise to that syndrome on those checks, and no errors on other checks? That is, is the cluster consisting of those qubits and those checks valid?
Define a sub-cell complex to be some set of cells of the large code (i.e., some cells of the cellulation if it is a topological code, and some set of X-and Z-checks and qubits if it is not), such that if a cell is in the subcomplex, all cells in its boundary are also (in the case of a code that is not a topological code, we mean that if some Z-stabilizer is in the subcomplex, then all qubits in its support are, and if a qubit is in the subcomplex, then all X-stabilizers supported on it are, i.e., given a vector corresponding to some cell of the subcomplex, all cells in the support of the boundary of that vector are in the subcomplex). We write such a sub-cell complex with regular capital letters such as P ; corresponding to that such a subcomplex there is a sub-chain complex which we write with calligraphic letters such as P; this is a set of vector spaces P j corresponding to j-cells of the subcomplex M , and define the obvious boundary operator on the subcomplex. For brevity, we will also refer to both P and P as subcomplexes.
Then, the question at the start of this section is equivalent to the question: given some subcomplex P (such that the given set of qubits is the set of (q + 1)-cells in P , and such that the given set of checks is the set of q-cells in P ), is there a vector supported on P q whose boundary is the given syndrome? Note that since we consider a subcomplex, we are guaranteed that a Z error on a qubit in P will not produce an error on any stabilizer which is not in the set of (q − 1)-cells of the complex.
Using the language of homology, asking if a syndrome vector can be written as a boundary is equivalent to asking: is the syndrome a closed chain (i.e., does its boundary vanish) and is the syndrome homologically trivial? This question can be answered in a simple way in one particular important case: that the subcomplex P is a homological product of some subcomplex M in the large code with some subcomplexC in the fixed code. We will write M to denote the sub-cell complex corresponding to M.
If C is the [[4, 2, 2]] erasure code, it makes sense to takeC = C always, but if C is a larger code it may be useful in practice to take other choices forC and to "grow" the subcomplexC in different clusters. The subcomplexC itself defines some CCS codeC with some number kC of logical qubits. Note thatC has trivial second homology since C does. We will further assume thatC has trivial zeroth homology; this holds ifC = C but may not hold in general.
The vector spaces P j can be regarded as subspaces of A j : they are the subspaces where vectors vanish on entries which do not correspond to cells of M . A syndrome on M is some element of A q which is in this subspace P j .
Then, we claim that the following algorithm will determine, given some syndrome v in P q , whether or not it is the boundary of some element w of P q+1 . First (this step is done offline, before running the union-find decoder), for each j = 1, . . . , kC, construct a vector x j in Z n C 2 so that these vectors span all possible logical X-operators for codeC. In the terminology of topology, the cohomology classes [x j ] must be independent. Then, for each j = 1, . . . , kC, define a vectorṽ j in M q−1 such that, for each (q − 1)-cell e of M , the coefficient ofṽ j on that cell is given by the inner product of the vector of coefficients of v on e with x j . We call this vectorṽ j the partial inner product of v with x j and we write it v j = (v, x j ) in an abuse of notation. Then, v is the boundary of some w if and only if ∂ v = 0 and eachṽ j is the boundary of some vector in M j . The question of whetherṽ j is such a boundary, however, is precisely the question that a union-find decoder for the large code must solve so by assumption we have an algorithm to do this, and we will show that the question of whether ∂v = 0 can always be solved in linear time.
Let us show that this algorithm is correct.

Lemma 2.
Let P be a product M ⊗C where M,C are subcomplexes of the large code and base code, respectively. Assume thatC has trivial zeroth and second homology. Consider some syndrome v ∈ A q such that v is supported on P q . Then M is a valid cluster for v, meaning that vs is a boundary of some vector in P q+1 , iff ∂ P v = 0 and, for all j ∈ {1, . . . , kC}, the vectorṽ j is a boundary in M, whereṽ j is the partial inner product v j = (v, x j ).
Note thatṽ j is a boundary in M iff its inner product with all (q − 1)-th cohomology representatives of M vanishes; in the case that the large code is the surface code, there is one such representative and this gives precisely the j-th entry of of the validity vector considered previously.
Proof. v is a boundary (i.e., it represents trivial homology) iff ∂v = 0 and its inner product with a basis of cohomology representatives vanishes. (This is a consequence of the universal coefficient theorem though it can be proven more simply in the case of Z 2 coefficients.) By Kunneth, given thatC has trivial zeroth and second homology, a basis x k for those cohomology representatives can be given by the product of nontrivial (q − 1)-th cohomology representatives of M with first cohomology representatives ofC, i.e., logical X operators, namely the x j . Verifying that all these inner products vanish is equivalent to verifying, that for each j = 1, . . . , kC, the inner product ofṽ j with all cohomology representatives of M vanishes, which in turn is equivalent to requiring that v j be a boundary in M.

Decoding
We have given an algorithm to determine if some vector v ∈ P q is a boundary of some w. We now give an algorithm that, if the answer to the previous question is yes, will find such a w. As before, we assume that we have an algorithm to solve this problem for the large code.
The construction is slightly notationally laborious in general but is straightforward: we add different boundaries to v to cancel various components of it on subspaces M q ⊗C 0 , M q−1 ⊗C 1 , and M q−2 ⊗C 2 in turn. The first cancellation and the last cancellation are straightforward using the vanishing of zeroth and second homology ofC (in fact the last cancellation happens "automatically" as a result of a previous cancellation). The second cancellation is a little trickier due to nontrivial first homology of C, but is reduced to the problem for the large code.
We begin with the first cancellation; this step is precisely the edge cancellation step of Section 2. Let v 0 be the component of v in subspace M q ⊗C 0 . Let ∂ M be the boundary operator on M. Define "∂ −1 C " to be an operator such that ∂C"∂ −1 C "y = y for any vector y ∈C 0 ; in words, given an syndrome forC, "∂ −1 C " computes an error pattern that gives that observed syndrome; this operator is precisely the decoder D Z used in Section 2. Such an operator exists because the zeroth homology ofC is trivial.
We have reduced to the problem of finding w such that v = ∂w for v vanishing in subspace M q ⊗C 0 . Now, take vector v and, for each j = 1, . . . , kC, compute a vectorṽ j as above. Then, apply the union-find decoder for the large code to find aw j such that ∂ Bwj =ṽ j . For each of the X logical operators x j find corresponding Z logical operators z j , so that (z j , x k ) = δ j,k . Then, consider vector v = v + ∂( jw j ⊗ z j ). Since z j is a Z logical operator, ∂Cz j = 0, so v still vanishes in subspace M q ⊗C 0 . Let v 1 be the component of v in subspace M q−1 ⊗C 1 . Since ∂v = 0, we have that for every (q − 1)-cell, the boundary (using ∂C) of the vector of coefficients of v on that cell vanishes, i.e., that vector of coefficients is a cycle. However, the term ∂( jw j ⊗ z j ) in the sum for v guarantees then that that vector represents trivial homology. So, it is a boundary. So, for each (q − 1)-cell e, there is some vector w e such that ∂ e w e gives the vector of coefficients of v on cell e.
So, consider vector v = v + ∂( e 1 e ⊗ w e ), where 1 e denotes the basis vector corresponding to cell e. Then, v vanishes on (M q ⊗C 0 ) ⊕ (M q−1 ⊗C 1 ). So, the only nonvanishing component of v is on M q−2 ⊗C 2 . Then, since ∂v = 0, by computing ∂v projected onto subspace M q−2 ⊗C 1 and using that the second homology ofC is trivial so that the only vector inC 2 with vanishing boundary is the zero vector, we find that v = 0.

Distance
The distance d of a homological product obeys the upper bound d ≤ d B d C by the Kunneth formula. It is known [2] that this bound is not necessarily tight. However, we now show that in many cases, including many choices of a topological large code, this bound indeed is tight.
We have the following trivial lower bound for the distance d B of the large code: if some equivalence class [x] for q-th cohomology has at least m distinct representatives, x 1 , . . . , x m , such that the support of x i is disjoint from the support of x j for i = j, then any representative of an equivalence class [z] for q-th homology which has nontrivial inner product with [x] will have weight at least m, since, of course, each representative must have some intersection with each x i . If this holds for all equivalence classes of q-th cohomology, then the Z distance of the code is at least m.
As an example of this, consider a toric code on a torus; assume the torus is L-by-L and call the two directions "vertical" and "horizontal". One choice of logical Z operator is a string of Pauli Z running in the vertical direction. There are L different such strings of minimal length, corresponding to different locations of the string in the horizontal direction. So, any logical X operator which anti-commutes with it must have weight at least L.
If some equivalence class [x] has this property of having m distinct representatives with disjoint support, we say that class has property ( * ). This bound has a trivial extension (we use (q + 1)-th rather than q-th homology now since we intend to apply this bound to the product code, but of course this bound is true for any q): if some equivalence class [x] for (q + 1)-th cohomology has at least m distinct representatives, x 1 , . . . , x m , such that the support of x i is disjoint from the support of x j for i = j, and such that any representative of an equivalence class [z] for (q + 1)-th homology which has nontrivial inner product with x i for any i must have weight at least d C on the support of x i , then any representative of [z] must have weight at least md C .
If some class [x] has this this property of having m distinct representatives with disjoint support and with lower bound d C on the weight of the intersection, we say that this class has property ( * * ).
We now show that if the class [x] for the large code has property ( * ), then the class [x ⊗ ] has property ( * * ) if represents an X logical operator of fixed code C. Proof: let z be some representative of a class with nontrivial inner product with [x ⊗ ]. Fix some i to choose a representative x i of [x]. Let us say, given a vector v in some subspace B q ⊗ C 1 or B q ⊗ C 0 that the partial inner product of that vector with some other vector u in B q is a vector in either C 1 or C 0 , respectively, defined in the obvious way: regard v as being a vector (of length dim(C 1 ) or dim(C 0 ), respectively) of vectors in B q , and take the inner product of each such vector with u. Consider the projection of z onto subspace B q ⊗ C 1 and take its partial inner product with x i to get a vector u in Z n C 2 . We have (u, ) = (z, x ⊗ ) = 1. We will next show that ∂u = 0. This will show that u represents a Z logical operator for C and so has weight at least d C , proving the desired result.
To show ∂u = 0, consider the projection of ∂z onto subspace B q ⊗ C 0 ; call this s. Of course, since ∂z = 0 we have s = 0. Take the partial inner product of s with x i to get a vector t; again t = 0. However, t is the sum of two contributions; the first is the partial inner product with x i of the boundary of the projection of z into B q+1 ⊗ C 0 , but this term vanishes since x i is a cocycle and so has vanishing inner product with any boundary. The second term is exactly equal to ∂u, so indeed ∂u = 0.
Then, with these results, for many cases such as the large code being a toric code on a torus or more generally any topological code on a torus, the distance of the homological product code equals the product d B d C . We leave open the question of the distance of the product code when the large code is a topological code with some boundaries.