The circuit
The 41\times161 matrix. Rows are wires and columns are rotations. A 1 means the wire takes part in the rotation, and the number beside each wire is its row weight. Scroll sideways to see every column.
| wire | 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 |
|---|---|
| out 0 (63) | 11·1·1···11·····11·1·········11·1·1·11······11··11··1·11··1·11·1·1··1·1·1·1······1··111··11·····11·11···········1·1·1·1·11·····1·1·11··1·11··111·1·1·11·1·1······ |
| out 1 (63) | 11·······1··111·11·1·1·······11··1·1·11·········11·1·1···11·11·········1111·11·1·1··1····1··11·111·1·1··········1·1··1·1·11········11·1·1···1111·······11111·11·1 |
| out 2 (63) | 11·······1··1···11·1·11··1·1·11······11·········11·······11·11·1·1··1·11111·11···1··1····1··1···11·1·11·1·1·1···1·1······11········11·······1111·1·1·1111111·1··· |
| out 3 (71) | ·1···1·1··1··111·1···1·1········1111111····1111·1··1·111·11···1111·····1111·········1·11··1··1·1·1···1···1··········1111111···11·111··1·111·11··1111···1111······ |
| out 4 (71) | 1··1····1··1·1··1····1·1··11··111111···1··1·1···1··111····1·1111····1·11··1·11·111···1·····1·1··1····1···1·11·····111111···1·1·1···1··111····11111···111··11·111· |
| out 5 (63) | ···1·1···1·1··1··1·1···1··1·11··1·11·11···111·1··11·1····1····11····1···111··1··1····11··1·1···1·1·1·····1·1····1···1·11·11··111··1·11·1····1···11···1··111··1·1· |
| out 6 (71) | 1····1·1·11·11··1··1··1··11··11·11··1·11··1·1·····11·111·11·1···1···1·1··11·1····1····11·11·11··1··1··1···11····1·1·11··1·11·1·1·····11·111·111···1··11··1111···· |
| out 7 (79) | 1····1·1·11·111·11·1·1···111·1··1···1·11··1·1·····11··11111·1·111···1··1·11·1··1·1····11·11·11·111·1·1····1111··1···1···1·11·1·1·····11··111111·111··1·1·111··1·· |
| out 8 (71) | 11·1·1·1··1·111·11····11·1·1·····1·111·······11····11111··1·1·111·······1·1·11···1··11111·1·11·111····1··11·1········1·111·······11···11111··11·111·····1·11·1··· |
| out 9 (63) | 1··1···1·1···11·11·1·1···111·1····1····1··1··1····111···1·1·····11····11·11··1·1·1···1·1·1···1·111·1·1····111··11·····1····1·1···1···111···1·1····11··11·11··11·· |
| out 10 (63) | ·········11111··1··1··1··1···111·1··1111···········1····111·1111····1··1·11·1··1·········11111··1··1··1···1···1·1·11·1··1111··········1····1111111···1·1·111··1·· |
| out 11 (71) | ·1···1·1·1·11·1·1··1··11·1·1·11·1111···1···1111·1····1·1····111··1··1·1·····11······1·11·1·11··11··1··11·11·1···1·1·1111···1··11·111····1·1···111··1·11····1·1··· |
| out 12 (63) | 1········11··11·11·1·1···1·1·11·······11·········111·1···11·11······1·11111·11···11······11··1·111·1·1····1·1···1·1·······11········111·1···1111·····1111111·1··· |
| out 13 (79) | 11·1·1·····11······1·111··11··111111······111·1·1·1·11·1··11111·····1·11··1·11·111··111····11······1·11··1·11·····111111·····111··11·1·11·1··1111····111··11·111· |
| out 14 (71) | 11········11·11·11····11······11··111·1···11·11·1·11··11111··111·1···11··11······1··1·····11·1·111····1··1········11··111·1··11··111·11··11111·111·1··1··11······ |
| out 15 (79) | 11·······1··1······1·111·11··1·11111·1·1··11·11·1·1··1111···1·11·1··1·111···1111·1··1····1··1······1·11··111····1··11111·1·1·11··111·1··1111··1·11·1·1111··1·11·· |
| out 16 (79) | ·········111111·11····11·11···11·1·1··11··11·1111··1··11111··111·1··1·1··11····11········11111·111····1··111······11·1·1··11·11··111··1··11111·111·1·11··11···11· |
| out 17 (31) | 1····1·1···1··1··1···11·············1······1·····1···1··1·····11·················1····11···1···1·1···11·················1·····1·1···1···1··1····11··············· |
| out 18 (71) | ·1··1··1·1····1··1·1···1·1·1·11·1111···1··1·111·111··1··1···111111··1·1·····11······1··1·1·····1·1·1·····11·1···1·1·1111···1·1·1·11111··1··1··111111·11····1·1··· |
| out 19 (71) | ·1·······11········1·111··11·1·1·1·11111··11·11······1111···1·11·1·····11···11·11··11····11········1·11··1·11···1··1·1·11111·11··11·····1111··1·11·1···11··1·111· |
| out 20 (31) | 11········11············1··1·····11·1··1········11·················1··1········111··1·····11················1········11·1··1·······11···············1·1·······11· |
| out 21 (63) | 11····11··1·111·11····11········1111·11······11·1·11·1···11·····11·····1111······1··1··1··1·11·111····1··1··········1111·11······111·11·1···11····11···1111······ |
| out 22 (79) | ···1·1····1·1····11···11··11··1111111··1··111·1··11·11·1111·11······1·11··1·11·11····11···1·1····1····1··1·11·····1111111··1·111··1·11·11·111111·····111··11·111· |
| out 23 (71) | ·1·1···1····1·1··1···11···11·11··11··111··1··1··111·1····1··111111··1·1·11·11·······11·1····1··1·1···11····11···1·1··11··111·1···1·111·1····1·111111·11·11·1····· |
| out 24 (79) | 11·1·1···11········1·111··11·1··11111111··111·1·1·1·11··11··········1·1·11··11·111··111··11········1·11··1·11···11··11111111·111··11·1·11··11········11·11·1·111· |
| out 25 (63) | ···1·1····1·111··1·······1·1····1·1·1·1·····11·····11111111·1·11·1·····1·1··11·······11···1·11·1·11·······1·1·······1·1·1·1····1·1····111111111·11·1···1·1·1·1··· |
| out 26 (71) | ·1···1·1··1··11·1····11··11···111·1·11·1··1·1···11111·1·1····1··1···1·111······11···1·11··1··1111····11···11······111·1·11·1·1·1···11111·1·1···1··1··1111·····11· |
| out 27 (63) | ·········111111····11····1·1·11·····1111···········1·1·1111·1·1·····1·11111·11···········11111·1···1······1·1···1·1·····1111··········1·1·11111·1····1111111·1··· |
| out 28 (63) | 1····1·1···1·1··1····1·1·11···111·1··1····1·1·····11·11·1····1·11·1·1·111······111····11···1·1··1····1···111······111·1··1···1·1·····11·11·1···1·11··1111·····11· |
| out 29 (63) | 1·11·1·1····11··1····1·1·1·1·····1·111·11·····1·1··11·111·1·1···1·······1·1·11···1···111····11··1····1···11·1········1·111·11·····11··11·111·11···1·····1·11·1··· |
| out 30 (63) | 11·······1··1······1·111·11··1·111111111·11·1·1·····11··11··············11·····111··1····1··1······1·11··111····1··111111111·1·1··1····11··11···········11····11· |
| check 31 (64) | ·1···1·1··1··1··1··1··1······11·1·1·1·111·11··1···111·111·1··1···1··1·1·1·1·········1·11··1··1··1··1··1·········1·1·1·1·1·11111···1··111·111·1·1···1·11·1·1······ |
| check 32 (48) | ·1·1···1····11··1··1··1··1·1·····1·1·1·····1··1·1····1···1···1···1······1·1·11······11·1····11··1··1··1···1·1········1·1·1····1···11····1···1··1···1····1·11·1··· |
| check 33 (72) | ···1·1···1·1·11·11·1·1····11······11·1·1····11·····11111··1··111·1·1··11·1··11·11····11··1·1·1·111·1·1·····11·········11·1·1···1·1····11111··1·111·11·11·1·1·111· |
| check 34 (80) | 11·11·········1··1···11··1111·1··1···11··11····1111··1·1·11111·1····111111·111·1·······111··1·1·1111··111···11··1·11··1·1111····11·11··1····1·111111··1·1111···1· |
| check 35 (80) | 1····1··1·1111·1······11···11··1111···1··1··111··1·11··1·1··1·1··11·1··1·11·1··1·11·11·1···1·11··11·1111··1···1··1··1·11·111··1111·1111··11111····11··1111···1··1 |
| check 36 (80) | 11·11··111·1·111111111·1·1··11····1··········11··1111·1·111··1··111··1·1·····1·1·1·1·11111··11··1111····1·111··11·11···1··11·11·······111··1····1·1···11·11·1·111 |
| check 37 (80) | ·1111··1·1·1111·1·1········11··1···1111·111·1111·111·1··1·1····1111···1111···1111···1·11··1··1·1·11···1111··1111···1111·111···11·111··1·1·1·1·········1···1··1··1 |
| check 38 (80) | 1··1··111111·1···1·1111······1·11··111·1···11··1·1111·1···1111·11·1·1·1·1·111·11·1···1··1···11···1··1··111·······11··11·11·1··1·1111··11·1···1··1··1·11·1·1·11·11 |
| check 39 (80) | ·········11111·11·1·11····11·1·1·1·111····11·11··111·1··11·1111··11····11···11·11········1111·11·1111·1111·11···1··1·1·111···11··11·11·1·11··1···11····11··1·111· |
| check 40 (80) | 1····1·1···1·11·11····11111·11···111·111···1111··1·1·1···11·····11·111·111·1··1··1····11···1·1·111····1··1··1111·1111····111··11·11·1·1·1···11····11··1···1111111 |
The gate is read off the output rows. An output row of odd weight gives a T, a pair of output rows with odd overlap gives a CS, and an odd triple overlap gives a CCZ. The circuit is a valid factory because every such parity that touches a check row is even.
Figures of merit
Output gate
As gates: \mathrm{T}_{0}\cdot \mathrm{T}_{1}\cdot \mathrm{T}_{2}\cdot \mathrm{T}_{3}\cdot \mathrm{T}_{4}\cdot \mathrm{T}_{5}\cdot \mathrm{T}_{6}\cdot \mathrm{T}_{7}\cdot \mathrm{T}_{8}\cdot \mathrm{T}_{9}\cdot \mathrm{T}_{10}\cdot \mathrm{T}_{11}\cdot \mathrm{T}_{12}\cdot \mathrm{T}_{13}\cdot \mathrm{T}_{14}\cdot \mathrm{T}_{15}\cdot \mathrm{T}_{16}\cdot \mathrm{T}_{17}\cdot \mathrm{T}_{18}\cdot \mathrm{T}_{19}\cdot \mathrm{T}_{20}\cdot \mathrm{T}_{21}\cdot \mathrm{T}_{22}\cdot \mathrm{T}_{23}\cdot \mathrm{T}_{24}\cdot \mathrm{T}_{25}\cdot \mathrm{T}_{26}\cdot \mathrm{T}_{27}\cdot \mathrm{T}_{28}\cdot \mathrm{T}_{29}\cdot \mathrm{T}_{30}
As monomials: 0+1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30 (output wires per term, separated by +)
This row stands for every gate that a CNOT circuit and S, Z and CZ gates on the outputs can reach from this one. They all prepare the same magic state. The wires are shown in the S_k-canonical frame.
Clifford correction
With every rotation a \mathrm{T}=\mathrm{diag}(1,e^{i\pi/4}), the rotations deposit the gate above times a diagonal Clifford. Undo it after the rotations and before the checks are measured, with 31 single-wire gates: \mathrm{S} on output 0, \mathrm{S} on output 1, \mathrm{S} on output 2, \mathrm{S} on output 3, \mathrm{S} on output 4, \mathrm{S} on output 5, \mathrm{S} on output 6, \mathrm{S} on output 7, \mathrm{S} on output 8, \mathrm{S} on output 9, \mathrm{S} on output 10, \mathrm{S} on output 11, \mathrm{S} on output 12, \mathrm{S} on output 13, \mathrm{S} on output 14, \mathrm{S} on output 15, \mathrm{S} on output 16, \mathrm{S} on output 17, \mathrm{S} on output 18, \mathrm{S} on output 19, \mathrm{S} on output 20, \mathrm{S} on output 21, \mathrm{S} on output 22, \mathrm{S} on output 23 and 7 more (listed below). The circuit's action is then exactly the gate above, and an error-free run passes every check with certainty.
All 31 correction gates
\mathrm{S} on output 0, \mathrm{S} on output 1, \mathrm{S} on output 2, \mathrm{S} on output 3, \mathrm{S} on output 4, \mathrm{S} on output 5, \mathrm{S} on output 6, \mathrm{S} on output 7, \mathrm{S} on output 8, \mathrm{S} on output 9, \mathrm{S} on output 10, \mathrm{S} on output 11, \mathrm{S} on output 12, \mathrm{S} on output 13, \mathrm{S} on output 14, \mathrm{S} on output 15, \mathrm{S} on output 16, \mathrm{S} on output 17, \mathrm{S} on output 18, \mathrm{S} on output 19, \mathrm{S} on output 20, \mathrm{S} on output 21, \mathrm{S} on output 22, \mathrm{S} on output 23, \mathrm{S} on output 24, \mathrm{S} on output 25, \mathrm{S} on output 26, \mathrm{S} on output 27, \mathrm{S} on output 28, \mathrm{S} on output 29, \mathrm{S} on output 30
Or no Clifford gate at all: run every rotation as \mathrm{T}^\dagger. A power of \mathrm{T} costs one magic state, like \mathrm{T} itself. For a code this is a transversal \mathrm{T} gate, \mathrm{T}^j on each qubit.
Rotations are numbered by matrix column, from 0. The correction comes from the columns by the weight expansion of Bravyi and Haah (2012). verify_catalog.py re-derives it, checks the corrected circuit's phase input by input against the gate, and on small circuits simulates it gate by gate.
Convert the output with CNOT and S
A CNOT circuit on the outputs, followed by S, Z and CZ gates, turns this factory's gate into other gates that prepare the same magic state. Type a target gate to check whether it is reachable. If it is, you get the circuit, checked on every basis state.
Or list every gate it reaches. The list is built in your browser and saved as a text file, one gate per line.
Python code that writes the same list
import json, urllib.request
NAMES = {1: "T", 2: "CS", 3: "CCZ"}
def equivalent_gates(k, terms, limit=1_000_000):
"""Every gate a CNOT circuit and S, Z, CZ gates reach from this one.
A gate is its set of terms mod Clifford: {a} is T, {a,b} is CS and
{a,b,c} is CCZ on those outputs. CNOT c->t sends x_t to
x_c + x_t - 2 x_c x_t, so a term on t but not c adds the term with t
replaced by c, and, below CCZ, the term with c added.
"""
start = frozenset(frozenset(m) for m in terms)
seen, queue = {start}, [start]
for gate in queue:
for c in range(k):
for t in range(k):
if c == t:
continue
new = set(gate)
for m in gate:
if t in m and c not in m:
new ^= {(m - {t}) | {c}}
if len(m) < 3:
new ^= {m | {c}}
new = frozenset(new)
if new not in seen:
seen.add(new)
queue.append(new)
if len(seen) > limit:
raise RuntimeError(f"more than {limit} equivalent gates")
return seen
def name(gate, k):
sep = "," if k > 10 else ""
terms = sorted((sorted(m) for m in gate), key=lambda m: (len(m), m))
return "·".join(NAMES[len(m)] + sep.join(map(str, m)) for m in terms) or "I"
url = "https://shubhamj810.github.io/magic-state-factory-repo/data/factories/161.31.3.a.json"
record = json.load(urllib.request.urlopen(url))
k = record["parameters"]["k"]
gates = equivalent_gates(k, record["gate"]["monomials"])
lines = sorted(name(g, k) for g in gates)
print(len(lines), "equivalent gates")
with open("equivalent-gates-161.31.3.a.txt", "w") as out:
out.write("\n".join(lines) + "\n")
Distance
d=3, exact. No fault of weight below 3 is both undetectable and damaging. One of weight 3 is.
Exactly 670 faults of weight 3 are undetectable and damaging, so A_{3}=670. If each rotation fails independently with probability p, an accepted run has a damaged output with probability A_{3}\,p^{3}+O(p^{4}).
A damaging fault of weight 3 sits on columns [0,17,101].
A fault is a set of faulty columns. It is undetectable when their check parts cancel, and damaging when their output parts do not.
Original source
S. P. Jain, A. Wills, and S. Singh, "Symmetry and AI-assisted discovery of magic-state factories," arXiv:2610.06535 (2026). arxiv.org/abs/2610.06535
Provenance
built from one of Wills's parent codes (weighted Reed-Muller, restricted-light or one-heavy) by searched punctures, paired-column contractions or logical-pair checks, in the pure-T distillation-exponent release (gamma = log(n/k)/log d, n < 1000); a verified witness, not a maximum -- only the release's own frontier points are the lowest gamma it knows
Found by: AI search (gamma frontier): from Wills parent codes
Discovery: AI search
1 recorded source
[
{
"regime": "AI search (gamma frontier): from Wills parent codes",
"file": "gamma_frontier_release/protocols/restricted_light_161_31_3.json",
"label": "restricted_light_161_31_3",
"N": 41,
"d": 3,
"d_is_exact": true,
"origin": "Wills-derived four-block Schur-orthogonal restricted-light parent (|S|=48), with searched graph punctures",
"provenance": "gamma frontier release record restricted_light_161_31_3 (source catalogue id restricted_light_161_31_3); construction: Wills-derived four-block Schur-orthogonal restricted-light parent (|S|=48), with searched graph punctures; matrix ad9312f7779cd3dd...; the release states d=3 (exact), gamma=1.4995437221046783 (exact)",
"notes": "matrix gamma_frontier_release/matrices/ad9312f7779cd3dde1940ecfe918da153e2095c0cf720daf69ab23f250bfe3fe.matrix"
}
]Use it in code
Load this factory and re-derive every number from its circuit with the catalogue's own verifier.
# git clone https://github.com/shubhamj810/magic-state-factory-repo
# cd magic-state-factory-repo/master_catalog
import json, urllib.request
import verify_catalog as VC
url = "https://shubhamj810.github.io/magic-state-factory-repo/data/factories/161.31.3.a.json"
record = json.load(urllib.request.urlopen(url))
columns = record["circuit"]["columns"]
k, N = record["parameters"]["k"], record["parameters"]["N"]
facts, problems = VC.derive(columns, k, N) # gate, T-count, degree, ...
distance = VC.measure_distance(columns, k, N) # exhaustive fault search
print(facts["gate_human"], distance["d_exact"] or distance["d_at_least"],
problems or "verified")
Raw record
Show the JSON this page is built from
Source: master_catalog.json, factories[790].