Experimental exploration of five-qubit quantum error correcting code with superconducting qubits

Quantum error correction is an essential ingredient for universal quantum computing. Despite tremendous experimental efforts in the study of quantum error correction, to date, there has been no demonstration in the realisation of universal quantum error correcting code, with the subsequent verification of all key features including the identification of an arbitrary physical error, the capability for transversal manipulation of the logical state, and state decoding. To address this challenge, we experimentally realise the $[\![5,1,3]\!]$ code, the so-called smallest perfect code that permits corrections of generic single-qubit errors. In the experiment, having optimised the encoding circuit, we employ an array of superconducting qubits to realise the $[\![5,1,3]\!]$ code for several typical logical states including the magic state, an indispensable resource for realising non-Clifford gates. The encoded states are prepared with an average fidelity of $57.1(3)\%$ while with a high fidelity of $98.6(1)\%$ in the code space. Then, the arbitrary single-qubit errors introduced manually are identified by measuring the stabilizers. We further implement logical Pauli operations with a fidelity of $97.2(2)\%$ within the code space. Finally, we realise the decoding circuit and recover the input state with an overall fidelity of $74.5(6)\%$, in total with $92$ gates. Our work demonstrates each key aspect of the $[\![5,1,3]\!]$ code and verifies the viability of experimental realization of quantum error correcting codes with superconducting qubits.


INTRODUCTION
Quantum computers can tackle classically intractable problems [1] and efficiently simulate many-body quantum systems [2]. However, quantum computers are notoriously difficult to control, due to their ubiquitous yet inevitable interaction with their environment, together with imperfect manipulations that constitute the algorithm. The theory of fault tolerance has been developed as the long-term solution to this issue, enabling universal error-free quantum computing with noisy quantum hardware [3][4][5][6][7]. The logical qubits of an algorithm can be represented using a larger number of flawed physical qubits. Providing that the machine is sufficiently large (high qubit count), and that physical errors happen with a probability below a certain threshold, then such errors can be systematically detected and corrected [8,9]. In experiment, several small quantum error correcting codes (QECCs), including the repetition code [10][11][12][13][14][15][16], the four qubit error detecting code [17][18][19], the seven qubit color code [20], the bosonic quantum error correcting code [21,22], and others [23][24][25][26], have been realized with different hardware platforms. These works have shown the success of realising error correcting codes with non-destructive stabilizer measurements and its application in extending the system lifetime [19,25]. Nevertheless, previous experiments are limited to restricted codes for correcting certain types of errors or the preparation of specific logical states. It remains an open challenge to realise a fully-functional QECC.
Here, we focus on the five-qubit [ [5,1,3]] code, the 'perfect' code that can protect a logical qubit from an arbitrary single physical error using the smallest number of qubits [6,7]. While proof-of-principle experimental demonstrations of the [ [5,1,3]] code have been conducted on NMR systems [27], whether it could be incorporated in more scalable quantum computing systems and protect errors presented in these systems remain open. Here, we focus on the realization of the five-qubit code with superconducting qubit systems. As a preparatory theoretical step, we recompile the universal encoding circuit that prepares an arbitrary logical state in order to realise it with the fewest possible number of nearest-neighbour two-qubit gates. In experiment, we implement basic functions of the code by realizing logical states preparation, transversal logical operations, and state decoding.

