# Realization of real-time fault-tolerant quantum error correction

C. Ryan-Anderson, J. G. Bohnet, K. Lee, D. Gresh, A. Hankin, J. P. Gaebler, D.
Francois, A. Chernoguzov, D. Lucchetti, N. C. Brown, T. M. Gatterman, S. K.
Halit, K. Gilmore, J. Gerber, B. Neyenhuis, D. Hayes, and R. P. Stutz
Honeywell Quantum Solutions, Broomfield, CO

###### Abstract

Correcting errors in real time is essential for reliable large-scale quantum
computations. Realizing this high-level function requires a system capable of
several low-level primitives, including single-qubit and two-qubit operations,
mid-circuit measurements of subsets of qubits, real-time processing of
measurement outcomes, and the ability to condition subsequent gate operations
on those measurements. In this work, we use a ten qubit QCCD trapped-ion
quantum computer to encode a single logical qubit using the $[[7,1,3]]$ color
code, first proposed by Steane [1]. The logical qubit is initialized into the
eigenstates of three mutually unbiased bases using an encoding circuit, and we
measure an average logical SPAM error of $1.7(2)\times 10^{-3}$, compared to
the average physical SPAM error $2.4(8)\times 10^{-3}$ of our qubits. We then
perform multiple syndrome measurements on the encoded qubit, using a real-time
decoder to determine any necessary corrections that are done either as
software updates to the Pauli frame or as physically applied gates. Moreover,
these procedures are done repeatedly while maintaining coherence,
demonstrating a dynamically protected logical qubit memory. Additionally, we
demonstrate non-Clifford qubit operations by encoding a
$\overline{T}\ket{+}_{L}$ magic state with an error rate below the threshold
required for magic state distillation. Finally, we present system-level
simulations that allow us to identify key hardware upgrades that may enable
the system to reach the pseudo-threshold.

##  I Introduction

Large-scale quantum computers promise to solve classically intractable
problems in areas such as quantum simulation, prime factorization, and others
[2, 3, 4, 5, 6, 7, 8]. However, these complex quantum computations demand
levels of precision that are currently unachievable due to imperfect control
and noise in gate operations between physical qubits. In fact, it is unlikely
that analog physical qubit control will ever be able to reach the precision
demanded by large scale computations. Quantum error correction (QEC) [9, 10,
1], was the key ingredient to digitize quantum operations, making extremely
low error rates possible in principle. QEC works by redundantly encoding
quantum information into a protected subspace within a larger Hilbert space of
many physical qubits. Using a polynomially scaling number of physical qubits,
the probability of a computation being corrupted can be suppressed
exponentially, making arbitrarily precise quantum computation feasible.

Achieving efficient error suppression by a QEC code introduces several
requirements for a quantum processor. Not only do the error rates of the
underlying physical operations (initialization, unitary gates, and
measurement) need to be below a certain threshold [11, 12, 13], but the
quantum processor must interact with a classical computer in real time to
diagnose and correct errors. These interactions between the quantum and
classical processors need to be repeated several times in every step of a
computation, defining new requirements in addition to the classic DiVincenzo
criteria [14]. These new criteria include the ability to measure a subset of
qubits with little impact on other qubits and the ability to classically
process measurements and determine corrections faster than the system
decoheres. Additionally, the implementation should be fault-tolerant (FT) to
at least the dominant physical layer errors in order to prevent physical
errors from cascading and causing logical errors [15, 16, 17].

Several required elements of FT QEC of a single logical qubit have been
demonstrated on a variety of quantum computing architectures: classical
repetition codes [18, 19, 20, 21, 22, 23, 24, 25, 26], error detection codes
[27, 28, 29, 30, 31, 32, 33], the 5-qubit code [34, 35], the [[7,1,3]] color
code [36, 37], the Bacon-Shor-13 code [38], the 9-qubit Shor code [39, 40],
Bosonic codes [41, 42, 43, 44, 45], as well as primitives utilizing cluster
states [46, 47]. However, a full demonstration of all necessary components for
a FT implementation of a QEC code capable of repeatedly correcting all single-
qubit errors has not yet been realized.

In this article, we report on realizing a FT implementation of the smallest
instance of the color code [1, 48, 49, 50]. Using a trapped-ion QCCD quantum
computer [51, 52] we encode, control, and repeatedly error correct a single
logical qubit using 10 physical qubits. On the physical layer, trapped-ion
qubits use high-fidelity single and two-qubit gates and mid-circuit
measurements and resets to execute the quantum circuits that fault-tolerantly
initialize the logical qubit, manipulate it via logical single-qubit Clifford
gates, perform error syndrome measurements, and apply corrections.
Importantly, the low crosstalk during mid-circuit measurements [20, 53] enable
ancilla measurements of the error syndromes without decohering the data qubits
that encode the logical information. The error syndrome measurements are sent
to a classical computer where real-time decoding and tracking of errors and
corrections takes place. Since all of this can be done with high-fidelity and
quickly compared to the dephasing rate of the physical qubits, the logical
qubit can be repeatedly error corrected, a crucial feature of scalable quantum
computing. We perform these operations with the six eigenstates of the logical
Pauli operators and intialize a magic state for non-Clifford operations. These
results demonstrate a universal set for quantum computation, with the notable
exception of an entangling gate between two logical qubits, which requires
more qubits than our system currently supports.

###  I.1 Background

QEC codes are identified by three parameters $[[n,k,d]]$, where $n$ is the
number of physical qubits, $k$ is the number of logical qubits the code
admits, and $d$ is the code distance, which is related to the minimum number
of arbitrary single-qubit errors the code will correct
$t=\lfloor\frac{d-1}{2}\rfloor$. The smallest example of the topological color
code [48], depicted in Fig. 1, is a $[[7,1,3]]$ stabilizer code, sometimes
referred to as the Steane code. The distance three code uses seven physical
qubits to encode a single logical qubit and protects against all instances of
a single physical qubit incurring an error ($t=1$). Advantages of topological
stabilizer codes include: requiring only local interactions, high error
thresholds, and minimal error detection overhead [54, 48, 55]. The $[[7,1,3]]$
color code has the added advantage of all single-qubit and two-qubit Clifford
gates being transversal, which are naturally FT [56]. While the term “color
code” generally refers to any member of the family of color codes, we only
investigate one version here, so for simplicity we drop the $[[7,1,3]]$
notation and refer to the code we study as the color code. We also note that
we place overbars and $L$ subscripts on logical qubit operators and states to
distinguish them from physical qubit operators and states.

The color code, like all stabilizer codes, detects errors by measuring a
commuting set of operators known as stabilizers (Fig. 1). The stabilizer
measurements form an error syndrome which is processed by a classical decoding
algorithm to determine a correction, a process that must be done in real-time
for any non-trivial logical computation. We henceforth define a QEC cycle as
the process of measuring syndromes (including measuring multiple times to
account for measurement errors), decoding, and applying corrections.

Figure 1: The $[[7,1,3]]$ color code. The seven data qubits are on the
vertices of the polygons and three ancilla qubits for syndrome measurements
are off to the side. For each polygon, the four qubits at the vertices define
both $X$-type and $Z$-type stabilizer measurements used in each error
correction cycle. The stabilizer generators and logical operators are tensor
products of single qubit Paulis with support indicated by the physical qubit
subscript index. For example, implementing the logical $\overline{Z}$
operation is done with physical layer $Z$ operations on qubits 5, 6, and 7.
Likewise, measuring $\overline{Z}$ is done by measuring $Z_{5}Z_{6}Z_{7}$
where the logical qubit measurement outcome is the product of the three
individual physical qubit measurement outcomes. Although not shown, $Y$-type
stabilizers are generated by the $X$ and $Z$-type stabilizers listed here.
Figure 2: The ion trap loaded with ten 171Yb+ qubit ions (red circles) and ten
138Ba+ coolant ions (white circles). The trap has different functional
regions, or zones, with functions determined by the electrode geometry and
laser beam configuration. Ion transport is used to arrange ions into zones for
gates and measurements. The electrodes in red and blue denote regions that
support transport operations including linear transport, crystal split and
combine, and physical swap. The green regions support linear transport and
storage of ions between gating operations. The three regions where qubit
initialization, gating, and measurement occur are marked by the crossing laser
beams. In the grey region, ions are loaded from an effusive atomic oven behind
the trap using photoionization.

Our quantum computer uses a Honeywell 2D surface electrode ion trap (Fig. 2)
similar to the one described in Ref. [52]. The trap is loaded with ten 171Yb+
qubit ions and ten 138Ba+ sympathetic cooling ions. The color code is
implemented using all ten available qubits, (Fig. 1), where seven data qubits
encode the logical state and three ancilla qubits perfom syndrome
measurements. The trap can execute parallel quantum operations across three
different zones and quantum circuits are executed as a series of interleaved
initialization, gating, measurement, and ion-transport operations. With just
three ion-transport primitive operations, qubits can be arbitrarily rearranged
in the middle of a circuit: qubit ions paired with coolant ions use (1) linear
transport of $\\{\mathrm{Yb,Ba}\\}$ and $\\{\mathrm{Yb,Ba,Ba,Yb}\\}$ crystals,
(2) split/combine operations to go between $\\{\mathrm{Yb,Ba}\\}$ crystals and
$\\{\mathrm{Yb,Ba,Ba,Yb}\\}$ crystals, and (3) physical (not quantum gate-
based) swap operations to switch the ordering of the qubit ions in a crystal
by transporting them around each other in two dimensions [57]. These
operations allow any two qubits to be paired for entangling gates, and allow
qubits to be isolated for single-qubit gates, initialization and measurement.
Dynamically rearranging the ions during the circuits ensures the one-
dimensional geometry trap does not restrict the geometry of codes that can be
used (the color code has a two-dimensional geometry).

The system is programmed according to the quantum circuit model. Logical qubit
operations are compactly described at the physical qubit level as quantum
circuits and are expressed in an extended version of OpenQASM 2.0 [58]. At the
time of developing the QEC experiments discussed in this paper, the OpenQASM
language did not fully support all of the conditional logical operations
needed for QEC. We therefore extended the language to include classical
assignment, classical operations, and expanded comparison of registers. These
OpenQASM extensions were key enablers for the highly dynamical QEC protocols
we chose to implement [49].

##  II Experiments

In this section we discuss our experiments demonstrating the QEC operations
necessary for universal QEC computation restricted to a single logical qubit.

###  II.1 QEC cycles

The main result of this paper is a full demonstration of the ability to repeat
QEC cycles, which includes the determination of corrections during
computation. This demonstration consists of initializing a logical Pauli basis
state using a FT encoding circuit, running multiple adaptive FT QEC cycles,
and then measuring in the appropriate logical basis, all while tracking
corrections, running a decoding algorithm, and updating the corrections after
each QEC cycle in real-time. A schematic of the overall procedure can be see
in Fig. 7. We now detail the various steps of this QEC protocol.

####  II.1.1 Logical state preparation

