Magna: simulating magic state factories as cheaply as Clifford circuits

Yifei Wang · Yingfei Gu · Tsinghua University

18 November 2026 · Freie Universität Berlin

  1. 1
    Magic states and factoriesteleportation, distillation, code switching, cultivation
  2. 2
    A hidden code in every factorytwo questions
  3. 3
    Extractthe genuine non-Clifford degrees of freedom
  4. 4
    Usefaults, two numbers, nonlinear feedforward
  5. 5
    Resultscultivation with actual gates

Clifford gates are cheap — and not enough

Cheap to protect

Many codes implement Clifford gates transversally or by lattice surgery.

Cheap to simulate

Gottesman–Knill: Clifford circuits on stabilizer states are classically efficient.

Not universal

Add . Eastin–Knill: no code has a transversal universal gate set.

The non-Clifford gate needs another route: consume a magic state.

Gottesman, arXiv:quant-ph/9807006 · Eastin, Knill, arXiv:0811.4262

Gate teleportation: a magic state becomes a gate

  • One is consumed per gate. If the data received , and repairs it.
  • Feedforward: a Clifford correction controlled by a measurement outcome. In factories the outcome is often a decoder's decision. Both forms come back later.

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

A factory is a noisy circuit from to magic states

Acceptance rate

How often an attempt passes postselection.

Logical error

Infidelity of the accepted output with the ideal target state.

15-to-1 distillation is teleportation through a code

A bent wire is a Bell pair. Apply at one end and project onto : the gate slides around the bend as its transpose (the same gate, since it is diagonal), 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. It consumes one noisy magic state, so 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. These three errors fire no check but flip the output. There are 35 such triples, so the output error is about .

Hidden code[[15,1,3]], transversal ·15 physical ·one out

Bravyi, Kitaev, arXiv:quant-ph/0403025

Many outputs, and inputs on logical qubits

Bravyi–Haah -to-

Bravyi, Haah, arXiv:1209.2426

Triorthogonal codes: one run produces magic states.

Logical-level distillation

Fowler et al., arXiv:1208.0928 · Litinski, arXiv:1808.02892

Each input is a surface-code patch. A decoder reads its syndromes and decides the correction before the next input: 15 decoder decisions in a row.

A decoder's decision is a nonlinear function of the outcomes. Keep it for later.

Hidden codetriorthogonal, transversal · physical · states out

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

The 15-qubit 3D color code (the same ) 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. This is one of three ways to switch codes.

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

Hidden code3D color code, transversal ·15 physical ·one out

Cultivation: check a Clifford, keep only clean runs

Inject a state into a color code.

Double check the logical Clifford transversally: a layer of , the check and its time reverse through a cat state, a layer of . Postselect on every detector.

Grow to , stabilize with three syndrome cycles, and double check again. The physical count grows with distance: 15 at , 53 at .

Escape quickly into a large surface code; fine-grained postselection decides which attempts to keep.

Hidden structurephysical layers implementing a Clifford check·15–53 physical ·one out

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

Diagnoses and repairs a degraded fault distance; three- and four-round models.

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 non-Clifford gates, repeated with postselection. One magic state out.

Why true is necessary

Restored distance

Chan et al., arXiv:2609.17706

Diagnoses and repairs a degraded fault distance; three- and four-round models.

  • Same color-code cultivation circuits and noise: Google's runs with an proxy, , and ours with actual . The acceptance agrees to four digits.
  • At the true logical error is 2.6× () and about 10× () the proxy's, and the gap widens as falls.
  • Hook errors become coherent Clifford errors after the final double check: fault distance 2 / 3 instead of 3 / 5. Flags restore at .

Gidney, Shutty, Jones, arXiv:2409.17595 · Chan et al., arXiv:2609.17706

A hidden code in every factory

and two questions it raises for simulation

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.

What limits existing simulators

State evolution

SOFT, Clifft, SymFT, PPVM, MPS

Track the state through time. Cost follows the intermediate states.

RP² : amplitudes at peak

Li et al., arXiv:2512.23037 · Chase, Labib, arXiv:2604.27058 · Fang, Lou, Li, arXiv:2607.28600 · Luo et al., arXiv:2610.18225 · Hartweg, Piñeiro Orioli, arXiv:2609.19116