THEORY
The five-qubit [ [5,1,3]] code is a type of stabilizer code that is defined by a set of independent operators from the Pauli group, called stabilizers, such that the code space only has eigenvalue +1. The four stabilizers of the five-qubit code are g 1 = X 1 Z 2 Z 3 X 4 I 5 , g 2 = I 1 X 2 Z 3 Z 4 X 5 , with I i , X i , Y i , Z i being the Pauli matrices acting on the i th qubit. The logical state space is defined by states |Ψ L = a |0 L + b |1 L that are simultaneously stabilized by the four stabilizers with g i |Ψ L = + |Ψ L , ∀i = 1, 2, 3, 4. Here, the logical states |0 L and |1 L are the basis states that are eigenstates of the logical Z L operator. Any logical state |Ψ L can be uniquely determined by the four stabilizers defined in Eq. (1) together with the fifth stabilizer That is, any logical state |Ψ L can be decomposed as |Ψ L Ψ| L = 2 −5 Π 5 i=1 (g 0 + g i ), where g 0 = I 1 I 2 I 3 I 4 I 5 is the trivial stabilizer of all pure quantum states. Logical Pauli operators is transversely realised by applying the corresponding single-qubit gates on each physical qubit, σ L = σ 1 σ 2 σ 3 σ 4 σ 5 for σ = X, Y, Z. General logical operators, such as the T L = e −iZ L π/8 gate, may not be transversely realised.
The five-qubit code has distance three and therefore all single-qubit errors can be identified (and thus corrected) while all double-qubit errors can be detected. When there is no error, all stabilizer measurements should yield +1 for the encoded state |Ψ L . When an error happens, one or more stabilizer measurements may yield −1. As there are four stabilizers whose measurement may take either +1 or −1 values, there are in total 15 syndrome measurement results with at least one outcome being −1.
If we consider the ways in which a single Pauli error can afflict one of the five qubits, we note that there are fifteen possibilities (three error types and five locations), with each mapping to a specific one of the fifteen syndromes. When a two-qubit error happens, we again find that at least one of the stabilizer measurements takes −1. This heralds the fact that some error has occurred. However, since different double-qubit errors may have the same syndrome, we can only detect double-qubit errors without the capability of identifying or correcting them. Nevertheless, this latter property can be useful in some situations, such as state preparation, where we can simply discard a faulty realisation and restart.
Without using ancillary qubits, the original circuit for encoding the logical state |Ψ L requires a number of two qubit gates which are non-local with respect to a linear architecture [6,7]. To tailor the circuit for superconducting systems that only involve nearest-neighbour controlled-phase gates, we recompile the encoding circuit to have the minimal possible number (eight) of nearestneighbour control phase gates as shown in Fig. 1(a). We leave the details of circuit compilation in Supplementary Data.

EXPERIMENTAL SET-UP
The device for the implementation of the five-qubit error correcting code is a 12-qubit superconducting quantum processor [28]. Among these 12 qubits, we chose five adjacent qubits to perform the experiment. The qubits are capacitively coupled to their nearest neighbours. The capacitively coupled XY control lines enable the application of single-qubit rotation gates by applying microwave pulses, and the inductively coupled Z control lines enable the double-qubit controlled-phase gates by adiabatically tune the two-qubit state |11 close to the avoid level crossing of |11 and |02 [28]. After careful calibrations and gate optimizations, we have the average gate fidelities as high as 0.9993 for single-qubit gates and 0.986 for twoqubit gates. With the implementation of only singlequbit rotation gates and double-qubit controlled-phase gates, we realized the circuit for encoding and decoding of the logical state. More details about the experimental set-up are shown in Supplementary Data.

