\chapter{Fault-Tolerant Quantum Error Correction}
\label{ch:Fault tolerance}

% Intro

In the previous chapter, we introduced the fundamental concepts of
classical and quantum error correction.
In this chapter, we shift our focus to some practical aspects of the
implementation of \ac{qec} systems.

% Fault tolerance as a general notion

The reason we turned to \ac{qec} in the first place is to allow us to
perform quantum computing despite the errors inherent to operations
using qubits.
While the use of error correcting codes may facilitate this, it also
introduces two new challenges \cite[Sec.~4]{gottesman_introduction_2009}:
\begin{itemize}
    \item We must be able to perform operations on the encoded state
        in such a way that we do not lose the protection against errors.
    \item \ac{qec} systems are themselves partially implemented in
        quantum hardware. In addition to the errors we have
        originally introduced them for, these systems must
        be able to account for the fact they are implemented on noisy
        hardware themselves.
\end{itemize}
In the literature, both of these points are viewed under the umbrella
of \emph{fault tolerance}.
We focus only on the second aspect in this work.

It was recognized early on as a challenge of \ac{qec} that the correction
machinery itself may introduce new faults \cite[Sec.~III]{shor_scheme_1995}.
Specifically for stabilizer codes, this can happen during the
syndrome extraction process.
We distinguish between the errors the QEC procedure is supposed to
correct, which we call \emph{input errors}, and
those introduced by the procedure itself, which we call \emph{internal errors}.
In order to be fault-tolerant, the procedure must be able to
address both.

% Definition of fault tolerance

We model the possible occurrence of errors during any processing
stage as different \emph{error locations} $E_i,~i\in [1:N]$
in the circuit.
$N \in \mathbb{N}$ is the total number of considered error locations.
The \emph{circuit error vector} $\bm{e} \in \{0,1\}^N$ is a vector
indicating which errors occurred, with
\begin{align*}
    e_i :=
    \begin{cases}
        1, & \text{Error $E_i$ occurred} \\
        0, & \text{otherwise}
    \end{cases}
    .%
\end{align*}
\Cref{fig:fault_tolerance_overview} illustrates the flow of errors.
Specifically for \ac{css} codes, a \ac{qec} procedure is deemed
fault-tolerant, if \cite[Def.~4.2]{derks_designing_2025}
\begin{gather*}
    \lVert \bm{e}_{\text{output},X} \rVert \le t \hspace{5mm}
    \forall\,  \bm{e}_\text{input}, \bm{e}_\text{internal} \in \{0,1\}^N:
    \lVert \bm{e}_\text{input} \rVert + \lVert \bm{e}_\text{internal}
    \rVert \le t \\[1mm]
    \text{and} \\[1mm]
    \lVert \bm{e}_{\text{output},Z} \rVert \le t \hspace{5mm}
    \forall\,  \bm{e}_\text{input}, \bm{e}_\text{internal} \in \{0,1\}^N:
    \lVert \bm{e}_\text{input} \rVert + \lVert \bm{e}_\text{internal}
    \rVert \le t
    ,%
\end{gather*}
where $t = \lfloor (d_\text{min} -1)/2 \rfloor$ is the number of
errors the code is able to correct.
The vectors $\bm{e}_{\text{output},X}$ and $\bm{e}_{\text{output},Z}$
denote only $X$ and $Z$ errors respectively.

% TODO: Properly introduce d_min for QEC, specifically for CSS codes
In order to deal with internal errors that flip syndrome bits,
multiple rounds of syndrome measurements must be performed.
Typically, the number of syndrome extraction rounds is chosen as $d_\text{min}$.

% % This is the definition of a fault-tolerant QEC gadget
% A \ac{qec} procedure is deemed fault tolerant if
% \cite[Def.~5]{gottesman_introduction_2009}
% \begin{align*}
%     % tex-fmt: off
%     \text{A)}
%     % tex-fmt: on
%     \hspace{5mm} & \lVert \bm{e}_\text{output} \rVert
%     \le \lVert \bm{e}_\text{internal} \rVert
%     \hspace{5mm} \forall\,
%     \bm{e}_\text{input}, \bm{e}_\text{internal} \in \{0,1\}^N :
%     \lVert \bm{e}_\text{internal} \rVert \le t \\
%     % tex-fmt: off
%     \text{B)}
%     % tex-fmt: on
%     \hspace{5mm} & \lVert \bm{e}_\text{output} \rVert = 0
%     \hspace{19.3mm} \forall\,
%     \bm{e}_\text{input}, \bm{e}_\text{internal} \in \{0,1\}^N :
%     \lVert \bm{e}_\text{input} \rVert + \lVert \bm{e}_\text{internal}
%     \rVert \le t
%     ,
% \end{align*}
% where $t = \lfloor (d_\text{min} -1)/2 \rfloor$ is the number of
% errors the original code is able to correct.
% Condition A limits the spread of input errors during the error
% correction process.
% Condition B means that as long as there are few enough internal and
% input errors, the scheme should be able to correct all of them.

% Practical considerations

% TODO: Are the fault-tolerant QEC procedures where we don't perform
% multiple measurement rounds?

\begin{figure}[t]
    \centering

    \begin{tikzpicture}
        \node[rectangle, draw, fill=orange!20, minimum
        height=2cm, minimum width=2.5cm, align=center] at (0,0)
        (internal) {Internal Errors\\ $\bm{e}_\text{internal}$};

        \node[signal, draw, fill=orange!20, minimum height=2cm,
        minimum width=2.5cm, align=center, signal pointer angle=140]
        at (-2.8, 0) (input) {Input Errors \\ $\bm{e}_\text{input}$};

        \node at (1.99,0) {\huge =};

        \node[rectangle, draw, fill=orange!20, minimum height=2cm,
        minimum width=2.5cm, align=center] at (4,0) (output)
        {Output Errors\\ $\bm{e}_\text{output}$};

        \node[above] at (input.north) {\small Input State};
        \node[above] at (internal.north) {\small QEC};
        \node[above] at (output.north) {\small Output State};
    \end{tikzpicture}

    \caption{
        Sources of error in a fault-tolerant \ac{qec} system.
        Adapted from \cite[Figure~2]{derks_designing_2025}.
    }
    \label{fig:fault_tolerance_overview}
\end{figure}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Noise Models}
\label{sec:Noise Models}

% Intro

We collect the probabilities of error at each location in the
\emph{noise model}, a vector $\bm{p} \in [0,1]^N$.
There are different types of noise models, each allowing for
different error locations in the circuit.

% Figure intro

