Main

We distil magic states to complete a universal set of fault-tolerant logic gates that is needed for large-scale quantum computing with low-density parity-check code architectures13,14,15,16,17,18. High-fidelity magic states are produced9,10,11 by processing noisy input magic states with fault-tolerant distillation circuits; experimental progress in preparing input magic states using trapped-ion architectures is described in refs. 3,7. It is expected that a considerable number of the qubits of a quantum computer will be occupied performing magic-state distillation schemes and, as such, it is valuable to find ways of reducing its cost. One way to reduce the cost is to improve the fidelity of input states11,19,20,21,22,23,24,25,26, such that magic states can be distilled with less resource-intensive circuits.

Here we propose and implement an error-suppressed encoding circuit to prepare a state that is input to magic-state distillation using a heavy-hexagonal lattice of superconducting qubits4,5,27. Our circuit prepares an input magic state, which we call a CZ state, encoded on a four-qubit error-detecting code. We explain how our encoded magic state can be used in large-scale quantum-computing architectures11,28 in the section ‘Using CZ states in large-scale quantum-computing architectures’. Our circuit is capable of detecting any single error during state preparation, as such, the infidelity of the encoded state is suppressed as \({\mathcal{O}}({{\varepsilon }}^{2})\), where ε is the probability that a circuit element experiences an error. By contrast, a standard encoding circuit prepares an input state with infidelity \({\mathcal{O}}({\varepsilon })\). Furthermore, we can improve the yield of the prepared magic states with the error-suppressed circuit using adaptive circuits that are conditioned in real time on the outcomes of mid-circuit measurements. We propose several tomographical experiments to interrogate the preparation of the magic state, including a complete set of fault-tolerant projective logical Pauli measurements that can also tolerate the occurrence of a single error during readout.

Magic-state preparation and logical tomography

We prepare the CZ state as follows:

$$\left|CZ\right\rangle \equiv \frac{\left|00\right\rangle +\left|01\right\rangle +\left|10\right\rangle }{\sqrt{3}},$$

encoded on a distance-2 error-detecting code, in which the distinct bit strings label orthogonal computational basis states over two qubits. We can achieve the CZ state by, first, preparing the \(\left|++\right\rangle ={\sum }_{a,b=0,1}\left|ab\right\rangle /2\) state and, then, projecting it onto the CZ = +1 eigenspace of the controlled-phase (CZ) operator CZ = diag(1, 1, 1, −1), that is, \(\left|CZ\right\rangle \propto {\Pi }^{+}\left|++\right\rangle \) with the projector \({\Pi }^{+}=({\mathbb{1}}+CZ)/2\). We can perform both these operations with the four-qubit code. Specifically, it has a fault-tolerant preparation of the |++ state and, as we will show, we can make a fault-tolerant measurement of the logical CZ operator to prepare an encoded CZ state.

Encoded states of the four-qubit code lie in the common +1 eigenvalue eigenspace of its stabilizer operators SX = XXXX, SZ = ZZZZ and SY = SZSX, where X and Z are the standard Pauli matrices. The four-qubit code encodes two logical qubits that are readily prepared in a logical \(\left|\overline{+}\,\overline{+}\right\rangle \) state by initializing four data qubits in the superposition state, |+ |0 + |1, and measuring SZ. We note that we use bars to indicate we are describing states and operations in the logical subspace. We prepare the state with SZ = +1 using either post-selection or, alternatively, an adaptive Pauli-X rotation on a single-qubit given a random −1 outcome from the SZ measurement.

The four-qubit code has a transversal implementation of the CZ gate on its encoded subspace, \(\overline{CZ}\simeq \sqrt{Z}\otimes {\sqrt{Z}}^{\dagger }\otimes {\sqrt{Z}}^{\dagger }\otimes \sqrt{Z}\), where \(\sqrt{Z}={\rm{diag}}(1,i)\). We can measure this operator as follows. We note that conjugating SX with the unitary rotation \(\widetilde{T}=T\otimes {T}^{\dagger }\otimes {T}^{\dagger }\otimes T\), where \(T={\rm{diag}}(1,\sqrt{i})\), gives the Hermitian operator:

$$\overline{W}\equiv \widetilde{T}{S}^{X}{\widetilde{T}}^{\dagger }\propto \overline{CZ}{S}^{X}.$$
(1)

Given that we prepare the code with SX = +1, measuring \(\overline{W}\) effectively gives a reading of \(\overline{CZ}\).

It is essential to our scheme that we reach the SZ = +1 eigenspace. This is because of the non-trivial commutation relations of \(\overline{W}\) with the stabilizer operators of the code29,30; \([{S}^{X},\overline{W}]=(1-{S}^{Z}){S}^{X}\overline{W}\). This commutator shows that \(\overline{W}\) only commutes with SX in the SZ = +1 subspace. If SZ = −1, we can check that \(\overline{W}\) and SX anti-commute, and are therefore incompatible observables in this subspace.

We can perform all of the aforementioned measurements, SX, \(\overline{W}\) and SZ, on the heavy-hexagon lattice geometry27. Figure 1 shows one such setup. The circuit is fault-tolerant in the sense that a Pauli error introduced by a circuit element, on the support of the circuit element, is always detected by a flag qubit or a stabilizer measurement. The verification of this is detailed in the section ‘Analysis in terms of single-gate errors’.

Fig. 1: A fault-tolerant circuit to make parity measurements.
figure 1

a, A circuit that measures SX, SZ and \(\overline{W}\) using flag qubits on the heavy-hexagonal lattice architecture. b, The four-qubit code is encoded on qubits with even indices and the other qubits are used to make the fault-tolerant parity measurement. The circuit measures SX by setting \(U={\mathbb{1}}\) and SZ by setting U = H, where H is the Hadamard gate. The circuit measures \(\overline{W}\) if we set U = T. The measurement outcome M gives the reading of the parity measurement. Essential to the fault-tolerant procedure are flag fault-tolerant readout circuits4,5,27,51 that identify errors that occur during the parity measurement. Outcomes f and g are flag qubit readings that indicate that the circuit may have introduced a logical error to the data qubits.

We, therefore, present a sequence of measurements that prepare the input magic state and, in tandem, identify a single error that may have occurred during the preparation procedure. Figure 2 shows the sequence and describes its function. As we can detect a single error, we expect the infidelity of the output state to be \({\mathcal{O}}({{\varepsilon }}^{2})\). We compare our error-suppressed magic-state preparation scheme to a standard scheme for encoding a two-qubit magic state, as well as a circuit that prepares the magic state on two physical qubits. Both of these schemes are described in the section ‘Standard magic-state preparation circuits’.

Fig. 2: Fault-tolerant schemes for magic-state preparation and logical tomography.
figure 2

a, Preparation of a CZ state on a four-qubit code in three steps. In the code-preparation step, the four-qubit code is prepared in the logical \(\left|\overline{+}\,\overline{+}\right\rangle \) state by measuring \({\left|+\right\rangle }^{\otimes 4}\) with the SZ operator. We can use adaptive circuits or post-selection to correct for SZ = −1 outcomes. In the magic-state initialization step, we measure the \(\overline{W}\) operator and post-select on the +1 outcome. In the final error-detection step, we identify the errors that may have occurred during preparation. We measure \(\overline{W}\) a second time to identify if a measurement error occurred during the magic-state initialization step. We finally measure SX and SZ a second time to identify Pauli errors that may have occurred, and to determine if the initial SZ measurement gave a readout error. b,c, We replace the parity measurements in the dashed box of a with circuits b and c to make logical tomographic measurements and, at the same time, infer a complete set of stabilizer data for error detection. For example, if we set SQ = SX and measure qubits in the R = Z basis, we infer the value of SZ, as in a, and we also obtain readings of the logical \({\overline{Z}}_{1}\), \({\overline{Z}}_{2}\) and \({\overline{Z}}_{1}{\overline{Z}}_{2}\). Likewise, we can set SQ = SZ with either R = X to infer SX as well as logical Pauli operators \(\overline{{X}_{1}}\), \(\overline{{X}_{2}}\) and \(\overline{{X}_{1}}\overline{{X}_{2}}\), or R = Y to infer SY as well as logical Pauli operators \(\overline{{X}_{1}}\overline{{Z}_{2}}\), \(\overline{{Z}_{1}}\overline{{X}_{2}}\) and \(\overline{{Y}_{1}}\overline{{Y}_{2}}\). In c, we include a \({\overline{Y}}_{j}\) measurement for logical qubit j = 1, 2 to measure logical operators of the form \({\overline{Y}}_{j}\), \({\overline{Y}}_{j}\overline{{X}_{k}}\) and \({\overline{Y}}_{j}\overline{{Z}_{k}}\) with k ≠ j and k = 1, 2, where we take an appropriate choice of R. The \({\overline{Y}}_{j}\) operator is measured twice to identify the occurrence of measurement errors. Operators \({\overline{Y}}_{j}\) are supported on three of the data qubits and can therefore be read out with an appropriate modification of the circuit shown in Fig. 1.