Global simplification

ZX / Tsim, stabilizer-rank estimators

Simplify the whole circuit first. The output state still costs its stabilizer rank.

: stabilizer rank believed exponential in

Kissinger, van de Wetering, arXiv:2109.01076 · Haenel, Luo, Zhao, arXiv:2604.01059 · Pashayan et al., arXiv:2101.12223 · Bravyi, Smith, Smolin, arXiv:1506.01396

Clifford proxies

,

Cheap, but shown to be unreliable for cultivation.

miss the degraded fault distance

Li et al., arXiv:2512.23037 · Wan, Zapirain, arXiv:2609.18922 · Chan et al., arXiv:2609.17706

Two questions

Q1

Extract

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

Q2

Use

How do we use it to simulate the noisy, adaptive factory, at a cost set by the logical magic — or even less — rather than the physical count?

physical count
Q1 · extract
?
Q2 · use
?

Q1 · Extract the structure

the genuine non-Clifford degrees of freedom

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

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

Make all feedforward coherent. Each becomes C from its ancilla, measured at the end. becomes CNOTs from R onto the qubits of , before the readout. The checks become projections.

Push the gadget CNOT into the initial Clifford. Passing only changes its axis, , by : a on the parity . Cliffords that arrive multiply into one Clifford.

Combine the diagonal gates: . A on the code qubit, and one on the ancilla, which is only measured in .

Push the CNOTs from R in as well. Passing turns it into on the parity ; it commutes with everything else on the way.

One commuting layer. What is left is diagonal: rotations about products of 's, which all commute.

Only now, abstract the ends. Everything before the layer is one stabilizer state; the readout and the checks become stabilizer projections.

Any protocolthe same exact rewrites give stabilizer boundaries around one commuting layer

Related: Pashayan et al., arXiv:2101.12223

The surviving labels form a code

Insert a complete basis at the diagonal layer: the boundaries keep only an affine space — it plays the role of the code labels .


Code, transversal gateNetwork
code labels ↔
stabilizers ↔: Clifford directions
logical ↔: the magic

Related: Cui, Gottesman, Krishna, arXiv:1608.06596

Determining the subspace where the gate acts as a Clifford

Goal: find , the directions along which is Clifford. The boundaries absorb ; only is expanded.

Tool: finite differences. Flip bit : ; in general flips a direction . All values mod 8.

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

Third differences define a trilinear form, , zero exactly for Clifford phases. — Gaussian elimination over , deterministic and polynomial.

The network becomes stabilizer terms: rank , known at compile time. : Bravyi, Smith, Smolin, arXiv:1506.01396

Related: Cui, Gottesman, Krishna, arXiv:1608.06596 · Heyfron, Campbell, arXiv:1712.01557

From the structure to a simulation: two questions

Q1 found the genuine non-Clifford coordinates of the ideal circuit — for cultivation, 53 or 101 physical gates become one coordinate.

1 · Errors

We sample faulty circuits, but the analysis was for the ideal one. Does every fault force a new analysis?

2 · What to compute

Even the logical magic can be large: Bravyi–Haah with outputs , whose stabilizer rank is believed exponential in . Do we need the output state at all?

Bravyi, Smith, Smolin, arXiv:1506.01396

physical count
Q1 · extract
logical magic
Q2 · use
?

Q2 · Use the structure

faults keep the code · two numbers, not a state · nonlinear feedforward

Faults do not change the code

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: the CNOT from R leaves unchanged and commutes with ; flips the ancilla's record — the sign of a boundary stabilizer.

Only signs changed: of rotations, with Clifford, and of boundary stabilizers, . The rewrite used only Pauli axes, so every draw keeps the same boundaries and the same layer: , the same and . Compile once; per draw, update signs — polynomial cost × , with known before sampling.

We need two numbers, not a state

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 state and no output state is ever built.