We will illustrate the most widely used types of error models on the
example of the three-qubit repetition code for $X$ errors.
This is a code with check matrix
\begin{gather}
    \label{eq:rep_code_H}
    \bm{H}_Z =
    \left[
        \begin{array}{ccc}
            1 & 1 & 0 \\
            0 & 1 & 1
        \end{array}
    \right]
    .
\end{gather}
We can see that it has stabilizers $Z_1Z_2$ and $Z_2Z_3$.
\Cref{fig:pure_syndrome_extraction} shows the corresponding
syndrome extraction circuit.
We refer to the qubits carrying the logical state
$\ket{\psi}_\text{L}$ as \emph{data qubits}.
Note that this is a concrete implementation using CNOT gates, as
opposed to the system-level view introduced in
\Cref{subsec:Stabilizer Codes}.
We visualize the different types of noise models in
\Cref{fig:noise_model_types}.

%%%%%%%%%%%%%%%%
\subsection{Bit-Flip Noise}
\label{subsec:Bit-Flip Noise}

The simplest type of noise model is \emph{bit-flip} noise.
This corresponds to the classical \ac{bsc}, i.e., only $X$ errors on the
data qubits are possible \cite[Appendix~A]{gidney_new_2023}.
This type of noise model is shown in \Cref{subfig:bit_flip}.

Note that we cannot use bit-flip noise to develop fault-tolerant
systems, as it does not account for errors during the syndrome extraction.

%%%%%%%%%%%%%%%%
\subsection{Depolarizing Channel}
\label{subsec:Depolarizing Channel}

Extending bit-flip noise to consider $X,Z$ or $Y$ instead of just $X$
errors, we obtain the \emph{depolarizing channel}
\cite[Sec.~7.6]{gottesman_stabilizer_1997}, depicted in
\Cref{subfig:depolarizing}.
It is well-suited for modeling memory experiments, where data qubits
are stored idly for some period of time and errors accumulate due to
decoherence.

While the depolarizing channel is still not suited for the design and
simulation of fault-tolerant systems, it is already complex enough to
be used to gauge the suitability of a code for the \ac{qec} problem.
Bit-flip noise and the depolarizing channel are sometimes referred to
as \emph{code capacity noise models}.

%%%%%%%%%%%%%%%%
\subsection{Phenomenological Noise}
\label{subsec:Phenomenological Noise}

The \emph{phenomenological noise model} is the first type of noise model we
examine that accounts for faults during the syndrome extraction.
Here, we consider multiple rounds of syndrome measurements with a
depolarizing channel before each round.
Additionally, we allow for measurement errors by having $X$ error
locations right before each measurement \cite[Appendix~A]{gidney_new_2023}.
Note that it is enough to only consider $X$ errors at these points,
since that is the only type of error directly affecting the
measurement outcomes.
This model is depicted in \Cref{subfig:phenomenological}.

While not fully capturing all possible error mechanisms,
phenomenological noise is already a significant step beyond the code
capacity noise models.
Additionally, there are applications where the
consideration of phenomenological noise is enough.
It can, for example, be used to guide the design of fault-tolerant
circuitry [DTTBE25, Sec. 4.2].

%%%%%%%%%%%%%%%%
\subsection{Circuit-Level Noise}
\label{subsec:Circuit-Level Noise}

The most general type of noise model is \emph{circuit-level noise}.
Here we not only consider noise between syndrome extraction rounds
and at the measurements, but at each gate.
Specifically, we allow arbitrary $n$-qubit Pauli errors after each
$n$-qubit gate \cite[Def.~2.5]{derks_designing_2025}.
An $n$-qubit Pauli error is simply a series of correlated Pauli
errors on each related individual qubit.
This type of noise model is shown in \Cref{subfig:circuit_level}.

While phenomenological noise is useful for some design aspects of
fault tolerant circuitry, for simulations, circuit-level noise should
always be used \cite[Sec.~4.2]{derks_designing_2025}.
Note that this introduces new challenges during the decoding process,
as the decoding complexity is increased considerably due to the many
error locations.

\begin{figure}[t]
    \centering

    % tex-fmt: off
    \begin{quantikz}%[row sep=4mm, column sep=4mm]
        \lstick[3]{$\ket{\psi}_\text{L}$} & \ctrl{3} &          &          &          &           &                 \\
                                          &          & \ctrl{2} & \ctrl{3} &          &           &                 \\
                                          &          &          &          & \ctrl{2} &           &                 \\
        \lstick{$\ket{0}_{\text{A}_1}$}   & \targ{}  & \targ{}  &          &          &  \meter{} & \setwiretype{c} \\
        \lstick{$\ket{0}_{\text{A}_2}$}   &          &          & \targ{}  & \targ{}  &  \meter{} & \setwiretype{c}
    \end{quantikz}
    % tex-fmt: on

    \caption{
        Syndrome extraction circuit for the three-qubit repetition
        code under bit-flip noise.
    }
    \label{fig:pure_syndrome_extraction}
\end{figure}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Detector Error Models}
\label{sec:Detector Error Models}

\emph{Detector error models} (\acsp{dem}) constitute a standardized
framework for
passing information about a circuit used for \ac{qec} to a decoder.
They are also useful as a theoretical tool to aid in the design of
fault-tolerant \ac{qec} schemes.
E.g., they can be used to easily determine whether a measurement
schedule is fault-tolerant \cite[Example~12]{derks_designing_2025}.

Other approaches of implementing fault tolerance exist, such as
flag error correction, which uses additional ancilla qubits to detect
potentially damaging high-weight errors \cite[Sec.~1]{chamberland_flag_2018}.
However, \acp{dem} offer some unique advantages
\cite[Sec.~4.2]{derks_designing_2025}:
\begin{itemize}
    \item They distinguish between errors based on their effect on
        the measurements, not based on their location in the circuit.
        This allows for merging equivalent errors, which decreases
        decoding complexity.
    \item Errors on the data qubits and on the measurements are
        treated in a unified manner. This leads to a more powerful
        description of the overall circuit.
\end{itemize}
In this work, we only consider the process of decoding under the
\ac{dem} framework.

% Core idea

To achieve fault tolerance, the goal we strive towards is to
consider the internal errors in addition to the input errors during
the decoding process.
The core idea behind detector error models is to do this by defining
a new \emph{circuit code} that describes the circuit.
Each \ac{vn} of this new code corresponds to an error location in the
circuit and each \ac{cn} corresponds to a syndrome measurement.
% This circuit code, combined with the prior probabilities of error
% given by the noise model, incorporates all information necessary for decoding.