To prepare different logical basis states,
$\\{\ket{0}_{L},\ket{1}_{L},\ket{+}_{L},\ket{-}_{L},\ket{+i}_{L},\ket{-i}_{L}\\}$,
we utilize a FT encoding circuit. The encoding circuit first prepares
$\ket{0}_{L}$ and fault-tolerantly verifies successful preparation by
measuring $\overline{Z}$ [59] via three CNOTS with an ancilla at the end as
shown in Fig. 7. If the measured ancilla is found in $\ket{0}$, the circuit
succeeded and moves to the next step. If the ancilla is found in $\ket{1}$,
all qubits are reinitialized and the circuit runs again. This procedure
repeats until successful, up to three iterations if necessary. This
verification step succeeds with a probability of approximately $99.984(9)\%$
with the first attempt succeeding approximately $97.9(2)\%$ of the time.
Regardless of successful preparation, we proceed by rotating $\ket{0}_{L}$ to
another logical Pauli basis-state by the appropriate application of the
$\overline{X}$, $\overline{H}$, and $\overline{S}$ operators as prescribed in
Fig. 1.

####  II.1.2 Adaptive syndrome extraction protocol

Next, to protect the logical qubit while idling during a computation, we
execute multiple QEC cycles and utilize ancilla qubits to measure syndromes in
a non-destructive manner. The syndrome extraction protocol operates by
detecting changes in stabilizer measurement outcomes that ideally give a +1
eigenvalue. Because syndrome extraction requires the use of noisy gates,
syndrome measurements must be repeated multiple times within a single QEC
cycle to be FT to syndrome measurement errors. For each FT QEC cycle, we
implement the ‘flagged’ three-parallel syndrome extraction protocol described
in Ref. [49] (see Fig. 7 and Pseudocode 1).

In order for the color code to be FT to all single qubit errors, we must
account for a special case of a single qubit error, called a ‘hook’ error
[54], which spreads to higher weight errors causing logical errors, see Fig. 8
a. The syndrome extraction protocol measures stabilizers in a way that flags
(identifies) malignant ‘hook’ errors. The protocol first uses flagged parallel
circuits to measure syndromes, the first set being
$\\{S^{f}_{1},S^{f}_{5},S^{f}_{6}\\}$. If there are no changes in stabilizers
measurements (i.e., no errors indicated), the second set of flagged
stabilizers $\\{S^{f}_{1},S^{f}_{3},S^{f}_{4}\\}$ is also measured, and again,
if there are no changes in stabilizers measurements, the syndrome extraction
protocol is deemed complete. However, if either of the flagged circuits do
indicate an error, an additional and final round of syndrome extraction is
triggered using standard circuits without flags $\\{S_{1},S_{2},S_{3},...\\}$
(Fig. 7). Note that both sets of stabilizers follow from the definitions given
in Fig. 1, but we use the $f$ superscript to differentiate between syndromes
measured using flagged circuits and unflagged circuits. The exact circuits
used along with pseudocode can be found in the supplemental material. During
every QEC cycle, syndrome changes are sent to a decoder to infer a correction
and the baseline stabilizer values are updated in software for the next QEC
cycle.

####  II.1.3 Decoder

Our decoder algorithm consists of two steps using two different lookup tables,
analogous to the decoders described in [60, 61]. Lookup tables are simple
decoders that map syndromes to corrections. We decode $X$ and $Z$ errors
separately and correct at the logical level instead of at the physical level
(that is, the corrections are whether to apply $\overline{I}$, $\overline{X}$,
$\overline{Y}$, or $\overline{Z}$). These choices reduce the size of the
decoder to a few if-statements in QASM (see Pseudocodes 8 \- 9). During a
particular QEC cycle, the decoder is called if and only if the final round of
syndrome extraction is triggered (i.e., the unflagged circuits, see Fig. 7).

The first stage in the decoding algorithm uses changes in the unflagged
syndrome measurements $S_{i}$ between QEC cycles; specifically, the final
round of syndrome extraction in the current QEC cycle versus the last QEC
cycle that triggered the execution of the unflagged circuits. It is only
necessary to consider changes in syndrome measurements between QEC cycles
because after an error changes the syndrome measurement, the subsequent
corrections do not change the syndromes back, as syndrome operators commute
with correction operators. Note, the last QEC cycle that triggered a final
round of syndrome extraction may or may not be the proceeding cycle. If no
previous rounds of a QEC cycle triggered the unflagged checks, the syndromes
is assumed to be trivial. This lookup table considers spatial but not temporal
errors to produce the initial logical correction.

The second stage of the decoding algorithm uses changes in the syndromes
between extraction rounds within the current cycle. Single qubit hook errors
produce the same syndrome measurements in the unflagged circuits as other less
damaging single qubit errors (see Fig. 8). Thus, to distinguish between these
two types of single qubit errors, we require additional syndrome information
provided by the flag circuits. We compare the two sets of syndrome information
($S^{f}_{i}$ vs $S_{i}$) and use a second lookup table to determine the final
logical correction. The combination of the conditional rounds of syndrome
extraction and the second lookup table makes the QEC cycle FT to both hook and
measurement errors.

####  II.1.4 Pauli frame update

Applying corrections physically via noisy gates can potentially induce more
errors. Fortunately, many errors can be corrected without implementing
physical gate operations and instead done with an essentially perfect software
correction. To this end, the correction for the logical qubit is stored in a
binary array, known as a Pauli frame [62], during the computation. The Pauli
frame is represented by two bits, corresponding to the possible corrections
$\\{\overline{I},\overline{X},\overline{Y},\overline{Z}\\}$. At the end of
each QEC cycle, the new correction is combined with the previous Pauli frame
according to Pauli matrix multiplication rules, and the binary array is
updated.

Finally, after completing a variable number of QEC cycles, the data qubits are
directly measured. The final destructive measurement projects the state into
the logical $\overline{X}$, $\overline{Y}$, or $\overline{Z}$ basis based on
the logical single-qubit gate applied before measurement, and from this
measurement two pieces of critical information are extracted. First, the raw
logical output is calculated by multiplying the $\pm 1$ outcomes of the non-
identity operations of the logical operator being measured (qubits 5, 6, and
7, see Fig.1). Second, while the process of measuring the data qubits is
destructive to the quantum state, the syndromes can be constructed from the
resulting classical information, allowing for a final correction. For example,
when measuring the fidelity of $\ket{+}_{L}$, we measure all data qubits in
the $X$ basis and the raw logical output is given by results of qubits 5, 6,
and 7 while the syndrome is equal to the measurement result tuple of
$\\{S_{1},S_{2},S_{3}\\}$. However, while for $\overline{X}$ and
$\overline{Z}$ measurements it is sufficient to infer the syndomes using
stabilizers of the same Pauli type in Fig. 1, this is not the case for the $Y$
basis. Fortunately, in the special case of a $\overline{Y}$ measurement, we
can infer the syndromes of the three $Y$ stabilizers that are the products of
the $X$ and $Z$ stabilizers listed in Fig. 1 that have identical non-trivial
support. After the syndromes are inferred from the final measurement, the
decoding algorithm is used to determine a correction, simply whether to flip
the raw logical output or not.

####  II.1.5 Results

Figure 3: Comparing the observed logical fidelities of the six logical Pauli
basis states over many QEC cycles. Averages and standard deviations were
determined by Jackknife resampling between individual experiments [63]. The
large points with error bars are experimental averages and standard
deviations. The smaller and lighter points are individual trials for a given
QEC cycle experiment. Note, for 0 QEC, numerous experimental trials have an
error rate of 0 and, thus, are not displayed due to the log scale. The lines
are fits to the experimental averages, where the fits are exponential decay
curves $p_{L}(c)=0.5+(p_{spam}-0.5)\left(1-2\;p_{cycle}\right)^{c}$. Here
$p_{L}(c)$ is the logical error rate of a cycle $c$ and logical basis $L$,
$p_{spam}$ the logical SPAM error, and $p_{cycle}$ is the logical QEC cycle
error. Note, $p_{spam}$ is determined directly from the 0 QEC results and
fixed when determining the fits. Thus, from the fits we obtain estimates of
$p_{cycle}$. The values of $p_{spam}$ and $p_{cycle}$ are reported in Table 1.

The experimental results for the full QEC protocol can be seen in Fig. 3. Each
basis state and QEC cycle iteration was run multiple times with a varying
number of trials. To better estimate the error bars due experimental noise
fluctuations, we used a Jackknife resampling method [63] to estimate the
average and the standard deviation of the different trials for a given state.
To estimate the logical SPAM and logical error rate per QEC cycle, we fit the
data to a exponential decay curve and extract the fitting parameters as shown
in Table 1. In the protocol, logical SPAM is equivalent to doing zero QEC
cycles. We measured the average logical SPAM error to be $1.7(6)\times
10^{-3}$, compared to the $2.4(8)\times 10^{-3}$ SPAM error of our physical
qubits. The data in Fig. 3 shows that while the initialization circuit
produces high-fidelity states, repeated QEC cycles introduce significant
logical errors of approximately $2.70(6)\%$ per QEC cycle as determined by an
exponential decay fit to the data. We observe that the logical $\overline{Z}$
basis is more robust than the other two bases, suggesting that qubit dephasing
is a significant error source.

The experimental run time of the logical SPAM portion of experiments,
including the encoding circuit, two rounds of single-qubit rotations, and the
final measurement, is $<60$ ms, and each QEC cycle takes less than $<200$ ms.
Transport accounts for $\sim 10$ ms of logical SPAM operations and $<70$ ms of
each QEC cycle. The remaining time is dominated by the cooling operations,
which occur prior to each two-qubit gate, similar to the experiments detailed
in Ref. [52].

To put the logical qubit error rates and clock-speed into context by comparing
to the physical layer; the dominant error at the physical level is the two-
qubit gate error of $\sim 3\times 10^{-3}$ (Table 4), and the physical layer
clock-speed (one round of gating between random pairs of qubits) is $10.5$ ms.
We note that a complete understanding of the overhead associated QEC will have
to wait until logical qubit entangling operations are characterized.

State | $p_{spam}$ | $p_{cycle}$
---|---|---
$\ket{+}_{L}$ | $1.7(7)\times 10^{-3}$ | $1.8(1)\times 10^{-2}$
$\ket{-}_{L}$ | $2.0(7)\times 10^{-3}$ | $1.7(2)\times 10^{-2}$
$\ket{+i}_{L}$ | $1.2(5)\times 10^{-3}$ | $2.4(1)\times 10^{-2}$
$\ket{-i}_{L}$ | $2.6(6)\times 10^{-3}$ | $2.5(1)\times 10^{-2}$
$\ket{0}_{L}$ | $1.3(5)\times 10^{-3}$ | $1.16(7)\times 10^{-2}$
$\ket{1}_{L}$ | $1.4(6)\times 10^{-3}$ | $0.94(7)\times 10^{-2}$
Table 1: Observed logical SPAM error $p_{spam}$ from 0 QEC experimental
results. And logical error per QEC cycle $p_{cycle}$ fit parameters for the
six Pauli basis states, obtained via exponential decay fit and used in the
plotted curves in Fig. 3. Where the average $p_{spam}$ is $1.7(2)\times
10^{-3}$ and the average $p_{cycle}$ is $1.75(4)\times 10^{-2}$]

###  II.2 Active vs software corrections

