Spanning Tree Matching Decoder for Quantum Surface Codes

We introduce the spanning tree matching (STM) decoder for surface codes, which guarantees the error correction capability up to the code’s designed distance by first employing an instance of the minimum spanning tree on a subset of ancilla qubits within the lattice. Then, a perfect matching graph is simply obtained, by selecting the edges more likely to be faulty. A comparative analysis reveals that the STM decoder, at the cost of a slight performance degradation, provides a substantial advantage in decoding time compared to the minimum weight perfect matching (MWPM) decoder. Finally, we propose an even more simplified and faster algorithm, the Rapid-Fire (RFire) decoder, designed for scenarios where decoding speed is a critical requirement.


I. INTRODUCTION
Leveraging the unique characteristics of quantum mechanics has considerably expanded the possibilities within the realm of information management, encompassing various domains such as sensing, processing, and communication [1]- [3].The key hurdle in constructing a quantum computer is the inevitable presence of errors that, if not addressed, rapidly degrade quantum information.Therefore, error correction is crucial for meaningful quantum computation [4]- [8].Surface codes are considered central to the architecture for the first generation of quantum computers, thanks to their high error thresholds, planar structure, and locality [9], [10].The minimum weight perfect matching (MWPM) decoder is presently the most widely used decoder for surface codes [11]- [13].This decoder results in large threshold error rates, but in practice, its polynomial time complexity introduces a latency that can be a bottleneck for fault-tolerant quantum computing architectures [5], [14], [15].Considerable efforts have been invested in optimizing the performance of this decoder [16], [17].Suboptimal algorithms based on the union-find (UF) decoder have also been proposed, achieving almost linear time in code length [18], [19].Additionally, there is ongoing research into neural network-based solutions [20].
In this letter, we present a fast decoding technique tailored for surface codes, called the spanning tree matching (STM) decoder.The STM algorithm involves implementing an instance of the minimum spanning tree (MST) on a subset of the ancilla qubits within the lattice.This is followed by The authors are with the Department of Electrical, Electronic, and Information Engineering "Guglielmo Marconi" and CNIT/WiLab, University of Bologna, V.le Risorgimento 2, 40136 Bologna, Italy.E-mail: {diego.forlivesi2,lorenzo.valentini13, marco.chiani}@unibo.it.Work funded in part by the European Union -Next Generation EU, PNRR project PRIN n. 2022JES5S2.a simple and fast construction of a perfect matching graph, resulting in the estimated error pattern.Finally, we propose an even more simplified and faster algorithm, the RFire decoder, tailored for situations where decoding speed is of paramount importance.We conduct a comparative analysis of the performance, considering logical error rates and execution times, between the STM, RFire, and MWPM decoders.We show that, at the price of some performance degradation, the proposed algorithms offer significant advantages in terms of decoding time.

A. Quantum Stabilizer Error-Correcting Codes
The Pauli operators are denoted as X, Y , and Z.We indicate with [[n, k, d]] a quantum error correcting code (QECC) encoding k logical qubits |ϕ into a codeword of n data qubits |ψ , with minimum distance d.The code allows the correction of all patterns with up to t = ⌊(d − 1)/2⌋ data qubit errors.
Employing the stabilizer formalism, each code is characterized by n− k independent and commuting operators G i ∈ G n , termed stabilizer generators or simply generators, with G n being the Pauli group on n qubits [5], [6].The subgroup of G n generated by all combinations of the G i ∈ G n is called stabilizer and indicated as S. The code C is the set of quantum states |ψ stabilized by S, i.e., satisfying S |ψ = |ψ ∀S ∈ S, or, equivalently, G i |ψ = |ψ , i = 1, 2, . . ., n − k.The operators that commute with the stabilizer group but are not part of it are called logical operators.The generators specify measurements on quantum codewords that do not disturb the original quantum state.These measurements are carried out using extra qubits, named ancillas.In fact, assume an error E ∈ G n affects a codeword, so that the state becomes E |ψ .It is possible to extract a binary sequence s (also referred to as error syndrome) where the i-th entry s i is zero if G i commutes with E, while s i = 1 if G i anticommutes with it.This enable the possibility to perform quantum error correction through error syndrome decoding using as input the binary sequence s.We will refer to ancillas measuring s i = 1 as defects.
Among stabilizer codes we find the surface codes.These codes arrange qubits on a planar sheet [9], [21]- [23].One of the advantages of such an arrangement, is that it requires only nearest-neighbor interactions between qubits.Also, this structure enables the possibility to perform a single round of stabilizer measurements with parallel operations [24].Logical operators can be easily identified on the surface codes: Z L (X L ) operator consists of a tensor product of Z's (X's) crossing horizontally (vertically) the lattice [21].In the case of a QECC over the depolarizing channel with data qubit error probability p ≪ 1, we can approximate the logical error rate as [25] p where β t+1 is the fraction of errors of weight t + 1 that the decoder is able to correct.