RESULTS
On a superconducting quantum processor [28], we experimentally realised the logical states |0 L , |1 L , |± L , and |±i L that are eigenstates of the logical Pauli operators X L , Y L , and Z L , and the magic state |T L = (|0 L + e iπ/4 |1 L )/ √ 2 that cannot be realized by apply-ing Clifford operations on any eigenstate of the logical Pauli operators. The expectation values of the stabilizer operators of |T L are shown in Fig. 1(b). The fidelity between the experimentally prepared state and the ideal state |Ψ L Ψ| L is determined by the measurement of the 32 stabilizer operators in Π 5 i=1 (g 0 + g i ). We omit the g 0 one as it is constantly 1. In this way, we obtained the state fidelity as the average of the 32 stabilizers by picking up corresponding measurement results among the state tomography results. Finally, the state fidelity of |T L reaches 54.5(4)%. The fidelities of other prepared states are shown in Supplementary Data, with an average fidelity being 57.1(3)%. The main error in preparing the encoded state is from decoherence, especially the relatively short dephasing time. In a numerical simulation of the experiment with decoherence (see Supplementary Data for details), the state fidelity of |T L is 58.9%. After numerically increasing the dephasing time to be the same as the energy relaxation time, the state fidelity can be increased to 92.1%, indicating a potential direction for future improvements.
The quality of the prepared logical states can also be divided into its overlap with the logical code space and its agreement with the target logical state after projecting it into the code space. Given the logical Pauli operators X L , Y L , Z L and I L = |0 L 0| L + |1 L 1| L , the normalised density matrix ρ L is defined by projecting the FIG. 2. Destructive syndrome detection on the logic magic state |T L . A single-qubit X-, Z-, or Y -type error, which corresponds to bit-flip, phase-flip, or a combined error, respectively, is applied to one of the five qubits Q1 to Q5. We destructively measure the four stabilizers and find consistent syndrome correlations that identify the quantum error.
experimentally prepared state ρ q into the code space with normalised probabilityP j = P j /P I and P j = Tr(ρ q σ L ), for all σ = I, X, Y , Z, where ρ q is the density matrix of the five-qubit state. We define the fidelity within the code space by F L = Ψ| L ρ L |Ψ L , as shown in Fig. 1(c), with the average value being as high as 98.6(1)%. Since projecting to the code space is equivalent to post-selecting all +1 stabilizer measurements, our result also indicates the possibility of high fidelity logical state preparation with future non-destructive stabilizer measurements. This relies on whether we can achieve accurate non-destructive stabilizer measurements, especially whether errors from the ancillary qubits and additional gates are sufficiently low. Given the realisation of logical state, one proceed with the verification of error correction/detection ability of the five qubit code. Acting on the logical encoded state |T L , we systematically introduce every type of single-qubit error by artificially applying the corresponding single qubit gate on one of the five qubits. Then, by measuring the four stabilizers g 1 , g 2 , g 3 , and g 4 , we aim to verify that each error would be properly identified. As shown in The χL matrix of the logical XL operation determined via quantum process tomography in the code space. The gate fidelity of logical XL operation is determined to be 97.2(2)%. The black-outlined hollow bars correspond to the ideal X gate. We refer to Supplementary Data for the definition of the χL matrix and details. Fig. 2(a) we do indeed find, for each case, the corresponding syndrome pattern that identifies the location of the single-qubit error. Suppose the expectation value of i-th stabilizer is p i , the probability that the syndrome measurement works is i (|p i | + 1)/2, which is 0.413 on average in experiment. We also apply double-qubit errors on |T L and find the same syndrome correlation that can always detect the existence of errors (see Supplementary Data for details). Notably, the (single-qubit or doublequbit) error-afflicted states have probabilities projecting onto the code space (around 3.3%), verifying the power of the error correcting code.
In a functioning fault-tolerant quantum computer, op- erations on logical qubits are realised through a series of operations on the component physical qubits. We implement and verify three such transversal logical operations: Starting from the magic state |T L presented in Fig. 3(a), we demonstrate the single logical qubit operations X L , Y L , and Z L , and plot the rotated states within the code space, as shown in Fig. 3(b), (c), and (d), respectively. To characterize these logical operations, we performed the quantum process tomography within the code space as shown in Figure 3(e), which reflects how well logical operations manipulate logical states. We determine gate fidelities of the logical X L , Y L , and Z L operations to be 97.2(2)%, 97.8(2)%, and 97.3(2)%, respectively.
Finally, after encoding the single-qubit input state into the logical state, we apply the decoding circuit, see Fig. 4(a), to map it back to the input state. With input states |0 , |1 , |+ , and |+i , we determine the state fidelity after decoding as 87.4(5)%, 91.6(4)%, 76.7(6)%, and 77.1(6)%, respectively. The relatively lower fidelities for |+ and |+i states are also caused by the short dephasing time. After quantum process tomography from the four output states, the process fidelity is determined as 74.5(6)% as shown in Fig. 4(b). The decoding circuit only apply operations on three qubits, highlighting the ability of quantum secret sharing with the five-qubit code [29]. This simplification owes to a consequence of locality: no observable on Q 1 can be affected by the omitted independent gate operations of the other qubits.