Pauli frame updates cannot always be used for a QEC computation since Pauli
operators have non-trivial transformations under conjugation by non-Clifford
gates. Thus, to implement corrections stored in software, we either physically
apply the correction to the qubits before the gate, or adapt the non-Clifford
gate to include the correction. To demonstrate the ability to physically apply
corrections as needed, we use the logical S gate as a stand in for the non-
Clifford T gate. We first initialized the state $\ket{+}_{L}$, ran one cycle
of QEC to generate potential corrections, physically applied a correction
(either $\overline{X}$, $\overline{Y}$, or $\overline{Z}$) according to the
Pauli frame, physically applied logical $\overline{S}$, performed an
additional QEC cycle and measured in the $\overline{Y}$ basis (note
$\overline{S}\ket{+}_{L}=\ket{+i}_{L}$), see Fig. 9), achieving a logical
fidelity of $93(2)\%$.

We also repeated this experiment without applying a physical correction and
instead rotated the Pauli frame according to Pauli transformations of the
physically applied $S$ gate. This software-correction version of the
experiment achieved a logical fidelity of $92(1)\%$. These two error rates are
not significantly different from each other, thus demonstrating the key
ability to take software tracked corrections and apply them in real-time as
necessary.

###  II.3 Preparing a magic state

Universal quantum computing requires the ability to implement non-Clifford
gates which, unlike Clifford gates, can not be constructed by simple
transversal operations in the color code. Non-Clifford gates can, however, be
implemented using state preparation primitives that produce so-called magic
states [64]. One choice of magic state that is sufficient to complete a
universal gate set is
$\overline{T}\ket{+}_{L}=\left(\ket{0}_{L}+e^{i\pi/4}\ket{1}_{L}\right)/\sqrt{2}$,
where $\overline{T}=\text{diag}(1,e^{i\pi/4})$. Note that we cannot use the FT
encoding circuit used for the logical Pauli states, because the verification
step requires the measurement of a logical operator which would collapse the
$T$-state, and thus, we use a non-fault tolerant encoding circuit for the
color code [65], shown in Fig. 10. Once prepared, $\overline{T}\ket{+}_{L}$
can be used to apply $\overline{T}$ gates via gate teleportation [66] in a
system capable of logical two-qubit gates. The fidelity of this operation is
estimated by measuring the operator
$\overline{T}\ket{+}_{L}\bra{+}_{L}\overline{T}^{\dagger}=\frac{1}{2}\left(\overline{I}+\frac{1}{\sqrt{2}}(\overline{X}+\overline{Y})\right)$
and we report an error of $2.2(6)\%$, significantly lower than the noise
threshold estimate of $33.5\%$ for magic state distillation [64]. Thus, even
with a non-FT encoding circuit, we are able to produce high quality,
distillable states to implement FT non-Clifford gates.

##  III Simulations and Analysis

To help understand the noise in our system, we compare the experimental
results of the QEC protocol to numerical simulations as seen in Fig. 4. The
simulations are state vector simulations [67, 68] utilizing a realistic error
model and experimentally measured error parameters (for further details see
Table 4). The error model includes simple depolarizing gate noise, leakage
errors, and modeling of coherent dephasing noise during transport and cooling
operations. The simulation uses the same instructions that are generated by
the compiler and sent to the quantum computer, including the same gate
decomposition, gate duration, and transport.

###  III.1 Comparison to simulations

Figure 4: Comparing the observed and simulated logical fidelities of the
logical Pauli bases. Averages and standard deviations were determined by
combining the data of both basis states of a given basis and using Jackknife
resampling between individual experiments [63]. The large points with error
bars are experimental averages and standard deviations. The smaller and
lighter points are individual trials for a given QEC cycle experiment. Note,
for 0 QEC, numerous experimental trials have an error rate of 0 and, thus, are
not displayed due to the log scale. The lines are fits to the simulated and
experimental averages, where the fits are exponential decay curves
$p_{L}(c)=0.5+(p_{spam}-0.5)\left(1-2\;p_{cycle}\right)^{c}$. Here $p_{L}(c)$
is the logical error rate of a cycle $c$ and logical basis $L$, $p_{spam}$ the
logical SPAM error, and $p_{cycle}$ is the logical QEC cycle error. Note,
$p_{spam}$ is determined directly from the 0 QEC experiments and fixed when
determining the fits. Thus, from the fits we obtain estimates of $p_{cycle}$.
The values of $p_{spam}$ and $p_{cycle}$ are reported in Table 2.

The complex physical layer error model can be distilled to a much simpler
logical error model described by an asymmetric depolarizing channel,

$\overline{\mathcal{E}}(\rho)=(1-p_{L})\rho+p_{x}\overline{X}\rho\overline{X}+p_{y}\overline{Y}\rho\overline{Y}+p_{z}\overline{Z}\rho\overline{Z},\\\
$ (1)

where the Pauli error probabilities $p_{x}$, $p_{y}$, and $p_{z}$ are fitting
parameters for both the experimental and simulation data. Note that
$p_{L}=p_{x}+p_{y}+p_{z}$ ensures the map is trace preserving and $p_{L}$ is
referred to as the logical error rate.

For individual basis states, only the Pauli operators that do not commute with
the state cause errors. For example, the $\overline{Z}$ basis is immune to
$\overline{Z}$ type noise but susceptible to $\overline{X}$ and $\overline{Y}$
type noise. Therefore, the error probabilities associated with the different
bases are given by the three equations,

$\begin{split}\textbf{$\overline{X}$}\;basis:p_{yz}=p_{y}+p_{z}\\\
\textbf{$\overline{Y}$}\;basis:p_{xz}=p_{x}+p_{z}\\\
\textbf{$\overline{Z}$}\;basis:p_{xy}=p_{x}+p_{y}.\end{split}$ (2)

By fitting the experimental and simulated data of individual basis states to
exponential decay curves, the probabilities $p_{yz}$, $p_{xz}$, and $p_{xy}$
are solved for and are reported in Table 2. The system of equations in Eq. 2
can then be inverted to solve for the depolarizing parameters $p_{x}$,
$p_{y}$, and $p_{z}$ and are reported in Table 3.

For most of the error parameters we have experimental estimates (see
supplemental materials). However, accounting for different sources of
dephasing noise is not straightforward. To account for dephasing, we vary the
dephasing rate used in the simulation and compare with the experimental
results. The depolarizing parameters determine the logical error rate $p_{L}$,
which is what we use to empirically determine the best fit dephasing rate.

The simulation and experimental results qualitatively agree, suggesting that
the most important sources of noise are understood. However, further
investigation is needed to fully understand the impact of additional known
errors, as well as unknown error sources. In particular, it is important that
we further characterize both coherent and incoherent phase noise sources
independent of QEC. We also note the bias in the logical error model toward
the $\overline{Z}$ component and the interesting asymmetry between the
$\overline{X}$ and $\overline{Y}$ components. While the $\overline{Z}$ bias
may be explained by the asymmetry in the microscopic noise model from the
presence of dephasing, there is no such asymmetry between $X$ and $Y$ in the
physical layer error model. Therefore, we suspect that the circuit structure
tends to convert $Z$ noise in an asymmetric manner, however we leave a
detailed analysis to future work.

Since the dephasing errors manifest from different sources (spatial and
temporal magnetic field fluctuations, relative phase drifts between different
laser beams, etc.) there are likely both coherent and incoherent sources of
qubit dephasing in our system. To gain understanding of the impact of coherent
dephasing on the QEC protocol, we ran both coherent (state-vector) and
incoherent (stabilizer) simulations. The coherent dephasing is modeled as the
channel

$R_{Z}(\theta)\;\rho\;R_{Z}(\theta)^{\dagger}=\exp(-iZ\theta/2)\;\rho\;\exp(+iZ\theta/2),$
(3)

which is applied between ideal gates where $\theta=dephasing\;rate\times
duration$. The duration corresponds to the time it takes for transport
operations or the qubit idling time while operations are being applied to
other qubits. For the incoherent simulation, dephasing is modeled as the Pauli
twirled version of the coherent channel, where $Z$ is applied stocastically
with a probability of

$p_{dephase}=\sin(\theta/2)^{2}.$ (4)

The dephasing rate needed to account for the logical QEC cycle error rate was
0.26 Hz for the coherent simulation and 0.43 Hz for the incoherent simulation,
indicating that coherent build up in the distance three color code may affect
its performance and should be studied in future work. However, we expect such
single-qubit coherent noise to be less of an issue as the distance of the code
is increased as suggested by [69]. Note that all simulation numbers reported
were generated using the coherent dephasing model; however, given identical
error parameters except for the dephasing rates mentioned above, the results
of the two simulations were nearly identical.

Basis | SPAM | QEC cycle
---|---|---
| Sim | Exp | Sim | Exp
$\overline{X}:\;p_{yz}$ | $4.9(1)\times 10^{-4}$ | $1.8(4)\times 10^{-3}$ | $2.0(1)\times 10^{-2}$ | $1.89(6)\times 10^{-2}$
$\overline{Y}:\;p_{xz}$ | $4.9(1)\times 10^{-4}$ | $1.7(3)\times 10^{-3}$ | $2.74(4)\times 10^{-2}$ | $2.4(1)\times 10^{-2}$
$\overline{Z}:\;p_{xy}$ | $4.7(1)\times 10^{-4}$ | $1.3(3)\times 10^{-3}$ | $7.2(1)\times 10^{-3}$ | $1.09(3)\times 10^{-2}$

Table 2: Experimental and simulated logical SPAM error obtained from the data
in Fig. 4. The average SPAM error rate is $1.6(4)\times 10^{-3}$ for
experiment and $4.9(1)\times 10^{-4}$ for simulation, and the average QEC
cycle error rate is $1.80(6)\times 10^{-2}$ for experiment and $1.85(7)\times
10^{-2}$ for simulation.

Error | SPAM | QEC cycle
---|---|---
| Sim | Exp | Sim | Exp
$p_{x}$ | $2.3(1)\times 10^{-4}$ | $6(3)\times 10^{-4}$ | $7.0(6)\times 10^{-3}$ | $8.1(6)\times 10^{-3}$
$p_{y}$ | $2.4(1)\times 10^{-4}$ | $6(3)\times 10^{-4}$ | $2(6)\times 10^{-4}$ | $2.8(6)\times 10^{-3}$
$p_{z}$ | $2.5(1)\times 10^{-4}$ | $1.1(3)\times 10^{-3}$ | $2.76(6)\times 10^{-2}$ | $1.60(6)\times 10^{-2}$
$p_{L}$ | $7.3(4)\times 10^{-4}$ | $2.4(3)\times 10^{-3}$ | $2.76(6)\times 10^{-2}$ | $2.70(6)\times 10^{-2}$

Table 3: Experimental and simulated logical SPAM and QEC cycle error channel
rates for the channel in Eq. 1 given basis error rates from Table 2.

###  III.2 Logical error channel and error budget

To understand how different physical error sources contribute to the logical
error rate of a QEC cycle, we construct an error budget for unitary gates (the
single and two qubit gates), measurement and initialization (SPAM as well as
mid-circuit measurement and reset, MCMR), and dephasing noise. Note, these
three error sources contain multiple noise mechanisms. For example, the
unitary gate errors contain not just depolarizing noise from the single and
two qubit unitary gates but also spontaneous emission, which includes leakage,
as well (see the supplemental material for more details). Given the error
model of the simulation, the error budget captures how the noise from the
three error sources impacts the logical error rate of a QEC cycle. This is
particularly useful since it can be unclear how errors such as leakage and
dephasing translate from the physical to the logical system.

The error budget was calculated via simulation assuming a second-order model
given by