B. Minimum Weight Perfect Matching
A key characteristic of surface codes is the availability of a minimum weight decoder, known as the MWPM.This syndrome decoder constructs a graph in which vertices represent defects, and edges are assigned weights depending on the error probability of the qubits separating the pair.For instance, in case of independent identically distributed (i.i.d.) data qubit errors, these weights correspond to the number of qubits between the pair.In general, such a weighting procedure is performed using the Dijkstra algorithm to connect the defects on the graph representing the full lattice [11].By suitably assigning distances on the lattice, Dijkstra's algorithm allows for the consideration of different systems and qubit error statistics.For surface and rotated surface structures [22], [26], considering i.i.d.data qubit errors, this step can be greatly simplified adopting the Manhattan distance between defects.Then, the MWPM proceeds by matching the graph to estimate the data qubit errors.A matching of a graph is a set of edges such that no two edges in the matching share a common vertex.A perfect matching is a matching that includes all vertices in the graph [27].For topological quantum codes without boundaries (toric codes), we can directly search for perfect matches using the MWPM algorithm on the resulting graph [14].For surface codes, which have boundaries, it is necessary to add ghost defects (also known as ghost ancillas [28]) before applying Dijkstra's algorithm.This is because errors occurring along a boundary excite only one ancilla, leading to an odd number of defects which impedes running the MWPM.Therefore, for each defect, a corresponding ghost defect is considered by the decoder.In the final graph, these defects are also connected between themselves with zero distance in order to preserve the error correction capability of the code [28].
The decoder based on the MWPM is able to guarantee the error correction capability t.In addition, it is also able to correct a significant amount of error patterns of weight greater than t.As an example, for the [ [9,1,3]] rotated surface code over the depolarizing channel, we have β 2 = 0.5, i.e., the decoder is able to correct 50% of the error patterns of weight two [26].As implemented in the library for efficient modeling and optimization in networks (LEMON), the MWPM algorithm complexity is O(N M log N ), where N and M represent the number of vertices and edges in the graph, respectively [29].Specifically, for a toric code we have N = n d and M = n d 2 , while for a surface code N = 2 n d and M = 2 n d 2 due to ghost ancillas, where n d denotes the number of defects.
Since planar architectures are favorable from an implementation point of view, we will focus on surface codes in the following.The STM decoder for toric codes can be easily constructed by straightforward variations on the algorithm described below.

III. SPANNING TREE MATCHING DECODER
In this Section, we introduce the STM decoder for surface codes.First, from (1) we observe that, for a code with given n and t, the error correction capability is determined by the fraction of errors of weight w = t + 1 that the decoder is able to correct.Since the surface codes belong to the class of Calderbank, Shor, and Steane (CSS) codes, for the sake of simplicity we will refer to the lattice where the sites constitute the X generators.The same reasoning can be applied to the dual lattice.
The STM decoder consists of three phases: MST evaluation, tree matching procedure, and error correction.

A. Minimum Spanning Tree Phase
We first construct the complete graph G = (n d , n d 2 ) connecting all defects, by using Dijkstra or the Manhattan distances.Note that, since there are no ghost ancillas at this stage, this graph has fewer edges and vertices than the one used by the MWPM.
Then, we execute the MST algorithm on the graph.This can be achieved with a complexity of O(M log N ), where M = n d 2 and N = n d stand for the edges and the vertices of the graph, respectively [30].At this stage, we construct two MSTs starting from the obtained one.If the number of defects is already even, one of the output trees is the original one, while the other is derived by introducing a ghost defect on both the left and right sides.If the number of defects is odd, an output tree is obtained by adding a ghost defect to the left, while the alternative output tree is built by adding a ghost defect to the right.Then, the added ghost defects are connected to the nearest defect in the lattice.An example of this phase is reported in Fig. 1(b).In case of multiple defects with a ghost defect at the same distance, we select the one with the highest minimum distance to other non-ghost defects.

B. Tree Matching Phase
During this step, we match the trees to obtain the estimated error patterns.For a tree T let us define as E its perfect matching graph.We use adj  The algorithm terminates when the graph T becomes empty, and gives a set of edges E representing a valid solution to the error correction problem.This procedure is carried out for both the MSTs obtained in Section III-A, and the two solutions are indicated as E 1 and E 2 .Examples of the tree matching procedure described above are depicted in Fig. 1(c) and in Fig. 2(c).