\begin{figure}[H]
    \centering

    \newcommand{\xerr}{\gate[style={fill=KITblue!50}]{\phantom{1}}}
    \newcommand{\xyzerr}{\gate[style={
                draw=black,
                fill=KITred,
                path picture={
                    % tex-fmt: off
                    \fill[KITblue!60]
                    ($(path picture bounding box.south west)+(0,0)$)
                    -- ($(path picture bounding box.north west)+(0,0)$)
                    -- ($(path picture bounding box.north west)+(0.28,0)$)
                    -- cycle;
                    \fill[KITorange!60]
                    ($(path picture bounding box.north east)+(0,0)$)
                    -- ($(path picture bounding box.south east)+(0,0)$)
                    -- ($(path picture bounding box.south east)+(-0.28,0)$)
                    -- cycle;
                    \fill[KITred!60]
                    ($(path picture bounding box.north east)+(0,0)$)
                    -- ($(path picture bounding box.south east)+(-0.28,0)$)
                    -- ($(path picture bounding box.south west)+(0,0)$)
                    -- ($(path picture bounding box.north west)+(0.28,0)$)
                    -- cycle;
                    % tex-fmt: on
                }
    }]{\phantom{1}}}

    \begin{minipage}{0.7\textwidth}
        \begin{minipage}{\textwidth}
            \centering
            % tex-fmt: off
            \begin{quantikz}[row sep=4mm, column sep=4mm]
                \lstick[3]{$\ket{\psi}_\text{L}$}        & \xerr & \ctrl{3} &            &          &           &           &                 \\
                                                & \xerr &          & \ctrl{2}   & \ctrl{3} &           &           &                 \\
                                                & \xerr &          &            &          & \ctrl{2}  &           &                 \\
                \lstick{$\ket{0}_{\text{A}_1}$} &       & \targ{}  & \targ{}    &          &           &  \meter{} & \setwiretype{c} \\
                \lstick{$\ket{0}_{\text{A}_2}$} &       &          &            & \targ{}  & \targ{}   &  \meter{} & \setwiretype{c}
            \end{quantikz}
            % tex-fmt: on

            \subcaption{Bit-flip noise.}
            \label{subfig:bit_flip}
        \end{minipage}

        \vspace*{7mm}

        \begin{minipage}{\textwidth}
            \centering
            % tex-fmt: off
            \begin{quantikz}[row sep=4mm, column sep=4mm]
                \lstick[3]{$\ket{\psi}_\text{L}$} & \xyzerr & \ctrl{3} &            &          &           &           &                 \\
                                                  & \xyzerr &          & \ctrl{2}   & \ctrl{3} &           &           &                 \\
                                                  & \xyzerr &          &            &          & \ctrl{2}  &           &                 \\
                \lstick{$\ket{0}_{\text{A}_1}$}   &         & \targ{}  & \targ{}    &          &           &  \meter{} & \setwiretype{c} \\
                \lstick{$\ket{0}_{\text{A}_2}$}   &         &          &            & \targ{}  & \targ{}   &  \meter{} & \setwiretype{c}
            \end{quantikz}
            % tex-fmt: on

            \subcaption{Depolarizing channel.}
            \label{subfig:depolarizing}
        \end{minipage}

        \vspace*{7mm}

        \begin{minipage}{\textwidth}
            \centering
            % tex-fmt: off
            \begin{quantikz}[row sep=4mm, column sep=4mm]
                \lstick[3]{$\ket{\psi}_\text{L}$} & \xyzerr & \ctrl{3} &           &          &          &       &           & \xyzerr        & & \setwiretype{n} &                                       \\
                                                  & \xyzerr &          & \ctrl{2}  & \ctrl{3} &          &       &           & \xyzerr         & & \setwiretype{n} & \gate[style={left,draw=none}]{\cdots} \\
                                                  & \xyzerr &          &           &          & \ctrl{2} &       &           & \xyzerr         & & \setwiretype{n} &                                       \\
                \lstick{$\ket{0}_{\text{A}_1}$}   &         & \targ{}  & \targ{}   &          &          & \xerr &  \meter{} & \setwiretype{c}                                                              \\
                \lstick{$\ket{0}_{\text{A}_2}$}   &         &          &           & \targ{}  & \targ{}  & \xerr &  \meter{} & \setwiretype{c}
            \end{quantikz}
            % tex-fmt: on

            \subcaption{Phenomenological noise.}
            \label{subfig:phenomenological}
        \end{minipage}

        \vspace*{7mm}

        \begin{minipage}{\textwidth}
            \centering
            % tex-fmt: off
            \begin{quantikz}[row sep=4mm, column sep=2mm]
                \lstick[3]{$\ket{\psi}_\text{L}$} & \xyzerr & \ctrl{3} & \xyzerr \wire[d][3]{q} &           &                        &          &                        &          &                        &       &           & \xyzerr          & & \setwiretype{n} &                                                    \\
                                                  & \xyzerr &          &                        & \ctrl{2}  & \xyzerr \wire[d][2]{q} & \ctrl{3} & \xyzerr \wire[d][3]{q} &          &                        &       &           & \xyzerr          & & \setwiretype{n} & \gate[style={left,draw=none,xshift=3.5mm}]{\cdots} \\
                                                  & \xyzerr &          &                        &           &                        &          &                        & \ctrl{2} & \xyzerr \wire[d][2]{q} &       &           & \xyzerr          & & \setwiretype{n} &                                                    \\
                \lstick{$\ket{0}_{\text{A}_1}$}   & \xyzerr & \targ{}  & \xyzerr                & \targ{}   & \xyzerr                &          &                        &          &                        & \xerr &  \meter{} & \setwiretype{c}                                                                           \\
                \lstick{$\ket{0}_{\text{A}_2}$}   & \xyzerr &          &                        &           &                        & \targ{}  & \xyzerr                & \targ{}  & \xyzerr                & \xerr &  \meter{} & \setwiretype{c}
            \end{quantikz}
            % tex-fmt: on

            \subcaption{Circuit-level noise.}
            \label{subfig:circuit_level}
        \end{minipage}
    \end{minipage}%
    \hfill%
    \begin{minipage}{0.23\textwidth}
        \centering
        % tex-fmt: off
        \begin{quantikz}[row sep=4mm, column sep=2mm]
            \setwiretype{n} & \xerr                            & \gate[style={right, draw=none, xshift=-15mm}]{\text{X error}}            \\
            \setwiretype{n} & \xyzerr                          & \gate[style={right, draw=none, xshift=-15mm}]{\text{X,Z, or Y error}}    \\
            \setwiretype{n} & \gate{\phantom{1}}\wire[d][1]{q} & \gate[style={right, draw=none, xshift=-15mm},2]{\text{Two-qubit error}} \\
            \setwiretype{n} & \gate{\phantom{1}}               &
        \end{quantikz}
        % tex-fmt: on
    \end{minipage}

    \vspace*{5mm}

    \caption{Types of noise models.}
    \label{fig:noise_model_types}
