Magic state preparation and its classical simulation

QR code: these slides online

Yifei Wang · Tsinghua ⁠University

30 November 2026 · IQOQI ⁠Innsbruck

  1. 1
    Magic ⁠state ⁠preparationnon-Clifford resources for fault-tolerant universal quantum ⁠computation
  2. 2
    Magnaefficiently simulating magic state ⁠preparation

Magic state preparation

non-Clifford resources for fault-tolerant universal quantum ⁠computation

What makes a universal gate set?

Which gates do we need to build any quantum ⁠computation?

+

  • Clifford ⁠gates , , CNOT map Pauli operators to Pauli ⁠operators.
  • Gottesman–Knill: Clifford circuits on stabilizer states are classically simulable — so Clifford gates alone cannot be ⁠universal.
  • Add one non-Clifford gate, for example ⁠.

Clifford gates + one non-Clifford gate form a universal gate ⁠set.

Gottesman, arXiv:quant-ph/9807006 · Nebe, Rains, Sloane, arXiv:math/0001038 · Dawson, Nielsen, arXiv:quant-ph/0505030

Stabilizer codes protect Clifford operations

  • A logical qubit is stored in a stabilizer code; errors are detected by measuring ⁠stabilizers.
  • Clifford gates map stabilizers to stabilizers, so they can be done transversally (qubit by qubit: errors do not spread) or by measuring ⁠Pauli ⁠products (lattice ⁠surgery).

Problem: given a fault-tolerant architecture that protects all Clifford operations (Clifford gates, Pauli measurements, computational-basis preparation), how do we make it ⁠universal?

We need one fault-tolerant non-Clifford gate. One promising way: gate ⁠teleportation.

Horsman et al., arXiv:1111.4022 · Litinski, ⁠arXiv:1808.02892

Gate teleportation: move a rotation off the data

Start: a rotation on an ancilla , a CNOT from the data, and a measurement of the ancilla. Which angle can we ⁠teleport?

Push the rotation through the CNOT: the CNOT maps to , so the rotation becomes . The CNOT now acts on as its target and does ⁠nothing.

Measure ⁠: the data receive — the gate for , its inverse for , each with probability ⁠1/2.

Correct: if , apply . A correction controlled by a measurement outcome is called ⁠feedforward.

Require the correction to be Clifford: gives . Then , and the teleported gate is ⁠.

Back to the initial circuit with : the ancilla state is the magic ⁠state . It can be prepared offline, before the data arrive; with it, costs only Clifford operations on the ⁠data.

Likewise and are products of rotations, teleported the same ⁠way.

Gottesman, Chuang, arXiv:quant-ph/9908010 · Zhou, Leung, Chuang, arXiv:quant-ph/0002039 · Bravyi, Kitaev, arXiv:quant-ph/0403025

New problem: prepare the magic state

Prepare fault tolerantly, encoded in a code from which it can be teleported into the ⁠computation.

A known state is easier than a gate on an unknown state

We only need to make one specific state ⁠well.

It is done offline, so we can postselect

A bad attempt is simply thrown away and repeated. With enough preparations running in parallel, the computation is not ⁠delayed.

Knill, arXiv:quant-ph/0402171

The naive route fails: prepare physically, then encode

  • Prepare on one physical qubit, then encode it: an encoding circuit, or injection (grow the code around it by stabilizer ⁠measurements).
  • Not fault tolerant: one early physical fault becomes a logical error. The output error is , not suppressed by the ⁠distance.

Three ways to repair ⁠it.

Horsman et al., arXiv:1111.4022 · Li, ⁠arXiv:1410.7808

Three repairs

1

Distillation

Teleport through a code: many noisy encoded states → fewer better ⁠ones.

2

Code switching

Do in a code where it is transversal, then move to the Clifford ⁠code.

3

Postselected encoding

Encode, but check so carefully that bad runs are discarded — e.g. magic state ⁠cultivation.

Repair 1 · Distillation: many noisy in, fewer purer out