C. Error Correction
After the previous phase we have two possible sets of faulty qubits, E 1 , E 2 , with a total number of data qubit errors w 1 and w 2 , respectively.An instance of STM decoding, involving both MSTs, is illustrated in Fig. 1.If w 1 ≤ t + 1 or w 2 ≤ t + 1, then we have found the correction operator 1 .
If, instead, both w 1 and w 2 have weight > t + 1, a simple processing considering both E 1 and E 2 can be applied, which guarantees the correction if the channel errors has weight ≤ t (see Section III-D).The basic idea is choosing the solution with the smallest number of horizontally traversed edges.This is motivated by the fact that logical operators traverse the lattice from one side to the other one.Hence, the correction with more operators along the horizontal dimension will more likely cause a logical operator (i.e., an undetected error).Edges of the same column Fig. 2. Spanning tree matching decoder with a [[85, 1,7]] surface code.
Both matched spanning trees have w > t + 1.Hence, the error correction is performed according to (2).
Definition 1.A column is the set of horizontal edges aligned in the vertical direction of the lattice, as shown in Fig. 2(a).
In this way, we can enumerate the columns from left to right ranging from 1 to d.Then, we can define two vectors c i with entries c i,j , where i = 1, 2 and j = 1, . . ., d, representing the cardinality of the intersection between E i and the j-th column.Since a solution E i with two edges in the j-th column is equivalent, by adding a stabilizer, to another solution without any edge in the j-th column, we also define as u i a vector with entries u i,j = c i,j mod 2. As a consequence, the function can be used as a metric to quantify how much correcting E i is likely to cause a logical operator.Thus, the final solution is that minimizing (2).For instance, in Fig. 2(c) there are three edges in solution E 1 , with weights w = 1, w = 2, and w = 5.They consist of one, two, and three horizontal qubits, respectively.However, the horizontal qubit of the edge with weight w = 1 belongs to the same column as the edge with weight w = 5.Hence, f (E i ) = 4.

D. Distance-preserving decoding
In this section we show that (2), in the case of a [[n, k, d = 2t + 1]] surface code, assures the correction of channel errors with weight w t.
Lemma 1.Given a surface code, let us call C an arbitrary Pauli Z error chain connecting two sites defects v 1 and v 2 .Then, the intersection of C with any column between v 1 and v 2 has cardinality 1 (mod 2).The intersection with any of the other columns has cardinality 0 (mod 2).
Proof.The minimal-weight chain linking v 1 and v 2 clearly satisfies the theorem.Every other chain can be obtained from this one, through the application of plaquette generators.Since each plaquette has two edges in the same column, it does not affect the modulo 2 counting.Lemma 2. Given any error pattern over an [[n, k, d]] surface code, resulting in an even number of site defects (including also ghost defects), all possible perfect matchings M have the same metric f (M).
Proof.We label the horizontal position of the sites in the lattice, from left to right, as 0, 1, . . ., d + 1, with 0 for the left ghost defect and d + 1 for the right ghost defect.Vertically aligned sites share the same label.Let us firstly examine the case where the lattice has four site defects.Reordering them we obtain four indexes 0 ≤ j 1 ≤ j 2 ≤ j 3 ≤ j 4 ≤ d + 1, representing the site positions.In this setup we can have three possible perfect matchings M i , with i = 1, 2, 3. Considering M 1 as the one connecting site 1 with 2, and site 3 with 4, by application of Lemma 1, we have that f (M 1 ) = (j 2 −j 1 )+(j 4 −j 3 ).It is easy to check that the other two matchings have the same metric.Finally, we observe that each perfect matching M in any graph G with an even number of defects can be obtained by iteratevely removing two edges and reconnecting them as needed.Hence, the claim follows since this operation does not affect the metric f (M).
Corollary 1.Each perfect matching has the same metric (2) as the MWPM.It follows that (2) can be interpreted as the minimum number of traversed columns for all perfect matchings of the same graph.
We have seen in Section III-A that, starting from a complete graph G formed by connecting all defects, we obtain two distinct graphs G 1 and G 2 by adding ghost ancillas.Due to the even number of defects in these graphs, we can compute two perfect matchings, denoted as E 1 and E 2 .It is noteworthy that applying a logical operator to one matching we get the other.Consequently, one of the solutions will correct the error (call it E c ), while the alternative, E a , will produce a logical error.
Theorem 1.Let us consider an [[n, k, d]] surface code and an error pattern of weight w ≤ t.A perfect matching leading to the correct solution, E c , has f (E c ) < f (E a ), with E a being any perfect matching on the alternative graph.
Proof.The number of columns in the lattice is d.Since we are considering error patterns with weight w ≤ t, we have that any perfect matching E c representing the correct solution, due to Lemma 2, satisfies f (E c ) ≤ t.Regarding the alternative solution E a , we have that f (E a ) = d − f (E c ), since they differ by a logical operator.This leads to f (E a ) ≥ t + 1 for d odd and f (E a ) ≥ t + 2 for d even, proving the statement.
The previous theorem states that a surface decoder chosing a matching with the minimum traversed column metric (2) preserves the error correction capability of the code.
The same theorem applies to rotated surface codes as well, owing to their similar lattice structure.