We verify our state-preparation schemes by performing two variants of quantum-state tomography to reconstruct the logical state. The first method uses fault-tolerant circuits that directly measure the logical operators; we refer to this tomographical method as ‘logical tomography’. For the second method, which we refer to as ‘physical tomography’, we perform standard state tomography on the full state of the four data qubits of the system and then project the reconstructed state onto the logical subspace. Logical tomography with the four-qubit code is shown in Fig. 2b,c. All of our logical tomography circuits can tolerate a single error at the readout stage, by repeating the measurement of logical operators and by comparing measurement outcomes to earlier readings of stabilizer measurements.

Logical tomography is more efficient than physical tomography because we are directly measuring and reconstructing the encoded logical state, rather than the physical state. In the case of the four-qubit code, this requires only 7 distinct circuits, whereas physical tomography requires 81 different measurement circuits.

Experimental results

We performed our experiments using the first-generation real-time control system architecture of IBM Quantum deployed on ibm_peekskill; one of the IBM Quantum Falcon Processors (https://quantum.ibm.com/). Device characterization can be found in the section ‘Device overview’. The control system architectures give access to dynamic circuit operations, such as real-time adaptive circuit operations that depend on the outcomes of mid-circuit measurements, that is, feedforward (see section ‘Real-time feedforward control of qubits’).

Our results are shown in Fig. 3, in which we present state infidelities for various state-preparation schemes calculated using both logical tomography and physical tomography. For results provided in the main text, we model the reconstructed state assuming that the readout is conducted with projective measurements. We also present an alternative analysis in the section ‘State tomography with readout error mitigation using noisy positive-operator-valued measurements’, in which we combine the readout error characterization with tomographic reconstruction using noisy positive-operator-valued measurements.

Fig. 3: Infidelities measured in magic-state preparation experiments.
figure 3

State infidelity for error-suppressed (error supp.) and standard schemes are shown in blue and orange, respectively. On the x-axis, a state is reconstructed with either logical or physical tomography. The correction for the initial SZ measurement in Fig. 2a is implemented using either real-time feedforward (FF) or post-selection (PS). For the physical data points, the state from physical tomography is projected onto the logical subspace before computing the infidelity by fitting to ideal projectors. Error bars represent 1σ from bootstrapping. For all tomographic methods, the error-suppressed scheme achieves a lower state infidelity compared with the standard scheme. The unencoded magic state prepared directly on two physical qubits gives an average (avg.) infidelity across 28 qubit pairs as approximately 6.2 × 10−2 (green dashed line) using 18 repetitions over a 24-h period with 105 shots per circuit. Of these, the best-performing pair yields a minimum (min.) infidelity of (2.354 ± 0.271) × 10−2 (red solid line) found over all repetitions for all qubit pairs. In all cases, the error-suppressed scheme exceeds the fidelity of the best two-qubit unencoded magic state.

To accommodate drift in device parameters over the data collection period, a complete set of tomography circuits was interleaved and submitted in batches of about 104 shots until a total of about 106 shots were collected over several days. The resulting counts database is uniformly sampled with a replacement for 10 bootstrap trials with a batch size limited to 20% of the total database before post-selection. The standard deviation, σ, of these bootstrapped trials is plotted as an error bar in all data figures.

The tomographic fitting was done using positive semi-definite constrained weight-least-squares convex optimization using the Qiskit Experiments tomography module31. For logical tomography, the fitting weights were set proportional to the inverse of the standard errors for each logical Pauli expectation value estimate. These weights accommodate the different logical yield rates for each logical Pauli measurement. The logical yield for each basis measurement is shown in Fig. 4 and discussed in more detail below.

Fig. 4: Magic-state yield for feedforward versus post-selection.
figure 4

Yield is calculated for logical tomography circuits shown in Fig. 2b,c for the error-suppressed (error supp.) scheme with feedforward (blue circles) versus post-selection (blue squares); a standard scheme is shown for reference (orange squares). All rates use datasets reported in Fig. 3 where error bars represent 1σ from bootstrapping. The shaded area of the graph shows the increase in yield for the error-suppressed scheme using feedforward (FF) compared with the post-selection (PS) scheme or the standard scheme. The optimal acceptance rate assuming no noise is 75% for the feedforward scheme, 37.5% for the post-selection scheme and 25% for the standard scheme. The observed acceptance rates are because of the additional detection of errors. We estimate the yield in the presence of noise in the section ‘Estimates for magic-state yield’. We observe a stark difference in yields between experiments conducted with the logical tomography circuit shown in Fig. 2b,c, shown to the left and right of the dashed line, respectively. We can attribute this to the depth of the logical tomography circuit, in which deeper circuits, such as those shown in Fig. 2c, are more likely to introduce detectable errors. This is discussed in the section ‘Estimates for magic-state yield’.

We first compare the state-preparation scheme using dynamic circuits with the same preparation scheme executed with static circuits and post-selection. This comparison is conducted using logical tomography. These are the left and middle data points shown in blue in Fig. 3. We find that the infidelities are commensurate in these two experiments. Using dynamic circuits with feedforward operations, we encode a two-qubit error-suppressed input magic state with a logical infidelity (1.87 ± 0.16) × 10−2. In the post-selection experiment, we obtain an infidelity of (1.23 ± 0.11) × 10−2. The feedforward operations in our experiment can introduce idling periods, of the order of hundreds of nanoseconds, during which additional errors can accumulate. To leading order we attribute the difference in fidelity between these preparation schemes to errors that occur while the control system is occupied performing the dynamical feedforward operation. In return for this loss in fidelity, we find that the use of dynamical circuits significantly increases the yield of magic states (Fig. 4).

We can analyse the commonly occurring errors in fault-tolerant circuits using syndrome outcomes to infer the events that are likely to have caused them32. This is done using the method detailed in the section ‘Analysis in terms of single-gate errors’ using the results of the error-suppressed scheme without any post-selection. Assuming an uncorrelated error model, we find that the average probability per single-error event is 0.19% with a standard deviation of 0.11%. The single most-likely error event occurs with probability 1.2%. This event corresponds to an error occurring during the X stabilizer measurement that spreads to and is detected by a flag qubit. Similar errors in other stabilizer measurements show the probability increasing from 0.35% for the initial Z measurement to 0.41% and 0.45% for the two \(\overline{W}\) measurements. This suggests that, rather than being caused by Pauli errors, these results might be caused by other effects such as an accumulation of leakage on the flag qubits.

We verify the performance of our logical tomography procedure by comparing our results with the infidelity obtained using physical tomography for the magic-state preparation procedure, in which we obtain the SZ = +1 eigenspace with post-selection. The fitter weights in this case are the standard Gaussian weights based on the observed frequencies of each projective measurement outcome of each basis element. In physical tomography, the yield after post-selection is constant in all 81 measurement bases. We find an acceptance rate of 14.9 ± 0.1% for the error-suppressed scheme using physical tomography, in which the standard deviation represents variation over 81 physical Pauli directions.

To compare the infidelity obtained with physical tomography even-handedly with that obtained using logical tomography, we reconstruct the logical subspace from the density matrix obtained from physical tomography on the data qubits of the code, ρphys. The logical subspace is obtained by projecting ρphys onto the logical subspace33,34. We obtain the elements of the density matrix of the logical subspace ρ using the equation

$${\rho }_{kl,mn}=\frac{\langle \overline{k}\,\overline{l}| {\rho }_{{\rm{phys}}}| \overline{m}\,\overline{n}\rangle }{{P}_{L}},$$
(2)

where k, l, m, n = 0, 1 specify orthogonal vectors in the logical subspace and \({P}_{L}={\sum }_{k,l}\langle \overline{k}\,\overline{l}| \rho | \overline{k}\,\overline{l}\rangle \) is the probability that the state we prepare is in the logical subspace. Using this method, we obtain the projected logical infidelity for the error-suppressed procedure as (1.70 ± 0.35) × 10−2 with the probability of finding ρphys in the logical subspace PL = 0.898 ± 0.008. An average post-selection acceptance rate over all physical Pauli directions is found to be 14.9 ± 0.1%. This projected logical infidelity is shown as the rightmost blue data point in Fig. 3 to be compared with the central blue data point. This comparison demonstrates the consistency between logical tomography and physical tomography. For reference, raw state fidelities from physical tomography before logical projection are reported in the section ‘State tomography with readout error mitigation using noisy positive-operator-valued measurements’.

We compare our error-suppressed magic-state preparation procedure with a standard static circuit that encodes a physical copy of the magic state into the four-qubit code. We show infidelity data points for the standard scheme in Fig. 3 with orange markers. Our experiments consistently demonstrate that our error-suppressed encoding scheme has an infidelity at least four times smaller than a standard scheme to encode magic states. We show yields using different logical tomography experiments for the standard preparation scheme with orange markers in Fig. 4. In the case of physical tomography, the encoded state on the four data qubits has a post-selection acceptance rate of 20.9 ± 0.1%, and the reconstructed density matrix is found in the code space with probability PL = 0.789 ± 0.004.

Finally, we compare our error-suppressed preparation procedure with a state-preparation experiment performed using physical qubits. We mark the lowest infidelity obtained over all of the adjacent pairs of physical qubits on the 27 qubit device, (2.4 ± 0.3) × 10−2, with a red line in Fig. 3. Remarkably, all fidelities for all of our error-suppressed magic-state preparation schemes exceed the fidelity of a simple experiment to prepare the CZ state with physical qubits.

Discussion

We have presented a scheme that encodes an input magic state with a fidelity higher than we can achieve with any pair of physical qubits on the same device using basic entangling operations. This improvement in fidelity, which is beyond the break-even point set by basic physical qubit operations, can be attributed to quantum error correction that suppresses the noise that accumulates during state preparation.

The yield of magic states benefited from the use of dynamic circuits in which mid-circuit measurements condition gate operations in real time. Remarkably, we find that the operation is sufficiently rapid that its execution came at only a small cost in output state fidelity on the superconducting device. These dynamic circuits are essential to future quantum-computing architectures as they will be needed, for example, to perform magic-state distillation circuits9,10,11 and gate teleportation35,36, as well as many other measurement-based methods13,17,18,19,37,38,39,40,41,42,43,44,45,46,47,48 that have been proposed to complete a universal set of logic gates.

We have shown that experimental progress has reached a point at which we can make prototype gadgets that can affect the resource cost of large-scale quantum computers. In the Methods, we explain how our prototype can be used together with magic-state distillation. It will be interesting to continue to design, develop and test new gadgets with real hardware that will improve the performance of the key subroutines needed for fault-tolerant quantum computing. Further developments in the theory of pieceable fault tolerance44 might show us ways of producing better magic states with small devices. Error-suppressed magic states could improve the time cost of recent proposals49,50 for error-corrected circuits that are supplemented by error-mitigation techniques to complete non-Clifford operations. Ultimately, experimental progress that we make to this end in the near term can benefit large-scale quantum-computing architectures.

Methods

Using CZ states in large-scale quantum-computing architectures

Magic states are distilled to complete a universal set of fault-tolerant logic gates (see Extended Data Fig. 1 for an overview of the details of a generic magic-state distillation protocol). In any such protocol, input magic states with some inherent error are encoded on quantum error-correcting codes. The encoded magic states are then used in distillation circuits to produce better magic states with higher fidelity. We can use magic states with near-perfect fidelity to perform fault-tolerant logic gates.

We choose different magic-state distillation protocols depending on the magic states we prepare. In the next section, we review details on how we can use CZ states in large-scale fault-tolerant quantum computing. Specifically, we can convert CZ states into Toffoli states using Pauli measurements and Clifford operations28, such that we can adopt well-known magic-state distillation protocols for further rounds of distillation11. This conversion technique is probabilistic, as it depends on obtaining the correct outcome from a Pauli measurement. In addition to these results, we show how we can recover a CZ state from the output state, assuming we get the incorrect outcome of the Pauli measurement, thereby conserving the available resource states.

We also provide some examples of how we can inject small codes into larger codes in the section ‘Injecting small codes into larger codes’, as it will be required to take the encoded state we prepared in the main text and use it in subsequent rounds of magic-state distillation. Specifically, we show how to take distance-2 codes and encode their state on the surface code, the heavy-hex code and the colour code with a higher distance. Notably, the heavy-hex code is readily implemented on the heavy-hex lattice geometry on which we conducted the experiment. For each of these injection schemes, we argue that we can detect any single error that may occur. This is important to maintain the error suppression obtained when preparing the CZ state.

In the case of the colour-code state-injection protocol, we inject the error-detecting code described in the main text directly into the larger code. In the case of the surface code and heavy-hex code, however, we inject a related code, that we call the [[4, 1, 2]] code. To complete these injection protocols, we need to take the CZ state prepared on the error-detecting code and copy its logical state onto two copies of the [[4, 1, 2]] code. We give a fault-tolerant procedure for this transformation in the section ‘Encoding the CZ state on two [[4, 1,  2]] codes using the heavy-hex lattice geometry’.

Magic-state distillation with the CZ state

Although magic-state distillation for the CZ state has not been well-studied in the literature, it is known that two copies of the state can be probabilistically converted into a Toffoli state using Pauli measurements and Clifford operations28. Given there are known methods for distilling Toffoli states11, let us review how the Toffoli state is produced from the copies of the CZ state. In the following sections, we show how to inject the CZ state into larger quantum error-correcting codes that are capable of performing fault-tolerant Clifford operations17,18,45 to complete these circuits.

The Toffoli state is defined as follows:

$$| {\rm{TOF}}\rangle \propto \sum _{j,k}| \,j\rangle | k\rangle | \,jk\rangle =| 000\rangle +| 010\rangle +| 100\rangle +| 111\rangle ,$$
(3)

where we sum over the bitwise values j, k = 0, 1.

Given two copies of the CZ state, \({\left|CZ\right\rangle }_{1,2}{\left|CZ\right\rangle }_{3,4}\), if we project qubits 2 and 3 onto the Z2Z3 = −1 eigenspace, then we obtain the intermediate state

$$\left|\xi \right\rangle =(\left|0010\right\rangle +\left|1010\right\rangle +\left|0100\right\rangle +\left|0101\right\rangle )/2.$$
(4)

We then obtain \(|1\rangle |{\rm{T}}{\rm{O}}{\rm{F}}\rangle \) with the following unitary circuit

$$\left|1\right\rangle \left|{\rm{TOF}}\right\rangle =C{X}_{4,3}C{X}_{3,1}C{X}_{2,1}C{X}_{1,3}\left|\xi \right\rangle ,$$
(5)

where indices C and T of the controlled-not gate CXC,T denote the control and target qubit, respectively.

We obtain the −1 outcome by measuring Z2Z3 of state \(\left|CZ\right\rangle \left|CZ\right\rangle \) with probability 4/9. Beyond the work in ref. 28, we find that we can recover a single copy of the CZ state given the Z2Z3 = +1 outcome at this step, thereby saving magic resource states. In the event that we obtain this measurement outcome, we produce the state

$$\left|\chi \right\rangle =\left|0000\right\rangle +\left|0001\right\rangle +\left|1000\right\rangle +\left|1001\right\rangle +\left|0110\right\rangle .$$
(6)

Applying the unitary operation \(C{X}_{2,3}C{X}_{2,4}\left|\chi \right\rangle \) and obtaining the two-qubit parity measurement outcome Z3Z4 = −1, we obtain the state \(\left|CZ\right\rangle \left|01\right\rangle \). We obtain this state with probability 3/5, assuming we obtained the Z2Z3 = +1 outcome previously.

Injecting small codes into larger codes

Magic-state distillation takes encoded magic states, and then processes these input states to probabilistically prepare a magic state with better fidelity. As such, it is necessary to encode magic states into quantum error-correcting codes. This process is commonly known as state injection.

Ideally, the injection process will introduce a minimal amount of noise to the logical state that is encoded, as this will reduce the noise of the output magic state. To this end, we look for ways to inject the magic state prepared on the four-qubit error-detecting code in larger quantum-error-correcting codes in such a way that local errors can be detected.

In what follows, we show how to inject the state encoded on the error-detecting code onto the surface code, the heavy-hex code and the colour code, thereby increasing the distance of the code that supports the magic state. Furthermore, we argue that we can detect any single error that may occur during the injection procedure. This enables us to maintain the error suppression we demonstrated experimentally in the main text.

In the main text, we showed how to prepare the CZ state on a four-qubit error-detecting code shown in Extended Data Fig. 2 (left). As we show later, states on this code can be injected directly onto the colour code. Two of the injection schemes, encoding onto the surface code, or the heavy-hex code, assume that the two logical qubits of the CZ state are encoded on two copies of the [[4, 1, 2]] code, shown in Extended Data Fig. 2 (right). In the following section, we show how to encode the magic state prepared on the error-detecting code onto two copies of the [[4, 1, 2]] code, in a fault-tolerant way such that any single error can be detected. For the remainder of this section, we assume the magic state has been prepared over two copies of the [[4, 1, 2]] code.

To distinguish the two small error-detecting codes of interest consistently, throughout the Methods we will refer to the error-detecting code used in the main text as the [[4, 2, 2]] code to contrast this code with the [[4, 1, 2]] code. Specifically, we label the codes by their encoding parameters [[n, k, d]]. Both of these codes have a distance d = 2 using n = 4 physical qubits. The two codes differ by the number of logical qubits they each encode. The [[4, 2, 2]] code encodes k = 2 logical qubits and the [[4, 1, 2]] code encodes k = 1 logical qubit.

The theory of code deformations

We inject a state into a larger code11,19,20,21,22,23,24,25,26,41,52 using code deformation19,46,53. In what follows, we describe the theory of code deformations using the stabilizer formalism. We remark that more general theories of code deformations can be found elsewhere in the literature46,53. The theory we present is sufficient to describe the state-injection operations of interest.

We describe code deformations using the stabilizer formalism54. Quantum error-correcting codes can be described with an Abelian subgroup of Pauli operators called the stabilizer group \({\mathcal{S}}\). The encoded state lies in the common +1 eigenvalue eigenspace of the elements of the stabilizer group. We call this subspace the code space. Stabilizer codes also have associated logical operators \({\mathcal{L}}\) that can be generated by a set of mutually anti-commuting pairs \({\overline{X}}_{j},{\overline{Z}}_{j}\in {\mathcal{L}}\) with 1 ≤ j ≤ k. These Pauli operators commute with the stabilizer group but are not themselves stabilizer operators. The distance of the code d is the weight of the least-weight logical operator. We can detect any single error if the code has a distance of at least d = 2. We give examples of small stabilizer codes, together with their logical operators in Extended Data Fig. 2. These examples will be relevant for the following discussion on state injection.

We measure the stabilizer operators to identify the errors. As the encoded state is specified by specific eigenstates of a list of commuting Pauli operators, finding a measurement of one or more of these operators in the incorrect eigenspace indicates that an error has occurred. By arguing that we can detect any single error, we must have a distance of at least d = 2.

A code deformation is where we perform a measurement that projects a stabilizer code onto another. Specifically, we assume we have prepared an initial code in which, once prepared, we start measuring the stabilizer operators of a second code that we call the final code. This projects the initial code onto the final code. Let us denote these two codes by their stabilizer group \({{\mathcal{S}}}_{{\rm{init}}}\) and \({{\mathcal{S}}}_{{\rm{fin}}}\), respectively. We assume errors may have occurred on the qubits of the initial state that must be detected by measuring the stabilizers of the final code. As such, this operation has an associated code distance, according to the number of local error events that must occur for an undetectable logical error to affect the encoded space.

We detect the errors by comparing repeated readings of stabilizer measurements. Specifically, once we measure the stabilizers \({{\mathcal{S}}}_{{\rm{fin}}}\), we look to compare their outcomes to stabilizers prepared in the initial code \({{\mathcal{S}}}_{{\rm{init}}}\). Variations in the values of these stabilizer measurements indicate that an error has occurred. As such we are interested in code-deformation stabilizers

$${{\mathcal{S}}}_{{\rm{def}}}={{\mathcal{S}}}_{{\rm{init}}}\cap {{\mathcal{S}}}_{{\rm{fin}}},$$
(7)

that is, stabilizers that are prepared in the initial system and checked again after the code deformation is made, when we measure the stabilizer group \({{\mathcal{S}}}_{{\rm{fin}}}\).

Logical information that is preserved over the code deformation has coinciding logical operators associated with both \({{\mathcal{S}}}_{{\rm{init}}}\) and \({{\mathcal{S}}}_{{\rm{fin}}}\). Specifically, the logical operators that are preserved over the code deformation \({\mathcal{L}}\) are of the form

$${\mathcal{L}}={{\mathcal{L}}}_{{\rm{init}}}\cap {{\mathcal{L}}}_{{\rm{fin}}},$$
(8)

where \({{\mathcal{L}}}_{{\rm{init}}}\) and \({{\mathcal{L}}}_{{\rm{fin}}}\) are the logical operators for \({{\mathcal{S}}}_{{\rm{init}}}\) and \({{\mathcal{S}}}_{{\rm{fin}}}\), respectively.

Ideally, we should maximize the number of stabilizers that coincide in the initial and final codes to maximize the number of errors we detect. In practice, physical constraints imposed by hardware may not allow us to maximize the intersection between \({{\mathcal{S}}}_{{\rm{init}}}\) and \({{\mathcal{S}}}_{{\rm{fin}}}\). Here we concentrate on very simple initialization procedures in which the initial stabilizer code is prepared in a product state, or a product state of Bell pairs, together with the small four-qubit codes that initially maintain the encoded magic state.

Error correction for state injection

In what follows, we will show state injection into the surface code, the heavy-hex code and the colour code. We will also argue that all of these state-injection protocols are tolerant to a single error, thereby maintaining the error suppression achieved in the experiment presented in the main text.

We are interested in the general error model, in which a single error occurs on a circuit element in the stabilizer readout circuit as we deform the initial code onto the final code. However, we argue that for each individual example, we need to study only single-qubit errors that occur immediately before the code deformation takes place.

In addition to the errors that occur on data qubits, we are also interested in errors that occur on the auxiliary measurement qubits we use to perform parity measurements. In essence, these can lead to two types of error: (1) readout errors, in which we obtain the incorrect measurement outcome; and (2) hook errors, in which an error during a stabilizer readout circuit is copied to several other qubits, thereby creating a correlated error. Let us mention how we treat these types of error in the following discussion.

First of all, we neglect to discuss hook errors, as we assume that measures can be taken to mitigate their effects, by either flag qubits or an appropriate choice of stabilizer readout circuit. These measures are well developed for the codes of interest, see, for example, refs. 27,55,56,57. We completed the experiment presented in the main text using a device that is tailored to realize the heavy-hex code using additional flag qubits to mitigate the effects of hook errors.

We can detect a measurement error using a generic method, namely, the repetition of measurements. By repeating the measurements at least once, we can identify a single measurement error if the outcomes of two repetitions of the same measurement do not agree. As this method is applicable to all of the following injection schemes, we will not discuss this error-detection method case by case. Rather, we argue now that by measuring the stabilizer generators of \({{\mathcal{S}}}_{{\rm{fin}}}\) twice we can detect any single error. If the measurements of the two rounds of \({{\mathcal{S}}}_{{\rm{fin}}}\) do not agree, we discard the state we have prepared and repeat the state-preparation procedure. Otherwise, assuming the two rounds of measurement for \({{\mathcal{S}}}_{{\rm{fin}}}\) do agree, we check the outcomes to determine whether any Pauli errors occurred during the preparation of \({{\mathcal{S}}}_{{\rm{init}}}\), or immediately before the \({{\mathcal{S}}}_{{\rm{fin}}}\) stabilizer generators are measured. Assuming no error is detected, we continue to conduct standard error correction with the final code.

Surface code

Let us start by discussing the example of the surface code58 (Extended Data Fig. 3). The stabilizers of the code are shown by the faces in Extended Data Fig. 3 (left), in which the light faces mark the support of Pauli-X-type stabilizers and the dark faces mark the support of Pauli-Z-type stabilizers. We also show the support of a Pauli-X logical operator in green and a Pauli-Z logical operator in blue. In the theory for code deformation given above, this is the stabilizer group for \({{\mathcal{S}}}_{{\rm{fin}}}\).

In Extended Data Fig. 3 (right), we show \({{\mathcal{S}}}_{{\rm{init}}}\). The figure shows the [[4, 1, 2]] code outlined in red in the bottom-left corner of the lattice. The remaining qubits are prepared in a product state, such that the blue qubits are initialized in the |0〉 state and the green qubits are initialized in the |+〉 state. These disentangled qubits can be regarded as being in the stabilizer state Zv or Xv. The logical operator of the initial state can be supported entirely on the [[4, 1, 2]] code. However, the initial code shares the logical operators of the final code if we multiply the logical operators of the [[4, 1, 2]] code by the product state stabilizers.

Importantly, all the qubits support at least one stabilizer operator of \({{\mathcal{S}}}_{{\rm{def}}}\) such that a single error can be detected. We note that the qubits that are initialized in a product state need to detect only one type of error, because the other type of error acts trivially on the initial state. For example, a Pauli-X error acts trivially on a green qubit and a Pauli-Z error acts trivially on a blue qubit, whereas, respectively, a Pauli-Z or Pauli-X error on the same qubit will be detected by a stabilizer of \({{\mathcal{S}}}_{{\rm{def}}}\). Finally, all qubits of the [[4, 1, 2]] code support one of each type of stabilizer of \({{\mathcal{S}}}_{{\rm{def}}}\) and as such can also detect both types of Pauli error. By inspection then, we see that we can detect any single-qubit error that occurs at the initialization step.

Heavy-hex code

We can also inject the [[4, 1, 2]] code into the heavy-hex code. This is particularly relevant with respect to the experiment presented in the main text, as the experiment is implemented on hardware that is tailored to realize the heavy-hex code. The heavy-hex code is a subsystem code closely related to the surface code. However, as the code is a subsystem code, stabilizers are not measured directly. Rather, we have a group of check operators, known as the gauge group, that we measure to infer the values of the stabilizer operators. Nevertheless, we find the arguments given above are sufficient to show that a state can be injected while detecting a single error.

To review, the gauge group of the heavy-hex code includes weight-2 Pauli-Z terms on adjacent pairs of qubits that share a row. We show one such term in Extended Data Fig. 4 (left). The code also has Pauli-X-type checks. These are identical to the Pauli-X-type stabilizer operators of the surface code (Extended Data Fig. 3). These checks are used to infer Pauli-X- and Pauli-Z-type stabilizer operators. The Pauli-X-type stabilizer operators are the product of Pauli-X terms on all of the qubits on two adjacent rows (Extended Data Fig. 4, left). The Pauli-Z stabilizer operators are the same as those of the surface code (Extended Data Fig. 3). We also show the support of logical Pauli-X and Pauli-Z stabilizer operators in Extended Data Fig. 4 (left) in green and blue, respectively. Once again, this stabilizer group can be regarded as \({{\mathcal{S}}}_{{\rm{fin}}}\) with respect to the simplified code-deformation theory we have presented. Although we infer their values from measuring the gauge checks, the basic theory of state injection holds for our discussion on error correction.

We show \({{\mathcal{S}}}_{{\rm{init}}}\) for the heavy-hex code in Extended Data Fig. 4 (right), in which the [[4, 1, 2]] code, highlighted in red, is prepared on qubits in the bottom-left corner of the lattice, and the green qubits are prepared in the |+〉v state and the blue qubits are prepared in the |0〉v state. These qubits have an associated stabilizer Xv or Zv. Once again, similar to the case of surface code, the logical operators that are completely supported on the [[4, 1, 2]] code can be multiplied by elements of the stabilizer group of \({{\mathcal{S}}}_{{\rm{init}}}\) such that they are equivalent to those of \({{\mathcal{S}}}_{{\rm{fin}}}\) shown in Extended Data Fig. 4 (left). As such, the encoded logical information is preserved over the state-injection procedure, as these logical operators are members of \({{\mathcal{L}}}_{{\rm{def}}}\).

As with the case of the surface code, we argue that we can tolerate any single-qubit error during the injection procedure. Every single green qubit supports at least one Pauli-X-type stabilizer and every single blue qubit supports at least one Pauli-Z-type stabilizer of \({{\mathcal{S}}}_{{\rm{def}}}\). As such, we can detect a single Pauli-Z error on the green qubits and a single Pauli-X error on the blue qubits that occurs up to the point the code deformation takes place. We are not concerned with Pauli-X errors acting on the green qubits and the Pauli-Z errors acting on the blue qubits as these errors act trivially on the initial state. Finally, all of the qubits of the [[4, 1, 2]] code support both a Pauli-X- and a Pauli-Z-type stabilizer of \({{\mathcal{S}}}_{{\rm{def}}}\), and as such, they can all detect both types of error. This accounts for single-qubit errors occurring on all of the qubits of the system during the state-injection process with the heavy-hex code.

Colour code

Let us finally discuss the colour code59. This is a particularly interesting example as the [[4, 2, 2]] code can be injected directly into the colour code. We show the colour-code lattice in Extended Data Fig. 5. For \({{\mathcal{S}}}_{{\rm{fin}}}\), each lattice face supports both a Pauli-X- and Pauli-Z-type stabilizer. The code supports two logical operators, where \({\overline{X}}_{A}\) is the product of Pauli-X terms supported on all the qubits along the bottom boundary of the lattice and \({\overline{Z}}_{A}\) is the product of Pauli-Z terms supported on all the qubits along the left boundary of the lattice. Likewise \({\overline{X}}_{B}\) is the product of Pauli-X terms supported on all the qubits along the left boundary of the lattice and \({\overline{Z}}_{B}\) is the product of Pauli-Z terms supported on all the qubits along the bottom boundary of the lattice. We highlight the support of the logical operators on the left and bottom boundaries in blue and green, respectively, in Extended Data Fig. 5.

We define the stabilizer group for \({{\mathcal{S}}}_{{\rm{init}}}\) in the caption of Extended Data Fig. 5, in which the [[4, 2, 2]] code is placed on a four-qubit face of the lattice, and all of the other qubits are prepared in Bell pairs, with stabilizer operators XaXb and ZaZb, marked by highlighted edges in the figure. We colour the edges either blue or green according to the colouring convention for edges used in ref. 59. Nevertheless, all highlighted edges, of both colours, support the same Bell pair.

We can multiply the logical operators of the [[4, 2, 2]] code by elements of \({{\mathcal{S}}}_{{\rm{init}}}\) such that we obtain the logical operators of \({{\mathcal{S}}}_{{\rm{fin}}}\). As such, the logical qubits encoded on the error-detecting code are preserved over the state-injection process.

We finally argue that we can detect any single-qubit error during the state injection process. Extended Data Fig. 5 shows the support of the stabilizer operators of \({{\mathcal{S}}}_{{\rm{def}}}\) with coloured faces. Specifically, there is both a Pauli-X- and Pauli-Z-type stabilizer on each of the coloured faces. By inspection, we see that every qubit supports at least one coloured face and, therefore, supports both a Pauli-X- and a Pauli-Z-type stabilizer. We note also that the error-detecting code also supports both a Pauli-X- and a Pauli-Z-type stabilizer on its respective face. As such, we can detect any single-qubit error over the state-injection process.

Some remarks on state-injection procedures

We have presented state-injection protocols for several different codes for the error-suppressed magic state we discussed in the main text. We argued that we can detect a single error that may occur in any of these protocols, such that we maintain the error suppression we have demonstrated in our experiment. The injection protocols we have presented can be improved by combining them with other methods presented in the literature to improve the performance and yield of state injection. For instance, in refs. 20,24, two-step preparation procedures are proposed, in which a magic state is injected onto an intermediate-sized code, where error detection is used to suppress errors, before injecting the intermediate-sized code onto a larger code. This method is compatible with the injection protocols we have presented here. We might also adopt the method presented in ref. 25, in which the authors propose estimating the logical error on the injected state in the decoding step of state injection.

It is worth remarking that these error-detection protocols can be improved by increasing the fraction of error events that can be detected. We might, for example, consider better choices of \({{\mathcal{S}}}_{{\rm{init}}}\) that can be prepared before the state-injection procedure begins. In the case of subsystem codes, we might also look for additional error-detection checks that can be made between intermediate gauge measurements we make to infer the values of the stabilizers, and the stabilizers of the initial code, during the preparation procedure.

Encoding the CZ state on two [[4, 1, 2]] codes using the heavy-hex lattice geometry

Two of our state-injection protocols described above require that the CZ state is encoded on copies of the [[4, 1, 2]] code. Here we show how to transform the encoded CZ state prepared on the [[4, 2, 2]] code as we have described in the main text onto two copies of the [[4, 1, 2]] code. This transformation is made using measurements. In this sense, it can be understood as a code deformation similar to that discussed in the previous section. We argue that we can detect any one single error over the code deformation process, thereby maintaining the error suppression obtained in the main text. We also show how this process can be mapped onto the heavy-hex lattice geometry. The protocol is outlined in Extended Data Fig. 6, and we show how the outline is mapped onto the heavy-hex geometry in Extended Data Fig. 7.

Before discussing the transformation, we first briefly review the ideas behind state teleportation abstractly. We can view the transformation as a small instance of a lattice surgery operation38 in which the gates are performed between logical qubits by measuring appropriate logical degrees of freedom. Furthermore, in this particular instance, we can view the operation as a lattice surgery operation between a small colour code and a small surface code48,60,61, in which we interpret the [[4, 2, 2]] code and the [[4, 1, 2]] code as a small colour code and surface code, respectively. After performing a logical parity measurement between the two codes, the transformation is completed with a partial condensation operation of the small colour code, as described in ref. 48.

To explain the operation, we consider the evolution of the stabilizers and logical operators of the code at each step of the measurement pattern shown in Extended Data Fig. 6 independently from the implementation of the code. We have three logical qubits indexed A, B and C, where, initially, A and B are encoded on the [[4, 2, 2]] code and C is encoded on the [[4, 1, 2]] code. In essence, the operation teleports the logical state encoded on qubit B onto qubit C, up to a Clifford operation. Logical qubit A is not involved in the operation, so we concentrate on qubits B and C.

The teleportation operation proceeds as follows:

  1. 1.

    Prepare \({\left|+\right\rangle }_{C}\),

  2. 2.

    Measure XBZC,

  3. 3.

    Measure ZB,

  4. 4.

    Apply Pauli correction.

The operation functions with A and B prepared in some arbitrary logical state, but to illustrate the operation we assume they are in a product state with \({\left|\psi \right\rangle }_{B}=a{\left|+\right\rangle }_{B}+b{\left|-\right\rangle }_{B}\). We omit qubit A from the discussion, as it is unchanged by the transformation, and we leave it as an exercise to the reader to verify the general case.

Initially, an arbitrary state in the B subsystem along with a logical \(\left|+\right\rangle \) state on the C subsystem can be described by the following vector state: \({(a\left|+\right\rangle +b\left|-\right\rangle )}_{B}\otimes {\left|+\right\rangle }_{C}\), in which we have chosen a convenient basis for the vectors on B. Upon measuring the joint logical operator XBZC and obtaining measurement outcome m2, the resulting state of the joint system is \(a{\left|+\right\rangle }_{B}{\left|{m}_{2}\right\rangle }_{C}+b{\left|-\right\rangle }_{B}{\left|1\oplus {m}_{2}\right\rangle }_{C}\). Finally, upon measuring ZB and obtaining the measurement outcome m3, the resulting state is \({\left|{m}_{3}\right\rangle }_{B}\otimes \left(a\right.{\left|{m}_{2}\right\rangle }_{C}+{(-1)}^{{m}_{3}}b{\left|1\oplus {m}_{2}\right\rangle }_{C}\). An appropriate Pauli correction depending on the measurement outcomes m2 and m3 enables us to recover the state \({\left|0\right\rangle }_{B}\otimes (a{\left|0\right\rangle }_{C}+b{\left|1\right\rangle }_{C})\). As such, we see the logical information that was originally encoded on the B subsystem in the form of the coefficients a and b now lies entirely on the C subsystem. Finally, we note that, with this operation, the basis of the logical information has been rotated by a Hadamard operation. This can be corrected at a later step. Extended Data Fig. 6 shows how this transformation is conducted between an encoded qubit of the [[4, 2, 2]] code and the logical qubit of the [[4, 1, 2]] code by performing logical measurements.

We now discuss how to implement the described state teleportation on a heavy-hex lattice (Extended Data Fig. 7). We begin by preparing the encoded CZ state as explained in the main text, together with an encoded [[4, 1, 2]] code. The [[4, 1, 2]] code is prepared in the logical state |+〉. We can prepare this state using qubits outlined in the orange box shown in Extended Data Fig. 7 (top), in which the four qubits, 4, 6, 15 and 17 are the data qubits of the code and qubits 5, 10 and 16 are used to perform weight-4 parity checks with qubits 5 and 16 used as flag qubits. The [[4, 1, 2]] code is prepared in a fault-tolerant manner by initializing the data qubits in the |+〉 state and then measuring each of the Pauli-Z-type stabilizer operators Z4Z6 and Z15Z17. These measurements can be facilitated with the ancillary qubits 5 and 16, respectively. Each of these operators is measured twice such that we can detect a single measurement error during preparation (see also ref. 4).

We transfer a single logical qubit of the [[4, 2, 2]] code onto the [[4, 1, 2]] code using logical measurements. In step 3, we perform a weight-4 measurement that measures the parity of two logical qubits over the two codes. To do this using the heavy-hexagonal lattice geometry, we first transport the codes. This can be performed in two rounds of swap gates or teleportation operations, as shown by the arrows in Extended Data Fig. 7 (top), in which the blue arrows are performed first, in parallel, and the green arrows are performed in parallel afterwards. It should be noted that these rounds of parallel swap gates are fault-tolerant because all individual swap operations involve a single data qubit as well as an ancillary qubit. Thus, any potential two-qubit gate error is effectively a single-qubit error on the code that would be detected. After the swap operation, we facilitate the logical parity measurement with qubits 5, 10 and 16, shown in the green box in Extended Data Fig. 7. The logical measurement is performed twice to identify a measurement error that may occur in this step. The outcomes of both of these measurements should agree. An odd parity in measurement outcomes indicates that a measurement error has occurred.

Finally, we measure the logical operator \({\overline{Z}}_{B}\) to complete the teleportation operation. We measure this operator on both of its two-qubit supports. Specifically, these are \({\overline{Z}}_{B}={Z}_{2}{Z}_{4}\) and \({S}^{Z}{\overline{Z}}_{B}={Z}_{13}{Z}_{15}\), in which SZ = Z2Z4Z13Z15 is the weight-4 Pauli-Z stabilizer of the [[4, 2, 2]] code. Measuring both of these weight-2 logical operators enables us to detect a single error, as the product of their outcomes should agree with the value of the Pauli-Z stabilizer SZ. This final measurement completes the teleportation operation and, moreover, projects the error-detecting code onto a second copy of the [[4, 1, 2]] code. Finally, we remark that projecting \({\overline{Z}}_{B}\) into a known eigenstate enables us to regard this logical operator as a weight-2 stabilizer. As such, we can now regard the [[4, 2, 2]] code that we prepared initially as a [[4, 1, 2]] code. We, therefore, have the state \({\mathbb{1}}\otimes H\left|CZ\right\rangle \) encoded on the logical space of two [[4, 1, 2]] codes shown in the purple and orange boxes shown in Extended Data Fig. 7(bottom).

Analysis in terms of single-gate errors

All circuits considered, both for magic-state preparation and logical tomography, use redundancy to detect errors. For the mid-circuit syndrome measurements, performed with the circuit shown in Fig. 1, this redundancy comes, in part, by using flag qubits. These yield an outcome of 0 unless an error has occurred. These outcomes are, therefore, error-sensitive events, allowing errors to be detected.

Additional error-sensitive events come from the results of the syndrome measurements themselves. For the circuit shown in Fig. 2b, these events are as follows:

  1. 1.

    The results of the two \(\overline{W}\) measurements should agree.

  2. 2.

    SX should yield 0, because the system is prepared in a +1 eigenstate of this operator.

  3. 3.

    Although the first SZ will yield a random outcome, the following feedforward means that the resulting state is in the +1 eigenspace of SZ. This will then be the expected outcome for the value of final SZ measurement.

For concreteness, we will consider the measurement of logical ZZ, for which the final SZ measurement is achieved through the final measurement of data qubits. The circuit, then, has eight flag results in addition to the above three conditions for syndrome measurements. This gives 11 error-sensitive events in all. To analyse how errors in the circuit are detected, we consider all the possible ways in which Pauli errors can be inserted around each gate. Specifically, we consider the insertion of X, Y and Z before any single-qubit gate, and all possible single- and two-qubit Paulis before any two-qubit gate, on the qubits that support the gate. We then simulate each of these circuits to determine how the error is detected.

This analysis has two important uses. First, it can be used to verify the fault tolerance of the scheme, by confirming that all Pauli errors with non-trivial effect are in some way detected by the error-sensitive events. Second, it can be used to determine the specific combination of error-sensitive events, s, that detect each error. This information can then be used to infer the corresponding probabilities εs that such errors occurred, by looking at how often the corresponding error signature occurs within the outcomes measured.

After performing this analysis, it was found that the circuit is fault-tolerant. The only cases in which an error was not detected are those where the system was in an eigenstate of the error operator, or where its application was immediately followed by a measurement in an eigenbasis of the Pauli error. In both of these cases, the error will have a trivial effect on the circuit output.

When calculating the εs, it is important to note that the error signatures, s, are not necessarily unique for each type of error. For example, X and Y Paulis inserted immediately before any measurement will yield the identical effect of a measurement error. We, therefore, also determine the degeneracy, Ns, for each error signature. This is the number of unique errors that gives rise to the same error signature. With this information, we can then analyse the syndrome outcomes from experimental data, looking for these signatures and determining the probabilities with which they occur32.

Owing to the limited number of error-sensitive events used in this experiment, these probabilities can be calculated directly. The combined probability, εs, for all forms of error that lead to a particular signature is determined using the number of shots for which that signature occurs, ns, and the number of shots for which no error is detected, n0. The ratio of these numbers of shots will be the ratio of the probability that the error occurs with the probability that it does not:

$$\frac{{n}_{s}}{{n}_{0}}\approx \frac{{\varepsilon }_{s}}{1-{\varepsilon }_{s}}.$$
(9)

Simply rearranging this relation gives us the value of εs (ref. 62). We then use the degeneracy to obtain the average probability for each possible single-qubit Pauli error with this signature: εs/Ns.

Standard magic-state preparation circuits

Here we describe magic-state preparation circuits with no error suppression that are compared with our error-suppressed scheme described in the main text.

In Extended Data Fig. 8a, we show a circuit that prepares an encoded CZ state by, first, preparing a CZ state on two physical qubits and, then, encoding the state such that the Pauli observables of the two qubits of the CZ state can be represented as logical operators of the error-detecting code we encode. Finally, we measure the stabilizer operators of the code to encode the state, assuming we obtain the correct stabilizer measurement outcomes. The circuit used for the preparation step is shown in Extended Data Fig. 8b.

We can make use of the stabilizer operators of the CZ state to simplify the preparation circuit shown in Extended Data Fig. 8b. We define a stabilizer operator U, with respect to state \(\left|\psi \right\rangle \), as an operator for which the action is trivial on its respective state, that is, \(U\left|\psi \right\rangle =\left|\psi \right\rangle \). We can check that the CZ state is invariant under the action of a controlled-not gate conditioned on the control qubit in the zero state

$$C{X}^{{\prime} }=\left|1\right\rangle \left\langle 1\right|\otimes {\mathbb{1}}+\left|0\right\rangle \left\langle 0\right|\otimes X.$$

This unitary gate is equivalent to a standard controlled-not gate, \(CX=\left|0\right\rangle \left\langle 0\right|\otimes {\mathbb{1}}+\left|1\right\rangle \left\langle 1\right|\otimes X\), followed by a bit flip on the target qubit, that is,

$$C{X}^{{\prime} }=({\mathbb{1}}\otimes X)CX.$$

This observation enables us to simplify the preparation circuit. Once the CZ state is prepared, we add the \(C{X}^{{\prime} }\) gate in the dashed box in Extended Data Fig. 8, as the state we have prepared at this stage is invariant under this inclusion. The inclusion of this operator enables us to simplify the circuit, as the repeated application of the two Pauli-X rotations and the repeated application of two controlled-not operations used in the circuit act like an identity operation. This trivial step in the circuit is marked on the figure between vertical dashed lines. We can, therefore, omit all of the controlled-not operations and the bit-flip operations from the circuit shown in our implementation of this method of state preparation. As such, this preparation step includes only two entangling gates: a controlled Hadamard gate and a swap gate. We perform logical tomography by appending the circuits shown in Fig. 2b,c to the end of the circuit shown in Extended Data Fig. 8a. Likewise, we can perform physical tomography on the output of the circuit shown in Extended Data Fig. 8a.

Moreover, we note that the CZ state is also stabilized by the swap gate:

$${\rm{swap}}=({\mathbb{1}}+X\otimes X+Y\otimes Y+Z\otimes Z)/2,$$

and CZ as defined in the main text. The CZ state is uniquely stabilized by the Abelian stabilizer group generated by the set \(\langle CZ,\,C{X}^{{\prime} }{\rm{swap}}\rangle \).

Finally, we also compare our error-suppressed magic-state preparation scheme to a circuit that prepares the same magic state on two physical qubits (Extended Data Fig. 8c). We prepare the state on two physical qubits using a single entangling gate, together with single-qubit rotations, before measuring the state in varying single-qubit Pauli bases, P and Q, to conduct state tomography on the circuit output.

Device overview

Encoded state data collection on ibm_peekskill v.2.4.0 spanned several days over a single region. During this time, monitoring experiments were interleaved with tomography data collection trials. Device coherence times for all qubits exceed about 100 μs and two-qubit errors per gate was found to range from 0.35% to 0.59%. Detailed monitoring of readout errors are provided in Extended Data Fig. 9f,g and time-averaged readout fidelities ranged from 98.1% to 99.6% for all qubits. Average device characterization data are summarized in Extended Data Tables 1 and 2. Unencoded magic-state data were collected over a single 24-h period on ibm_peekskill v.2.5.4 on all physical pairs and the best-performing edge is reported in Extended Data Table 2. Although the unencoded magic-state data were not interleaved with encoded-state tomography, the best-performing pair of physical qubits was found to have a low two-qubit error per gate of 0.38%, and this error is comparable with the lowest two-qubit error per gate for edges used in the encoded magic-state experiments.

Real-time feedforward control of qubits

In the past decade, several experiments were performed that exploit fast feedback or real-time control within the execution of a quantum program. Fast feedback has been used for conditional reset63,64,65,66, state and gate teleportation67,68,69 with low branching complexity and in more demanding algorithms such as the iterative-phase estimation protocol70, to name a few. More recently, there have been demonstrations of quantum error correction using real-time control in various systems2,6,71,72. There have also been examples of work toward classical-control microarchitectures that enable the seamless integration of qubits and classical operations with tens of qubits.

Our work was performed with the first-generation real-time control system of IBM Quantum, in which we use centralized processing of mid-circuit measurement outcomes to classically condition a quantum circuit. The control system architecture is based on a hierarchical heterogeneous system of field-programmable gate array controllers with computing elements for concurrent real-time processing, microwave control and qubit readout. These are synchronized through a global clock and linked with a real-time communication network to enable synchronized collective operations such as control flow. Branching incurs a constant latency penalty to execute the branch (of the order of 500 ns). Real-time computations will incur a variable latency overhead depending on the complexity of the decision. The system provides specialized fast-path control-flow capabilities for rapid and deterministic conditional reset operations. Collective control of the system requires orchestration through a proprietary heterogeneous hardware compiler and code generator. We use an open-access platform that is programmable through Qiskit and OpenQASM 3—an open-source imperative C-style real-time quantum programming language73. All experiments were performed through Qiskit and IBM Quantum Services74,75.

Estimates for magic-state yield

Let us attempt to model the error rate of the components of the device using the yield we have evaluated experimentally. The yield is a helpful figure of merit as it tells us precisely how often a single-error event occurs to leading order in the error rate. We first try to model the yield using simple three-parameter models that we derive below. We also compare the yield to numerical simulations of our circuits. We show the estimated yield for different experiments in Extended Data Table 3, in comparison with our analytical model and numerical results.

Both of our analyses have good agreement with the experiment if we assume a two-qubit gate-error rate and a measurement error rate of the order of 2%. This is a high error rate compared with those measured in Extended Data Tables 1 and 2. However, we remark that neither our analytical model nor our simulations account for common error processes such as leakage, cross talk, two-level systems and idling errors that may occur during slow-circuit processes that will introduce additional noise to the system. We suggest discrepancies in our modelling, and the experimentally observed yields can be attributed to these details that are difficult to model analytically or numerically.

Let us present our analytical model to evaluate the yield. We can estimate the magic-state yield as QR, where Q is the probability that the random measurement outcomes we obtain throughout our experiment yield the values we need to complete the magic-state preparation scheme and R is the probability that the experiment does not experience a single error.

If we have that εP is the probability that a single parity measurement introduces an error and D is the number of parity measurements that are conducted in an experiment, that is, the depth, we can write \(R={(1-{\varepsilon }_{P})}^{D}\), thereby giving the equation

$$\,{\rm{logical\; yield}}\,=Q{(1-{\varepsilon }_{P})}^{D}.$$
(10)

We note that Q and D vary for different experiments.

For our rough calculation, we find reasonably good agreement with the experimental data if we take εP ≈ 22%. This equates, approximately, to a two-qubit gate-error rate and a measurement error rate of about 2%. Each parity measurement we perform uses eight entangling gates and three mid-circuit measurements. Therefore, neglecting higher-order terms, we obtain the probability that a parity measurement introduces a single error is

$${\varepsilon }_{P}\approx 8{\varepsilon }_{2Q}+3{\varepsilon }_{M},$$
(11)

where ε2Q is the two-qubit gate-error rate and εM is the probability of a measurement error. If we set ε2Q = εM = 2%, we find that εP = 22%.

We also need to predict Q for different experiments. Let us begin with the error-suppressed experiment in which we use feedforward. Here, in the noiseless case, we have one random measurement outcome, in which we initially measure \(\overline{W}\). It is readily checked that the probability that we project the |++ state onto the +1 eigenvalue eigenspace of the CZ operator is QFF = ++(1 + CZ)++/2 = 3/4. In the case that we do not use feedforward, in addition to obtaining the correct outcome for the \(\overline{W}\) measurement, we must also post-select on obtaining the correct outcome of the initial measurement of SZ. We obtain the +1 eigenvalue subspace of this operator with probability 1/2. We, therefore, have QPS = 3/4 × 1/2 = 3/8. Finally, in the standard preparation procedure, we measure both SZ and SX, and we require that both give the +1 outcome. Each measurement gives the correct outcome with probability 1/2. We, therefore, have QSTND = 1/2 × 1/2 = 1/4.

Let us comment on the features of this model that agree with the experiment. First of all, we observe that the error-suppressed scheme using feedforward has a consistently better yield than the other two schemes, both the error-suppressed scheme using post-selection and the standard preparation scheme. Furthermore, we observe that the error-suppressed post-selection scheme and the standard scheme have comparable yields, for both tomography circuits shown in Fig. 2.

Furthermore, our model explains the difference in yield between different tomography experiments conducted using the two different circuits shown in Fig. 2. The tomography circuit in Fig. 2c uses two additional parity measurements than that shown in Fig. 2b. As such the tomography circuit in Fig. 2c is inherently more noisy than that in Fig. 2b. This is reflected in Fig. 4 in which the yield for tomography circuits shown in Fig. 2b,c are shown in Fig. 4 (left, right).

Our rudimentary analytical model correctly predicts several qualitative features of our experimental data. However, it neglects many details of the circuit. As we might expect, we find better agreement with the experimentally observed yield if we simulate our circuit. We assume an error rate for each of the two-qubit entangling gates and a measurement error rate of 2%. These results are also shown in Extended Data Table 3. Again, the physical error rate of these circuit elements is considerably higher than the observed error rates of these components. As mentioned at the beginning of this section, we attribute this to noise processes that are not captured by either our analytical model or our numerical simulations. In practice, it is extremely difficult to capture all of the physical details that occur in an experiment.

State tomography with readout error mitigation using noisy positive-operator-valued measurements

The state tomography in the main text uses the Qiskit Experiments implementation of state tomography31. A notable change from the previous works is that we do not use readout error mitigation in the main text. Instead, we perform tomographic fitting assuming ideal measurements, which attributes any undetectable measurement errors to errors in the reconstructed quantum state. For physical tomography, we use the cvxpy_gaussian_lstsq fitter with measurement data using the default Pauli-measurement basis on each physical qubit to obtain a weighted maximum-likelihood estimate, constrained to the space of positive, semi-definite, unit trace density matrices. For logical tomography, we use the cvxpy_linea_lstsq fitter with a custom measurement basis using Pauli expectation values, rather than Pauli eigenstate probabilities. In this case, the custom fitter weights are calculated from the inverse of the standard error in the Pauli expectation value estimates for each post-selected logical Pauli operator measurement.

Susceptibility to measurement error is a common issue in tomographic methods. In general, tomographic tools are only as good as the noise model of the measurement apparatus, that is, our ability to calculate the likelihood representing the conditional probability of obtaining a dataset given some test density matrix. In this section, we discuss an alternative approach combining readout error characterization with tomographic reconstruction. Although the dominant measurement error source in tomography experiments is because of qubit readout, it is a common practice to assume local, uncorrelated readout errors in the Z basis. A set of noisy positive operator-valued measurements (POVMs) on a single-qubit is,

$${Z}_{0}^{{\prime} }:=\left[\begin{array}{cc}1-p & 0\\ 0 & q\end{array}\right],{Z}_{1}^{{\prime} }:=\left[\begin{array}{cc}p & 0\\ 0 & 1-q\end{array}\right],$$
(12)

where p is the probability of assigning outcome 1 to a state initially prepared as |0 and q is the probability of assigning outcome 0 to astate initially prepared as |1; that is, p = P(10) and q = P(01). We can also construct noisy POVMs for measurements in the Pauli-X or Pauli-Y eigenbases by rotating the noisy POVMs shown in equation (12) by an appropriate angle assuming ideal unitaries, because the measurement error is typically several orders of magnitude greater than the one-qubit gate error.

By interleaving small batches of experimental data collection with readout calibration experiments, one can construct noisy POVMs for each data qubit applicable to a small duration of data collection to be used in fitting procedures discussed above. In Extended Data Fig. 9a, state infidelities from fitting with noisy POVMs can be compared with fitting with ideal projectors (p, q ≡ 0), in which the latter is reported in the main text. Using readout mitigation, the fault-tolerant tomography routines far outperform both unencoded tomography and the physical tomography of the encoded state. As the terminating measurements in logical tomography are very similar to those in physical tomography, we would expect both of these experiments to demonstrate similar infidelities. Resolving this discrepancy remains an open research question.

Furthermore, it is unclear if our assumed construction of noisy POVMs, or the measured readout error calibrations, collectively reflect the true measurement errors experienced by data qubits. We, therefore, test the sensitivity of the outcomes of state tomography to the choice of measurement compensation in Extended Data Fig. 9b–d. State infidelity is calculated by fitting experimental tomography data to POVMs parameterized by p and q. To simplify, these readout error probabilities are set to be constant for all qubits and time. Dark-blue regions of low infidelity (with the minima marked with a red star) do not coincide with the state infidelity calculated using the global average of experimentally measured readout calibrations (marked by a black dot). This disparity suggests that either the target experiments experienced initialization or measurement errors at a higher rate than measured by simpler calibrations and/or fitting with potentially incorrect A-matrices yields a highly non-positive state that is mapped to a high-fidelity physical state under constrained optimization.

Combining readout mitigation with tomography thus remains an open question for further work, and the results of the main text are limited by unaddressed readout error on terminal measurements. We expect that state tomography experiments in Extended Data Fig. 9b–e at p = q = 0 provide a reasonable upper bound on the error of the underlying magic state.