How? And only with the protected Clifford ⁠operations.

Repair 1 · Distillation: teleportation through a code

A bent wire is a Bell pair. Apply at one end and project onto : the gate slides around the bend, and the other end carries the magic state ⁠.

The same thing as a circuit. A CNOT prepares the Bell pair; the projection becomes an measurement with a known correction on R — teleportation ⁠again.

Encode the measured half in the code. on every qubit acts as a logical , so R again receives . The readout gives 4 parity checks: accept only if all ⁠pass.

Every is a gate-teleportation gadget. The inputs — noisy magic states — enter here, inside the circuit; the output leaves on R. A faulty input acts as a error on its ⁠line.

One faulty input is caught. Its error flips one outcome, and two of the parity checks fire: the run is ⁠rejected.

Two faulty inputs are caught too. At least one check always fires for one or two ⁠errors.

Three ⁠can ⁠pass. There are 35 such triples: . Bravyi–Haah: many outputs per run. Repeat in rounds for any target ⁠error.

Every line is a code patch. Each input is an encoded noisy magic state, and the whole circuit is a logical Clifford circuit, protected by the ⁠code.

Bravyi, Kitaev, arXiv:quant-ph/0403025 · Bravyi, Haah, arXiv:1209.2426 · Litinski, arXiv:1905.06903 · Experiment, logical 5-to-1 on neutral atoms: ⁠arXiv:2412.15165

Repair 2 · Code switching: transversal in 3D, Clifford gates in 2D

The 15-qubit 3D color code has a transversal : apply to every qubit of ⁠.

Measure the 8 qubits off one face in . The face is the 7-qubit 2D color code, where all Clifford gates are ⁠transversal.

A correction set by the outcomes fixes the face's checks: feedforward ⁠again.

Gauge fixingshown

Anderson, Duclos-Cianci, Poulin, arXiv:1403.2734 · Bombín, ⁠arXiv:1412.5079

Transversal CNOT, teleportation

Daguerre, Kim, ⁠arXiv:2410.07327

Generalized lattice surgery

Wang, Gu, arXiv:2503.19758 — switches directly into codes that are not subsystems of the 3D code, e.g. 3D color → 2D surface ⁠code

Experiment · Innsbruck

First fault-tolerant code switching: 7-qubit color code ↔ 10-qubit code with transversal , trapped ⁠ions.

Pogorelov et al., arXiv:2403.13732 · theory: Butt et al., ⁠arXiv:2306.17686

Experiment · Quantinuum

Magic states by switching from the code to the Steane ⁠code.

Daguerre et al., ⁠arXiv:2506.14169

Repair 3 · Postselected encoding

Encode the physical into a small code, check it with enough redundancy that any low-weight fault is detected, and discard those ⁠runs.

An early example: Li (2015)

Inject into the surface code and postselect on the first two syndrome rounds: the encoded magic state's infidelity falls below half that of a single CNOT. The error is still first order in — which motivates checking the state ⁠itself.

Li, ⁠arXiv:1410.7808

Further ⁠work: arXiv:quant-ph/0402171 · arXiv:1410.7808 · Sci. Rep. 6, 19578 (2016) · arXiv:1811.00566 · arXiv:2003.03049 · arXiv:2403.03991 · arXiv:2409.17595 · ⁠…

Experiments: Postler et al., arXiv:2111.12654 (Innsbruck: fault-tolerant magic state with flag qubits, teleported as a logical ) · Gupta et al., arXiv:2305.13581 (IBM: encoded magic state beyond ⁠break-even)

Check the state: the magic state is an eigenstate of a Clifford

is a Clifford operator with . Measuring the logical checks the magic state — and a fault-tolerant Clifford measurement is something codes can ⁠do.

Cultivation: check a Clifford, keep only clean runs

Stabilizer configurations while escaping: a d = 7 color code, a surface code grown from it, the grafted color/surface code at d = 19, and the grafted matchable code
color code, grow a surface codegrafted code, drop the color region: matchable

