# Lesson 28 — From ideal qubits to error-corrected machines

## A long computation changes the reliability requirement

Lesson 27 counted the complete logical workload rather than one convenient component. We now ask what it takes to execute that workload with imperfect physical operations. Twelve occupation qubits for the selected nitrogen model do not imply a twelve-qubit fault-tolerant machine. Those logical data may need many physical qubits, repeated syndrome measurements, classical decoding, routing space, and non-Clifford resource-state factories.

The chemistry sources remain pinned to `97a3ff4f`. For external models, this chapter also inspects public Microsoft QDK source at commit `95c039f4b0447928aa041f5ae5ad52e7041d8937` and public documentation reviewed for this chapter. Those sources describe model implementations and assumptions, not a verified installed package or measured hardware. No error-correction simulation, resource estimate, or physical experiment is performed here.

Suppose N operations each have an independent fault probability p. The probability of at least one fault is \(1-(1-p)^N\), approximately Np only when Np is small. In a hypothetical million-operation experiment with p=\(10^{-6}\), that probability is about 63%. Even individually reliable operations can therefore produce an unreliable long computation.

A fault is not necessarily a wrong final answer: some faults cancel or do not affect the observable. Error correction deliberately makes many physical faults harmless. The relevant failure rate is ultimately the rate of **logical** faults that change the encoded information or computation, not simply the number of physical imperfections. The example is probability arithmetic, not a specification or measurement of any device.

## Physical and logical qubits

A **physical qubit** is a hardware degree of freedom manipulated and measured by a device. A **logical qubit** is encoded information protected across multiple physical degrees of freedom. Its basis states \(|0_L\rangle\) and \(|1_L\rangle\) are collective states of a code block, not individual hardware bits.

The no-cloning theorem forbids copying an arbitrary unknown state into independent copies. Error-correction encoding does not do that. For instance, a toy encoding can map

\[
(\alpha|0\rangle+\beta|1\rangle)|00\rangle
\longmapsto\alpha|000\rangle+\beta|111\rangle.
\]

The output is generally entangled, not three copies of \(\alpha|0\rangle+\beta|1\rangle\). Information is distributed into a larger correlated subspace in a reversible way. We can ask carefully chosen questions about error syndromes without learning the amplitudes \(\alpha,\beta\).

A bit-flip error acts like X. A phase-flip error acts like Z, changing relative phase rather than occupation probabilities. Y combines the two up to phase. General small errors can be analyzed through combinations of such operators, but real devices may also have leakage, loss, coherent drift, biased noise, and correlations. A code/noise model must specify what its claimed protection covers.

The **codespace** is the subspace representing valid encoded states. A **logical operator** acts nontrivially within that codespace, such as exchanging \(|0_L\rangle\) and \(|1_L\rangle\). Not every physical error produces a detectable syndrome; an unfortunate combination can mimic a logical operator.

## Measuring a syndrome without measuring the logical state

Consider the three-qubit bit-flip repetition encoding above. The parity checks \(Z_0Z_1\) and \(Z_1Z_2\) both have eigenvalue +1 for either encoded basis state, and therefore for every superposition in the codespace. Measuring these joint parities does not distinguish \(\alpha|000\rangle+\beta|111\rangle\) from another logical superposition.

The pair of check outcomes is an **error syndrome**. A single X on qubit 0 gives syndrome (−1,+1); X on qubit 1 gives (−1,−1); X on qubit 2 gives (+1,−1). Under the promise of at most one bit flip and ideal checks, these outcomes identify which correction to apply. Auxiliary check qubits can collect a parity and be measured while the encoded data remain coherent.

This is not a complete quantum memory. A Z error on one data qubit changes the relative logical phase without changing those Z-parity checks. The toy code protects one error type but not arbitrary qubit errors. A quantum error-correcting code must address both bit- and phase-like errors, with a carefully compatible set of checks.

In stabilizer codes, checks are commuting Pauli operators that define the codespace by their eigenvalues. This reuses the stabilizer vocabulary from Lesson 15, but the purpose differs. Chemical tapering uses an already known conserved sector to remove redundant problem variables; QEC adds physical redundancy to protect unknown logical amplitudes. A chemical Z₂ symmetry and a hardware-code stabilizer are not interchangeable data.

Real check measurements can themselves be wrong. Repeating checks over time lets a **decoder**, a classical algorithm, infer a likely error history from changes in the syndrome. Different physical histories can give the same observed checks. Choosing a correction with the wrong logical effect produces a logical failure. A resource model that supplies a fitted logical-error rate is not automatically running a detailed decoder or simulating each noisy check circuit.