$p_{L}(s)=s\sum_{i}a_{i}p_{i}+s^{2}\sum_{i,j}b_{ij}p_{i}p_{j}=s\sum_{i}A_{i}+s^{2}\sum_{i,j}B_{i,j},$
(5)

where $s$ is a scaling factor used for fitting, $p_{i}$ are the relative
probabilities of SPAM, two-qubit gate, and dephasing errors at the physical
level, and $A_{i}=a_{i}p_{i}$ and $B_{ij}=b_{ij}p_{i}p_{j}$ are the
coefficients we solve for to determine the relative impact of the physical
layer errors on the logical qubit. We first set two of the three errors to
zero and then, for each error, scale $s$ in simulations to determine $A_{i}$
and $B_{ii}$ using three different quadratic curve fits. The off-diagonal
elements of $B$ are then solved for by only setting one error to zero and
setting $s=1$. The estimated individual and correlated contributions to the
logical error are shown in Fig. 5.

The error budget breakdown indicates that the noise due to unitary gates and
dephasing account for the majority of the logical error, accounting for
approximately $49\%$ and $45\%$, respectively, while measurement and
initialization account for the remaining $6\%$. However, studying only the
individual contributions, obtained by the calculation in Fig. 5, we miss some
important information contained in $A$ and $B$. As can be seen in Fig. 5, the
contribution to the logical error that is linear in the physical errors, $A$,
is dominated by the gate errors. Ideally, the logical error probability should
be quadratic in the gate error, and the large linear dependence is likely due
to the leakage error associated with the gate operations. This point will be
further illustrated below as we study the pseudo-threshold of the code.

Figure 5: The logical qubit error budget. The pie chart shows the percent
contribution to the logical QEC cycle error rate from the physical noise due
to SPAM and mid-circuit measurement and reset (MCMR), unitary gates, and qubit
dephasing. $A$ and $B$ are the vector and matrix in Eq. 5 and the elements are
ordered as $\\{SPAM/MCMR,gates,dephasing\\}$. The individual contributions in
the pie chart indexed by $i$ are calculated as
$(A_{i}+\sum_{j}B_{ij})/(\sum_{i}A_{i}+\sum_{ij}B_{ij})$.

###  III.3 Pseudo-threshold estimates

While the error budget is useful in studying the current level of impact
different physical error sources have on the QEC protocol, we now investigate
a simulation tool better suited to predicting the protocol performance
assuming improved physical error rates.

For QEC to be helpful in computations, logical level error rates must be below
the physical level error rates. This crossover point is known as the ‘pseudo-
threshold’. In general, pseudo-threshold estimates are difficult because they
require a detailed understanding of the system’s underlying physics. However,
in cases where the dominant physical noise mechanism is known, one method is
to scale that noise mechanism in simulations and solve for the
pseudothreshold, defining it as the point where the logical error rate is
equal to the dominant physical noise source. The largest error rate in the
simulation model is the two-qubit depolarizing error rate of $p2=3.1\times
10^{-3}$ (see supplementary material for details). Note that the two-qubit
gate not only contributes depolarizing noise, but also leakage noise via
spontaneous emission at a probability of $5.5\times 10^{-4}$; however, to
simplify discussions we consider only the two-qubit depolarizing rate. Also,
while dephasing has a large impact on the logical error budget, the physical
level dephasing error rate per physical qubit operation is an order of
magnitude lower than $p2$. That is, with a dephasing rate of $0.26$ Hz and
each duration between gates, the stochastic error probability averaged over
the entire circuit is approximately $2.2\times 10^{-4}$ for each qubit. Thus,
in the simulations, on the physical per operation level, the dephasing error
channel has a lower error rate than the two-qubit depolarizing rate.

While our simulations lack the level of detail needed for precise estimates,
we use a crude model to estimate system improvements needed to pass the
conjectured pseudo-threshold. To this end, we first simulated the logical
error rate of a single QEC cycle and scale all physical error rates used (see
Table 4) by a common scaling factor. This is a coarse view of how much our
dominant bare physical error (the two-qubit gate) needs to improve to reach
the simulated pseudo-threshold. As seen in Fig. 6, simply improving all our
errors by a common factor is not enough to reduce our logical error rate below
the two-qubit depolarizing error rate $p2$. To understand this, we also
simulated three other models with different relative error budget breakdowns,
first reducing the dephasing rate to $1/10$th the original value, then
reducing the leakage rate to $1/10$th the original value and then both
reducing the dephasing and leakage rate to $1/10$th their original value. By
scaling these additional error models by an overall scaling factor, we find
that suppressing the dephasing rate is likely not sufficient to reach the
pseudo-threshold, but that substantially reducing the relative leakage rate
and the dephasing rate should put the pseudo-threshold within reach if the
two-qubit gate error can be reduced by approximately a factor of 3.

The relative importance of taming leakage errors is not unexpected. Most QEC
protocols were designed to correct errors within the qubit manifold, an
assumption that leakage errors violate. When leakage errors occur (e.g.,
during spontaneous laser scattering events), leaked qubits can spread errors
as they the interact with other qubits and the circuits for the color code are
in fact only FT to qubit errors and not leakage errors. While leakage is not a
leading source of error in our system, if left untreated it will saturate the
system, eventually corrupting all the qubits and the logical information. As
shown in Ref. [70], leakage errors can be reduced by roughly three orders of
magnitude through physical mitigation techniques. Alternatively, circuit level
techniques can be incorporated in the QEC procotol [71, 72].

Additionally, we believe there are routes to improving dephasing rates,
including the use of dynamical decoupling, additional shielding and spatial
phase tracking in the control software to account for spatial inhomogeneities
in magnetic field.

Figure 6: Comparison of the logical error rate to different error models as
the physical error rates are scaled. The dashed line is equal to the physical
layer two-qubit depolarizing error rate, $p2$, times the scaling factor
defining the x-axis, which we use to define our pseudo-threshold line. The
four solid lines represent the logical qubit error rate for different
simulated error model scenarios and are plotted as a function of an overall
scaling of the error model parameters. The red line (circles) uses our current
error model parameters estimate detailed in Table 4, the blue line (triangles)
was generated assuming our current error parameters except with the dephasing
rate being reduced by 10x, the green line (squares) was generated assuming our
current error parameters except with the leakage rate being reduced by 10x,
and the purple line (starts) was generated by starting with our current error
parameters and suppressing both the dephasing and the leakage rates by 10x.
The vertical dotted line ($x=1/3$) is approximately where the purple line
crosses the pseudo-threshold. We find that reducing the leakage will be key to
achieving a QEC cycle logical error rate below pseudo-threshold (when the
logical error rate is less than the leading physical error rate). Note, some
error bars are smaller than the markers.

##  IV Conclusion

In this work, we demonstrated the primitives needed for quantum error
correction restricted to a single logical qubit, including high fidelity
state-preparation and readout of logical basis states and a magic state,
logical single-qubit gates, and repeatable error correction cycles. By
establishing the necessary hardware capabilities along with detailed
simulations of the processes, we can now begin developing a QCCD system
architecture that is optimized for computations at the logical level.

The experimental data and simulated results highlight the need for substantial
error rate improvements to get well below the pseudo-threshold. The largest
contributor to the physical level error budget is the two-qubit gate and, as
noted in Ref. [52], we believe the dominant error mechanisms can be suppressed
with upgraded electrode voltage sources and laser systems. Using the simulator
developed here, we identify leakage and dephasing as crucial sources of noise.
Interestingly, while leakage is not currently a dominant physical error,
scaling the physical error rates in simulation indicates that leakage will
dominate the logical error rate. While leakage errors are particularly
detrimental to code performance, they can be converted to Pauli errors with
the addition of a leakage repumping routine [70] and should not present a
fundamental roadblock. Perhaps surprisingly, even though dephasing errors are
relatively small compared to two-qubit gate errors at the physical level, our
logical qubit error budget indicates dephasing errors have a large impact on
the code performance. Fortunately, trapped-ion hyperfine qubits have been
shown to exhibit much longer coherence times [73] compared to our current
dephasing rates, and we believe this particular error can be significantly
improved by a combination of improved shielding, dynamical decoupling, and
accurate mapping of magnetic field inhomogeneities and spatial phase tracking
in the control software. Additionally, dephasing errors can be suppressed
further through speed improvements, which are currently bottlenecked by laser
cooling and transport operations, both of which can be substantially improved
through advanced techniques [74, 75], and we note that smaller trap geometries
[76] or 2-dimensional topologies [77] could also improve transport times. At
the logical level, some interested noise mitigation techniques include Pauli
or Clifford twirling, randomized compiling, circuit-level gadgets to suppress
coherent errros [78, 79, 80] and leakage errors [71, 72], subsystem codes,
codes designed for biased noise [81], and larger distance codes [69].

These experiments and emulation tools pave the way for co-designing QCCD
systems and QEC software to implement large-scale fault-tolerant quantum
computers. The next milestones on the road to a fully error corrected quantum
computer include logical operations between multiple qubits [33, 82], and
operation below the pseudo-threshold.

##  V Acknowledgements

We would like to thank Charlie Baldwin and Michael Foss-Feig for helpful
comments on the manuscript and Daniel Lidar for useful discussion. Most
importantly, we thank the entire group at HQS for their superb work and many
contributions. Particularly, we thank Joe Chambers and Tom Skripka for the
real-time engine implementation capable of making fast control decisions based
on mid-circuit measurement results, we thank Raanan Tobey and Matt Bohn for
specialized laser system work enabling high-fidelity gate operations, and we
thank Bryan Spann for his work to construct parallelized laser beam delivery
systems.