DISCUSSION
An essential milestone on the road to fault-tolerant quantum computing is the achievement of error-corrected logical qubits that genuinely benefit from error correction, outperforming simple physical qubits. There are three steps for achieving this goal -(1) realizing encoded logical qubits in a code capable of detecting and correcting errors, (2) realizing operations on encoded qubits and error correction cycles, and (3) adding more ancillary qubits and improving the operation fidelity to achieve fault-tolerance. Our experiment completes step (1) by realising the basic ingredients of the full functional fivequbit error correcting code. Our work partially achieves (2) as we indeed perform logical operations and verify error detection; however because we are only able to evaluate stabilizers destructively, we cannot perform full error correction. Direction for future works include the the realization of non-destructive error detection [25,26,30] and error correction, and the implementation of logical operations on multiple logical qubits for the five-qubit code. Our work also has applications in error mitigation for near-term quantum computing [31].

DATA AVAILABILITY STATEMENT
All data analyzed to evaluate the conclusions are available from the authors upon reasonable request.

ACKNOWLEDGMENTS
The authors thank the USTC Center for Micro-and Nanoscale Research and Fabrication, Institute of Physics CAS and National Center for Nanoscience and Technology for the support of the sample fabrication. The authors also thank QuantumCTek Co., Ltd. for supporting the fabrication and the maintenance of room temperature electronics.    The five-qubit quantum error correcting code (QECC) maps an input state |φ = a |0 + b |1 to a five-qubit state, |Ψ L = a |0 L + b |1 L , where the logical |0 L and |1 L states are defined by (S1) The five-qubit code is a stabilizer code [1], which is defined by a set of independent operators from the Pauli group that have eigenvalues ±1. The stabilizer operators of the five-qubit code together with its logical Pauli operators are listed in Table S1. The logical state space is defined by states |Ψ L = a |0 L + b |1 L which are simultaneously stabilized by the four stabilizers with g i |Ψ L = + |Ψ L , ∀i = 1, 2, 3, 4. Logical Pauli operators can be transversally realised by applying the corresponding operation separately on each physical qubit. The logical states |0 L and |1 L are eigenstates of the logical Z L operator. General logical operators, such as the T L = e −iZ L π/8 gate, the Hadamard gate H L , may not be transversally realised. S1. The stabilizer generators of the five-qubit code and the logical ZL, XL, and YL operations. Here Ii, Xi, Yi, Zi are the Pauli matrices acting on the i th qubit.

Name
Operator

B. Fidelity evaluation
The logical state |Ψ L = a |0 L + b |1 L can be uniquely determined by the four stabilizers defined in Table S1 together with the fifth stabilizer That is, any logical state |Ψ L can be decomposed as where g 0 = I 1 I 2 I 3 I 4 I 5 . Therefore the fidelity between the experimentally prepared state ρ q and the ideal target state |Ψ L Ψ| L can be also determined by the measurement of the 32 stabilizer operators 5 i=1 (g 0 + g i ). That is, where g j is one of the 32 terms by expanding 5 i=1 (g 0 + g i ). The fidelity of the prepared logical states can also be divided into its overlap with the logical code space and its agreement with the target logical state after projecting it into the code space. Given the logical Pauli operators, with |± L = (|0 L ±|1 L )/ √ 2 and |±i L = (|0 L ±i |1 L )/ √ 2, the normalised density matrix ρ L is defined by projecting ρ q into the code space with normalised probabilityP j = P j /P I and P j = Tr(ρ q j L ), for all j = I, X, Y , Z. After projecting ρ q into the code space, we define the fidelity within the code space by