Inject a state into a color ⁠code.

Double check the logical transversally: a layer of , the check and its time reverse, a layer of . Postselect on every ⁠detector.

Grow ⁠to ⁠, stabilize, and double check again. Physical gates: 15 at , 53 at ⁠.

Escape: graft a large surface code onto the small color code, stabilize it, then drop the color-code region. The result is a large matchable code with standard decoders. Figure from Gidney, Shutty, ⁠Jones.

Cost moves into postselection

Acceptance at : 69 ⁠% at , 14 ⁠% at . It falls fast with distance, so cultivation stops at small and escapes — it does not scale up by ⁠itself.

Experiment · Google

color code grafted into a surface code; fidelity 0.9999(1), keeping 8 % of ⁠attempts.

Rosenfeld et al., ⁠arXiv:2512.13908

Gidney, Shutty, Jones, ⁠arXiv:2409.17595

A family of cultivation protocols

Color code

Gidney, Shutty, Jones, ⁠arXiv:2409.17595

The original: transversal check on the color ⁠code.

15 / 53

RP² surface code

Chen et al., ⁠arXiv:2503.18657

Surface code on the projective ⁠plane.

31 / 101

Fold-transversal

Sahay et al., ⁠arXiv:2509.05212

Fold-transversal Clifford check on the surface ⁠code.

Restored distance

Chan et al., ⁠arXiv:2609.17706

Repairs a degraded fault distance with ⁠flags.

Gauged

Hetényi, Brown, Williamson, ⁠arXiv:2603.05429

Measures the logical Clifford by gauging, in constant ⁠depth.

129 at

Common skeleton: a logical Clifford check built from physical gates, with heavy postselection. One magic state ⁠out.

Three routes to an encoded magic state

RouteWhy fault tolerantPrice
Distillationcode with transversal ; detects bad encoded inputsmany logical qubits and cycles
Code switchingtransversal in a second code3D connectivity or a switching circuit
Postselected encoding, cultivationheavy checks, discardacceptance falls with distance

All are noisy circuits from to an encoded magic state, with measurements, feedforward and postselection. Figures of merit: acceptance and logical error ⁠.

Magna

efficiently simulating magic state ⁠preparation

in collaboration with Yingfei Gu · ⁠arXiv:2610.22315

A naive simulation is exponential in the number of gates

To design or compare factories we need to estimate and ⁠efficiently.

amplitudes in a state ⁠vector

stabilizer terms for 129 ⁠gates

amplitudes at the peak of state ⁠evolution

  • State ⁠vector: amplitudes, with = 40–70 qubits. ⁠Impossible.
  • Stabilizer ⁠+ ⁠: the cost follows the stabilizer rank of the gates, at best for gates. Cultivation at has 53–129 physical gates: up to ⁠terms.
  • State ⁠evolution ⁠in ⁠time: RP² cultivation at reaches amplitudes at its ⁠peak.

Bravyi, Gosset, arXiv:1601.07601 · Qassim, Pashayan, Gosset, arXiv:2106.07740 · Li et al., arXiv:2512.23037 · Fang, Lou, Li, ⁠arXiv:2607.28600

We need the numbers with actual gates

  • The cheap way around the cost: replace by and simulate with Stim — the same circuits and noise, and the same ⁠acceptance.
  • At and , the true logical error is already 2.6× the ⁠proxy's.
  • At the gap grows to about 10×: the proxy misses real failure ⁠modes.

Proxy data: Gidney, Shutty, Jones, arXiv:2409.17595 · proxies shown unreliable: Li et al., arXiv:2512.23037 · Wan, Zapirain, arXiv:2609.18922 · Chan et al., ⁠arXiv:2609.17706

A key observation: many physical gates, little logical magic

ProtocolHidden structurePhysical Logical output
15-to-1 distillationtransversal on 15one
Bravyi–Haahtriorthogonal code copies of
Code switchingtransversal on the 3D color code15one
Cultivation (color, RP², gauged, …) layers implementing a transversal Clifford check15–129one