Closing the network cancels the output's magic

  • In the output's logical coordinates meet their conjugate in ; in they meet the target.
  • The same radical computation on the closed networks leaves no non-Clifford coordinate in any distillation, cultivation or code-switching benchmark: .
  • Bravyi–Haah : throughout. Per draw 6.9 → 50 μs; preparation within 1.5× of the same circuit with in place of .
  • Each draw gives the exact and , averaged over all outcomes: importance sampling reaches –.
Preparation and per-draw sampling time for Bravyi-Haah distillation up to k = 100, against a matched Clifford circuit
physical count
Q1 · extract
logical magic
Q2 · use
Clifford cost

The whole program: compile once, update per draw

Simulation workflow: input, construct once, reference networks, sampling, output
  1. Input. The protocol with output, postselection and irrelevant legs, and the target .
  2. Construct once. Coherent feedforward and each on an auxiliary give one commuting layer between stabilizer boundaries; gives , and the resource .
  3. Reference networks. Join to : attaches the target, traces the output. Closing cancels the output's magic.
  4. The sampling complexity is determined at this point.
  5. Sampling. A fault only flips signs: update both networks, contract once each for and .
  6. Output. Average over draws; the cost per draw is polynomial × .

Figure: Wang, Gu, arXiv:2610.22315, Fig. 1

Nonlinear feedforward

  • Logical-level factories, TQD, escape: after each round a decoder reads the outcomes and chooses the next correction, .
  • A global simplification compiles the whole circuit before any outcome is known — but this circuit depends on the outcomes. Writing the decoder as gates would add many non-Clifford gates.

1 · Keep the compiled structure

How can a decision change the circuit without changing what we compiled?

2 · Draw the outcomes

How can we sample round with its physical probability before the later decisions exist?

1 · Every decision becomes a Pauli insertion

  • The controlled gate is fixed at compile time. Only depends on the outcomes — exactly like a fault, so the covariance applies.
  • What remains: draw the outcomes that needs with their physical probabilities, before the later decisions are known.

2 · Sample the outcomes without the future

The sampling network, every outcome leg open (triangles): and its conjugate 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 — postselection included, because it is traced too — 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 — a trace can be taken from open legs, never undone.

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

Draw from .

Insert , reopen, repeat: uses only decisions already made. Proposals come from the affine support with weight ; in our examples every weight is 1.

Validation: logical-level 15-to-1 with 15 decoder rounds

Acceptance and conditional infidelity of logical-level 15-to-1 distillation against the exact formula

Six surface-code patches, 102 qubits, 15 decoder-controlled stages and a decoder postselection.

Exact formula reproduced within 1 SE, down to .

All three networks . 1.27 ms per draw, half of it in the decoder.

Protocol: Litinski, arXiv:1808.02892 · Haah, Hastings, arXiv:1709.02832

Results

resources, speed, and cultivation with actual gates

Every benchmark reduces to one term, or almost

ExampleQubitsNon-CliffordOutput fid / acc / sampPrepare (ms)Sample (ms / draw)
Bravyi–Haah 14-to-23014 1 / 1 / –3.660.0069
Bravyi–Haah 68-to-2015668 1 / 1 / –27.80.014
Bravyi–Haah 308-to-100716308 1 / 1 / –2010.0503
Color cultivation 4253 color1 / 1 / –11.20.0104
RP² cultivation 61101 RP²1 / 1 / –12.40.00877
3D → 2D color code3815 2D color1 / 1 / 14.370.0148 (0.0144)
3D color → 2D surface code7015 surface1 / 1 / –10.70.00711
Logical-level distillation10215 surface1 / 1 / 13191.27 (0.64)
TQD , 8 rounds1511250 CC toric4 / 2 / 1455016.5 (12.6)

Paper Table I; Mac Studio (Apple M1 Ultra), one CPU thread. In parentheses: sampling time without the decoder.

Bravyi, Haah, arXiv:1209.2426 · Gidney, Shutty, Jones, arXiv:2409.17595 · Wan, Zapirain, arXiv:2609.18922 · Chen et al., arXiv:2503.18657 · Daguerre, Kim, arXiv:2410.07327 · Wang, Gu, arXiv:2503.19758 · Litinski, arXiv:1808.02892 · Davydova et al., arXiv:2503.15751 · Magdalena de la Fuente et al., arXiv:2604.02033