C. Error detection and correction
The five-qubit code has a distance three, and therefore any single-qubit or two-qubit errors will be detected by a stabilizer change, and single-qubit errors can be successfully corrected (while if the correction protocol were applied to a two-qubit error state, a logical error would result). When there is no error, the stabilizers are all 1 for the encoded state |Ψ L . When error happens, the stabilizers may have negative values. As there are four stabilizers either taking ±1 values, there are in total 15 syndrome measurement results with at least one stabilizer value being negative. For each one of the 15 cases with one single qubit error happens on one of the five qubits, it corresponds to a unique syndrome. When a two-qubit error happens, one of the stabilizers must take a negative value, indicating the existence of errors. As different two-qubit errors may have the same syndrome (degeneracy), we can only detect two-qubit errors without the capability of correcting them.

D. Encoding circuit
In our experiment, we also consider the case where we relabel the code by mapping the original labels of the qubits as follows, 1 = 1, 2 = 5, 3 = 2, 4 = 4, 5 = 3. (S8) The four stabilizers of the relabeled code are summarized in Table S2.
The encoding circuit of the conventional five-error correction code is shown in Fig. S1. We manually searched this circuit so that minimal number of Controlled-Not (CNOT) gates is used. Here the gates that are used in the circuit are defined as FIG. S1. Encoding circuit for the five-qubit error correction code. Qubit 1 is the unknown to-be encoded state a |0 + b |1 and qubit 2 to 5 are the ancillae |0 .
In our experiment, we relabel the qubits from 1, 2, 3, 4, 5 to 1 , 3 , 5 , 4 , 2 in order to make the nonlocal gates to be nearest-neighbour gates. By reordering the qubits as 1 , 2 , 3 , 4 , 5 , we obtain the encoding circuit that only involves 6 nearest-neighbour gates and 2 swap gates, shown in Fig. S2. Each swap gate can be realized with 3 CNOT gates. The total number of nearest-neighbour CNOT gates are 12. It is worth noting that relabelling or reordering the ancillary qubits do not affect the code. The code is equivalent simply with stabilizers and all other measurement reordered.
Furthermore, we show that the number of nearest-neighbour CNOT gates can be reduced to 8 by numerically optimising the circuit. This is achieved by focusing on two clusters of gates in the two dashed boxes. As shown in S2. Encoding circuit for the relabelled five-qubit error correction code. Fig. S3, we recompile these two clusters of gates by replacing the swap gate with the Control-Z (CZ) gate and in the meanwhile inserting more parameterized single qubit gates. For each single qubit gate, we decompose it as with R z (α) = e −iασz/2 and R y (α) = e −iασy/2 . We also add a parameter to the unitary to represent its global phase. Suppose the target unitary is U and the parameterised compiled circuit is U ( θ), with θ denoting all the parameters. Then we need to minimise the distance between U and U ( θ) where U = i,j |U i,j | 2 . We numerically optimise the distance over all the parameters and we find that the circuits of the two dashed boxes can be simplified as desired with four CZ or CNOT gates reduced.
FIG. S3. Quantum circuit compilation. We recompile the two small circuits by fixing its structure with several parameterized single qubit gates. We replace the swap gate with the CZ gate and add general single qubit gates between every two CZ gates. Each single qubit gate has three parameters and we also add a global phase to the whole circuit. Circuit (a) has 28 parameters and Circuit (b) has 19 parameters. We perform the numerical optimization with the MATLAB fminsearch function, which realized the simulated annealing algorithm. As the parameter space is quite large, we run the algorithm with random initial parameters and find a local minimum at each time. We end the search until the distance is minimized that is below a certain threshold, say 10 −3 . In practice, we only need to try tens of random initial parameters to find the global minimum. In general, the found rotation angles are not the exact factional number as shown in Fig. S4 owing to numerical accuracy. We manually replace the rotation angles with the closest fractional numbers and verify the compiled circuit by obtaining negligible distance, say 10 −10 .