## Distance, threshold, and the assumptions behind suppression

The **code distance** d is the minimum weight of a nontrivial logical operator, where weight counts affected physical qubits, for the usual ideal code definition. A distance-d code can correct up to \(\lfloor(d-1)/2\rfloor\) arbitrary Pauli errors under the corresponding ideal-syndrome assumptions. Faulty measurements and gates require a fault-tolerant extraction/decoding process; distance alone does not prove the complete circuit has that performance.

A **threshold** is an error-rate boundary below which increasing code size can suppress logical error under a specified noise, connectivity, extraction, and decoding model. It is not a universal material constant or a guarantee that every correlated error process is corrected. Operating above a model’s threshold cannot be repaired merely by asking the estimator for a larger d.

A common phenomenological scaling form is

\[
p_L(d)\approx A\left(\frac{p_{\mathrm{phys}}}{p_{\mathrm{th}}}\right)^{(d+1)/2}.
\]

Here A is a fitted prefactor, \(p_{\mathrm{phys}}\) a modeled physical error rate, \(p_{\mathrm{th}}\) the associated threshold, and \(p_L\) a logical-error measure for a specified operation/time unit. This is a representative model, not a universal law. Its unit—per syndrome round, per logical operation, or another exposure—must be identified before multiplying it by a workload count.

If L relevant logical exposures share this bound, the union estimate \(Lp_L\le\delta_L\) can guide a distance choice for allocated failure probability \(\delta_L\). Solving the idealized relation suggests that distance grows roughly logarithmically with required workload reliability below threshold, while patch area grows roughly quadratically in distance. This explains why modest changes in physical error or target failure probability can change resource requirements sharply. It does not justify extrapolation beyond the fit’s valid noise regime.

Biased noise means different error types have different probabilities; correlated faults can affect several qubits or times together. Leakage and loss may need additional detection/replacement mechanisms. Measurement delay, decoder latency, and fabrication/connectivity constraints affect the fault-tolerant implementation. A single scalar error rate can be useful for a model sweep and still omit important physics.

## Surface codes and repeated local checks

A surface code arranges data and check operations in a two-dimensional structure, using local parity checks to protect logical information. In a common rotated planar construction, distance d involves roughly d² data qubits plus a similar number of check ancillas. Logical information is associated with nonlocal strings across the patch; short local errors can be detected and corrected, while a spanning error chain can cause a logical fault.