The physical count grows with the distance; the logical magic is fixed by the output. Maybe the code structure can remove the ⁠difficulty.

Two questions

Q1

Extract

Can a deterministic ⁠algorithm find this structure — with no human insight and no protocol-specific ⁠input?

Q2

Use

Can the simulation cost follow the logical magic — or even less — instead of the physical ⁠count?

physical count
Q1 · extract
?
Q2 · use
?

15-to-1 is one diagonal layer between stabilizer boundaries

Push a Clifford through rotations: . A Clifford maps a Pauli axis to a Pauli axis, so every rotation stays a rotation with a new axis, and the Cliffords pile up at the ⁠ends.

Start from the gadget form. Every is teleported: ancilla , CNOT, measurement, correction. The logical outcome sets the correction on R. Shown: 3 of the 15 code ⁠qubits.

Make all feedforward coherent (deferred measurement): becomes C from the ancilla, measured at the end; becomes CNOTs from R before the readout. The checks become ⁠projections.

Push the gadget CNOT into the initial Clifford. Passing only changes its axis, : a on the parity ⁠.

Combine the diagonal gates: : a on the code qubit and one on the ⁠ancilla.

Push the CNOTs from R in as well: becomes on the parity ⁠.

One ⁠commuting ⁠layer: rotations about products of 's, which all ⁠commute.

Abstract ⁠the ⁠ends: everything before the layer is one stabilizer state; the readout and checks are stabilizer projections. Any protocol gives this ⁠form.

Related: Pashayan et al., ⁠arXiv:2101.12223

The surviving basis states form a code

Paper · Sec. II C


In the networkIn a code
basis states the boundaries do not kill, ↔code words: the classical code
directions in which flipping bits changes only by Clifford terms↔ stabilizers
the remaining directions↔logical qubits: the genuine magic

We find the Clifford directions by linear algebra over bits — deterministic, polynomial time, no knowledge of the code. how? ⁠→

The network becomes stabilizer terms, known before sampling. Q1: physical count → logical ⁠magic.

Related: Cui, Gottesman, Krishna, ⁠arXiv:1608.06596

Detail · Finding the Clifford directions

Third differences define a trilinear form, , zero exactly for Clifford phases. Clifford directions: , by Gaussian elimination over ⁠.

Finite differences: flips the bits in direction . All values mod ⁠8.

Gatefirst difference second third Level
Pauli
Clifford
non-Clifford
CClifford
Cnon-Clifford
CCnon-Clifford

Remaining directions : the network becomes stabilizer terms. On the 15-qubit code is the 4-dimensional -stabilizer space and ⁠(triorthogonality).

Cui, Gottesman, Krishna, arXiv:1608.06596 · Heyfron, Campbell, arXiv:1712.01557 · Bravyi, Smith, Smolin, ⁠arXiv:1506.01396

Pauli covariance: inserting Paulis does not change the structure

Paper · Sec. II D

A fault in the coherent 15-to-1 circuit: on code qubit 1 after the encoder. Shown: that qubit, its gadget ancilla and R. Push the fault to the readout, gate by ⁠gate.

Through a Clifford, the Pauli changes: the CNOT maps to , ⁠.

Through a rotation, only a sign changes. C is three rotations, about , and ; anticommutes with the first two, so their signs flip. In phases: gains , a Clifford ⁠term.

At ⁠the ⁠readout: commutes with ; flips the ancilla's record — the sign of a boundary ⁠stabilizer.

Only ⁠signs ⁠changed: of rotations, by Clifford terms, and of boundary stabilizers. Every Pauli insertion keeps the same boundaries, the same layer and the same remaining directions. Compile once; per sample, update signs. Faults are the first kind of Pauli insertion; decoder decisions will be the second.

We need two numbers, not a state

Paper · Sec. II B

Run ⁠the ⁠protocol ⁠ with a fault draw . Its ending legs: output , postselection , and irrelevant (records no longer needed, discarded ⁠qubits).