## References

  * Steane [1996] A. M. Steane, Phys. Rev. Lett. 77, 793 (1996).
  * Feynman [1986] R. P. Feynman, Foundations of Physics 16, 507 (1986).
  * Shor [1999] P. W. Shor, SIAM Review 41, 303 (1999).
  * Shor [1994] P. W. Shor, in  _Proceedings 35th Annual Symposium on Foundations of Computer Science_ (IEEE, 1994) pp. 124–134.
  * Abrams and Lloyd [1997] D. S. Abrams and S. Lloyd, Phys. Rev. Lett. 79, 2586 (1997).
  * Aspuru-Guzik  _et al._ [2005] A. Aspuru-Guzik, A. D. Dutoi, P. J. Love, and M. Head-Gordon, Science 309, 1704 (2005).
  * von Burg  _et al._ [2020] V. von Burg, G. H. Low, T. Häner, D. S. Steiger, M. Reiher, M. Roetteler, and M. Troyer, arXiv:2007.14460 (2020).
  * Orus  _et al._ [2019] R. Orus, S. Mugel, and E. Lizaso, Reviews in Physics 4, 100028 (2019).
  * Shor [1995] P. W. Shor, Phys. Rev. A 52, R2493 (1995).
  * Calderbank and Shor [1996] A. R. Calderbank and P. W. Shor, Physical Review A 54, 1098 (1996).
  * Aharonov and Ben-Or [2008] D. Aharonov and M. Ben-Or, SIAM Journal on Computing (2008).
  * Kitaev [1997] A. Y. Kitaev, in  _Quantum Communication, Computing, and Measurement_ (Springer, 1997) pp. 181–188.
  * Knill  _et al._ [1996] E. Knill, R. Laflamme, and W. Zurek, arxiv:9610011 (1996).
  * DiVincenzo [2000] D. P. DiVincenzo, Fortschritte der Physik: Progress of Physics 48, 771 (2000).
  * Gottesman [1997] D. Gottesman, arxiv:9705052 (1997).
  * Gottesman [2010] D. Gottesman, in  _Quantum Information Science and its Contributions to Mathematics, Proceedings of Symposia in Applied Mathematics_ , Vol. 68 (2010) pp. 13–58.
  * Gottesman [1998] D. Gottesman, Phys. Rev. A 57, 127 (1998).
  * Chen  _et al._ [2021] Z. Chen, K. J. Satzinger, J. Atalaya, A. N. Korotkov, A. Dunsworth, D. Sank, C. Quintana, M. McEwen, R. Barends, P. V. Klimov, _et al._ , arXiv:2102.06132 (2021).
  * Cory  _et al._ [1998] D. G. Cory, M. Price, W. Maas, E. Knill, R. Laflamme, W. H. Zurek, T. F. Havel, and S. S. Somaroo, Phys. Rev. Lett. 81, 2152 (1998).
  * Chiaverini  _et al._ [2004] J. Chiaverini, D. Leibfried, T. Schaetz, M. D. Barrett, R. Blakestad, J. Britton, W. M. Itano, J. D. Jost, E. Knill, C. Langer, _et al._ , Nature 432, 602 (2004).
  * Schindler  _et al._ [2011] P. Schindler, J. T. Barreiro, T. Monz, V. Nebendahl, D. Nigg, M. Chwalla, M. Hennrich, and R. Blatt, Science 332, 1059 (2011).
  * Cramer  _et al._ [2016] J. Cramer, N. Kalb, M. A. Rol, B. Hensen, M. S. Blok, M. Markham, D. J. Twitchen, R. Hanson, and T. H. Taminiau, Nat. Commun. 7, 1 (2016).
  * Reed  _et al._ [2012] M. D. Reed, L. DiCarlo, S. E. Nigg, L. Sun, L. Frunzio, S. M. Girvin, and R. J. Schoelkopf, Nature 482, 382 (2012).
  * Riste  _et al._ [2015] D. Riste, S. Poletto, M.-Z. Huang, A. Bruno, V. Vesterinen, O.-P. Saira, and L. DiCarlo, Nat. Commun. 6, 1 (2015).
  * Ristè  _et al._ [2020] D. Ristè, L. C. Govia, B. Donovan, S. D. Fallek, W. D. Kalfus, M. Brink, N. T. Bronn, and T. A. Ohki, npj Quantum Inf. 6, 1 (2020).
  * Wootton and Loss [2018] J. R. Wootton and D. Loss, Phys. Rev. A 97, 052313 (2018).
  * Linke  _et al._ [2017] N. M. Linke, M. Gutierrez, K. A. Landsman, C. Figgatt, S. Debnath, K. R. Brown, and C. Monroe, Science Advances 3, 10.1126/sciadv.1701074 (2017).
  * Takita  _et al._ [2017] M. Takita, A. W. Cross, A. D. Córcoles, J. M. Chow, and J. M. Gambetta, Phys. Rev. Lett. 119, 180501 (2017).
  * Córcoles  _et al._ [2015] A. D. Córcoles, E. Magesan, S. J. Srinivasan, A. W. Cross, M. Steffen, J. M. Gambetta, and J. M. Chow, Nat. Commun. 6, 1 (2015).
  * Harper and Flammia [2019] R. Harper and S. T. Flammia, Phys. Rev. Lett. 122, 080504 (2019).
  * Kelly  _et al._ [2015] J. Kelly, R. Barends, A. G. Fowler, A. Megrant, E. Jeffrey, T. C. White, D. Sank, J. Y. Mutus, B. Campbell, Y. Chen, _et al._ , Nature 519, 66 (2015).
  * Andersen  _et al._ [2020] C. K. Andersen, A. Remm, S. Lazar, S. Krinner, N. Lacroix, G. J. Norris, M. Gabureac, C. Eichler, and A. Wallraff, Nat. Phys. 16, 875 (2020).
  * Erhard  _et al._ [2021] A. Erhard, H. P. Nautrup, M. Meth, L. Postler, R. Stricker, M. Ringbauer, P. Schindler, H. J. Briegel, R. Blatt, N. Friis, _et al._ , Nature 589, 220 (2021).
  * Gong  _et al._ [2021] M. Gong, X. Yuan, S. Wang, Y. Wu, Y. Zhao, C. Zha, S. Li, Z. Zhang, Q. Zhao, Y. Liu, _et al._ , National Science Review (2021).
  * Knill  _et al._ [2001] E. Knill, R. Laflamme, R. Martinez, and C. Negrevergne, Phys. Rev. Lett. 86, 5811 (2001).
  * Nigg  _et al._ [2014] D. Nigg, M. Mueller, E. A. Martinez, P. Schindler, M. Hennrich, T. Monz, M. A. Martin-Delgado, and R. Blatt, Science 345, 302 (2014).
  * Hilder  _et al._ [2021] J. Hilder, D. Pijn, O. Onishchenko, A. Stahl, M. Orth, B. Lekitsch, A. Rodriguez-Blanco, M. Müller, F. Schmidt-Kaler, and U. Poschinger, Fault-tolerant parity readout on a shuttling-based trapped-ion quantum computer (2021), arXiv:2107.06368 [quant-ph] .
  * Egan  _et al._ [2020] L. Egan, D. M. Debroy, C. Noel, A. Risinger, D. Zhu, D. Biswas, M. Newman, M. Li, K. R. Brown, M. Cetina, _et al._ , arXiv:2009.11482 (2020).
  * Luo  _et al._ [2020] Y.-H. Luo, M.-C. Chen, M. Erhard, H.-S. Zhong, D. Wu, H.-Y. Tang, Q. Zhao, X.-L. Wang, K. Fujii, L. Li, _et al._ , arXiv:2009.06242 (2020).
  * Aoki  _et al._ [2009] T. Aoki, G. Takahashi, T. Kajiya, J.-i. Yoshikawa, S. L. Braunstein, P. Van Loock, and A. Furusawa, Nat. Phys. 5, 541 (2009).
  * Hu  _et al._ [2019] L. Hu, Y. Ma, W. Cai, X. Mu, Y. Xu, W. Wang, Y. Wu, H. Wang, Y. Song, C.-L. Zou, _et al._ , Nat. Phys. 15, 503 (2019).
  * Heeres  _et al._ [2017] R. W. Heeres, P. Reinhold, N. Ofek, L. Frunzio, L. Jiang, M. H. Devoret, and R. J. Schoelkopf, Nat. Commun. 8, 1 (2017).
  * Flühmann  _et al._ [2019] C. Flühmann, T. L. Nguyen, M. Marinelli, V. Negnevitsky, K. Mehta, and J. P. Home, Nature 566, 513 (2019).
  * Ofek  _et al._ [2016] N. Ofek, A. Petrenko, R. Heeres, P. Reinhold, Z. Leghtas, B. Vlastakis, Y. Liu, L. Frunzio, S. Girvin, L. Jiang, _et al._ , Nature 536, 441 (2016).
  * Campagne-Ibarcq  _et al._ [2020] P. Campagne-Ibarcq, A. Eickbusch, S. Touzard, E. Zalys-Geller, N. E. Frattini, V. V. Sivak, P. Reinhold, S. Puri, S. Shankar, R. J. Schoelkopf, _et al._ , Nature 584, 368 (2020).
  * Yao  _et al._ [2012] X.-C. Yao, T.-X. Wang, H.-Z. Chen, W.-B. Gao, A. G. Fowler, R. Raussendorf, Z.-B. Chen, N.-L. Liu, C.-Y. Lu, Y.-J. Deng, _et al._ , Nature 482, 489 (2012).
  * Lu  _et al._ [2008] C.-Y. Lu, W.-B. Gao, J. Zhang, X.-Q. Zhou, T. Yang, and J.-W. Pan, Proceedings of the National Academy of Sciences 105, 11050 (2008).
  * Bombin and Martin-Delgado [2006] H. Bombin and M. A. Martin-Delgado, Phys. Rev. Lett. 97, 180501 (2006).
  * Reichardt [2020] B. W. Reichardt, Quantum Science and Technology 6, 015007 (2020).
  * Bermudez  _et al._ [2019] A. Bermudez, X. Xu, M. Gutiérrez, S. C. Benjamin, and M. Müller, Physical Review A 100, 10.1103/physreva.100.062307 (2019).
  * Kielpinski  _et al._ [2002] D. Kielpinski, C. Monroe, and D. J. Wineland, Nature 417, 709 (2002).
  * Pino  _et al._ [2021] J. M. Pino, J. M. Dreiling, C. Figgatt, J. P. Gaebler, S. A. Moses, C. H. Allman, M. S. an Baldwin, M. Foss-Feig, D. Hayes, K. Mayer, C. Ryan-Anderson, and B. Neyenhuis, Nature 592, 209 (2021).
  * Barrett  _et al._ [2004] M. D. Barrett, J. Chiaverini, T. Schaetz, J. Britton, W. M. Itano, J. D. Jost, E. Knill, C. Langer, D. Leibfried, R. Ozeri, and D. J. Wineland, Nature 429 (2004).
  * Dennis  _et al._ [2002] E. Dennis, A. Kitaev, A. Landahl, and J. Preskill, Journal of Mathematical Physics 43, 4452 (2002).
  * Fowler  _et al._ [2012] A. G. Fowler, M. Mariantoni, J. M. Martinis, and A. N. Cleland, Phys. Rev. A 86, 032324 (2012).
  * Nielsen and Chuang [2000] M. A. Nielsen and I. L. Chuang,  _Quantum Computation and Quantum Information_ (Cambridge University Press, 2000).
  * Splatt  _et al._ [2009] F. Splatt, M. Harlander, M. Brownnutt, F. Zähringer, R. Blatt, and W. Hänsel, New Journal of Physics 11, 103008 (2009).
  * Cross  _et al._ [2017] A. W. Cross, L. S. Bishop, J. A. Smolin, and J. M. Gambetta, Open quantum assembly language (2017), arXiv:1707.03429 [quant-ph] .
  * Goto [2016] H. Goto, Scientific reports 6, 1 (2016).
  * Chao and Reichardt [2018a] R. Chao and B. W. Reichardt, Physical review letters 121, 050502 (2018a).
  * Chao and Reichardt [2018b] R. Chao and B. W. Reichardt, npj Quantum Information 4, 1 (2018b).
  * Knill [2005] E. Knill, Nature 434, 39 (2005).
  * Efron [1982] B. Efron,  _The Jackknife, the Bootstrap and Other Resampling Plans_ (SIAM, 1982).
  * Bravyi and Kitaev [2005] S. Bravyi and A. Kitaev, Phys. Rev. A 71, 022316 (2005).
  * Preskill [1998] J. Preskill, Proceedings of the Royal Society of London. Series A: Mathematical, Physical and Engineering Sciences 454, 385 (1998).
  * Zhou  _et al._ [2000] X. Zhou, D. W. Leung, and I. L. Chuang, Phys. Rev. A 62, 052316 (2000).
  * Ryan-Anderson [2018a] C. Ryan-Anderson,  _Quantum Algorithms, Architecture, and Error Correction_ , Ph.D. thesis, University of New Mexico (2018a).
  * Ryan-Anderson [2018b] C. Ryan-Anderson, Pecos: Performance estimator of codes on surfaces, https://github.com/PECOS-packages/PECOS (2018b).
  * Iverson [2019] J. Iverson, arXiv:1912.04319 (2019).
  * Hayes  _et al._ [2020] D. Hayes, D. Stack, B. Bjork, A. Potter, C. Baldwin, and R. Stutz, Phys. Rev. Lett. 124, 170501 (2020).
  * Suchara  _et al._ [2015] M. Suchara, A. W. Cross, and J. M. Gambetta, in  _2015 IEEE International Symposium on Information Theory (ISIT)_ (IEEE, 2015) pp. 1119–1123.
  * Brown  _et al._ [2020] N. C. Brown, A. Cross, and K. R. Brown, in  _2020 IEEE International Conference on Quantum Computing and Engineering (QCE)_ (IEEE, 2020) pp. 286–294.
  * Wang  _et al._ [2021] P. Wang, C.-Y. Luan, M. Qiao, M. Um, J. Zhang, Y. Wang, X. Yuan, M. Gu, J. Zhang, and K. Kim, Nat. Commun. 12 (2021).
  * Jordan  _et al._ [2019] E. Jordan, K. A. Gilmore, A. Shankar, A. Safavi-Naini, J. G. Bohnet, M. J. Holland, and J. J. Bollinger, Phys. Rev. Lett. 122, 053603 (2019).
  * van Mourik  _et al._ [2020] M. W. van Mourik, E. A. Martinez, L. Gerster, P. Hrmo, T. Monz, P. Schindler, and R. Blatt, Phys. Rev. A 102, 022611 (2020).
  * Ivory  _et al._ [2020] M. Ivory, W. J. Setzer, N. Karl, H. McGuinness, C. DeRose, M. Blain, D. Stick, M. Gehl, and L. P. Parazzoli, (2020), arXiv:2011.12376 [quant-ph] .
  * Wright  _et al._ [2013] K. Wright, J. M. Amini, D. L. Faircloth, C. Volin, S. C. Doret, H. Hayden, C.-S. Pai, D. W. Landgren, D. Denison, T. Killian, R. E. Slusher, and A. W. Harter, New Journal of Physics 15, 033004 (2013).
  * Debroy  _et al._ [2018] D. M. Debroy, M. Li, M. Newman, and K. R. Brown, Phys. Rev. Lett. 121, 250502 (2018).
  * Zhang  _et al._ [2021] B. Zhang, S. Majumder, P. H. Leung, S. Crain, Y. Wang, C. Fang, D. M. Debroy, J. Kim, and K. R. Brown, arXiv:2104.01119 (2021).
  * Parrado-Rodríguez  _et al._ [2021] P. Parrado-Rodríguez, C. Ryan-Anderson, A. Bermudez, and M. Müller, Quantum 5, 487 (2021).
  * Tuckett  _et al._ [2018] D. K. Tuckett, S. D. Bartlett, and S. T. Flammia, Phys. Rev. Lett. 120, 050505 (2018).
  * Landahl and Ryan-Anderson [2014] A. J. Landahl and C. Ryan-Anderson, arXiv:1407.5103 (2014).
  * Baldwin  _et al._ [2020] C. H. Baldwin, B. J. Bjork, J. P. Gaebler, D. Hayes, and D. Stack, Phys. Rev. Research 2, 013317 (2020).
  * Magesan  _et al._ [2011] E. Magesan, J. M. Gambetta, and J. Emerson, Phys. Rev. Lett. 106, 180504 (2011).
  * Olmschenk  _et al._ [2007] S. Olmschenk, K. C. Younge, D. L. Moehring, D. N. Matsukevich, P. Maunz, and C. Monroe, Phys. Rev. A 76, 052314 (2007).
  * Steiger  _et al._ [2018] D. S. Steiger, T. Häner, and M. Troyer, Quantum 2, 49 (2018).
  * Ozeri  _et al._ [2007] R. Ozeri, W. M. Itano, R. B. Blakestad, J. Britton, J. Chiaverini, J. D. Jost, C. Langer, D. Leibfried, R. Reichle, S. Seidelin, J. H. Wesenberg, and D. J. Wineland, Phys. Rev. A 75, 042329 (2007).