um
FIG. S5. False-color optical image of the superconducting quantum processor. There are in total 12 qubits, from which we choose five adjacent qubits labeled with Q1 to Q5 to perform the experiment. Each qubit couples to a corresponding resonator for state readout.

A. Device
The device we used is a superconducting quantum processor. As illustrated in Fig. S5, there are 12 transmon qubits of the Xmon variety [2][3][4] arranged in a 1D chain [5]. All qubits are frequency-tunable by their corresponding Z control lines. Each qubit couples to its nearest-neighbour qubits via fixed capacitors. The nearest-neighbour coupling strength is about 12 MHz. For each qubit, individual XY and Z control lines enable the ability to fully control the qubit state. Each qubit couples to a λ/4 resonator for state readout. All twelve resonators couple to a common transmission line. Among these qubits, we choose five high-quality adjacent qubits, labelled from Q 1 to Q 5 in Fig. S5, to perform the experiment. The performances of the qubits are listed in Table. S3. The relaxation time T 1 ranges from 27.5 µs to 48.6 µs. The dephasing time T * 2 ranges from 2.7 µs to 5.6 µs. To reduce the ZZ coupling between the neighboring qubits, the idle frequencies of the qubits alternate in a zigzag pattern. The minimum frequency difference between neighboring qubits is 740 MHz. A schematic diagram of the experimental wiring setup is shown in Fig. S6.

B. Implementation of quantum circuits
The single-qubit rotation gates around X-or Y -axis are realized by applying Gaussian-enveloped microwave pulses through the XY control lines. A derivative reduction by adiabatic gate (DRAG) [6] protocol is used to reduce the phase error and state leakage to the second excited state in the application of single qubit gates. Note that for the realization of the single-qubit rotation gates around the Z-axis, i.e., R z (θ), we shift the phase of the reference for a certain angle θ instead of applying a physical detuning pulse. The controlled-phase gates used in our experiment is the fast adiabatic CZ gates [3,7], realized by tuning the two qubit |11 state close to the avoid-crossing of |11 and |02  The Z and DC lines are combined via bias tees before connected to the quantum processor. We use microwave (MW) sources, IQ mixers and digital-analog converters (DACs) to generate XY control signals. The Z control signals are realized by the DACs. The qubits are flux-biased at their idle points by the DC sources. The state of different qubit can be read out simultaneously using frequency multiplexing. A Josephson parametric amplifier is connected to the second cryogenic circulator. A HEMT is used on the 4K plate for readout amplification. The signal is further amplified via a room-temperature amplifier and then demodulated and digitized by an analog-digital converter (ADC). The setups of attenuators and filters for different control lines are different to minimize the noise.
state following an adiabatic trajectory. For calibration of the two-qubit gates, the first step is to correct the z pulse cross talk and z pulse distortion [5,8]. After that, we choose the operation point avoiding noticeable two level systems (TLSs). After the operation point is chosen, we use Nelder-Mead algorithm to optimize the waveform parameters, including the gate amplitude, length, and the parameters controlling the shape of the waveform. The cost function is chosen as the process fidelity estimated via quantum process tomography. We cannot use RB as the cost function as the dynamical phase for the qubits is not determined when optimizing the waveform parameters. At last, we measure the dynamical phases of all relevant qubits. The single-and double-qubit gate fidelities, determined via interleaved randomized benchmarking (RB), are listed in Table. S3, with the average fidelity obtained as 99.93% and 98.6%, respectively. The experimental waveform sequences are shown in Fig. S7. The evolution time for both encoding and decoding processes are about 810 ns. For each result measured in our experiment, we repeat the waveform sequences and state readout for 5,000 to 10,000 times.

C. Logical state preparation
We prepare seven logical states, including the six eigenstates |0 L , |1 L ,  Table S4, where the raw state fidelities are determined as the fidelity between the experimentally obtained density matrix and that of the ideal state. Focusing on states in the code space, the state fidelity can be enhanced from 55.3% to 98.6% on average. The probability of projecting the state to the code space is 56.2%, which is close to the raw state fidelity after multiplying the fidelity in the code space. The expectation values of logical Pauli operators and the state fidelity of the magic state |T L are shown in Fig. 1 (c) in main text. The results for the other six states are shown in Fig. S8.