\end{figure}

%%%%%%%%%%%%%%%%
\subsection{Measurement Syndrome Matrix}
\label{subsec:Measurement Syndrome Matrix}

% Mathematical definition

We describe the circuit code using the \emph{measurement syndrome
matrix} $\bm{\Omega} \in \mathbb{F}_2^{M\times N}$, with
\begin{align*}
    \Omega_{\ell,i} =
    \begin{cases}
        1, & \text{Error $i$ flips measurement $\ell$}\\
        0, & \text{otherwise}
    \end{cases}
    ,%
\end{align*}
where $M \in \mathbb{N}$ is the number of measurements.
To obtain $\bm{\Omega}$, we must propagate Pauli errors through the
circuit, tracking which measurements they affect
\cite[Sec.~2.4]{derks_designing_2025}.

% Example

We turn to our example of the three-qubit repetition code to
illustrate the construction of the syndrome measurement matrix.
We begin by extending our check matrix in \Cref{eq:rep_code_H}
to represent three rounds of syndrome extraction.
Each round yields an additional set of syndrome bits,
and we combine them by stacking them in a new vector
$\bm{s} \in \mathbb{F}_2^{R(n-k)}$.
We thus have to replicate the rows of $\bm{\Omega}$, once for each
additional syndrome measurement, to obtain
\begin{align*}
    \bm{\Omega} =
    \begin{pmatrix}
        1 & 1 & 0 \\
        0 & 1 & 1 \\
        1 & 1 & 0 \\
        0 & 1 & 1 \\
        1 & 1 & 0 \\
        0 & 1 & 1 \\
    \end{pmatrix}
    .%
\end{align*}
\Cref{fig:rep_code_multiple_rounds_bit_flip}
depicts the corresponding circuit.
Note that we have not yet introduced error locations in the syndrome
extraction circuitry, so we still consider only bit flip noise at this stage.
Recall that $\bm{\Omega}$ describes which \ac{vn} is connected to
which parity check and the syndrome indicates which parity checks
are violated.
This means that if an error exists at only a single \ac{vn}, we can
read off the syndrome in the corresponding column.
If errors occur at multiple locations, the resulting syndrome will be
the linear combination of the respective columns.
We thus have
\begin{align*}
    \bm{s} \in \text{span} \{\bm{\Omega}\}
    .%
\end{align*}

% Expand to phenomenological

We now wish to expand the error model to phenomenological noise, though
only considering $X$ errors in this case.
We introduce new error locations at the appropriate positions,
arriving at the circuit depicted in
\Cref{fig:rep_code_multiple_rounds_phenomenological}.
For each additional error location, we extend $\bm{\Omega}$ by
appending the corresponding syndrome vector as a column.
\begin{gather}
    \label{eq:syndrome_matrix_ex}
    \bm{\Omega} =
    \left(
        \begin{array}{ccccccccccccccc}
            1 & 1 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0
            & 0 & 0 & 0 & 0 & 0  \\
            0 & 1 & 1 & 0 & 1 & 0 & 0 & 0 & 0 & 0
            & 0 & 0 & 0 & 0 & 0  \\
            1 & 1 & 0 & 0 & 0 & 1 & 1 & 0 & 1 & 0
            & 0 & 0 & 0 & 0 & 0  \\
            0 & 1 & 1 & 0 & 0 & 0 & 1 & 1 & 0 & 1
            & 0 & 0 & 0 & 0 & 0  \\
            1 & 1 & 0 & 0 & 0 & 1 & 1 & 0 & 0 & 0
            & 1 & 1 & 0 & 1 & 0  \\
            0 & 1 & 1 & 0 & 0 & 0 & 1 & 1 & 0 & 0
            & 0 & 1 & 1 & 0 & 1
        \end{array}
    \right) . \\[-6mm]
    \hspace*{-58.7mm}
    \underbrace{
        \phantom{
            \begin{array}{ccc}
                0 & 0 & 0
            \end{array}
        }
    }_\text{Original matrix}
\end{gather}
Notice that the first three columns correspond to the original
measurement syndrome matrix, as these columns correspond to the error
locations on the data qubits.

In this example, all measurements we considered were syndrome measurements.
Assuming no errors, the results of those measurements were
deterministic, irrespective of the actual logical state
$\ket{\psi}_\text{L}$, as they only depend on whether
$\ket{\psi}_\text{L} \in \mathcal{C}$, not on the concrete state.
It is, in general, possible to also consider non-deterministic measurements.
As an example, it is usual to consider a round of noiseless
measurements of the actual data qubit states after the last syndrome
extraction round.