##  Appendix A Methods

The physical qubits are encoded in the ${}^{171}Yb+$ $S_{1/2}$ hyperfine clock
states $\ket{F=0,m_{f}=0}$ and $\ket{F=1,m_{f}=0}$ with $F$ and $m_{f}$
respectively being the total angular momentum and the z-projection quantum
numbers. Gating operations are implemented with stimulated Raman transitions
[52, 83] with single-qubit gates being performed with 2-ion
$\\{\mathrm{Yb,Ba}\\}$ crystals using two co-propagating circularly polarized
beams at 368.0 nm, and two-qubit operations being performed with 4-ion
$\\{\mathrm{Yb,Ba,Ba,Yb}\\}$ crystals using two beams with a wave-vector
difference $\Delta k$ coupling to the axial motion. The single 171Yb+ axial
center-of-mass mode frequency is 1.0 MHz and we use the first higher-order
mode at 1.74 MHz for entangling operations. Before any two-qubit gate
operations, motional excitations are cooled out of the system using a
combination of Doppler and resolved sideband cooling on the 138Ba+ ions.

We characterize physical qubit operations using error rates extracted from
parallel randomized benchmarking [84]. Physical qubits are initialized and
measured using standard optical pumping and state-dependent fluorescence
techniques [85] with an average SPAM error of $2.4(9)\times 10^{-3}$, where
the uncertainty indicates the typical variations across the zones and over
time. During qubit measurement and reset, laser scatter and ion fluorescence
absorbed by idle qubits cause errors ranging from $<1.0\times 10^{-4}$ to
$3\times 10^{-3}$ depending on the measurement zone and the other qubits’
physical locations. Single-qubit and two-qubit gate errors are respectively
measured to be $7(1)\times 10^{-5}$ and $3.0(1)\times 10^{-3}$. The memory
error in a depth-one circuit is benchmarked at $<5(3)\times 10^{-4}$. Our
estimates for errors in transport operations, such as physical swap, is
negligible compared to other errors.

We compile OpenQASM to a hardware-specific pulse language that combines
electrode and laser control. The sequences are executed with AWG’s driving
electrode voltages and DDS components controlling laser pulses, both sequenced
by a distributed network of controllers which combine programmable logic
components with ARM microprocessors. The microprocessor allows for sequencing
the error corrections as optional laser pulses embedded in a fixed ion
transport schedule. To execute conditional gates, qubit measurements are
analyzed and broadcast by a single microprocessor. Typically, the conditional
information is distributed in parallel with unconditional circuit operations,
and in worst case conditions, adds $<$250 $\mu$s of distribution latency.

Figure 7: A detailed schematic of the QEC demonstration. The encoding circuit
first prepares $\ket{0}_{L}$ and uses an ancilla to verify this preparation.
If the ancilla measured is found in $\ket{0}$, the circuit succeeded and moves
the next step. If the ancilla is found to be in $\ket{1}$, then all qubits are
reinitialized and the circuit ran again until successful, up to three times.
After a maximum of three initialization attempts, we proceed by applying
single qubit unitaries to make a logical rotation to prepare the desired
logical state. Adaptive QEC cycles are then performed. The first set of three
syndromes is measured using the flag circuit
$\\{S^{f}_{1},S^{f}_{5},S^{f}_{6}\\}$. If these syndromes do not indicate an
error, then the second set of three sydromes is measured
$\\{S^{f}_{1},S^{f}_{3},S^{f}_{4}\\}$ and if no errors are indicated, the
syndrome extraction protocol is complete. If either of the flagged circuits do
indicate an error, the protocol moves to measuring all six stabilizers using
the unflagged circuit $\\{S_{1},S_{2},S_{3},...\\}$, thus completing the
syndrome extraction. The syndrome information is then fed to the decoder to
infer a correction and the Pauli frame is updated. Finally, the state is
rotated to the appropriate basis for measurement using single qubit unitaries.
Upon measurement, syndrome information is inferred and sent to the decoder for
a final correction. Figure 8: An outline of the decoder procedure and two
different error configurations. a) A single qubit hook error occurs on an
ancilla and spreads to two data qubits. This triggers the additional round of
syndrome extraction using the unflagged circuits. We denote the errors on the
data qubits (gray circles) and the changed syndromes measurements (black
circles) pictorially on the color code figure. b) A single qubit error occurs
on a data qubit and causes a change in the syndrome measurements, again,
triggering an additional round of syndrome extraction. In both a) and b) the
final round of syndrome measurements are identical, meaning the first step of
the decoder cannot distinguish between these two error configurations. The
second step of the decoder compares the syndromes measured within the QEC
cycle to distinguish between cases such as this. We see that the two sets of
measured syndromes are different for the hook error, but the same for the
single qubit data error.  Figure 9: A schematic of the $\overline{S}$ gate
experiments. In this set of experiments, we compare physically applied
corrections to implementing the corrections in software using the Pauli frame.
The main elements are the same as those used in Fig. 7. First, using the FT
encoding circuit, we prepare $\ket{0}_{L}$ and rotate to $\ket{+}_{L}$ with an
$\overline{H}$ gate. We then perform one QEC cycle to generate corrections.
Next, we either physically apply corrections to the qubits, or update the
Pauli frame in software, followed by physically applying the $\overline{S}$
gate. We then apply one last QEC cycle to generate further corrections, rotate
to the $\overline{Y}$ basis, and measure the data qubits. The final corrective
steps infer the syndromes, decode, and apply corrections to the output data as
outlined in the main text and Fig. 7. Figure 10: A non-fault-tolerant encoding
circuit used to prepare the magic state $\overline{T}\ket{+}_{L}$.

###  A.1 Simulations

The simulator used in this work is a modified version of the software PECOS
[68] that receives instructions directly from compiler, which is composed of
the native quantum gate set, classical operations, and transport operations.
That is, the instructions that were used to encode the QEC experiments in this
paper and were executed by the simulator were same instructions that QCCD
device was instructed to perform (before being translated to hardware-specific
pulses). The simulations models errors both coherently using a state-vector
backend [86] as well as incoherently using a stabilizer simulation [67]. All
simulation results presented in this paper are those of the coherent
simulation; however, both the coherent and incoherent simulations produce
nearly identical results given a dephasing rate of $0.25$ Hz and $0.43$ Hz,
respectively.

The error model includes simple depolarizing gate noise, leakage errors, and
dephasing noise during transport and cooling operations. Errors on physical
qubits are modeled as stochastic processes (excluding dephasing). Most errors
are applied with probabilities determined by independent experiments as
summarized in Table 4, with the exception of dephasing errors. The coherent
simulation modeled dephasing as $RZ(\theta)$ following ideal gates, where
$\theta$ is the dephasing rate, $0.26$ Hz times the time between gates due to
qubit idling or transport operations. For the incoherent simulations,
dephasing errors are applied as stochastic $Z$ errors between gate operations
with a probability of $p=sin(\theta/2)^{2}$. That is, probability obtained
from Pauli twirling the coherent channel. Note here, the same $theta$ is used
as the coherent model. Both dephasing rates ($0.26$ Hz and $0.43$ Hz) were
empirically found, as discussed in the main text.