The directly inspected external [`SurfaceCode` model](https://github.com/microsoft/qdk/blob/95c039f4b0447928aa041f5ae5ad52e7041d8937/source/qdk_package/qdk/qre/models/qec/_surface_code.py) is specifically a gate-based rotated-surface-code resource transform. It requires H, CNOT, and Z-measurement instruction data. Its default space coefficient is \(2d^2-1\), from d² data and d²−1 check qubits. Its default syndrome-cycle timing combines one one-qubit-gate layer, four two-qubit-gate layers, and measurement time, with available override/offset parameters. A modeled lattice-surgery operation takes d such cycles.

The same source uses default threshold 0.01 and crossing prefactor 0.03 in its logical-error scaling, based on cited modeling references. These are model constants, not experimental numbers discovered by QDK Chemistry. Its default distance-query domain is odd distances 3 through 25. A domain enumerates candidate model settings; it does not declare all hardware with those distances built or validated.

The physical instruction times matter differently. A very fast one-qubit gate does not eliminate slow measurement or two-qubit layers from each syndrome cycle. A cycle-time offset can represent additional modeled latency if justified; leaving it zero is an assumption, not proof that control electronics and decoding take no time.

There are other surface-code implementations and layouts. The convenience estimator’s older `surface_code` formulas are not identical to every direct `SurfaceCode` or `ThreeAux` model. The name of a code family is not a complete numerical resource specification.

## ThreeAux is a particular measurement-based surface-code model

The chemistry notebooks name `ThreeAux`, so we should explain the actual model rather than guess from its name. The external [`ThreeAux` source](https://github.com/microsoft/qdk/blob/95c039f4b0447928aa041f5ae5ad52e7041d8937/source/qdk_package/qdk/qre/models/qec/_three_aux.py) describes a pairwise-measurement-based surface code using three auxiliary qubits per stabilizer measurement. It requires physical X, Z, XX, and ZZ measurements, rather than the gate-based H/CNOT primitive set used above.

Its space coefficient is

\[
d^2+3(d^2-1)=4d^2-3.
\]

That is a modeled protected-operand cost, not the total application footprint. It does not include every algorithmic patch, routing region, buffer, or magic-state factory just by evaluating this expression once.

At the inspected public revision, `single_rail=False` is the default. The model uses extraction depth four for that choice and five for single rail, threshold 0.0066 or 0.0051 respectively, and prefactor 0.05. Its lattice-surgery timing value is \(t_{\mathrm{joint}}(\mathrm{depth}\,d+4)\), where \(t_{\mathrm{joint}}\) is the slower supplied XX/ZZ measurement time. Its physical error input is the maximum among the required measurement error rates.

These constants make explicit why replacing `SurfaceCode` with `ThreeAux` is not just changing a label. The required primitive operations, space, timing, and fitted suppression assumptions all change. The source’s `code_cycle_time` property also includes a distance factor in this model; do not infer a universal one-syndrome-round meaning from a property name without reading the model contract.

`ThreeAux.q(distance=[...])` asks the external estimator to enumerate such candidate code implementations. It does not perform noisy check-circuit simulations or verify the model on a device. The relevant public model cites the improved pairwise measurement-based surface-code work; those derivations and hardware realizability remain evidence inputs beyond the chemistry circuit itself.

## Floquet codes: a different check schedule and interface

A Floquet-code approach obtains protection from a repeating time-dependent pattern of checks. The logical encoding can evolve through that pattern rather than being described by one static set of simultaneously measured stabilizers. Hastings and Haah’s [Dynamically Generated Logical Qubits](https://arxiv.org/abs/2107.02194v2) describes a construction based on two-qubit Pauli measurements; this is a distinct QEC idea, not the explicitly driven chemical Hamiltonian of Lesson 23.

The older convenience estimator exposes the model identifier `floquet_code`. Its inspected [fault-tolerance implementation](https://github.com/microsoft/qdk/blob/95c039f4b0447928aa041f5ae5ad52e7041d8937/source/resource_estimator/src/system/modeling/fault_tolerance.rs) accepts that built-in model with the measurement-based Majorana instruction set and rejects the gate-based pairing. Its default model formulas use threshold 0.01, prefactor 0.07, time \(3t_{\mathrm{meas}}d\), and physical-qubit expression \(4d^2+8(d-1)\), referring to planar Floquet-code modeling.

Those formulas are a coarse resource model, not a full construction or noisy-code benchmark in this course. The direct `qdk.qre.models` code catalog inspected at the same external revision does not export a corresponding `FloquetCode` class. Do not assume a convenience-interface string can be passed unchanged into the direct query-model interface or invent that constructor. Lesson 29 separates those APIs explicitly.

## A hardware architecture is a set of modeled instructions

An **instruction set architecture**, abbreviated ISA, specifies available operations and their properties: arity, time, space, error rate, and physical/logical encoding. Arity is the number of operands an operation acts on. An architecture model supplies the physical primitives; code and factory models derive protected operations from compatible inputs.

The public [`GateBased` model](https://github.com/microsoft/qdk/blob/95c039f4b0447928aa041f5ae5ad52e7041d8937/source/qdk_package/qdk/qre/models/qubits/_gate_based.py) takes gate and measurement times in nanoseconds, an error rate, and optionally a separate two-qubit-gate time. Its numerical defaults/required fields are external API choices, not calibrated values for the nitrogen problem. Physical qubit connectivity and detailed routing must be consistent with the operations a code model assumes, even when an abstract instruction hides that implementation.

The chemistry notebooks use `Majorana(error_rate=1e-5)`. The inspected public [`Majorana` model](https://github.com/microsoft/qdk/blob/95c039f4b0447928aa041f5ae5ad52e7041d8937/source/qdk_package/qdk/qre/models/qubits/_msft.py) supplies X/Z preparation and single-/two-qubit X/Z measurements plus a physical T operation. With that argument and defaults, the model assumes 1000 ns for its operations and maps the Clifford measurement/preparation rate \(10^{-5}\) to a **different physical T error rate of 0.015**. It does not assume every operation has error \(10^{-5}\).

The default error-rate options in that model are \(10^{-4},10^{-5},10^{-6}\), associated with different assumed T rates when no explicit override is supplied. They are scenario parameters from a proposed architecture model, not evidence of present device performance or a hardware delivery date. The source’s motivation mentions topological protection for some operations; the model does not demonstrate that protection experimentally or extend it automatically to non-Clifford T operations.

Also distinguish the mathematical Majorana operators used for fermion-to-qubit mapping in Lesson 14 from physical Majorana-based hardware. Using `MajoranaMapping.jordan_wigner` or a Majorana algebra engine says nothing about the physical qubit technology on which the resulting circuit must run.

## Logical operations and lattice surgery

Protected logical qubits still need to interact. **Lattice surgery** is a method of changing/combining code-patch boundaries to measure joint logical properties, then separating them again. A joint logical parity measurement can correlate patches without directly reading each logical amplitude. Appropriate sequences with ancillas implement useful logical operations.

This is not the same as executing an ideal CNOT on two unprotected physical qubits. Repeated syndrome extraction, boundary geometry, extra patches, decoding, and time are involved. A trace transform can express a many-Pauli measurement in terms of a logical lattice-surgery instruction, while the QEC model gives that instruction its modeled space/time/error.

Parallel logical operations can demand additional routing or ancillary space. A patch kept idle while waiting for a magic state still needs protection. Classical readout and decoding must keep up with the syndrome stream; delayed decisions may need buffering or conservative scheduling. A resource model can approximate these effects, but a single operation-time scalar does not automatically include every engineering latency.

The public [`Architecture` and ISA context](https://github.com/microsoft/qdk/blob/95c039f4b0447928aa041f5ae5ad52e7041d8937/source/qdk_package/qdk/qre/_architecture.py) record instruction properties and provenance. Compatibility requires that an available ISA actually supplies the operations required by the trace/code/factory transforms. Choosing individually attractive but mutually incompatible components should yield no valid study point, not a fictional best-of-everything machine.

## Why non-Clifford gates require another supply chain

The **Clifford group** consists of unitary operations that transform Pauli operators into Pauli operators under conjugation. Conjugating means forming U P U†, with P a Pauli operator and U the gate. H, S, and CNOT generate the usual qubit Clifford operations; their inverses and compositions remain in the group. This closure makes stabilizer tracking efficient, but Clifford operations alone do not provide arbitrary quantum computation. A T gate is a non-Clifford example.

A universal computation needs more than Clifford operations alone. One route implements a T gate by consuming a **magic state**, such as a state proportional to \(|0\rangle+e^{i\pi/4}|1\rangle\), together with Clifford operations, measurements, and corrective feedback. This procedure is called state injection. The resource state carries the non-Clifford capability.

Noisy physical preparation generally produces imperfect magic states. **Distillation** consumes several noisy states and performs a checking protocol to produce fewer higher-quality states, sometimes rejecting a batch. Output error, acceptance probability, circuit faults, and repetition must all be accounted for. It is not enough to count only the accepted output states.

A **magic-state factory** is the protected hardware/process footprint producing these resource states. It is not the algorithm-factory registry introduced in Lesson 3, nor an AI orchestration tool. A computation may need many copies running in parallel to supply T states at the rate demanded by its logical schedule.

The inspected external [`RoundBasedFactory`](https://github.com/microsoft/qdk/blob/95c039f4b0447928aa041f5ae5ad52e7041d8937/source/qdk_package/qdk/qre/models/factories/_round_based.py) explores multi-round pipelines built from specified 15-to-1 unit models, including RM-preparation and space-efficient variants. These are quantitative protocol models, not actual distillation circuits executed by the chemistry package. Its unit error expressions include a cubic term \(35p_T^3\) plus a contribution from modeled Clifford/logical operation error, and its failure expressions include both input-state and circuit-error contributions. The cubic suppression alone is not the whole factory behavior.

The model adjusts the number of parallel units in a round to meet output-supply requirements under a default internal pipeline failure allowance of 1%, divided among its rounds. This internal distillation-rejection requirement is distinct from the application’s total allowed logical error. A batch rejected by a factory is not automatically the same event as an undetected bad magic state corrupting the algorithm.

By default, the model sums per-round space rather than assuming all physical qubits are reused across rounds; an alternative aggregation can represent reuse, but its timing/scheduling assumptions must remain consistent. Compute-code distance and factory-code distances can be chosen separately. The factory’s `code_query` must match the architecture: a gate-based default code query is not automatically compatible with a measurement-only architecture. The chemistry examples explicitly pair ThreeAux compute and factory-code queries for their Majorana scenario.

## Factory throughput can dominate the machine

Suppose a logical algorithm demands \(N_T\) resource states, and one factory produces an average usable rate r_T under its specified acceptance/error model. With F such factories, the supply rate is roughly \(Fr_T\). A simple lower-bound picture for duration is

\[
T_{\mathrm{run}}\gtrsim\max\left(T_{\mathrm{dependency}},\frac{N_T}{Fr_T}\right),
\]

where \(T_{\mathrm{dependency}}\) is the time imposed by the computation’s operation dependencies. This is an explanatory bound, not the exact QDK estimator formula. Startup, discrete batches, buffers, routing, idle protection, and time-varying demand can matter.

Increasing F can reduce supply-limited duration while increasing qubits. Slowing logical operations can reduce the required number of simultaneous factories while increasing memory time and logical-error exposure. Increasing code distance can suppress faults while increasing patch area and cycle time. These choices interact, so an optimal compute patch in isolation need not belong to an optimal whole machine.

A schematic footprint is

\[
Q_{\mathrm{physical}}\approx N_Lq_{\mathrm{patch}}(d)
+Fq_{\mathrm{factory}}+Q_{\mathrm{routing}}+Q_{\mathrm{buffer}}+\cdots.
\]

\(N_L\) is the number of simultaneous protected logical operands, not the sum of qubits over all sequential shots. The ellipsis is not free space: it identifies additional architecture-specific costs that must either be modeled or declared outside scope.

More accurate arbitrary rotations can increase T-state demand, which changes required factory throughput and footprint. Thus the chemical algorithm’s precision decision propagates through compilation into QEC/hardware design. A source-level rotation count alone cannot settle that design.

## Separate the budgets by what can go wrong

A chemical energy tolerance, a unitary approximation bound, statistical confidence, and a probability of logical failure answer different questions. “One percent error budget” does not mean an energy is within one percent of its true value, nor that a gate-noise simulation has reproduced an experimental device.

A conventional resource budget can divide allowed error among logical computation, imperfect distilled T states, and rotation synthesis. That partition is an estimator modeling convention; its components must use compatible error measures and compositional bounds. Under a union-bound interpretation, many rare error contributions are summed conservatively. A product formula such as \(1-\prod_i(1-p_i)\) carries different assumptions about independent events. The external API exposes such choices, which we inspect in Lesson 29 rather than conflating them with a confidence interval.

If a workload uses many magic states, the tolerated error per state can need to be far smaller than the desired total failure probability. If the logical data remain encoded for many cycles, idle and operation exposures both contribute. If multiple complete trials are required, the success and failure accounting must apply to the actual campaign, not one favorable bit circuit.

The resource estimator does not infer that campaign’s target-state success probability from an energy or overlap field. Fresh-state IQPE, finite-resolution amplification, postselection, and model error retain their own scientific/algorithmic limitations. A fault-tolerant machine can execute a precisely specified wrong algorithm very reliably.

## What evidence each specialist must supply

The chemistry and application side supplies the scientific model, intended state/sector, total workload, approximation tolerances, and evidence supporting the success criterion. It must distinguish active energies from core-inclusive or SOS-shifted energies and count repeated state preparations, powers, measurements, and retries correctly.

The compiler/synthesis side supplies a valid lower-level trace or logical count representation, gate-set assumptions, synthesis error allocation, dependency structure, and ancilla lifetimes. It must preserve phases needed under control and specify which adaptive or measurement-based operations it can lower.

The QEC-model side supplies the code family, distance/error scaling, supported logical operations, extraction/decoder assumptions, and factory protocol performance. A fitted threshold and prefactor need a provenance and range of validity. The hardware-model side supplies compatible primitive operations, timings, error characterization, connectivity, measurement/readout behavior, and relevant correlations or leakage assumptions.

These are functional roles, not claims about an organization’s internal team structure. The estimator integrates the models and enumerates candidate combinations; it does not create missing calibration evidence. A credible study asks for coherent parameter sets and sensitivity ranges rather than taking the best independent value from unrelated platforms or publications.

The official [resource-estimator introduction](https://learn.microsoft.com/en-us/azure/quantum/intro-to-resource-estimation), inspected for this chapter, presents the same layered idea: application, architecture, error correction/factories, and an allowed error budget are distinct inputs. The public models and documents do not assert that choosing a model instantiates the corresponding physical machine.

## The proper conclusion from a modeled machine

QEC makes reliable long computations possible in principle by turning many physical operations and qubits into fewer protected logical capabilities. It also introduces substantial space, time, control, and resource-state costs. Those costs depend on the workload and on the detailed assumptions of the selected code and hardware models.

For the nitrogen course, the immediate deliverable is not a hardware date or a single qubit count. It is a reproducible mapping from the complete logical workload to compatible protected instruction models, with stated error budgets and omitted engineering effects. SurfaceCode, Floquet, and ThreeAux names identify different supported modeling paths, not interchangeable guarantees.

The next lesson turns this understanding into two concrete resource-estimation interfaces, shows how to interpret their results and Pareto frontiers, and specifies the evidence needed before reporting a conditional physical cost as a meaningful scientific engineering result.