puts the protocol next to its conjugate ⁠.

The ⁠trace joins the irrelevant legs of the two ⁠copies.

becomes projectors on the postselection ⁠legs.

Acceptance ⁠network: the output legs are traced too. Contracting it gives ⁠.

Fidelity ⁠network: the output legs meet a small noiseless target circuit . No intermediate or output state is ever ⁠built.

In the closed networks the output's magic meets its conjugate and cancels: one ⁠stabilizer ⁠term in every benchmark — even Bravyi–Haah 308-to-100, whose output is . Q2: logical magic → Clifford cost.

Nonlinear feedforward: decoders inside the circuit

Paper · Sec. II E
  • Necessary: recall distillation with code patches: each input is an encoded patch; its correction depends on a logical outcome that a decoder infers from noisy syndromes — a nonlinear function ⁠.
  • Difficult ⁠for ⁠us: we reduce the whole circuit globally first, but this circuit is not determined until the outcomes are ⁠drawn.

Causality

A sampling network draws the early outcomes with their correct distribution without applying any later feedforward: the future is trace ⁠preserving.

Pauli covariance

Every feedforward enters as a Pauli insertion on a fixed compiled circuit, which does not change its ⁠structure.

Validation: logical-level 15-to-1, 102 qubits, 15 decoder rounds — the exact formula is reproduced down to . details ⁠→

Detail · Every decision becomes a Pauli insertion

  • The controlled gate is fixed at compile time, on a virtual control qubit. Only depends on the outcomes — exactly like a fault, so Pauli covariance ⁠applies.
  • Nonlinear postselection: the virtual qubit is projected onto in the acceptance and fidelity ⁠networks.

Detail · Sample the outcomes without the future

The sampling network, every outcome leg open (triangles): and as staircases, one step per round. Output and postselection are traced. Nothing is drawn and no decision is known ⁠yet.

Trace every round after round 1. Everything after round 1 is then trace preserving, so the later decisions, still unknown, drop ⁠out.

Draw ⁠ from ⁠.

Only now can the decoder act: enters as a Pauli insertion. Return to the open network, with ⁠fixed.

Trace every round after round 2. The future is trace preserving again, and it needs only ⁠.

Draw ⁠ from ⁠.

Insert , reopen, repeat: each conditional probability uses only decisions already made; each step is a Pauli ⁠update.

The whole cultivation family, with actual gates

  • Protocols from five groups, run with no change to the simulator; they agree with exact series from to ⁠.
  • RP² : 0.0088 ms per sample, against 7.5–193 ms for state-evolution ⁠simulators.
  • Gauged ⁠: 129 gates, one stabilizer term, logical error down to — to our knowledge the first actual- ⁠data.
  • GPU sampling: one version published in magna, another in ⁠preparation.
Acceptance and conditional logical error of color-code and RP2 cultivation at d = 3 and 5 against exact series Acceptance and conditional logical error of gauged cultivation at d = 3 and 5

Circuits and exact series: Wan, Zapirain, arXiv:2609.18922 · Gidney, Shutty, Jones, arXiv:2409.17595 · Chen et al., arXiv:2503.18657 · Hetényi, Brown, Williamson, ⁠arXiv:2603.05429

Summary

Magic state preparation

Clifford gates are the easy part of fault tolerance. The gate is supplied by encoded magic states, prepared offline with postselection: distillation, code switching, ⁠cultivation.

Simulating it

Factories hide a code: many physical gates, little logical magic. Extract it by linear algebra; Pauli insertions only flip signs; ask for two numbers, not a state; decoders enter as insertions. Clifford-like cost for actual- ⁠factories.

Thank you

github.com/itpyi/magna · arXiv:2610.22315
We thank Hong-Ye Hu, Kwok Ho Wan, Ainhoa Zapirain, Zikang Zhang and Tian-Gang Zhou for useful ⁠discussions.

QR code: paper on arXiv
paper
QR code: magna on GitHub
code
QR code: these slides online
slides