Physical qubit initialization to $\ket{0}$ occurs at the beginning of each
circuit and after each measurement. The fidelity of this procedure is limited
by off-resonant coupling which is numerically simulated. The residual
population remains in the $F=1$ manifold, $2/3$’s of which is distributed in
the leakage states $\ket{F=1,m_{f}=\pm 1}$. The single-qubit and two-qubit
gate errors are modeled as being dominated by a depolarization process whose
amplitude is measured via randomized benchmarking experiments. The spontaneous
emission that occurs during stimulated Raman transitions is estimated through
atomic physics calculations closely following Ref. [87]. While the spontaneous
emission is estimated to be small compared to the total error, the leakage
induced by the process is more detrimental than errors that keep the ion in
the qubit subspace, and we therefore explicitly include this error in addition
to the depolarizing error. Note that the spontaneous emission process is
modeled as causing leakage with probability $1/2$, and causing $X$ and $Y$
errors each with probability $1/4$. Single-qubit rotations about the z-axis
are done entirely in software, and therefore contribute negligible errors. We
model measurement errors as bit flips and note that leaked qubits return
measurement results that are indistinguishable from $\ket{1}$ due to the
measurement process described in Ref. [85].

Operation | Channel | Probability
---|---|---
Initialization | Bit flip | $1.66\times 10^{-6}$
Leakage | $3.33\times 10^{-5}$
X/Y Single-qubit gate | Depolarizing | $7\times 10^{-5}$
Spontaneous Emission | $1.25\times 10^{-5}$
Two-qubit gate | Depolarizing | $3.1\times 10^{-3}$
Spontaneous Emission | $2.75\times 10^{-4}$
Measurement | Bit flip | $2.4\times 10^{-3}$
Leakage | $5\times 10^{-3}$
Crosstalk | Initialization | $2.3\times 10^{-5}$
Measurement | $2.3\times 10^{-4}$
Operation | Channel | Rate (Hz)
Dephasing | Coherent | $0.26$
Incoherent | $0.43$
Table 4: Simulation error parameters. With the exception of the dephasing
rate, the parameters used come from either experimental measurement or well
defined microsopic noise analysis. Values based on microscopic noise analysis
include further break-down of the errors such as initialization error
consisting of 1/3 bit-flip errors and 2/3 leakage, and spontaneous emission
consisting of 1/2 leakage error, 1/4 $X$ error, and 1/4 $Z$ error. The
dephasing rates used in the simulations were determined separately for the
incoherent and coherent simulations by adjusting the dephasing rate until the
logical error rate for a QEC cycle matched the value found from the
experiment.

⬇

1def qec_cycles_exp(init_state: str, meas_basis: str, num_cycles: int, shots:
int) -> Tuple[int, int]:

2 """

3␣␣Pseudocode␣representing␣the␣repeated␣QEC␣cycle␣and␣the␣magic-
state␣experiments.

4

5␣␣Args:

6␣␣␣␣init_state:␣The␣logical␣state␣to␣initialize.

7␣␣␣␣meas_basis:␣The␣logical␣measurement␣basis␣to␣measure␣in␣the␣end.

8␣␣␣␣num_cycles:␣The␣number␣of␣QEC␣cycles.

9␣␣␣␣shots:␣The␣number␣of␣experiments␣to␣attempt.

10

11␣␣Returns:

12␣␣␣␣A␣tuple␣of␣the␣number␣of␣shots␣and␣the␣number␣of␣shots␣with␣measurement␣outcomes␣consistent␣with␣state␣preparation.

13␣␣"""

14 runs = 0 # Number of total shots

15 success = 0 # Number of shots that had expected outcomes

16

17 for i in range(shots):

18

19 # Initialize the logical state

20 if init_state == ’|T>’:

21 # Encode $T\ket{+}$ using Steane code encoding circuit from Ref. [65]

22 state = prep_tstate()

23 else:

24 # Use FT circuit from Ref. [59] to prepare logical $\ket{0}$ (see Fig. 7)

25 state = ftprep_zero() # prepare state with up to 3 attempt to verify,
continue regardless of final verification

26

27 # Rotate that state from logical |0> to another logical state as
apporpriate

28 state = logical_rotate_init_basis(state, init_state)

29

30 # Run the QEC cycles

31 last_syndromes_x = [0, 0, 0]

32 last_syndromes_z = [0, 0, 0]

33 pf = [0, 0] # The Pauli frame: [Apply logical X?, Apply logical Z?]

34

35 for j in range(num_cycles):

36 state, last_syndromes_x, last_syndromes_z, pf = qec_cycle(state,
last_syndromes_x, last_syndromes_z, pf)

37

38 # Rotate the logical measurement basis

39 state = rotate_meas_basis(state, meas_basis)

40

41 # Do a destructive logical measurement

42 meas_output = logical_meas(state, meas_basis, last_syndromes_x,
last_syndromes_z, pf)

43

44 runs += 1

45

46 # Determine if measurement result was as expected. If so, upade success
count.

47 expected_outcome = expected_result(meas_output, init_state, meas_basis)

48 success += expected_outcome

49

50 return runs, success

Pseudocode 1: The main program for the repeated QEC cycle and the magic-state
experiment.

⬇

1def active_corr_exp(active_correction: bool, shots: int) -> Tuple[int, int]:

2 """

3␣␣Pseudocode␣representing␣the␣active␣vs␣software␣experiments.

4

5␣␣Args:

6␣␣␣␣active_correction:␣Whether␣to␣physically␣apply␣the␣logical␣corrections␣before␣the␣logical␣S␣gate␣or␣not.

7␣␣␣␣shots:␣The␣number␣of␣experiments␣to␣attempt.

8

9␣␣Returns:

10␣␣␣␣A␣tuple␣of␣the␣number␣of␣shots␣and␣the␣number␣of␣shots␣with␣measurement␣outcomes␣consistent␣with␣state␣preparation.

11␣␣"""

12 runs = 0 # Number of total shots

13 success = 0 # Number of shots that had expected outcomes

14

15 for i in range(shots):

16

17 # Initialize the |+> ogical state

18 # Use FT circuit from Ref. [59] to prepare logical $\ket{0}$ (see Fig. 7)

19 state = ftprep_zero() # prepare state with up to 3 attempt to verify,
continue regardless of final verification

20

21 # Rotate that state from logical |0> to logical |+>

22 state = logical_rotate_init_basis(state, init_state=’|+>’)

23

24 # Run the QEC cycles

25 last_syndromes_x = [0, 0, 0]

26 last_syndromes_z = [0, 0, 0]

27 pf = [0, 0] # The Pauli frame: [Apply logical X?, Apply logical Z?]

28

29 # Do a single QEC cycle

30 state, last_syndromes_x, last_syndromes_z, pf = qec_cycle(state,
last_syndromes_x, last_syndromes_z, pf)

31

32 if active_correction: # Physically apply any logical X or Z corrections

33 # We apply both X and Z; however, you don’t have to apply Z since S and Z
commute

34 state = apply_pauli_frame(state, pf)

35 pf = [0, 0] # Reset Pauli frame

36 else:

37 # Apply the S gate rotation to the Pauli frame

38 # Z -> Z, X -> Y

39 pf = sgate2pf(pf) # equivalent to XORing: pf[1] = pf[1] ^ pf[0]

40

41 # Physically apply the logical S gate

42 state = logical_sgate(state)

43

44 # Rotate the logical measurement basis to Y since S: |+> -> |+i>

45 state = rotate_meas_basis(state, meas_basis=’Y’)

46 # Do a destructive logical measurement

47 meas_output = logical_meas(state, meas_basis, last_syndromes_x,
last_syndromes_z, pf)

48

49 runs += 1

50

51 # Determine if measurement result was as expected. If so, upade success
count.

52 expected_outcome = expected_result(meas_output, init_state, meas_basis)

53 success += expected_outcome

54

55 return runs, success

Pseudocode 2: The main program for the active vs software correction
experiment with the logical S.

⬇

1def logical_rotate_init_basis(state: QuantumState, init_state: str) ->
QuantumState:

2 """

3␣␣Pseudocode␣representing␣rotating␣to␣appropriate␣logical␣basis.

4

5␣␣Args:

6␣␣␣␣state:␣The␣logical␣state␣to␣rotate.

7␣␣␣␣init_state:␣The␣logical␣state␣to␣rotate␣to.

8

9␣␣Returns:

10␣␣␣␣A␣rotated␣logical␣state.

11␣␣"""

12

13 if init_state == ’|0>’:

14 # |0> -> |0>

15 pass # do nothing

16

17 elif init_state == ’|1>’:

18 # X |0> -> |1>

19 state = logical_x(state) # X on qubits 5, 6, and 7 (|0> -> |1>)

20

21 elif init_state == ’|+>’:

22 # H |0> -> |+>

23 state = logical_h(state) # $H$ on all data qubits

24

25 elif init_state == ’|->’:

26 # H X |0> -> |->

27 state = logical_x(state) # $X$ on qubits 5, 6, and 7 (|0> -> |1>)

28 state = logical_h(state) # $H$ on all data qubits (|1> -> |->)

29

30 elif init_state == ’|+i>’:

31 # S H |0> -> |+i>

32 state = logical_h(state) # $H$ on all data qubits (|0> -> |+>)

33 state = logical_s(state) # $S^{\dagger}$ on all data qubits (|+> -> |+i>)

34

35 elif init_state == ’|-i>’:

36 # S H X |0> -> |-i>

37 state = logical_x(state) # $X$ on qubits 5, 6, and 7 (|0> -> |1>)

38 state = logical_h(state) # $H$ on all data qubits (|1> -> |->)

39 state = logical_s(state) # $S^{\dagger}$ on all data qubits (|-> -> |-i>)

40

41 return state

Pseudocode 3: Rotate logical $\ket{0}$ to the appropriate state.

⬇

1def qec_cycle(state: QuantumState, last_syndrome_x: List[int, int, int],
last_syndrome_z: List[int, int, int], pf: List[int, int]) ->
Tuple[QuantumState, List[int, int, int], List[int, int, int], List[int, int]]:

2 """

3␣␣Pseudocode␣representing␣a␣single␣QEC␣cycle.

4

5␣␣Args:

6␣␣␣␣init_state:␣The␣logical␣state␣to␣initialize.

7␣␣␣␣meas_basis:␣The␣logical␣measurement␣basis␣to␣measure␣in␣the␣end.

8␣␣␣␣num_cycles:␣The␣number␣of␣QEC␣cycles.

9␣␣␣␣shots:␣The␣number␣of␣experiments␣to␣attempt.

10

11␣␣Returns:

12␣␣␣␣A␣logical␣state,␣the␣last␣X-type␣syndromes␣measured␣(not␣including␣flagged␣syndromes),␣the␣last␣Z-type␣syndromes␣measured␣(not␣including␣flagged␣syndromes),␣and␣the␣updated␣Pauli-
frame,␣which␣tracks␣whether␣to␣apply␣a␣logical␣X␣and/or␣Z␣correction.

13␣␣"""

14 flag_diff_x = [0, 0, 0]

15 flag_diff_z = [0, 0, 0]

16

17 # Measure the first set of stabilizers in parallel.

18 fx0, fz1, fz2 = meas_flagging_syndromes_xzz(state)

19 # XOR with previously measured syndrome to get the difference

20 flag_diff_x[0] = fx0 ^ last_syndrome_x[0]

