Correcting a noisy quantum computer using a quantum computer Pan Zhang Abstract Quantum computers require error correction to achieve universal quantum computing. However, current decoding of quantum error-correcting codes relies on classical computation, which is slower than quantum operations in superconducting qubits. This discrepancy makes the practical implementation of real-time quantum error correction challenging. In this work, we propose a decoding scheme that leverages the operations of the quantum circuit itself. Given a noisy quantum circuit A A , we train a decoding quantum circuit B B using syndrome measurements to identify the logical operators needed to correct errors in circuit A A . The trained quantum circuit B B can be deployed on quantum devices, such as superconducting qubits, to perform real-time decoding and error correction. Our approach is applicable to general quantum codes with multiple logical qubits and operates efficiently under various noise conditions, and the decoding speed matches the speed of the quantum circuits being corrected. We have conducted numerical experiments using surface codes up to distance 7 under circuit-level noise, demonstrating performance on par with the classical minimum-weight perfect matching algorithm. Interestingly, our method reveals that the traditionally classical task of decoding error-correcting codes can be accomplished without classical devices or measurements. This insight paves the way for the development of self-correcting quantum computers. An ideal quantum computer holds the potential to achieve exponential speedups over classical computation in tasks such as prime factoring Shor 1999 ; Gidney and Ekerå 2021 . However, quantum computers are susceptible to noise at the physical level Preskill 2018 , which must be corrected to ensure accurate computation results Fowler et al. 2012 ; Horsman et al. 2012 ; Campbell 2019 ; Bonilla Ataides et al. 2021 ; Bravyi et al. 2024 ; Hastings and Haah 2021 ; Xu et al. 2024 ; Landahl et al. 2011 ; Fowler 2011 ; Bombín 2010 ; Duclos-Cianci and Poulin 2010 ; Bravyi et al. 2014 ; Bombin et al. 2012 ; Bombin and Martin-Delgado 2007 ; Bacon et al. 2017 . Quantum error-correcting codes tackle this challenge by integrating multiple physical qubits into a smaller number of logical qubits, encoding the logical information through redundant measurements on ancilla qubits Honciuc Menendez et al. 2024 ; Reichardt et al. 2024 ; Hong et al. 2024 ; Da Silva et al. 2024 ; Mayer et al. 2024 ; Ryan-Anderson et al. 2021 ; Zhao et al. 2022 ; Bluvstein et al. 2024 ; Google Quantum AI 2023 ; Google Quantum AI and collaborators 2025 ; Google Quantum AI 2021 . When an error occurs, nontrivial measurement results are triggered and used to infer how the logical information has changed, allowing for appropriate corrections. This inference process, known as decoding, is considered a classical statistical inference problem. A wide range of decoding algorithms Dennis et al. 2002 ; Higgott 2022 ; Higgott and Gidney 2023 ; Wu and Zhong 2023 ; Fowler 2013 ; Higgott et al. 2023 ; Roffe et al. 2020 ; Panteleev and Kalachev 2021 ; Cao et al. 2025a have been proposed to address this problem, including minimum-weight perfect matching (MWPM), union-finding, belief propagation with ordered statistics for decoding (BPOSD) Fossorier and Lin 1995 ; Fossorier 2001 ; Roffe et al. 2020 , tensor network methods Google Quantum AI 2023 ; Chubb 2021 , and neural-network decoders Bausch et al. 2024 ; Cao et al. 2025b ; Cao et al. 2023 . Despite the availability of numerous decoders and accelerations using modern computational power like GPUs and FPGAs, accurately correcting practical quantum codes under actual circuit-level noise at a speed aligned with the operation of quantum devices with superconducting qubits remains challenging, making real-time decoding difficult. In this work, we propose to address the decoding problem using a quantum circuit rather than classical computational devices, thereby aligning the decoding speed with the operation speed of the quantum circuit to be corrected. In the following sections, we will first formulate the decoding problem within the context of quantum error correction codes. We will then introduce our method and demonstrate its performance through numerical experiments using surface codes up to distance 7 under circuit-level noise. Finally, we will extend our proposed method to explore the possibility of self-correcting quantum circuits, which can correct errors without requiring ancilla qubit measurements or classical electronic interactions. Figure 1: Top : Pictorial illustration (middle) of the Tanner graph generated from various codes. The top left panel depicts a rotated surface code under qubit noise, while the top right panel shows a distance-3 repetition code under circuit-level noise. In the notation, R stands for reset, M for measurement, and I for idling. Their corresponding Tanner graphs are illustrated in the top middle panel, with only three syndrome measurements depicted in different colors. Bottom : A decoding circuit composed of three qubits. The decoding circuit consists of two blocks of unitary operations. Each block contains three X-rotation gates and three Y-rotation gates, along with two Controlled-Z gates. The color of each rotation gate corresponds to the syndrome measurement shown in the top middle panel. The parameters of the rotation gates are \theta_{i}x_{i} where \theta_{i} is a learnable parameter and x_{i}=\{0,1\} denotes the syndrome. Quantum codes and decoding We introduce the Tanner graph representation of a quantum code, as shown in the top middle panel of Fig. 1 . The circles in the graph represent error sources, each of which has a certain probability of experiencing an X or Z error, depending on the error model. For qubit-error models, the error sources are the qubits themselves; an example of the surface code is depicted in the top left panel. For circuit-level noise models, the error sources could be specific regions within the circuit; an example of the repetition code under circuit-level noise is illustrated in the top right panel. The colored squares in the Tanner graph represent XOR measurements on the error sources, which are constructed using measurements on ancilla qubits. The results of these measurements, known as the syndrome, indicate whether an odd number of errors has occurred in a particular set of error sources. If no error occurs, the syndrome would be trivial (all zeros). However, if an error does occur, certain measurements will be triggered and report a non-trivial syndrome. For m measurements, there are 2^{m} possible syndromes \gamma=\{\gamma_{1},\gamma_{2},\cdots,\gamma_{m}\}\in\{0,1\}^{m} . The task of decoding is to infer the logical operation \beta made by the error, given the syndrome \gamma . The minimum-weight decoders convert the problem to finding the most likely error consistent with the syndrome. Here, weight is related to the negative log-probability of the error being generated in the error model. For the surface code with independent X and Z noises, minimum-weight decoding can be achieved very efficiently, and the resulting algorithm, such as the minimum-weight perfect matching algorithm (MWPM), has been widely applied. Minimum-weight decoders often compromise decoding accuracy because they overlook the degeneracy of errors. Many errors belong to the same logical sector and are equivalent due to their identical commutation relations with logical operators. To elaborate, the number of logical sectors is 4^{k} , where k is the number of logical qubits. A logical sector can be identified using a vector \beta=\{\beta_{1},\beta_{2},\cdots,\beta_{2k}\}\in\{0,1\}^{2k} . The maximum likelihood decoders (MLD) address this degeneracy by considering the most likely logical sector given a syndrome. In essence, an MLD can be viewed as a mapping from \gamma to \beta . Neural networks can be employed to learn such mapping, i.e., the conditional probability P(\beta|\gamma) from training data and generalize to unseen syndromes Bausch et al. 2024 ; Cao et al. 2025b ; Cao et al. 2023 . Since they are based on learning a variational distribution, neural network decoders do not depend on the code’s topology and can be readily applied to various codes. They can also incorporate additional hardware information, such as leakage. However, the decoding time of neural network decoders is still longer than the operation of quantum circuits due to the intensive operations, the latency of classical devices, and the overhead of classical electronics. This discrepancy makes the application of learning-based decoding to real-time scenarios challenging. Decoding using a quantum circuit— We propose to address the efficiency issue of learning-based decoding by employing a variational decoding quantum circuit. This decoding circuit incorporates parameters that we can optimize to make the probability distribution related to the final state of the circuit closely approximate P(\beta|\gamma) . The learning phase is akin to training a neural network model and can be executed using the tensor network method Pan and Zhang 2022 ; Pan et al. 2022 . Once the learning process is complete, the quantum circuit can be deployed on a quantum device to efficiently sample a logical operator \beta from the final state of the decoding circuit, given a syndrome \gamma . To illustrate our scheme, consider the example depicted in Fig. 1 . The top panel demonstrates how quantum codes with various noise models can be mapped to Tanner graphs (as shown in the top middle). The top left panel illustrates a surface code under qubit noise, where physical qubits correspond to circles and stabilizers to colored squares in the Tanner graph. The top right panel shows a distance-3 repetition code quantum memory under circuit-level noise, where error mechanisms map to circles and detectors Gidney 2021 to colored squares in the middle panel. The measurement outcomes in the Tanner graph generate a syndrome, which is subsequently used to decode the logical sector and apply corrections. The decoding circuit is depicted in the bottom panel. Here, syndromes are encoded as parameters of single-qubit gates, and the operations of the quantum circuit involve parameterized single-qubit gates and non-parameterized two-qubit gates (e.g., the Controlled-Not gate), culminating in a measurement that indicates the logical sector \beta . In the bottom panel of Fig. 1 , the decoding circuit comprises Q=3 qubits and B=2 blocks of unitary operations. Each block consists of a group of rotation X gates \{R^{X}_{q,b,i}\} followed by a group of rotation Y gates \{R^{Y}_{q,b,x_{i}}\} , where q\in\{1,2,3\} denotes the qubit index in the decoding circuit, b\in\{1,2\} indicates the block index, and i is the syndrome index. The parameters of the rotation gates are determined by the product of a learnable parameter \theta and the syndrome \gamma . The matrix form of the X -rotation gates is R^{X}_{q,b,i}=\left[\begin{matrix}\cos\frac{\theta_{q,b}\cdot\gamma_{i}}{2}&-i\sin\frac{\theta_{q,b}\cdot\gamma_{i}}{2}\\ -i\sin\frac{\theta_{q,b}\cdot\gamma_{i}}{2}&\cos\frac{\theta_{q,b}\cdot\gamma_{i}}{2}\end{matrix}\right], and that of the Y-rotation gates is R^{Y}_{q,b,i}=\left[\begin{matrix}\cos\frac{\phi_{q,b}\cdot\gamma_{i}}{2}&-\sin\frac{\phi_{q,b}\cdot\gamma_{i}}{2}\\ \sin\frac{\phi_{q,b}\cdot\gamma_{i}}{2}&\cos\frac{\phi_{q,b}\cdot\gamma_{i}}{2}\end{matrix}.\right] Here, \theta and \phi are learnable parameters; the total number of parameters is 2QBm . In practice, one can construct a more complex circuit ansätze using other types of parameterized gates, more qubits, and more blocks of operations. Once the parameters are properly learned, the circuit can perform decoding by running it on a quantum device. Specifically, after applying the single-qubit gates and two-qubit gates to the initial state, the final state is prepared and then measured in the computational basis. This process effectively yields the probability distribution corresponding to the final state in the computational basis |\psi(\beta_{1},\beta_{2},\cdots,\beta_{Q})|^{2} , which represents the conditional probability of a bit string \{\beta_{1},\beta_{2},\cdots,\beta_{Q}\} given the syndrome \gamma , denoted as q(\beta|\gamma) . When Q>k , meaning the number of qubits Q in the decoding circuit exceeds the number of logical qubits k , we can measure or select a subset of the decoding qubits. For instance, in the example of quantum memory with k=1 as illustrated in Fig. 1 , we only need to measure one qubit in the decoding circuit to obtain a sample of the logical sector from q(\beta|\gamma_{1},\gamma_{2},\cdots,\gamma_{m}) . Optionally, we can repeat the process several times to estimate the conditional probability of the logical sector given the syndrome, then choose a logical sector that maximizes the conditional probability, rather than sampling from it. The structure of the decoding circuit is not tied to a specific code, making it applicable to various codes and noise models. In addition to its versatility, the proposed circuit-based decoder offers several advantages: 1. Decoding speed: The operation time of the decoding circuit is comparable to the running time of the operation circuit. Most of the operations are single-qubit operations, whose duration is approximately 30 ns on superconducting qubits Google Quantum AI 2023 . Additionally, when the syndrome of the i -th measurement is \gamma_{i}=0 , the X and Y rotations are effectively identity operations, meaning we do not need to apply the unitary operation. This implies that in the decoding, only a small fraction of the single-qubit gates will be applied. This significantly reduces the operation time, especially when the syndrome is sparse (e.g., for detector error models with detectors defined using the XOR of consecutive ancilla measurements Gidney 2021 ). 2. Quantum sampling advantage: With a large number of logical sectors, such as in high-rate codes with multiple qubits, generating a logical sector given a syndrome involves sampling from a joint distribution P(\beta|\gamma) , where \beta\in\{0,1\}^{Q} resides in a high-dimensional space. Classical sampling from the joint distribution typically requires modeling conditional probabilities for each variable P(\beta_{i}|\beta_{