\begin{figure}[t]
    \centering

    \newcommand{\preperr}[1]{
        \gate[style={fill=blue!20}]{\scriptstyle #1}
    }

    \begin{minipage}{0.3\textwidth}
        \centering
        \begin{tikzpicture}
            \node{$%
                \bm{\Omega} =
                \begin{pmatrix}
                    1 & 1 & 0 \\
                    0 & 1 & 1 \\
                    1 & 1 & 0 \\
                    0 & 1 & 1 \\
                    1 & 1 & 0 \\
                    0 & 1 & 1
                \end{pmatrix}%
                $
            };

            \draw [
                line width=1pt,
                decorate,
                decoration={brace,mirror,amplitude=3mm,raise=5mm}
            ]
            (1,0.55) -- (1,1.4)
            node[midway,right,xshift=10mm]{$\text{SE}_1$};

            \draw [
                line width=1pt,
                decorate,
                decoration={brace,mirror,amplitude=3mm,raise=5mm}
            ]
            (1,-0.4) -- (1,0.45)
            node[midway,right,xshift=10mm]{$\text{SE}_2\hspace{2mm},$};

            \draw [
                line width=1pt,
                decorate,
                decoration={brace,mirror,amplitude=3mm,raise=5mm}
            ]
            (1,-1.38) -- (1,-0.5)
            node[midway,right,xshift=10mm]{$\text{SE}_3$};
        \end{tikzpicture}
    \end{minipage}%
    \begin{minipage}{0.3\textwidth}
        \centering
        \vspace*{-6mm}
        \begin{gather*}
            \bm{s} \in \text{span} \mleft\{ \bm{\Omega} \mright\}
        \end{gather*}
    \end{minipage}

    \vspace*{5mm}

    \begin{quantikz}[
            row sep=4mm, column sep=3.4mm,
            wire types={q,q,q,q,q,n,n,n,n},
            execute at end picture={
                \draw [
                    line width=1pt,
                    decorate,
                    decoration={brace,amplitude=3mm,raise=9mm}
                ]
                (\tikzcdmatrixname-4-19.north east)
                --
                (\tikzcdmatrixname-5-19.south east)
                node[midway,right,xshift=14mm]{$\text{SE}_1$};
                \draw [
                    line width=1pt,
                    decorate,
                    decoration={brace,amplitude=3mm,raise=9mm}
                ]
                (\tikzcdmatrixname-6-19.north east)
                --
                (\tikzcdmatrixname-7-19.south east)
                node[midway,right,xshift=14mm]{$\text{SE}_2$};
                \draw [
                    line width=1pt,
                    decorate,
                    decoration={brace,amplitude=3mm,raise=9mm}
                ]
                (\tikzcdmatrixname-8-19.north east)
                --
                (\tikzcdmatrixname-9-19.south east)
                node[midway,right,xshift=14mm]{$\text{SE}_3$};
            }
        ]
            % tex-fmt: off
            \lstick[3]{$\ket{\psi}_\text{L}$}        & \preperr{E_0} & \ctrl{3} &           &          &          &                                 &                 & \ctrl{5} &           &          &          &                                 &                 & \ctrl{7} &           &          &          &           &                 \\
                                            & \preperr{E_1} &          & \ctrl{2}  & \ctrl{3} &          &                                 &                 &          &  \ctrl{4} & \ctrl{5} &          &                                 &                 &          & \ctrl{6}  & \ctrl{7} &          &           &                 \\
                                            & \preperr{E_2} &          &           &          & \ctrl{2} &                                 &                 &          &           &          & \ctrl{4} &                                 &                 &          &           &          & \ctrl{6} &           &                 \\
            \lstick{$\ket{0}_{\text{A}_1}$} &               & \targ{}  & \targ{}   &          &          &                                 &                 &          &           &          &          &                                 &                 &          &           &          &          &  \meter{} & \setwiretype{c} \\
            \lstick{$\ket{0}_{\text{A}_2}$} &               &          &           & \targ{}  & \targ{}  &                                 &                 &          &           &          &          &                                 &                 &          &           &          &          &  \meter{} & \setwiretype{c} \\
                                            &               &          &           &          &          & \lstick{$\ket{0}_{\text{A}_3}$} & \setwiretype{q} & \targ{}  &  \targ{}  &          &          &                                 &                 &          &           &          &          &  \meter{} & \setwiretype{c} \\
                                            &               &          &           &          &          & \lstick{$\ket{0}_{\text{A}_4}$} & \setwiretype{q} &          &           &  \targ{} & \targ{}  &                                 &                 &          &           &          &          &  \meter{} & \setwiretype{c} \\
                                            &               &          &           &          &          &                                 &                 &          &           &          &          & \lstick{$\ket{0}_{\text{A}_5}$} & \setwiretype{q} & \targ{}  &  \targ{}  &          &          &  \meter{} & \setwiretype{c} \\
                                            &               &          &           &          &          &                                 &                 &          &           &          &          & \lstick{$\ket{0}_{\text{A}_6}$} & \setwiretype{q} &          &           &  \targ{} & \targ{}  &  \meter{} & \setwiretype{c}
            % tex-fmt: on
    \end{quantikz}

    \caption{
        Repeated syndrome extraction circuit for the three-qubit
        repetition code under bit flip noise.
    }
    \label{fig:rep_code_multiple_rounds_bit_flip}
\end{figure}

\begin{figure}[t]
    \begin{gather*}
        \hspace*{-33.3mm}%
        \begin{array}{c}
            E_6 \\
            \downarrow
        \end{array}
    \end{gather*}
    \vspace*{-8mm}
    \begin{gather*}
        \bm{\Omega} =
        \left(
            \begin{array}{
                    cccccc%
                    >{\columncolor{red!20}}c%
                    cccccccc
                }
                1 & 1 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0
                & 0 & 0 & 0 & 0 & 0  \\
                0 & 1 & 1 & 0 & 1 & 0 & 0 & 0 & 0 & 0
                & 0 & 0 & 0 & 0 & 0  \\
                1 & 1 & 0 & 0 & 0 & 1 & 1 & 0 & 1 & 0
                & 0 & 0 & 0 & 0 & 0  \\
                0 & 1 & 1 & 0 & 0 & 0 & 1 & 1 & 0 & 1
                & 0 & 0 & 0 & 0 & 0  \\
                1 & 1 & 0 & 0 & 0 & 1 & 1 & 0 & 0 & 0
                & 1 & 1 & 0 & 1 & 0  \\
                0 & 1 & 1 & 0 & 0 & 0 & 1 & 1 & 0 & 0
                & 0 & 1 & 1 & 0 & 1
            \end{array}
        \right),
        \hspace*{7mm}
        \bm{s} \in \text{span} \mleft\{
        \bm{\Omega} \mright\}
    \end{gather*}

    \vspace*{5mm}

    \newcommand{\preperr}[1]{
        \gate[style={fill=blue!20}]{\scriptstyle #1}
    }
    \newcommand{\measerr}{\gate[style={fill=blue!20}]{\phantom{1}}}

    \newcommand{\noise}{
        \gate[style={noisy}]{\text{\small X}}%
        \setwiretype{n}%
        \wire[l][1]{q}
    }
    \newcommand{\redwire}[1]{
        \wire[r][#1][style={draw=red, line width=1.5pt}]{q}
    }
    \newcommand{\redtarg}{
        \targ[style={draw=red}]{}%
        \setwiretype{n}%
        \wire[l][1]{q}
    }
    \newcommand{\redctrl}[1]{
        \ctrl[style={draw=red,fill=red,line width=1.5pt}]{#1}
    }
    \newcommand{\redmeter}{\meter[style={draw=red,fill=red!20}]{}}

    \tikzset{
        noisy/.style={
            starburst,
            starburst point height=2.5mm,
            fill=red!25, draw=red!85!black,
            line width=1.5pt,
            inner xsep=-2pt, inner ysep=-2pt
        },
    }

    \centering

    % tex-fmt: off
    \begin{quantikz}[row sep=4mm, column sep=3mm, wire types={q,q,q,q,q,n,n,n,n}]
        \lstick[3]{$\ket{\psi}_\text{L}$} & \preperr{E_0}         & \ctrl{3} &           &          &          & \preperr{E_5}                   &                 & \ctrl{5} &                      &                     &          & \preperr{E_{10}}                &                 & \ctrl{7} &                     &                     &          &                  &                                                                    &                 \\
                                          & \preperr{E_1}         &          & \ctrl{2}  & \ctrl{3} &          & \noise\redwire{14}              &                 &          & \redctrl{4}          & \redctrl{5}         &          & \preperr{E_{11}}                &                 &          & \redctrl{6}         & \redctrl{7}         &          &                  &                                                                    &                 \\
                                          & \preperr{E_2}         &          &           &          & \ctrl{2} & \preperr{E_7}                   &                 &          &                      &                     & \ctrl{4} & \preperr{E_{12}}                &                 &          &                     &                     & \ctrl{6} &                  &                                                                    &                 \\
        \lstick{$\ket{0}_{\text{A}_1}$}   &                       & \targ{}  & \targ{}   &          &          &                                 &                 &          &                      &                     &          &                                 &                 &          &                     &                     &          & \preperr{E_3}    & \meter{}                                                           & \setwiretype{c} \\
        \lstick{$\ket{0}_{\text{A}_2}$}   &                       &          &           & \targ{}  & \targ{}  &                                 &                 &          &                      &                     &          &                                 &                 &          &                     &                     &          & \preperr{E_4}    & \meter{}                                                           & \setwiretype{c} \\
                                          &                       &          &           &          &          & \lstick{$\ket{0}_{\text{A}_3}$} & \setwiretype{q} & \targ{}  & \redtarg\redwire{10} &                     &          &                                 &                 &          &                     &                     &          & \preperr{E_8}    & \redmeter\wire[r][1][style={draw=red,double, line width=1.5pt}]{q} & \setwiretype{n} \\
                                          &                       &          &           &          &          & \lstick{$\ket{0}_{\text{A}_4}$} & \setwiretype{q} &          &                      & \redtarg\redwire{9} & \targ{}  &                                 &                 &          &                     &                     &          & \preperr{E_9}    & \redmeter\wire[r][1][style={draw=red,double, line width=1.5pt}]{q} & \setwiretype{n} \\
                                          &                       &          &           &          &          &                                 &                 &          &                      &                     &          & \lstick{$\ket{0}_{\text{A}_5}$} & \setwiretype{q} & \targ{}  & \redtarg\redwire{4} &                     &          & \preperr{E_{13}} & \redmeter\wire[r][1][style={draw=red,double, line width=1.5pt}]{q} & \setwiretype{n} \\
                                          &                       &          &           &          &          &                                 &                 &          &                      &                     &          & \lstick{$\ket{0}_{\text{A}_6}$} & \setwiretype{q} &          &                     & \redtarg\redwire{3} & \targ{}  & \preperr{E_{14}} & \redmeter\wire[r][1][style={draw=red,double, line width=1.5pt}]{q} & \setwiretype{n}
    \end{quantikz}
    % tex-fmt: on

    \caption{
        Repeated syndrome extraction circuit for the three-qubit
        repetition code under phenomenological noise.
    }
    \label{fig:rep_code_multiple_rounds_phenomenological}
\end{figure}

%%%%%%%%%%%%%%%%
\subsection{Detector Matrix}
\label{subsec:Detector Matrix}

% Core idea

Instead of using stabilizer measurement results directly, we
generalize the notion of what constitutes a parity check slightly.
We formally define a \emph{detector} as a deterministic parity constraint on
a set of measurement outcomes \cite[Def.~2.1]{derks_designing_2025}.
In the most straightforward case, we may simply use the stabilizer
measurements as detectors.
We immediately recognize that we will have as many linearly
independent detectors as there are separate deterministic measurements.
We generally aim to utilize the maximum number of linearly
independent detectors \cite[Sec.~2.2]{derks_designing_2025}.

% The detector matrix

We describe the relationship between measurements and detectors using
the \emph{detector matrix} $\bm{D} \in \mathbb{F}_2^{D\times M}$
\cite[Def.~2.2]{derks_designing_2025}, with $~D\in \mathbb{N}$
denoting the number of detectors.
Similar to the way a \ac{pcm} associates bits with parity checks, the
detector matrix links measurements and detectors.
Each column corresponds to a measurement, while each rows corresponds
to a detector.
We should note at this point that the combination of measurements
into detectors has no bearing on the actual construction of the
syndrome extraction circuitry.
It is something that happens ``virtually'' after the fact and only
affects the decoder.

Note that we can use the detector matrix $\bm{D}$ to describe the set
of possible measurement outcomes under the absence of noise.
The same way we use a \ac{pcm} to describe the code space as
\begin{align*}
    \mathcal{C}
    = \{ \bm{x} \in \mathbb{F}_2^{n} : \bm{H}\bm{x}^\text{T} = \bm{0} \}
    ,%
\end{align*}
the set of possible measurement outcomes is simply $\text{kern}\{\bm{D}\}$
\cite[Sec.~2.2]{derks_designing_2025}.

%%%%%%%%%%%%%%%%
\subsection{Detector Error Matrix}
\label{subsec:Detector Error Matrix}

% The detector error matrix

We now know how the errors at different locations in the circuit
affect the measurements (through $\bm{\Omega}$), and we know how the
measurements relate to the detectors (through $\bm{D}$).
For decoding, we are interested in the effect of the errors on the
detectors directly.
We thus construct the \emph{detector error matrix} $\bm{H} \in
\mathbb{F}_2^{D\times N}$ \cite[Def.~2.9]{derks_designing_2025} as
\begin{align*}
    \bm{H} := \bm{D}\bm{\Omega}
    .%
\end{align*}

% There are multiple ways of choosing the detectors

There is a degree of freedom in how we choose the detectors, which is
reflected in the fact that we can construct multiple different
detector matrices $\bm{D}$ from the same circuit.
For two detector matrices $\bm{D}_1$ and $\bm{D}_2$, as long as
\begin{gather}
    \label{eq:kern_condition}
    \text{kern}\{\bm{D}_1\} = \text{kern}\{\bm{D}_2\}
\end{gather}
they describe the same set of possible measurement outcomes (under
the absence of noise) and thus the same circuit.
In fact, as long as \Cref{eq:kern_condition} holds, the detector
error matrices constructed from them can distinguish between the
same pairs of error sets \cite[Lemma~6]{derks_designing_2025}.
To see this, we note that we can distinguish between two circuit
error vectors $\bm{e}_1$ and $\bm{e}_2$ as long as they do not
violate the same set of detectors, i.e.,
\begin{align*}
    \hspace{-15mm}
    % tex-fmt: off
                        && \bm{H} \bm{e}_1^\text{T} & \neq \bm{H} \bm{e}_2^\text{T} \\
    \iff \hspace{-33mm} && \bm{H} \left( \bm{e}_1 - \bm{e}_2 \right)^\text{T} & \neq 0 \\
    \iff \hspace{-33mm} && \bm{D} \bm{\Omega} \left( \bm{e}_1 - \bm{e}_2 \right)^\text{T} & \neq 0 \\
    \iff \hspace{-33mm} && \bm{\Omega} \left( \bm{e}_1 - \bm{e}_2 \right)^\text{T} & \notin \text{kern} \{\bm{D}\}
    % tex-fmt: on
    .%
\end{align*}
We conclude that altering our perspective by choosing a different
detector matrix
does not modify the error correcting capabilities of the code.
It may, however, change the decoding performance when using a practical decoder.

% How to choose the detectors

What constitutes a good set of detectors is difficult to assess
without performing explicit decoding simulations, since it ultimately
depends on the decoder employed.
For iterative decoders, high sparsity is generally beneficial, but
finding detectors that maximize sparsity is an NP-complete problem
\cite[Sec.~2.6]{derks_designing_2025}.
There is, however, one way of defining the detectors that will prove useful
at a later stage.
To the measurement results from each syndrome extraction round we
can add the results from the previous round, as illustrated in
\Cref{fig:detectors_from_measurements_general}.
We thus have $D=n-k$.
Concretely, we denote the outcome of
measurement $\ell \in [1:n-k]$ in round $r \in [1:R]$ by
$m_\ell^{(r)} \in \mathbb{F}_2$
and define
\begin{gather*}
    \bm{m}^{(r)} :=
    \begin{pmatrix}
        m_1^{(r)} \\
        \vdots \\
        m_{n-k}^{(r)}
    \end{pmatrix}
    .%
\end{gather*}
Similarly, we denote the outcome of detector $j\in[1:D]$ in
round $r$ by $d_j^{(r)} \in \mathbb{F}_2$ and define
\begin{gather}
    \label{eq:measurement_combination}
    \bm{d}^{(r)} =
    \begin{pmatrix}
        d_1^{(r)} \\
        \vdots \\
        d_D^{(r)}
    \end{pmatrix}
    := \bm{m}^{(r)} + \bm{m}^{(r-1)}
    ,%
\end{gather}
with $\bm{m}^{(0)} = \bm{0}$.

\begin{figure}[t]
    \centering

    \tikzset{
        gate/.style={
            draw, %line width=1pt,
            minimum height=2cm,
        }
    }

    % tex-fmt: off
    \begin{quantikz}[row sep=2mm, column sep=4mm, wire types={q,q,q,n,n,n}]
        \lstick[3]{$\ket{\psi}_\text{L}$} & \gate[3]{\text{SE}_1}          &                & \gate[3]{\text{SE}_2}                   &                & \gate[3]{\text{SE}_3}                   &                & \gate[3]{\text{SE}_4}                   &                            \\
                                          &                                &                &                                         &                &                                         &                &                                         & & \setwiretype{n} & \ldots \\
                                          & \wire[d][3]{c}                 &                & \wire[d][1]{c}                          &                & \wire[d][1]{c}                          &                & \wire[d][1]{c}                          &                            \\
                                          & \ctrl[wire=c]{0}\wire[r][1]{c} & \wire[d][1]{c} & \ctrl[vertical wire=c]{1}\wire[r][1]{c} & \wire[d][1]{c} & \ctrl[vertical wire=c]{1}\wire[r][1]{c} & \wire[d][1]{c} & \ctrl[vertical wire=c]{1}\wire[r][1]{c} &                            \\
                                          &                                & \wire[r][1]{c} & \targ{}\wire[d][1]{c}                   & \wire[r][1]{c} & \targ{}\wire[d][1]{c}                   & \wire[r][1]{c} & \targ{}\wire[d][1]{c}                   &                            \\
                                          & \gate[1]{\bm{d}^{(1)}}             &                & \gate[1]{\bm{d}^{(2)}}                      &                & \gate[1]{\bm{d}^{(3)}}                      &                & \gate[1]{\bm{d}^{(4)}}                      &                            \\
    \end{quantikz}
    % tex-fmt: on

    \caption{Construction of detectors from measurements in the general case.}
    \label{fig:detectors_from_measurements_general}
\end{figure}

We again turn our attention to the three-qubit repetition code.
In \Cref{fig:rep_code_multiple_rounds_phenomenological} we can see
that $E_6$ has occurred and has subsequently tripped the last four measurements.
We now take those measurements and combine them according to
\Cref{eq:measurement_combination}.
We can see this process graphically in
\Cref{fig:detectors_from_measurements_rep_code}.
To understand why this way of defining the detectors is useful, we
note that the error $E_6$ in
\Cref{fig:rep_code_multiple_rounds_phenomenological} has not only
tripped the measurements in the syndrome extraction round immediately
afterwards, but all subsequent ones as well.
To only see errors in the rounds immediately following them, we
consider our newly defined detectors instead of the measurements,
that effectively compute the difference between the measurements.

Each error can only trip syndrome bits that follow it.
This is reflected in the triangular structure of $\bm{\Omega}$ in
\Cref{eq:syndrome_matrix_ex}.
Combining the measurements into detectors according to
\Cref{eq:measurement_combination}, we are effectively performing
row additions in such a way as to clear the bottom left of the matrix.
The detector error matrix
\begin{align*}
    \bm{H} =
    \left(
        \begin{array}{ccccccccccccccc}
            1 & 1 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0  \\
            0 & 1 & 1 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0  \\
            0 & 0 & 0 & 1 & 0 & 1 & 1 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0  \\
            0 & 0 & 0 & 0 & 1 & 0 & 1 & 1 & 0 & 1 & 0 & 0 & 0 & 0 & 0  \\
            0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 1 & 1 & 0 & 1 & 0  \\
            0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 1 & 1 & 0 & 1
        \end{array}
    \right)
\end{align*}
we obtain this way has a block-diagonal structure.
Note that we exploit the fact that each syndrome measurement round is
identical to obtain this structure.

\begin{figure}[t]
    \centering

    \newcommand{\redwire}[1]{
        \wire[r][#1][style={draw=red, line width=1.5pt, double}]{q}
    }
    \newcommand{\inwire}{
        \wire[l][1][style={draw=red, line width=1.5pt}]{q}
    }
    \newcommand{\redtarg}{
        \targ[style={draw=red,line width=1.5pt}]{}%
        \setwiretype{n}%
    }
    \newcommand{\redctrl}[1]{
        \ctrl[style={draw=red,fill=red, line width=1.5pt}]{0}%
        \wire[d][#1][style={draw=red, line width=1.5pt, double}]{q}
    }
    \newcommand{\redmeter}{\meter[style={draw=red,fill=red!20}]{}}
    \newcommand{\redgate}[1]{\gate[style={draw=red,fill=red!20}]{\textcolor{red}{#1}}}

    % tex-fmt: off
    \begin{quantikz}[row sep=4mm, column sep=3mm, wire types={n,n,n,n,n,n}]
        & \meter{}\wire[l][1]{q}\wire[r][1]{c} & \setwiretype{c}               &                           &             & \ctrl[vertical wire=c]{2} &                           & \gate{D_1} \\
        & \meter{}\wire[l][1]{q}\wire[r][1]{c} & \setwiretype{c}               &                           &             &                           & \ctrl[vertical wire=c]{2} & \gate{D_2} \\
        & \redmeter{}\inwire\redwire{6} &      & \redctrl{2}                   &                           & \targ{}     &                           & \redgate{D_3} \\
        & \redmeter{}\inwire\redwire{6} &      &                               & \redctrl{2}               &             & \targ{}                   & \redgate{D_4} \\
        & \redmeter{}\inwire\redwire{2} &      & \redtarg\wire[r][4]{c}        &                           &             &                           & \gate{D_5} \\
        & \redmeter{}\inwire\redwire{3} &      &                               & \redtarg\wire[r][3]{c}    &             &                           & \gate{D_6}
    \end{quantikz}
    % tex-fmt: on

    \caption{Construction of detectors from the measurements of a
    three-qubit repetition code.}
    \label{fig:detectors_from_measurements_rep_code}
\end{figure}

%%%%%%%%%%%%%%%%
\subsection{Detector Error Models}
\label{subsec:Detector Error Models}

A \emph{detector error model} is the combination of the detector
error matrix $\bm{H}$ and the noise model $\bm{p}$.
\cite[Sec.~6]{derks_designing_2025}.
It serves as an abstract representation of a circuit and can be used
both to transfer information to a decoder but also to aid in the
design of fault-tolerant systems.
E.g., it can be used to investigate the properties of a circuit with
respect to fault tolerance.
It contains all information necessary for the decoding process.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Practical Considerations}
\label{sec:Practical Considerations}

The previous sections give an overview over available noise models
and the function of \acp{dem}.
In order to successfully apply these concepts in practice, we must
consider a few further aspects.

%%%%%%%%%%%%%%%%
\subsection{Choice of Noise Model}
\label{subsec:Choice of Noise Model}

While these types of noise models give us some constraints on the
types and locations of errors, the question of how exactly to choose
their probabilities remains.
When performing simulations, we typically sweep a range of values of
the \emph{physical error rate} $p$, and there are different ways of
obtaining the noise model $\bm{p}$ from this physical error rate.
For the depolarizing channel in particular, we usually choose the
same error rate $p/3$ for $X$, $Z$, and $Y$ errors.
For circuit-level noise, various options exist, such as the \emph{SI1000}
(superconducting inspired) or the \emph{EM3} (entangling
measurements) models \cite[Sec.~2.1]{gidney_fault-tolerant_2021}.
These differ in the way they compute individual error probabilities
from the physical error rate.

In this work we only consider \emph{standard circuit-based depolarizing
noise}, as this is the standard approach in the literature.
We thus set the error probabilities of all error locations in the
circuit-level noise model to the same value, the physical error rate
$p_\text{phys}$.

%%%%%%%%%%%%%%%%
\subsection{Per-Round Logical Error Rate}
\label{subsec:Per-Round Logical Error Rate}

% Per-round LER

Another aspect that is important to consider is the meaning of the
\ac{ler} in the context of a \ac{qec} system with multiple
rounds of syndrome measurements.
In order to facilitate the comparability of results obtained from
simulations with different numbers of syndrome extraction rounds, we
use the \emph{per-round-\ac{ler}}.

The simplest way of calculating the per-round \ac{ler} is by modeling
each round as an independent experiment.
For each experiment, an error might occur with a certain probability
$p_\text{e,round}$.
The overall probability of error is then
\begin{align}
    \hspace{-12mm}
    p_\text{e,total} &= 1 - (1 - p_\text{e,round})^{R} \nonumber\\
    \label{eq:per_round_ler}
    \implies \hspace{3mm} p_\text{e,round} &=
    1 - (1 - p_\text{e,total})^{1 / R}
    .%
    \hspace{12mm}
\end{align}
We approximate $p_\text{e,total}$ using a Monte Carlo simulation and
compute the per-round-\ac{ler} using \Cref{eq:per_round_ler}.
This is a common approach taken in the literature
\cite{gong_toward_2024}\cite{wang_fully_2025}.

Another common approach \cite{chen_exponential_2021}%
\cite{bausch_learning_2024}\cite{beni_tesseract_2025} is to assume an
exponential decay for the decoder's \emph{logical fidelity}
\cite[Eq.~2]{bausch_learning_2024}
\begin{align*}
    F_\text{total} = (F_\text{round})^{R}
    .%
\end{align*}
The logical fidelity is a measure of the quality of a logical state
\cite[Appendix~E]{postler_demonstration_2024}.
As it is related to the error rate through $F = 1 - 2p$, we obtain
\cite[Eq.~4]{bausch_learning_2024}
\begin{align}
    (1 - 2p_\text{e,total}) &= (1 - 2p_\text{e,round})^{R} \nonumber\\
    \implies \hspace{15mm} p_\text{e,round} &= \frac{1}{2}
    \left[ 1 - (1 - 2p_\text{e,total})^{1/R} \right]
    .%
\end{align}

We have chosen to use the first approach, i.e.,
\Cref{eq:per_round_ler}, as the related literature is closer in
topic to our own work.

%%%%%%%%%%%%%%%%
\subsection{Stim}
\label{subsec:Stim}

It is not immediately apparent how the \ac{dem} will look from looking
at a code's \ac{pcm}, because it heavily depends on the exact circuit
construction and choice of noise model.
As we noted in \Cref{subsec:Measurement Syndrome Matrix}, we can
obtain a measurement syndrome matrix by propagating Pauli frames
through the circuit.
The standard choice of simulation tool used for this purpose is
\emph{stim}%
\footnote{https://github.com/quantumlib/Stim}
\cite{gidney_stim_2021}, which is available as a Python 3
pypi package.
In fact, it was in this tool that the concept of the \ac{dem} was
first introduced.

One capability of stim, and \acp{dem} in general, that we didn't go
into detail about in this chapter is the merging of error mechanisms.
Since \acp{dem} differentiate errors based on their effect on the
measurements and not on their Pauli type and location
\cite[Sec.~1.4.3]{higgott_practical_2024}, it is natural to group
errors that have the same effect.
This slightly lowers the computational complexity of decoding, as the
number of resulting \acp{vn} is reduced.

While stim is a useful tool for circuit simulation, it doesn't
include many utilities for building syndrome extraction circuitry automatically.
The user has to define most, if not all, of the circuit manually,
depending on the code in question.
This is somewhat natural, as stim is meant first and foremost as a
simulator, and circuit generation is contingent upon the \ac{qec}
scheme in question.