IV. RAPID-FIRE DECODER
We show now to design an even faster decoder that ensures the correction for all errors with weights w t.Due to Corollary 1, each matching is equivalent to the minimum one in terms of (2).Hence, it is possible to compute E i with i = 1, 2 without evaluating and matching the MST.Firstly, we compute the complete graph G on the defects.Then, we construct two graphs S i by adding to G ghost ancillas on boundaries with the same strategy described in Sections III-A.For each S i , we iteratively pair each defect with its closest one in a greedy fashion, we update the solution E i , and we remove both the defects from S i .This process results in two potential sets of faulty qubits, E 1 and E 2 .Finally, we determine the error correction operator to adopt, following the procedure outlined in Section III-C.In this way, we guarantee the correction of all errors of weight up to w = t by Theorem 1.We call this the RFire decoder.

V. NUMERICAL RESULTS
In this section we compare the performance of surface and rotated surface codes using MWPM, STM, and RFire decoding via Monte Carlo simulations.These decoders are implemented in C++ and run with an Apple Silicon M2 processor.In the implementation, we exploit the LEMON C++ library for an efficient MWPM algorithm [29].To evaluate the complexity of the decoders we measure the average execution time of the processing that starts with the initial complete graph G (generation of G not included) and ends returning the solution E. The evaluation, carried out when varying the lattice size and the number of defects, is reported in Table I.As expected, the computational time saving is remarkable when STM and RFire are adopted.Furthermore, in Fig. 3, the logical error rate of some surface codes over a depolarizing channel is depicted.In particular, the performance gap between MWPM and the proposed fast decoders widens progressively as the distance of the code increases.This is due to the fact that, although the STM and the RFire decoders effectively correct all the errors with weights up to t, the MWPM decoder corrects a larger fraction of those with weight t + 1.In terms of speed, the RFire decoder is the fastest, but it looses in error correction capability.Note that although we showcased our decoder using standard surface codes for the sake of clarity, its performance remains consistent when applied to rotated surface types, as illustrated in Fig. 3 for the [[9, 1, 3]] code.Among the decoders available in the literature, we concentrate on comparing with the only current fast decoder, which is the UF [10].To accomplish this, we utilized the Qsurface library [10].Specifically, for the [[85, 1, 7]] surface code and a physical error rate p Z = 0.03, the UF shows a speedup by a factor of approximately ×2 with respect to MWPM.In the same settings, the speedup of RFire and MST decoders with respect to MWPM is ×3625, and ×164, resulting in the quickest execution

VI. CONCLUSIONS
We have introduced two fast decoders designed for surface codes and compared their performance with the widely used MWPM decoder.While observing a slight reduction in error correction capability for errors of weight j t+1, our findings highlight a substantial advantage in terms of execution times, with a speedup of a factor ×10.000, for both the STM and the RFire decoders.
(v, G) to indicate the set of vertices adjacent to the vertex v in the graph G, and deg(v, G) for the degree of v in the graph G. B(T ) = {v ∈ T | deg(v, T ) = 1} is the set of boundary vertices in T .A simple algorithm for obtaining the perfect matching of an MST consists of the following steps.1.For each b ∈ B(T ) Let a = adj(b, T ); If deg(a, T ) = 2: call the edges e 1 = (a, b) and e 2 = (a, adj(a, T )\{b}).Add e 1 to E, and remove the subgraph ({a, b}, {e 1 , e 2 }) from T .2. For each b ∈ B(T ) Let a = adj(b, T ); If deg(a, T ) = 3: call {v 1 , v 2 } = adj(a, T ) \ {b}, and the edges e 1 = (a, b), e 2 = (a, v 1 ), e 3 = (a, v 2 ).

w2 = 3 t + 1 w1 = 8 > t + 1 ErrorsFig. 1 .
Fig. 1.Spanning tree matching decoder with a [[85, 1, 7]] surface code.a) Three Z channel errors occur on the lattice.Exited ancillas are depicted in red.b) Two alternative MSTs obtained with the nearest ghost ancilla to the left (above) and to the right (below) boundary, respectively.c) Resulting E from the tree matching procedure.