21 flag_diff_z[1] = fz1 ^ last_syndrome_z[1]

22 flag_diff_z[2] = fz2 ^ last_syndrome_z[2]

23

24 # If no change detected, go on to the next flagging syndromes

25 if flag_diff_x == [0, 0, 0] and flag_diff_z == [0, 0, 0]:

26 # Measure the second set of stabilizers in parallel.

27 fz0, fx1, fx2 = meas_flagging_syndromes_zxx(state)

28 # XOR with previously measured syndrome to get the difference

29 flag_diff_z[0] = fz0 ^ last_syndrome_z[0]

30 flag_diff_x[1] = fx1 ^ last_syndrome_x[1]

31 flag_diff_x[2] = fx2 ^ last_syndrome_x[2]

32

33 # If any change in syndromes was detected, re-measure the set of six
stabilizer generators without flagging

34 if flag_diff_x != [0, 0, 0] or flag_diff_z != [0, 0, 0]:

35 sx0, sx1, sx2, sz0, sz1, sz2 = meas_six_syndromes(state)

36 syndromes_x = [sx0, sx1, sx2]

37 syndromes_z = [sz0, sz1, sz2]

38 # Get the change in sydromes

39 syndrome_diff_x = bitwise_xor(syndromes_x, last_syndrome_x)

40 syndrome_diff_z = bitwise_xor(syndromes_z, last_syndrome_z)

41

42 # Determine a Pauli-frame update to track correction in software

43 pf_new_x = decoder_2d(syndrome_diff_x)

44 pf_new_z = decoder_2d(syndrome_diff_z)

45 # Now modify the 2D decoder corrections based on flagging

46 pf_flag_new_x = decoder_flag_update(syndrome_diff_x, flag_diff_x)

47 pf_flag_new_z = decoder_flag_update(syndrome_diff_z, flag_diff_z)

48 # Update the Pauli frame with the new corrections vis XORing

49 pf[0] = pf[0] ^ pf_new_x ^ pf_flag_new_x

50 pf[1] = pf[1] ^ pf_new_z ^ pf_flag_new_z

51

52 # Set the last syndromes to the current ones

53 last_syndrome_x = last_syndrome_x

54 last_syndrome_z = last_syndrome_z

55

56 return state, last_syndrome_x, last_syndrome_z, pf

Pseudocode 4: A QEC cycle

⬇

1def rotate_meas_basis(state: QuantumState, meas_basis: str) -> QuantumState:

2 """

3␣␣Rotate␣logical␣measurement␣basis.

4

5␣␣Args:

6␣␣␣␣state:␣The␣logical␣state.

7␣␣␣␣meas_basis:␣The␣logical␣measurement␣basis␣to␣measure␣in␣the␣end.

8

9␣␣Returns:

10␣␣␣␣A␣logical␣state.

11␣␣"""

12 if meas_basis == ’Z’:

13 pass # do nothing. we measure in Z by default

14

15 elif meas_basis = ’X’:

16 state = logical_h(state) # $H$ on all data qubits

17

18 elif meas_basis = ’Y’:

19 state = logical_sdg(state) # $S$ on all data qubits

20 state = logical_h(state) # $H$ on all data qubits

21

22 return state

Pseudocode 5: Rotate measurement to the correct logical basis

⬇

1def logical_meas(state: QuantumState, meas_basis: str, last_syndrome_x:
List[int, int, int], last_syndrome_z: List[int, int, int], pf: List[int, int])
-> int:

2 """

3␣␣Destructive␣logical␣measurement.

4

5␣␣Args:

6␣␣␣␣state:␣The␣logical␣state␣to␣measure.

7␣␣␣␣meas_basis:␣The␣logical␣measurement␣basis␣being␣measured␣in.

8␣␣␣␣last_syndrome_x:␣The␣last␣X-type␣syndromes␣measured␣(not␣including␣flagged␣ones)

9␣␣␣␣last_syndrome_z:␣The␣last␣Z-type␣syndromes␣measured␣(not␣including␣flagged␣ones)

10

11␣␣Returns:

12␣␣␣␣Logical␣measurement␣outcome.

13␣␣"""

14 # Note: The logical measurement basis might have rotated outside of this
function.

15

16 # Measure each data qubit with a single-qubit Z-basis measurement.

17 # Measurement labeling corresponds to the labeling of data qubits in Fig. 7

18 m1, m2, m3, m4, m5, m6, m7 = meas_z_data(state) # get measurement results

19

20 # Due to symmetry we can treat the X, Y, and Z basis in a similar manner:

21

22 # Get logical measurement output of logical X, Y, or Z (as appropriate)

23 meas_output = m5 ^ m6 ^ m7 # XOR measurements of logical operator on qubits
5, 6, 7

24

25 # Get syndromes by XORing measurement bits together

26 # Note: Due to the meas. basis, these results may be for X, Y, or Z type
stabilizers

27 s1 = m1 ^ m2 ^ m3 ^ m4

28 s2 = m2 ^ m3 ^ m5 ^ m6

29 s3 = m3 ^ m4 ^ m6 ^ m7

30 syndromes = [s1, s2, s3]

31

32 # Get change of syndrome depending on measurement basis

33 if meas_basis == ’X’:

34 syndrome_diff = bitwise_xor(syndromes, last_syndrome_x)

35 elif meas_basis == ’Y’:

36 syndrome_diff = bitwise_xor(syndromes, last_syndrome_x)

37 syndrome_diff = bitwise_xor(syndromes, last_syndrome_z)

38 elif meas_basis == ’Z’:

39 syndrome_diff = bitwise_xor(syndromes, last_syndrome_z)

40 else:

41 raise Exception() # No other basis expected

42

43 # Get correction from the syndrome diff as determined from measurement

44 final_correction = decoder_2d(syndrome_diff)

45

46 # Update logical measurement outcome based on the measured syndromes

47 meas_output = meas_output ^ final_correction # XOR together => flip outcome
or not

48

49 # Apply correction from Pauli frame to measurement outcome

50 if meas_basis == ’X’:

51 meas_output = meas_output ^ pf[1] # Apply logical Z

52 elif meas_basis == ’Y’:

53 meas_output = meas_output ^ pf[0] # Apply logical X

54 meas_output = meas_output ^ pf[1] # Apply logical Z

55 elif meas_basis == ’Z’:

56 meas_output = meas_output ^ pf[0] # Apply logical X

57 else:

58 raise Exception() # No other basis expected

59

60 return meas_output

Pseudocode 6: A measurement in the logical Z basis.

⬇

1def expected_result(meas_output: int, init_state: str, meas_basis: str) ->
int:

2 """

3␣␣Determining␣whether␣a␣measurement␣result␣is␣consistant␣with␣expectation.

4

5␣␣Args:

6␣␣␣␣meas_output:␣Logical␣measurement␣output␣after␣correction.␣0␣=>␣+1,␣1␣=>␣-1

7␣␣␣␣init_state:␣The␣logical␣state␣intended␣to␣be␣initialized.

8␣␣␣␣meas_basis:␣The␣logical␣measurement␣basis␣measured␣in.

9

10␣␣Returns:

11␣␣␣␣A␣logical␣state.

12␣␣"""

13 # Measurement basis and state pairs that should have 0/+1 outcomes

14 zero_outcomes = {(’X’, ’|+>’), (’Y’, ’|+i>’), (’Z’, ’|0>’),

15 (’X’, ’|T>’), (’Y’, ’|T>’)}

16 # Note, the measurements of the |T> state is not a measurement of fidelity
but instead understood as the probability of being in the +1 eigenstate of the
measured basis.

17

18 # Measurement basis and state pairs that should have 1/-1 outcomes

19 one_outcomes = {(’X’, ’|->’), (’Y’, ’|-i>’), (’Z’, ’|1>’)}

20

21 if (meas_basis, init_state) in zero_outcomes:

22 expected_val = 0

23

24 elif (meas_basis, init_state) in one_outcomes:

25 expected_val = 0

26

27 else:

28 # No other measurement basis and state pairs are expected to be evaluated.

29 raise Exception(’Unexpect␣init_state␣and␣measurement␣basis␣combination!’)

30

31

32 if expected_val == meas_out:

33 success = 1

34 else:

35 success = 0

36

37 return success

Pseudocode 7: Determining if the result is expected.

⬇

1 def decoder_2d(syndrome_diff: List[int, int, int]) -> int:

2 """

3␣␣␣␣␣␣␣␣A␣2D␣decoder␣that␣determines␣logical␣corrections.␣Due␣to␣symmetry␣this,␣can␣be␣used␣to␣decode␣stabilizer␣measurements␣of␣any␣Pauli␣type.

4

5␣␣␣␣␣␣␣␣Args:

6␣␣␣␣␣␣␣␣␣␣syndrome_diff:␣The␣change␣in␣syndromes␣compared␣to␣the␣last␣time␣they␣where␣measured.

7

8␣␣␣␣␣␣␣␣Returns:

9␣␣␣␣␣␣␣␣␣␣A␣bit␣representing␣whether␣a␣logical␣error␣has␣occurred.

10␣␣␣␣␣␣␣␣"""

11 # Syndromes that indicate tha a single Pauli fault has flipped the logical
operator representative on data qubits 5, 6, and 7.

12 bad_syndromes = {[0, 1, 0], [0, 1, 1], [0, 0, 1]}

13

14 if syndrome_diff in bad_syndromes:

15 logical_error = 1

16 else:

17 logical_error = 0

18

19 return logical_error

Pseudocode 8: The basic 2D decoder that infers if a logical error has occured.

⬇

1 def decoder_flag_update(syndrome_diff: List[int, int, int], flag_diff:
List[int, int, int]) -> int:

2 """

3␣␣␣␣␣␣␣␣A␣2D␣decoder␣that␣determines␣logical␣corrections.␣Due␣to␣symmetry␣this,␣can␣be␣used␣to␣decode␣stabilizer␣measurements␣of␣any␣Pauli␣type.

4

5␣␣␣␣␣␣␣␣Args:

6␣␣␣␣␣␣␣␣␣␣syndrome_diff:␣The␣change␣in␣syndromes␣compared␣to␣the␣last␣time␣they␣were␣measured.

7␣␣␣␣␣␣␣␣␣␣flag_diff:␣The␣change␣in␣flags␣compared␣to␣the␣last␣time␣syndromes␣were␣measured.

8

9␣␣␣␣␣␣␣␣Returns:

10␣␣␣␣␣␣␣␣␣␣A␣bit␣representing␣whether␣the␣2D␣decoder’s␣correction␣should␣be␣changed␣due␣to␣the␣relationship␣between␣flags␣and␣syndromes.

11␣␣␣␣␣␣␣␣"""

12 # The following indicate hook faults have occured:

13

14 # flag -> syndrome: 0 -> 1

15 if flag_diff == [1, 0, 0] and syndrome_diff == [0, 1, 0]:

16 change_correction = 1

17

18 # flag -> syndrome: 0 -> 2

19 elif flag_diff == [1, 0, 0] and syndrome_diff == [0, 0, 1]:

20 change_correction = 1

21

22 # flag -> syndrome: 1,2 -> 2

23 elif flag_diff == [0, 1, 1] and syndrome_diff == [0, 0, 1]:

24 change_correction = 1

25

26 else:

27 change_correction = 0

28

29 return change_correction

Pseudocode 9: An additional decoder that updates the correction based on flag
information.