Encoding a magic state with beyond break-even fidelity

To run large-scale algorithms on a quantum computer, error-correcting codes must be able to perform a fundamental set of operations, called logic gates, while isolating the encoded information from noise1–8. We can complete a universal set of logic gates by producing special resources called magic states9–11. It is therefore important to produce high-fidelity magic states to conduct algorithms while introducing a minimal amount of noise to the computation. Here we propose and implement a scheme to prepare a magic state on a superconducting qubit array using error correction. We find that our scheme produces better magic states than those that can be prepared using the individual qubits of the device. This demonstrates a fundamental principle of fault-tolerant quantum computing12, namely, that we can use error correction to improve the quality of logic gates with noisy qubits. Moreover, we show that the yield of magic states can be increased using adaptive circuits, in which the circuit elements are changed depending on the outcome of mid-circuit measurements. This demonstrates an essential capability needed for many error-correction subroutines. We believe that our prototype will be invaluable in the future as it can reduce the number of physical qubits needed to produce high-fidelity magic states in large-scale quantum-computing architectures.

Introduction.We distill magic states to complete a universal set of fault-tolerant logic gates that is needed for large-scale quantum computing with lowdensity parity-check code architectures [13][14][15][16][17][18].Highfidelity magic states are produced [9][10][11] by processing noisy input magic states with fault-tolerant distillation circuits, where experimental progress to prepare 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 states [11,[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 magicstate distillation using a heavy-hexagonal lattice of superconducting qubits [4,5,27].Our circuit prepares an input magic state, that 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 quantumcomputing architectures [11,28] in Methods I. Our circuit is capable of detecting any single error during state preparation, as such, the infidelity of the encoded state is suppressed as O(ϵ 2 ) where ϵ is the probability that a circuit element experiences an error.In contrast a standard encoding circuit prepares an input state with infidelity O(ϵ).Furthermore, we can improve the yield of the magic states we successfully prepare with the errorsuppressed circuit using adaptive circuits that are conditioned in real time on the outcomes of mid-circuit measurements.We propose several tomographical experi-ments 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: encoded on a distance-2 error-detecting code where distinct bit-strings label orthogonal computational basis states over two qubits.We can achieve the CZ-state by, first, preparing the | + +⟩ = a,b=0,1 |ab⟩/2 state and, then, projecting it onto the CZ = +1 eigenspace of the controlled-phase (CZ) operator CZ = diag(1, 1, 1, −1), i.e. |CZ⟩ ∝ Π + | + +⟩ with the projector Π + = (1 1 + CZ)/2.We can perform both of 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 S X = X ⊗ X ⊗ X ⊗ X, S Z = Z ⊗ Z ⊗ Z ⊗ Z, and S Y = S Z S X where X and Z are the standard Pauli matrices.The four-qubit code encodes two logical qubits that are readily prepared in a logical |+ +⟩ state by initializing four data qubits in the superposition state, |+⟩ ∝ |0⟩ + |1⟩, and measuring S Z .We note that we use bars to indicate we are describing states and operations in the logical subspace.We prepare the state with S Z = +1, using either post selection or, alternatively, an adaptive Pauli-X rotation on a single qubit given a FIG.1: Figure title -A fault-tolerant circuit to make parity measurements: (a) A circuit that measures S X , S Z and 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 faulttolerant parity measurement.The circuit measures S X (S Z ) by setting U = 1 1 (H), where H is the Hadamard gate.As explained in the main text, the circuit measures W if we set U = T .Measurement outcome M gives the reading of the parity measurement.Essential to the fault-tolerant procedure are flag fault-tolerant readout circuits [4,5,27,31], 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.
random −1 outcome from the S Z measurement.
The four-qubit code has a transversal implementation of the CZ-gate on its encoded subspace, (1, i).We can measure this operator as follows.We note that conjugating S X with the unitary rotation T = T ⊗ T † ⊗ T † ⊗ T , where T = diag(1, √ i), gives the hermitian operator: Given that we prepare the code with S X = +1, measuring W effectively gives a reading of CZ.
It is essential to our scheme that we reach the S Z = +1 eigenspace.This is due to the non-trivial commutation relations of W with the stabilizer operators of the code [29,30]; [S X , W ] = (1 − S Z )S X W .This commutator reveals that W only commutes with S X in the S Z = +1 subspace.If S Z = −1, one can check that W and S X anti-commute, and are therefore incompatible observables in this subspace.
We can perform all of the aforementioned measurements, S X , W and S Z , on the heavy-hexagon lattice geometry [27].We show one such setup in Fig. 1.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 Methods II.
We therefore present a sequence of measurements that prepare the input magic state and, in tandem, identifies a single error that may have occurred during the preparation procedure.We show the sequence in Fig. 2 and describe its function in the figure caption.As we can detect a single error, we expect the infidelity of the out- Error-detection measurements Code preparation Magic state initialisation by measurement FIG. 2: Figure title -Fault-tolerant schemes for magicstate preparation and logical tomography: (a) The 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 |+ +⟩ state by measuring |+⟩ ⊗4 with the S Z operator.We can use adaptive circuits or post-selection to correct for S Z = −1 outcomes.In the magic state initialization step we measure the W operator and post-select on the +1 outcome.In the final error-detection step we identify errors that may have occurred during preparation.We measure W a second time to identify if a measurement error occurred during the magic state initialization step.We finally measure S X and S Z a second time to identify Pauli errors that may have occurred or if the initial S Z measurement gave a readout error.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 S Q = S X and measure qubits in the R = Z basis, we infer the value of S Z , as in (a), and we also obtain readings of the logical Z1, Z2 and Z1Z2.Likewise, we can set S Q = S Z and R = X(Y ) to infer S X (S Y ) as well as logical Pauli operators X1, X2 and X1X2 (X1Z2, Z1X2 and Y1Y2).In (c) we include a Y j measurement for logical qubit j = 1, 2 to measure logical operators of the form Y j , Y j X k and Y j Z k with k ̸ = j and k = 1, 2, and an appropriate choice of R. The Y j operator is measured twice to identify the occurrence of measurement errors.Operators Y j are supported on three of the data qubits and can therefore be read out with an appropriate modification to the circuit shown in Fig. 1.
put state to be O(ϵ 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 Methods III.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 novel 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 into the logical We show state infidelity for error-suppressed and standard schemes in blue and orange, respectively.On the x-axis, a state is reconstructed with either Logical or Physical tomography.The correction for the initial S Z measurement in Fig. 2(a) is implemented either using 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 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 to the standard scheme.The unencoded magic state prepared directly on two physical qubits gives an average infidelity across 28 qubit pairs as ≈ 6.2 × 10 −2 (green dashed line) using 18 repetitions over a 24-hour period with 10 5 shots per circuit.Of these, the best performing pair yields a minimum infidelity of (2.354 ± 0.271) × 10 −2 (red solid line).In all cases, the error-suppressed scheme outperforms the best two-qubit unencoded magic state.
subspace.Logical tomography with the four-qubit code is summarized in Fig. 2(b)-(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 since 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 us to sample 81 different measurement circuits.Experimental results.We performed our experiments using IBM Quantum's first-generation real-time control system architecture deployed on ibm peekskill; one of the IBM Quantum Falcon Processors [32].Device characterization can be found in Methods IV.The control system

FIG. 4:
Figure title -Magic-state yield for feedforward vs. post-selection: Yield is calculated for logical tomography circuits shown Fig. 2 (b),(c) for the errorsuppressed scheme with feedforward (blue circles) vs. postselection (blue squares); standard scheme shown for reference (orange squares).Error-bars represent 1σ from bootstrapping.The shaded area of the graph shows the increase in yield for the error-suppresed scheme using feedforward compared with the post-selection scheme or indeed the standard scheme.The optimal acceptance rate assuming no noise is 75%, 37.5% and 25% for the feedforward scheme, the postselection scheme and the standard scheme, respectively.The observed acceptance rates are due to the additional detection of errors.We estimate the yield in the presence of noise in Methods VI.We observe a stark difference in yields between experiments conducted with the logical-tomography circuit shown in Fig. 2(b) and Fig. 2(c), shown to the left and right of the dashed line, respectively.We can attribute this to the depth of the logical tomography circuit, whereby deeper circuits, such as that shown in Fig. 2(c), are more likely to introduce detectable errors.This is discussed in Methods VI.
architectures gives us access to dynamic circuit operations, such as real-time adaptive circuit operations that depend on the outcomes of mid-circuit measurements, i.e., feedforward (see Methods V for details).
Our results are summarized in Fig. 3 where we present state infidelities for various state preparation schemes calculated using both logical and physical tomography.For results described in the main text we model the reconstructed state assuming readout is conducted with projective measurements.We also present an alternative analysis in Methods VII where we combine readout error characterization with tomographic reconstruction using noisy positive operator-valued measurements.
To accommodate drift in device parameters over the data collection period, a complete set of tomography circuits were interleaved and submitted in batches of ∼ 10 4 shots until a total of ∼ 10 6 shots were collected over several days.The resulting counts database is uniformly sampled with replacement for ten bootstrap trials with batch size limited to 20% of the total database before post-selection.The standard deviation, σ, of these bootstrapped trials are plotted as error bars in all data figures.All tomographic fitting was done using positivesemidefinite constrained weight-least-squares convex optimization using the Qiskit Experiments tomography module [33].For logical tomography the fitting weights were set proportional to 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.
We first compare the state preparation scheme using dynamic circuits against 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 displayed in blue in Fig. 3, respectively.We find that the infidelities are commensurate in these two experiments.Using dynamic circuits with feedforward operations, we encode a twoqubit 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 time 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, see Fig. 4.
We can analyze the commonly occurring errors for fault-tolerant circuits using syndrome outcomes to infer the events that are likely to have caused them [34].This is done using the method detailed in Methods II for 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 highest value is 1.2%, corresponding to errors during the X stabilizer measurement which spread to and are detected by the flag qubits.Similar errors for the other stabilizer measurements show the probability rising from 0.35% for the initial Z measurement, up to 0.41% and 0.45% for the two W measurements.This could suggest that, rather than being caused by Pauli errors, other effects such as an accumulation of leakage on the flag qubits may be the cause of these results.
We verify the performance of our logical tomography procedure by comparing our results to the infidelity obtained using physical tomography for the magic state preparation procedure scheme where we obtain the S Z = +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, where the standard deviation represents variation over 81 physical Pauli directions.
To compare the infidelity obtained with physical tomography evenhandedly 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 subspace, see, e.g., Ref. [35,36].We obtain the elements of the density matrix of the logical subspace ρ via the equation: where k, l, m, n = 0, 1 specify orthogonal vectors in the logical subspace and P L = k,l ⟨k l|ρ|k l⟩ is the probability that the state we prepare is in the logical subspace.
Using this method we obtain projected logical infidelity (1.70 ± 0.35) × 10 −2 with the probability of finding ρ phys in the logical subspace P L = 0.898 ± 0.008.An average post-selection acceptance rate over all physical Pauli directions is found to be 14.9 ± 0.1%.This data point is shown in blue to the right of Fig. 3 to be compared with the central blue data point.This demonstrates consistency between logical and physical tomography.For reference, raw state fidelities from physical tomography prior to logical projection are reported in Methods VII.We compare our error-suppressed magic state preparation procedure to 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 4× 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 P L = 0.789 ± 0.004.
Finally, we compare our error-suppressed preparation procedure to a state preparation experiment performed using physical qubits.We mark the lowest infidelity we 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 errorsuppressed 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, that takes us beyond the break-even point set by basic physical qubit operations, can be attributed to quantum error correction which suppresses the noise that accumulates during state preparation.
The yield of magic states benefited from the use of dynamic circuits where 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.Such dynamic circuits are essential to future quantum-computing architectures as they will be needed, for example, to perform magic-state distillation circuits [9][10][11] and gate teleportation [37,38], and as well as many other measurement-based methods [13,[17][18][19][39][40][41][42][43][44][45][46][47][48][49][50] that have been proposed to complete a universal set of logic gates.
We have shown that experimental progress has reached a point where we can make prototype gadgets that can impact the resource cost of large-scale quantum computers.In the accompanying Supplementary Information, we explain how our prototype can be used together with magic-state distillation.It will be exciting 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.Perhaps further developments in the theory of pieceable fault tolerance [46] might show us ways of producing better magic states with small devices.Error-suppressed magic states could improve the time cost of recent proposals [51,52] for error-corrected circuits that are supplemented by error mitigation techniques to complete non-Clifford operations.Ultimately, experimental progress we make to this end in the near term can benefit large-scale quantumcomputing architectures.Acknowledgements.We acknowledge the use of IBM Quantum services for this work.These system capabilities are available as open-access to device users.We also acknowledge the work of the IBM Quantum software and hardware teams that enabled this project.The views expressed are those of the authors, and do not reflect the official policy or position of IBM or the IBM Quantum team.B.J.B. is grateful for the hospitality of the Center for Quantum Devices at the University of Copenhagen.J.R.W. acknowledges support from the NCCR SPIN, a National Centre of Competence in Research, funded by the Swiss National Science Foundation (grant number 51NF40-180604).R.S.G. and S.T.M. acknowledge support from the Army Research Office under QCISS (W911NF-21-1-0002).T.A., M.H., and M.B.H. acknowledge support from IARPA under LogiQ (contract W911NF-16-1-0114) on real-time control software work.All statements of fact, opinion or conclusions contained herein are those of the authors and should not be construed as representing the official views or policies of the US Government.Author contributions.R.S.G., N.S., T.A., M.H, M.B.H enabled experimental execution using real-time control flow; S.T.M. performed unencoded magic-state tomography experiments, R.S.G performed encoded magic-state tomography experiments and simulations; C.J.W., S.T.M. conceived and developed tomographic fitting procedures, with and without error-mitigation, implemented by R.S.G; J.R.W. conducted numerical simulations to test the fault-tolerant properties of the preparation circuits, and for analysis of experimental results; R.S.G., C.J.W., S.T.M., J.R.W., M.T. and B.J.B. performed data analysis; T.J., T.Y, A.W.C. and B.J.B. developed the fault-tolerant magic-state preparation circuits that were initially conceived of by B.J.B.; R.S.G. assumed primary responsibility for experimental execution, analysis, codebase and data management; M.T. and B.J.B supervised the project; R.S.G., N.S., T.A., C.J.W., S.T.M., J.R.W., M.T. and B.J.B. wrote the manuscript with input from all of the authors.Competing interests.A patent (Application No. 18/053087) was filed on 7 November 2022 with listed inventors B.J.B., A.W.C., R.S.G., T.J., and T.Y.Authors declare no other competing financial or non-financial interests.other supporting code is available upon reasonable request.Additional information.All correspondence and requests for materials may be addressed to B.J.B at benjamin.brown@ibm.com.

I. USING CZ STATES IN LARGE-SCALE QUANTUM-COMPUTING ARCHITECTURES
Magic states are distilled to complete a universal set of fault-tolerant logic gates, see Fig. 5 and its caption 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 errorcorrecting 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 Sec.I A we review details on how we can use CZ states in largescale fault-tolerant quantum computing.Specifically, we can convert CZ states into Toffoli states using Pauli measurements and Clifford operations [28], such that we can adopt well known magic-state distillation protocols for further rounds of distillation [11].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 to the Pauli measurement, thereby conserving available resource states.
We also give some examples for how we can inject small codes into larger codes in Sec.I B, as 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 two codes and encode their state on the surface code, the heavy-hex code and the color code with a higher distance.Notably, the heavy-hex code is readily implemented on the heavyhex 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 color-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.In order 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 Sec.I F.
A. Magic-state distillation with the CZ state While 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 operations [28].Given there are known methods for distilling Toffoli states, [11], let us review how the Toffoli state is produced from 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 operations [17,18,47], to complete these circuits.
The Toffoli state is defined as follows: where we sum over the bitwise values j, k = 0, 1.
Given two copies of the CZ state, |CZ⟩ 1,2 |CZ⟩ 3,4 , if we project qubits 2 and 3 onto the Z 2 Z 3 = −1 eigenspace, then we obtain the intermediate state We then obtain |Tof⟩|1⟩ with the following unitary circuit where indices C and T of the controlled-not gate CX C,T denote the control and target qubit, respectively.We obtain the −1 outcome by measuring Z 2 Z 3 of state |CZ⟩|CZ⟩ with probability 4/9.Beyond the work of Ref. [28], we find that we can recover a single copy of the CZ state given the Z 2 Z 3 = +1 outcome at this step, thereby saving magic resource states.In the event that we obtain this measurement outcome, we produce the state Applying the unitary operation CX 2,3 CX 2,4 |χ⟩ and obtaining the two-qubit parity measurement outcome Z 3 Z 4 = −1 we obtain the state |CZ⟩|01⟩.We obtain this state with probability 3/5, assuming we obtained the Z 2 Z 3 = +1 outcome previously.

B. 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 errorcorrecting 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 color 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 Fig. 6(left).As we show later, states on this code can be injected directly onto the color code.Two of the injection schemes, encoding onto the surface code, or the heavyhex code, assume the two logical qubits of the CZ state are encoded on two copies of the 4, 1, 2 code, shown in Fig. 6(right).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, in the following section.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 in a consistent way, throughout this Supplementary Information 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 codes by their encoding parameters n, k, d .Both of these codes have 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 ( 4, 1, 2 code) encodes k = 2 (1) logical qubits (qubit).

C. The theory of code deformations
We inject a state into a larger code [11, 19-26, 43, 53] using a code deformation [19,48,54].In what follows we describe a theory of code deformations using the stabilizer formalism.We remark that more general theories of code deformations can be found elsewhere in the literature [48,54].The theory we present is sufficient to describe the state injection operations of interest.
We describe code deformations using the stabilizer formalism [55].Quantum error-correcting codes can be described with an Abelian subgroup of Pauli operators called the stabilizer group 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 L that can be generated by a set of mutually anti-commuting pairs X j , Z j ∈ 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.A code has a distance of at least d = 2 if we can detect any single error.We give examples of small stabilizer codes, together with their logical operators, in Fig. 6, and in the caption.These examples will be relevant for the following discussion on state injection.
We measure the stabilizer operators to identify 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 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 where, 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 S init.and S 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 in order for an undetectable logical error to affect the encoded space.
We detect errors by comparing repeated readings of stabilizer measurements.Specifically once we measure the stabilizers S fin., we look to compare their outcomes to stabilizers prepared in the inital code S init. .Variations in the values of these stabilizer measurements indicate that an error has occurred.As such we are interested in code deformation stabilizers i.e., stabilizers that are prepared in the initial system and checked again after the code deformation is made when we measure the stabilizer group S fin. .Logical information that is preserved over the code deformation has coinciding logical operators associated to both S init.and S fin. .Specifically, the logical operators that are preserved over the code deformation L are of the form where L init. and L fin. are the logical operators for S init.and S fin., respectively.Ideally, we should maximise the number of stabilizers that coincide in the initial and final code to maximise the number of errors we detect.Of course, in practice physical constraints imposed by hardware may not allow us to maximise the intersection between S init.and S fin. .Here we concentrate on very simple initialisation procedures where 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.

D. Error correction for state injection
In what follows we will show state injection into the surface code, the heavy-hex code and the color 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, where 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 only study single-qubit errors that occur immediately before the code deformation takes place.
In addition to 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; readout errors, where we obtain the incorrect measurement outcome and hook errors, where an error during a stabilizer readout circuit is copied to several other qubits thereby creating a correlated error.Let mention how we treat these types of errors in the following discusstion.
First of all, we neglect to discuss hook errors, as we assume that measures can be taken to mitigate their effects, either by flag qubits or an appropriate choice of stabilizer readout circuit.These measures are well developed for the codes of interest, see, e.g., Refs.[27,[56][57][58].Indeed, 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 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 S fin.twice we can detect any single error.If the measurements of the two rounds of S 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 S fin.do agree, we check the outcomes to determine if any Pauli errors occurred during the preparation of S init., or, immediately before the S 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 code [59], see Fig. 7.The stabilizers of the code are shown by the faces in Fig. 7(left) where the light (dark) faces mark the support of Pauli-X (Pauli-Z) type stabilizers.We also show the support of a Pauli-X (Pauli-Z) logical operator in green (blue).In the theory for code deformation given above, this is the stabilizer group for S fin. .In Fig. 7(right) we show S 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 (green) qubits are initialised in the |0⟩ (|+⟩) state.These disentangled qubits can be regarded as being in the stabilizer state Z v (X v ).The logical operator of the initial state can be supported entirely on the 4, 1, 2 code.However, we find 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 S def.such that a single error can be detected.We note that the qubits that are initialised in a product state need only detect one type of error, since the other type of error acts trivially on the initial state.For example, a Pauli-X (Pauli-Z) error acts trivially on a green (blue) qubit, whereas a Pauli-Z (Pauli-X) error on the same qubit will be detected by a stabilizer of S def. .Lastly, all qubits of the 4, 1, 2 code support one of each type of stabilizer of S def. and as such can also detect both types of Pauli errors.By inspection then, we see that we can detect any single qubit error that occurs at the initialisation 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 realise 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 argue that a state can be injected while detecting a single error.
To review, the gauge group of the heavy-hex code includes weight-two Pauli-Z terms on adjacent pairs of qubits that share a row.We show one such term in Fig. 8(left).The code also has Pauli-X type checks.These are identical to the Pauli-X type stabilizer operators of the surface code, shown in Fig. 7.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, see Fig. 8(left).The Pauli-Z stabilizer operators are the same as those of the surface code, again, see Fig. 7.We also show the support of a logical Pauli-X and Pauli-Z stabilizer operator in Fig. 8(left) in green and blue, respectively.Once again, this stabilizer group can be regarded as S fin. with respect to the simplified code-deformation theory we have presented.While we infer their values from measuring the gauge checks, the basic theory of state injection holds for our discussion on error correction.We show S init.for the heavy-hex code in Fig. 8(right) where the 4, 1, 2 code, highlighted in red, is prepared on qubits in the bottom-left corner of the lattice, and the green (blue) qubits are prepared in the |+⟩ v (|0⟩ v ) state.These qubits have an associated stabilizer X v (Z v ).Once again, like with the surface code case, the logical operators that are completely supported on the 4, 1, 2 code, can be multiplied by elements of the stabilizer group of S init.such that they are equivalent to those of S fin.shown in Fig. 8(left).As such, the encoded logical information is preserved over the state injection procedure, as these logical operators are members of L 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 (blue) qubit supports at least one Pauli-X (Pauli-Z) type stabilizer of S def. .As such, we can detect a single Pauli-Z (Pauli-X) error on the green (blue) qubits that occurs up to the point the It can be performed in a fault-tolerant manner using qubits 5, 10, and 16, as shown in the green box in Fig. 11(bottom).We complete the operation by measuring the logical operator Z2 in step 4.This weight-two measurement can be repeated in two locations on the 4, 2, 2 code such that a single measurement error can be detected.This final measurement projects the 4, 2, 2 code onto the 4, 1, 2 -code by reassigning the ZB logical operators as stabilizers of the system.
code deformation takes place.We are not concerned with Pauli-X (Pauli-Z) errors acting on the green (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 S 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.

Color code
Let us finally discuss the color code [60].This is a particularly interesting example as the 4, 2, 2 code can be injected directly into the color code.We show the color-code lattice in Fig. 9.For S fin. each lattice face supports both a Pauli-X and Pauli-Z type stabilizer.The code supports two logical operators where X A (Z A ) is the product of Pauli-X (Pauil-Z) terms supported on all the qubits along the bottom (left) boundary of the lattice.Likewise X B (Z B ) is the product of Pauli-X (Pauil-Z) terms supported on all the qubits along the left (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 Fig. 9.
We define the stabilizer group for S init . in the caption of Fig. 9 where the 4, 2, 2 code is placed on a four-qubit of the lattice, and all of the other qubits are prepared in Bell pairs, with stabilizer operators X a X b and Z a Z b , 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. [60].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 S init.such that we obtain the logical operators of S 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.Fig. 9 highlights the support of the stabilizer operators of S 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 anda 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.

E. 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.Let us remark that 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, where a magic state is injected onto an intermediate-sized code using error detection is used to suppress errors, before injecting the intermediate-sized code onto a larger code.This method is compatible with the injection protocol we have presented here.We might also adopt the method presented in Ref. [25] where 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 S init.that can be prepared before the state injection procedure begins.In the case of subsystem codes, we might also look for additional errordetection checks that can be made between intermediate We prepare the encoded CZ-state as defined in the main text using the qubits outlined in the purple box.We additionally prepare a 4, 1, 2 -code in the logical |+⟩ state using the qubits outlined in the box.To perform step 3, as shown in Fig. 10, we first move the codes, as in step 2. This can be performed using swap gates between adjacent qubits.Swap gates are performed, first, between pairs of qubits marked by a blue arrow, and then between pairs of qubits marked with green arrows.Each set of swap gates, the blue set and the green set, can be performed in parallel.Completing the swap operations moves the codes over the qubit map.We show the locations of the codes after the swap operations by outlining their supporting qubits with a purple and orange box, respectively, in the bottom figure.In their new locations, the logical parity measurement of step 3 can be performed using ancillary qubits 5,10 and 16, outlined in the green box in the bottom figure.At the final step we facilitate the measurement of Z4Z6 and Z15Z17 using ancillary qubits 5 and 16, respectively.
gauge measurements we make to infer the values of the stabilizers, and the stabilizers of the initial code, during the preparation procedure.
F. 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, 2code.This transformation is made using measurements.
In this sense it can be understood as a code deformation similar to those 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 Fig. 10, and we show how the outline is mapped onto the heavy-hex geometry in Fig. 11.Before discussing the transformation, we first briefly review the ideas behind state teleportation abstractly.One can view the transformation as a small instance of a lattice surgery operation [40] where gates are performed between logical qubits by measuring appropriate logical degrees of freedom.As an aside, in this particular instance, we can view the operation as a lattice surgery operation between a small color code and a small surface code [50,61,62], where we interpret the 4, 2, 2 code ( 4, 1, 2 code) as a small color code (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 color code, as described in Ref. [50].
To elucidate the operation, we consider the evolution of the stabilizers and logical operators of the code at each step of the measurement pattern shown in Fig. 10 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:

Apply Pauli correction.
The operation functions with A and B can be prepared in some arbitrary logical state, but to illustrate the operation we assume they are in a product state with |ψ⟩ B = a|+⟩ B + b|−⟩ 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 |+⟩ state on the C subsystem can be described by the following vector state: (a|+⟩ + b|−⟩) B ⊗ |+⟩ C , where we have chosen a convenient basis for the vectors on B. Upon measuring the joint logical operator X B Z C and obtaining measurement outcome m 2 , the resulting state of the joint system is: Finally, upon measuring Z B and obtaining the measurement outcome m 3 , the resulting state is: An appropriate Pauli correction depending on the measurement outcomes m 2 and m 3 allows us to recover the state |0⟩ B ⊗ (a|0⟩ C + b|1⟩ 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.Lastly, we note that, with this operation, the basis of the logical information has been rotated by a Hadaamard operation.This can be corrected at a later step.Fig. 10 explains details on 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, as outlined in Fig. 11.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 Fig. 11(top), where 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-four parity checks with qubits 5 and 16 used as flag qubits.The 4, 1, 2 code is prepared in a fault-tolerant manner by initialising the data qubits in the |+⟩ state and then measuring each of the Pauli-Z type stabilizer operators Z 4 Z 6 and Z 15 Z 17 .These measurements can be facilitated with the ancillary qubits 5 and 16, respectively.Each of these operators are measured twice such that we can detect a single measurement during preparation.See also [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-four measurement, that measures the parity of two logical qubits over the two codes.In order 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 illustrated by arrows in Fig. 11(top), where 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 since 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 singlequbit 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 Fig. 11.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 Z B to complete the teleportation operation.We measure this operator on both of its two-qubit supports.Specifically, these are Z B = Z 2 Z 4 and S Z Z B = Z 13 Z 15 , where S Z = Z 2 Z 4 Z 13 Z 15 is the weight-four Pauli-Z stabilizer of the 4, 2, 2 code.Measuring both of these weighttwo logical operators enables us to detect a single error, as their parity should agree with the value of the Pauli-Z stabilizer S Z .This final measurement completes the teleportation operation and, moreover, projects the error detecting code onto a second copy of the 4, 1, 2 -code.Fi-nally, we remark that projecting Z B into a known eigenstate allows us to regard this logical operator as a weighttwo stabilizer.As such, we can now regard the 4, 2, 2code that we prepared initially as a 4, 1, 2 -code.We therefore have the state 1 1 ⊗ H|CZ⟩ encoded on the logical space of two 4, 1, 2 -codes shown in the purple and orange boxes shown in Fig. 11(bottom).

II. ANALYSIS IN TERMS OF SINGLE GATE ERRORS
All circuits considered, both for magic state preparation and logical tomography, contain redundancy required to detect the occurrence of errors.For the midcircuit syndrome measurements, performed with the circuit shown in Fig. 1, this redundancy comes in the form of the two flag qubits.These yield an outcome of 0 unless an error has occurred.Such 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. 2 (b), these are as follows: • The results of the two W measurements should agree.
• S X should yield 0, since the system is prepared in a +1 eigenstate of this operator; • Though the first S Z will yield a random outcome, the following feedforward means that the resulting state is in the +1 eigenspace of S Z .This will then be the expected outcome for the value of final S Z measurement.
For concreteness we will consider the measurement of logical ZZ, for which the final S Z measuement 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 eleven error sensitive events in all.To analyze how errors in the circuit are detected, we consider all the possible ways that a Pauli errors can be inserted around each gate.Specifically, we consider the insertion of X, Y and Z prior to any single qubit gate, and all possible singleand two-qubit Paulis prior to 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.Firstly, 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.Secondly, 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 indeed fault-tolerant.The only cases in which an error was not detected are where the error acted on 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, N s for each error signature.This is the number of unique errors that give rise to the same error signature.With this information we can then analyze the syndrome outcomes from experimental data, looking for these signatures and determining the probabilities with which they occur [34] Due 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, n s , and the number of shots for which no error is detected n 0 .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 Simply rearranging this relation then gives us the value of ϵ s [63].We then use the degeneracy to obtain the average probability for each possible single qubit Pauli error with this signature: ϵ s /N s .

III. STANDARD MAGIC-STATE PREPARATION CIRCUITS
Here we describe magic-state preparation circuits with no error suppression, that we compare to our errorsuppressed scheme described in the main text.
In Fig. 12(a) 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 errordetecting 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 Fig. 12(b).
We can make use of the stabilizer operators of the CZ-state to simplify the preparation circuit shown in Fig. 12(b).We define a stabilizer operator U , with respect to state |ψ⟩, as an operator whose action is trivial on its respective state, i.e., U |ψ⟩ = |ψ⟩.One can check that the CZ state is invariant under the action of The magic state is then encoded using stabilizer measurements S X and S Z .The preparation circuit, (b), first prepares a CZ state and two physical qubits before preparing the state to encode it in the four-qubit code by stabilizer measurements.We find that we can simplify the circuit once the CZ state is prepared by making use of the stabilizer operators of the CZ state.As discussed in the main text we observe that the circuit element in the box with a dotted outline acts trivially on the CZ-state.The inclusion of this stabilizer operator allows us to remove all of the Pauli-X and controlled-not operations shown in the circuit, as the circuit elements in the box negate their adjacent self-inverse gates.Indeed, the circuit elements that lie in between the vertical dashed lines act like the identity operator.(c) The CZ state is prepared on two physical qubits.The circuit makes use of V = exp(iθY ) a Pauli-Y rotation with tan θ = √ 2, a controlled-Hadamard gate and a bitflip.We perform state tomography on this state by making different choices of singlequbit Pauli measurements, P and Q, on the output of this circuit.
a controlled-not gate conditioned on the control qubit in the 0-state This unitary gate is equivalent to a standard controllednot gate, CX = |0⟩⟨0| ⊗ 1 1 + |1⟩⟨1| ⊗ X., followed by a bit flip on the target qubit, i.e., This observation allows us to simplify the preparation circuit.Once the CZ state is prepared, we add the CX ′ gate in the dashed box in Fig. 12, as the state we have prepared at this stage is invariant under this inclusion.The inclusion of this operator allows us to simplify the circuit, as the repeated application of the two Pauli-X rotations and the repeated application of two controllednot 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 only includes two entangling gates: a controlled-Hadamard gate and a swap gate.We perform logical tomography by appending the circuits shown in Figs.2(b) and (c) to the end of the circuit shown in Fig. 12(a).Likewise, we can perform physical tomography on the output of the circuit shown in Fig. 12(a).
As an aside, we note that the CZ state is also stabilized by the swap gate and CZ as defined in the main text.The CZ state is uniquely stabilized by the Abelian stabilizer group generated by the set ⟨CZ, CX ′ swap⟩.
Finally, we also compare our error-suppressed magicstate preparation scheme to a circuit that prepares the same magic state on two physical qubits, see Fig. 12(c).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.

IV. DEVICE OVERVIEW
Encoded state data collection on ibm peekskill v2.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 ∼ 100µs and two qubit error per gate was found to range from 0.35 − 0.59%.Detailed monitoring of readout errors are provided in Fig. 13(f),(g) and time-averaged readout fidelities ranged from 98.1 − 99.6% for all qubits.Average device characterization data is summarized in Tables I,II.Unencoded magic state data was collected over a single 24-hour period on ibm peekskill v2.5.4 on all physical pairs and the best performing edge is reported in Table .II.While the unencoded magic state data was 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 to the lowest two qubit error per gate for edges used in the encoded magic state experiments.

V. REAL-TIME FEEDFORWARD CONTROL OF QUBITS
In the last decade, a number of experiments have been performed that exploit fast feedback or real-time control within the execution of a quantum program.Fast feedback has been used for conditional reset [64][65][66][67], state and gate teleportation [68][69][70] with low branching complexity, and in more demanding algorithms such as the iterative phase estimation protocol [71], to name a few.More recently, there have been quantum error correction demonstrations using real-time control in various systems [2,6,72,73].There have also been examples of work toward classical-control micro architectures that enable the seamless integration of qubits and classical operations with tens of qubits.
Our work was performed with IBM Quantum's firstgeneration real-time control system, where 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 FPGA 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 allow synchronized collective operations such as control flow.Branching incurs a constant latency penalty to execute the branch (of order 500ns).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 Open-QASM 3; an open-source imperative C-style real-time quantum programming language [74].All experiments were performed through Qiskit and IBM's Quantum Services [75,76].

VI. 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 a simple three parameter model that we derive below.We also compare the yield to numerical simulations of our circuits.We show the estimated yield for different experiments in Table III, in comparison to our analytical model, and numerical results.
Both of our analyses have good agreement with 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 to those measured in Tables I and II.However, we remark that neither our analytical model, nor our simulations, account for common error processes such as leakage, cross talk, two level systems, as well as idoling errors that may occur during slow circuit processes, that will introduce additional noise to the system.We suggest discrepancies in our modeling 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 yield.To leading order we can estimate the magic-state yield as QR where Q is probability the random measurement outcomes we obtain throughout our experiment are correct, multiplied by the probability that the experiment  does not experience a single error R.
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, i.e., the depth, we can write R = (1−ϵ P ) D , thereby giving the equation 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, approxiamtely, to a two-qubit gate error rate, and a measurement error rate of ∼ 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 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 where We calculate the yield for the error-suppressed preparation experiment using feedforward (FF) and the error-suppressed preparation experiment using (PS).We also estimate acceptance rates for the standard experiment.The depth of the circuits D vary depending on the different tomography experiment we run, so we treat them separately.We append 2(b) and 2(c) to the different experiments depending on the tomography circuit we used, in reference to the circuits shown in Fig. 2(b) and (c) in the main text.
we use feed forward.Here, in the noiseless case, we have one random measurement outcome, where we initially measure W .It is readily checked that the probability that we project the | + +⟩ state onto the +1 eigenvalue eigenspace of the CZ operator is In the case that we do not use feedforward, in addition to obtaining the correct outcome for the W measurement, we must also post select on obtaining the correct outcome of the initial measurement of S Z .We obtain the +1 eigenvalue subspace of this operator with probability 1/2.We therefore have Lastly, in the standard preparation procedure, we measure both S Z and S X , and we require that both give the +1 outcome.Each measurement gives the correct outcome with probability 1/2, we therefore have that Let us comment on the features of this model that agree with 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 as well as the standard preparation scheme.Furthermore, we observe that the error-suppressed post-selection scheme and the standard scheme have comparable yields, for both to-mography circuit 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. 2(c) uses two additional parity measurements than that shown in Fig. 2(b).As such the tomography circuit in Fig. 2(c) is inherently more noisy than that in Fig. 2(b).This is reflected in Fig. 4 where the yield for tomography circuits shown in Fig. 22(b) (Fig. 22(c)) are shown to the left (right) in Fig. 4.
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 the measurement error rate of 2%.These results are also shown in Table III.Once 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.

VII. 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 tomography [33].A significant change from 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 for tomographic methods.In general, tomographic tools are only as good as the noise model of the measurement apparatus, i.e., our ability to calculate the likelihood representing the conditional probability of obtaining a data set given some test density matrix.In this section, we discuss an alternative approach combining readout error characterization with tomographic reconstruction.While the dominant measurement error source in tomography experiments is due to 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, where p (q) is the probability of assigning outcome 1 (0) to a true state |0⟩ (|1⟩); i.e. p = P (1|0) and q = P (0|1).We can also construct noisy POVMs for measurements in the Pauli-X or Pauli-Y eigenbases by rotating the noisy POVMs shown in Eqn. ( 12) by an appropriate angle assuming ideal unitaries, since 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 Fig. 13 (a), state infidelities from fitting with noisy POVMs can be compared to fitting with ideal projectors (p, q ≡ 0), where the latter is reported in the main text.Using readout mitigation the fault-tolerant tomography routines far-outperform both un-encoded tomography, but also the physical tomography of the encoded state.Since the terminating measurements in the logical tomography are very similar to those in the physical tomography, we would expect both of these experiments to demonstrate similar infidelities.Resolving this discrepancy remains an open research question.
It is additionally 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 Fig. 13 (b)-(d).State infidelity is calculated from fitting experimental tomography data to POVMs parameterized by p, 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 (a) the target experiments experienced initialization or measurement errors at a higher rate than measured by simpler calibrations and/or (b) 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 results of the main text are limited by unaddressed readout error on terminal measurements.We expect that state tomography experiments in Fig. 13 a reasonable upper bound on the error of the underlying magic state.

FIG. 3 :
FIG. 3: Figure title -Infidelities measured in magicstate preparation experiments:We show state infidelity for error-suppressed and standard schemes in blue and orange, respectively.On the x-axis, a state is reconstructed with either Logical or Physical tomography.The correction for the initial S Z measurement in Fig.2(a) is implemented either using 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 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 to the standard scheme.The unencoded magic state prepared directly on two physical qubits gives an average infidelity across 28 qubit pairs as ≈ 6.2 × 10 −2 (green dashed line) using 18 repetitions over a 24-hour period with 10 5 shots per circuit.Of these, the best performing pair yields a minimum infidelity of (2.354 ± 0.271) × 10 −2 (red solid line).In all cases, the error-suppressed scheme outperforms the best two-qubit unencoded magic state.

FIG. 5 :
FIG.5: Figure title -A generic magic-state distillation protocol: Encoded input magic states are combined such that higher fidelity magic states are produced with some probability.The error of an input magic state ϵ is suppressed like ϵ → ϵ d where d is a constant determined by the magicstate distillation protocol.Applying distillation recursively allows us to produce magic states with an arbitrarily high fidelity.By initialising error-suppressed magic states in the first step, where the error is suppressed as ϵ 2 we obtain a quadratic improvement in the fidelity of the output magic state.

FIG. 6 :
FIG. 6: Figure title -Small codes: We describe how to encode these codes into higher distance codes.(left) The errordetecting code prepared in the main text.We refer to this code as the 4, 2, 2 code to distinguish it from the 4, 1, 2 code shown to the right of the figure.The 4, 2, 2 code has stabilizer generators S X = X1X2X3X4 and S Z = Z1Z2Z3Z4 and logical operators XA = X1X2, ZA = Z1Z3, XB = X1X3 and ZB = Z1Z2 for logical operators indexed A and B. (right) The 4, 1, 2 code is an error detecting code that encodes a single logical qubit.It is closely related to the error detecting code shown (left).It has stabilizer generators S X = X1X2X3X4, S Z T = Z1Z2 and S Z B = Z3Z4, and logical operators X = X1X2, Z = Z1Z3.

XFIG. 7 :
FIG. 7: Figure title -Injecting an encoded magic state into the surface code: The magic state is initially encoded on a 4, 1, 2 code.(left) The standard surface code with physical qubits on the vertices of a square lattice and standard Pauli-X and Pauli-Z type stabilizers marked by lattice faces.Supports for the logical Pauli-X and Pauli-Z operators are shown in green and blue, respectively.(right) We show the initial state that is injected into the surface code.The 4, 1, 2 code is shown in red in the bottom-left corner.The remaining qubits of the surface code lattice are prepared in a product state, where blue (green) qubits are prepared in the |0⟩v (|+⟩v) state.We show the code deformation stabilizers, i.e. S def.= Sinit.∩ S fin., shaded on the right lattice.

FIG. 8 :
FIG. 8: Figure title -Injecting an encoded state into the heavy-hex code: The injected state is initially encoded on the 4, 1, 2 code.(left) A lattice with qubits on the vertices.We show the support of a single Pauli-Z gauge check and a Pauli-X stabilizer operator.The support of the Pauli-Z gauge check is shown in dark gray.The Pauli-X stabilizer operator is shaded grey towards the top of the lattice.We also show the support of a Pauli-X and Pauli-Z type stabilizer in green and blue, respectively.(right) The stabilizer group for Sinit..The 4, 1, 2 code is outlined in red in the bottom-left corner of the lattice.The other qubits are initialised in a product state with blue (green) qubits initialised in the |0⟩ (|+⟩) state.Stabilizer operators S def.= Sinit.∩ S fin. are shaded in the figure.

FIG. 9 :
FIG. 9: Figure title -Injecting an encoded two-qubit state into the color code:The state is initially encoded with the 4, 2, 2 code.A qubit is supported on each of the vertices of the lattice.We initialise the system Sinit.such that the 4, 2, 2 code, shaded in red, is supported on a weight-four face in the bottom left corner of the lattice.The other qubits are prepared in Bell pairs on the highlighted blue and green edge terms.As such, we shade the faces of S def.where both a Pauli-X and Pauli-Z stabilizer is supported.The support of the logical operators on the left and bottom boundaries are highlighted in blue and green, respectively.

)FIG. 12 :
FIG.12: Figure title -Magic-state preparation without error suppression: We can encode a physical CZ state using the circuit outlined in (a), where the preparation step, Prep., is shown in (b).The magic state is then encoded using stabilizer measurements S X and S Z .The preparation circuit, (b), first prepares a CZ state and two physical qubits before preparing the state to encode it in the four-qubit code by stabilizer measurements.We find that we can simplify the circuit once the CZ state is prepared by making use of the stabilizer operators of the CZ state.As discussed in the main text we observe that the circuit element in the box with a dotted outline acts trivially on the CZ-state.The inclusion of this stabilizer operator allows us to remove all of the Pauli-X and controlled-not operations shown in the circuit, as the circuit elements in the box negate their adjacent self-inverse gates.Indeed, the circuit elements that lie in between the vertical dashed lines act like the identity operator.(c) The CZ state is prepared on two physical qubits.The circuit makes use of V = exp(iθY ) a Pauli-Y rotation with tan θ = √ 2, a controlled-Hadamard gate and a bitflip.We perform state tomography on this state by making different choices of singlequbit Pauli measurements, P and Q, on the output of this circuit.

FIG. 13 :
FIG. 13: Figure title -Combining readout-error mitigation with state tomography methods: (a) State infidelity for the standard (orange) vs. error-suppressed (blue) schemes using different tomographic methods; error-bars represent 1σ std.dev.from bootstrapping.On the x-axis, a state is reconstructed with either logical tomography (Logical) or physical tomography after logical projection (Physical); tomography assumes either ideal projectors, as in the main text, or noisy POVMs representing uncorrelated, local readout errors (RO) on terminal data qubit measurements.Raw physical tomography (Raw Phys.) refers to the state on four physical qubits prior to logical projection.Red dotted (green dot-dashed) lines show lowest (average) state infidelities of the two-qubit unencoded magic state prepared with RO mitigation.With RO mitigation, logical tomography outperforms the min.unencoded state supporting conclusions in the main text.(b)-(e) Heatmap of state infidelity vs. avg.measurement error, p ≡ P (1|0), q ≡ P (0|1).Experimental tomography data is fit to noisy POVMs using a parameterized A-matrix, A := [[1 − p, q], [p, 1 − q]], where p, q are constant for all qubits and time.Experimental readout calibrations data are averaged over time and qubits and correspond to a single state infidelity in (b)-(e) (black dots).These state infidelities (black dots) do not coincide with local minima (red stars) or even high-fidelity regions.(f)-(g) Readout calibration measurements of p, q vs. time for all four data qubits over several days; average rates (black solid) are used in (b)-(e) for state fidelities marked by black dots.
At step 1 the codes are prepared.The 4, 2, 2 code that encodes the two-qubit CZ-state is represented by the red square where its four qubits lie at the vertices of the square.This preparation is described in the main text.The code is prepared adjacent to a 4, 1, 2 -code that is initialised in an eigenstate of the |+⟩ state.The qubits in the figure are indexed according to the qubit-map shown in Fig.11.At step 2 the qubits are transported in order to perform a logical parity measurement in step 3 using the heavy-hex lattice geometry.Note that the qubit indices have changed.This step can be performed with swaps, for instance, as shown in Fig.11(top).At step 3 a logical parity measurement is made.

TABLE I :
Table title -Average single-qubit benchmarks: Data shown is for qubits of ibm peekskill used in this work.

TABLE II :
Table title -Average two-qubit gate benchmarks: Data shown are for qubits of ibm peekskill used in this work.CX gates, constructed from echoed cross-resonance pulse sequence, are specified in one direction, with the reverse directions accessed by addition of single qubit gate.Error per gate (EPG) is extracted from isolated two-qubit randomized benchmarking (spectator qubits idling).The notation * denotes error rates for the best performing physical qubit pair on ibm peekskill during unencoded magic state preparation experiments defining the minimum (red line) in Fig.3.

TABLE III :
Table title -Estimated magic-state yield compared with experiment: We compare our analytical model, Eqn.(10), and numerics to the experimental data.