The gap to state-evolution simulators opens as circuits grow

Cultivation gatesmagna peak amplitudesmagnaSymFTClifftPPVM
Color 151160.00590.00200.000310.017
RP² 3112560.00640.00660.00460.088
Color 5311 0240.01040.0440.0270.53
RP² 1011262 1440.00887.468.14193

Sampling time in ms per draw at , one thread, Mac Studio, excluding preparation. Peak amplitudes coincide for SymFT, Clifft and PPVM. Per draw, not per equal precision: each magna draw already averages over all measurement outcomes.

Comparators — SymFT: Fang, Lou, Li, arXiv:2607.28600 · Clifft: Chase, Labib, arXiv:2604.27058 · PPVM: Luo et al., arXiv:2610.18225

One simulator, the whole cultivation family, actual gates

  • Protocols from five groups, translated and run with no change to the simulator.
  • Color and RP² at : acceptance and logical error agree with the exact series of Wan and Zapirain from to .
  • Independent samples at every ; bars are ±1.96 SE.
Acceptance and conditional logical error of color-code and RP2 cultivation at d = 3 and 5 against exact series

Circuits and exact series: Wan, Zapirain, arXiv:2609.18922 · Gidney, Shutty, Jones, arXiv:2409.17595 · Chen et al., arXiv:2503.18657

Fold-transversal and Chan et al. cultivation

  • : resolved, within statistical error of the series.
  • Chan et al. : resolved, except four rounds at .
  • Fold-transversal : central values near the series, but each estimate is dominated by single rare fault configurations. Those bars are indicative only.
Acceptance and conditional logical error of fold-transversal and Chan et al. cultivation against exact series

Circuits and exact series: Sahay et al., arXiv:2509.05212 · Chan et al., arXiv:2609.17706 · Wan, Zapirain, arXiv:2609.18922

Gauged cultivation at with actual gates

  • matches the exact series through (public Wan–Zapirain code), within 1 SE at four of five rates.
  • : 69 qubits, 129 , 6488 noise locations. ; SymFT and Clifft: 1024 amplitudes.
  • Logical error down to ; indicative.
  • To our knowledge the first actual- data; the original study used a -state substitute.
  • Also compared with Wan and Zapirain's leading-order analysis.
Acceptance and conditional logical error of gauged cultivation at d = 3 and 5

Circuits: Hetényi, Brown, Williamson, arXiv:2603.05429 · Wan, Zapirain, arXiv:2609.18922

What the cultivation campaign cost

8.6 × 109

Fault configurations per hard point, under an hour each.

4.3 M/ s

Fault configurations evaluated per second on the hard curves.

Status: these runs use a GPU sampler that is in development and not yet in public magna. The released version (v0.2.0) samples on the CPU; the paper's timings are single-thread CPU.

Scope: what is released, what is in progress

Released · magna v0.2.0

  • Clifford + , C, CC gates; Pauli noise
  • Pauli and Clifford feedforward from measurement records or Python decoders; postselection
  • Physical sampling, importance sampling, low-weight enumeration

In progress

  • GPU sampler, used for the cultivation results shown here
Limits

is certified per circuit at compile time — small in every benchmark here, not guaranteed for every factory. Rare events still need importance sampling. Coherent (non-Pauli) errors are not supported yet.

Summary

I

Extract the genuine non-Clifford degrees of freedom

Inspired by the algebraic structure of codes: the radical of the phase trilinear form recovers the hidden code — deterministic, polynomial time.

II

Compute only the required scalars

Acceptance and fidelity, not the output state — closing the network avoids paying for the output's magic.

1
Pauli covariance for fast sampling. A fault only flips signs: compile once, update per draw.
2
Causality for dynamical circuits. The trace-preserving future lets global reduction handle decoder feedforward.

Outlook

  • Simulation inside the design loop: codes, schedules, postselection rules and decoders, optimized with the actual gates under realistic noise.
  • A hardness measure that sees how non-Clifford gates are organized, not only how many there are.
  • Beyond Pauli noise: coherent errors as general-angle rotations; tensor-network contraction of the residual coordinates.
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.