D. Two-qubit error detection
The result of single qubit error identification is shown in the main text. We found that the measured syndrome correlation can uniquely determine the artificially introduced single error. To check the two-qubit error detection with the five-qubit error correction code, we firstly prepared the logical encoded state |T L . Then, by applying two single-qubit gates on two of the five qubits, we introduce artificial two-qubit errors. The single-qubit gates are chosen  from the X, Z and Y gates. We measured the four stabilizer operators g 1 , g 2 , g 3 , and g 4 , and realized the error detection of the two-qubit error. The exact syndrome indicates that the existence of two-qubit errors can be exactly detected. The results are shown in Fig. S9.

E. Logical gate operations
The fidelity of logical gate operations are determined by performing quantum process tomography(QPT) [9,10] of the corresponding operations. The χ matrix determined in QPT is defined as ε(ρ) = ΣE m ρE † n χ mn , where ε is the quantum operation, ρ is the density matrix of the input state, and E m 's are the operation bases, which in our case corresponds to {I, σ x , −iσ y , σ z }. We prepare 4 input states of Q 1 in total, i.e. |0 , |1 , |+ , and |+i , and measure the quantum state tomography (QST) of the output state of Q 1 with each input state. For each quantum state tomography components, we repeat the gate sequences and measurement for 5,000 times. After correcting the measurement error of QST with maximum-likelihood estimation, we reconstruct the 4×4 experimental χ matrix from the 4 density matrices. The process fidelity is determined as the trace overlap between the χ matrices of the ideal process and that obtained from QPT. The raw gate fidelities are determined to be 86.8%, 87.2%, and 86.1%, for X L , Y L , and Z L , respectively. Instead, we can also consider gate fidelities only in the code space. For each state tomography, we extract the density matrix of the state within the code space. For Y L and Z L , the gate fidelities in the code space are determined to be 97.8(2)% and 97.3(2)%, respectively. After the logical X L , Y L , and Z L operations , the average probability of staying within the code space for logical states |0 L , |1 L , |+ L , and |i L is 0.576, 0.568, 0.541, and 0.566, respectively. The results are shown in Fig. S10.

F. Simulation of quantum circuits with decoherence
We use operator-sum representations to simulate the evolution of the system with relaxation and dephasing [11]. After replacing ideal quantum gates with Kraus operators, the evolution of the system with quantum gate G applied to can be written as: where G is the ideal quantum gate, E k s are the operation elements representing decoherence, and E k G constitutes one of the Kraus operators.
The matrix forms are different for different kinds of decoherence. For relaxation, the matrix forms are where γ is the probability of losing a exciton within the gate time and thus corresponds to the ratio of the gate time   Table. S3. For the rows labeled "Long T2 = T1", we numerically increase the T2 to be the same as T1.  to the relaxation time T 1 (γ = k t gate T 1 ). In this work, we set k equal to 1. For dephasing, the matrix forms are where γ φ is the probability that the exciton being scattered within the gate time and thus proportional to the ratio of the gate time to the dephasing time T φ (γ φ = k t gate T φ ). We set the scale factor k to 2 considering no spin echoes applied in this work. Taking both relaxation and dephasing into account, we combine these operation elements into a new element set In this way, we can numerically simulate the evolution of designed quantum circuits with decoherence. As shown in Table. S5, the numerical simulation results for both encoding and decoding are close to the experimental results, indicating that the main error in our experiment is decoherence. Moreover, after numerically increasing the dephasing time to be the same as the energy relaxation time, the state fidelities of encoded states and process fidelity of decoding increase significantly.
We then further calculate the fidelity between the observed state and the numerically simulated state. For |T L state, the fidelity is 0.489. The fidelity is different from 1 might owe to the incomplete estimation of the noise