FA-91326 / Quantum circuit simulation / Open access
T-count tests the quarter-turn class before the half-turn class · case 01
rz(pi/2), an S gate, is counted as a T gate.
ROOT CAUSE
Every multiple of 1/2 is also a multiple of 1/4, and the T branch is checked first.
THE FAILURE
Every multiple of 1/2 is also a multiple of 1/4, and the T branch is checked first.
Unsuccessful approach: The attempted repair keeps the order but defines the Clifford class as denominator == 2, so rz(pi) (a Z gate) is still counted as T.
Case contract
Input a gate list. t and tdg count one T each; h, s, sdg, x, y, z, cx, cz, swap count one Clifford; ccx costs 7 T and 8 Clifford; ["rz", q, a] with a in units of pi reduced mod 2 is skipped if 0, Clifford if a multiple of 1/2, one T if an odd multiple of 1/4, else ["unsupported", index]; other names give ["unknown-gate", index]. Return {"t_count", "clifford_count"}.
Why this case matters
T-count is the dominant fault-tolerant cost metric; misclassifying rotations skews resource estimates.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(x):
t = cliff = 0
for idx, op in enumerate(x):
name = op[0]
if name in ('t', 'tdg'):
t += 1
elif name in ('h', 's', 'sdg', 'x', 'y', 'z', 'cx', 'cz', 'swap'):
cliff += 1
elif name == 'ccx':
t += 7
cliff += 8
elif name == 'rz':
a = Fraction(op[2]) % 2
if a == 0:
continue
if (a * 4).denominator == 1:
t += 1
elif (a * 2).denominator == 1:
cliff += 1
else:
return ['unsupported', idx]
else:
return ['unknown-gate', idx]
return {'t_count': t, 'clifford_count': cliff}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: rz pi is Z', [['rz', 0, '1']], {'t_count': 0, 'clifford_count': 1}], ['regression: rz half pi is S', [['rz', 0, '1/2']], {'t_count': 0, 'clifford_count': 1}], ['regression: random t-count 1', [['rz', 0, '-2'], ['ccx', 0, 1, 2], ['rz', 0, '1'], ['rz', 0, '1'], ['rz', 0, '0'], ['x', 0]], {'t_count': 7, 'clifford_count': 11}], ['control: rz two pi', [['rz', 0, '2']], {'t_count': 0, 'clifford_count': 0}], ['control: rz zero', [['rz', 0, '0']], {'t_count': 0, 'clifford_count': 0}], ['control: rz quarter pi', [['rz', 0, '1/4']], {'t_count': 1, 'clifford_count': 0}], ['control: tdg', [['tdg', 0]], {'t_count': 1, 'clifford_count': 0}]], [['regression: random t-count 1', [['rz', 0, '-2'], ['ccx', 0, 1, 2], ['rz', 0, '1'], ['rz', 0, '1'], ['rz', 0, '0'], ['x', 0]], {'t_count': 7, 'clifford_count': 11}], ['regression: random t-count 3', [['rz', 0, '1/2'], ['rz', 0, '0'], ['t', 0]], {'t_count': 1, 'clifford_count': 1}], ['regression: random t-count 5', [['ccx', 0, 1, 2], ['rz', 0, '1'], ['rz', 0, '5/4'], ['tdg', 0]], {'t_count': 9, 'clifford_count': 9}], ['control: toffoli', [['ccx', 0, 1, 2]], {'t_count': 7, 'clifford_count': 8}], ['control: unsupported angle', [['h', 0], ['rz', 0, '1/8']], ['unsupported', 1]], ['control: rz four pi', [['rz', 0, '4']], {'t_count': 0, 'clifford_count': 0}], ['control: unknown gate', [['u3', 0]], ['unknown-gate', 0]]], [['regression: random t-count 7', [['rz', 0, '1/2'], ['tdg', 0], ['rz', 0, '1'], ['h', 0]], {'t_count': 1, 'clifford_count': 3}], ['regression: random t-count 11', [['s', 0], ['rz', 0, '5/4'], ['rz', 0, '-1'], ['x', 0], ['t', 0]], {'t_count': 2, 'clifford_count': 3}], ['regression: random t-count 12', [['t', 0], ['tdg', 0], ['rz', 0, '-1']], {'t_count': 2, 'clifford_count': 1}], ['control: random t-count 0', [['rz', 0, '-1/4'], ['rz', 0, '3/4'], ['rz', 0, '4']], {'t_count': 2, 'clifford_count': 0}], ['control: random t-count 2', [['sdg', 0], ['rz', 0, '1/4'], ['cx', 0]], {'t_count': 1, 'clifford_count': 2}], ['control: random t-count 4', [['ccx', 0, 1, 2]], {'t_count': 7, 'clifford_count': 8}], ['control: random t-count 6', [['ccx', 0, 1, 2], ['x', 0], ['x', 0], ['rz', 0, '0'], ['sdg', 0], ['t', 0], ['ccx', 0, 1, 2]], {'t_count': 15, 'clifford_count': 19}]], [['regression: random t-count 13', [['rz', 0, '-1/4'], ['rz', 0, '7/2'], ['rz', 0, '3/4'], ['s', 0]], {'t_count': 2, 'clifford_count': 2}], ['regression: random t-count 15', [['ccx', 0, 1, 2], ['sdg', 0], ['t', 0], ['rz', 0, '3/2']], {'t_count': 8, 'clifford_count': 10}], ['regression: random t-count 16', [['rz', 0, '3/4'], ['rz', 0, '-1'], ['tdg', 0], ['sdg', 0], ['rz', 0, '-2'], ['rz', 0, '3/2'], ['sdg', 0]], {'t_count': 2, 'clifford_count': 4}], ['control: random t-count 8', [['rz', 0, '-1/4'], ['ccx', 0, 1, 2], ['ccx', 0, 1, 2], ['ccx', 0, 1, 2], ['cx', 0]], {'t_count': 22, 'clifford_count': 25}], ['control: random t-count 9', [['rz', 0, '1/4']], {'t_count': 1, 'clifford_count': 0}], ['control: random t-count 10', [['ccx', 0, 1, 2], ['s', 0], ['ccx', 0, 1, 2], ['tdg', 0]], {'t_count': 15, 'clifford_count': 17}], ['control: random t-count 14', [['sdg', 0]], {'t_count': 0, 'clifford_count': 1}]], [['regression: random t-count 18', [['t', 0], ['rz', 0, '4'], ['rz', 0, '3/2'], ['ccx', 0, 1, 2], ['rz', 0, '3/4'], ['rz', 0, '-2']], {'t_count': 9, 'clifford_count': 9}], ['regression: random t-count 20', [['cx', 0], ['rz', 0, '-1'], ['ccx', 0, 1, 2], ['tdg', 0], ['rz', 0, '1/2'], ['t', 0]], {'t_count': 9, 'clifford_count': 11}], ['regression: random t-count 23', [['rz', 0, '-2'], ['tdg', 0], ['ccx', 0, 1, 2], ['t', 0], ['rz', 0, '4'], ['rz', 0, '-1']], {'t_count': 9, 'clifford_count': 9}], ['control: random t-count 17', [['tdg', 0]], {'t_count': 1, 'clifford_count': 0}], ['control: random t-count 19', [['rz', 0, '3/4'], ['rz', 0, '-1/4'], ['rz', 0, '5/4']], {'t_count': 3, 'clifford_count': 0}], ['control: random t-count 21', [['tdg', 0], ['rz', 0, '5/4']], {'t_count': 2, 'clifford_count': 0}], ['control: random t-count 22', [['tdg', 0], ['tdg', 0], ['tdg', 0], ['rz', 0, '-1/4'], ['x', 0]], {'t_count': 4, 'clifford_count': 1}]]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: rz pi is Z | {'clifford_count': 0, 't_count': 1} | {'clifford_count': 1, 't_count': 0} | Failed |
| regression: rz half pi is S | {'clifford_count': 0, 't_count': 1} | {'clifford_count': 1, 't_count': 0} | Failed |
| regression: random t-count 1 | {'clifford_count': 9, 't_count': 9} | {'clifford_count': 11, 't_count': 7} | Failed |
| control: rz two pi | {'clifford_count': 0, 't_count': 0} | {'clifford_count': 0, 't_count': 0} | Passed |
| control: rz zero | {'clifford_count': 0, 't_count': 0} | {'clifford_count': 0, 't_count': 0} | Passed |
| control: rz quarter pi | {'clifford_count': 0, 't_count': 1} | {'clifford_count': 0, 't_count': 1} | Passed |
| control: tdg | {'clifford_count': 0, 't_count': 1} | {'clifford_count': 0, 't_count': 1} | Passed |
SHA-256 / c5c8e109e5b92e98b27b03d4d24ed317faf99796d02186634aaae41e0f6e10d7
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(x):
t = cliff = 0
for idx, op in enumerate(x):
name = op[0]
if name in ('t', 'tdg'):
t += 1
elif name in ('h', 's', 'sdg', 'x', 'y', 'z', 'cx', 'cz', 'swap'):
cliff += 1
elif name == 'ccx':
t += 7
cliff += 8
elif name == 'rz':
a = Fraction(op[2]) % 2
if a == 0:
continue
if a.denominator == 2:
cliff += 1
elif (a * 4).denominator == 1:
t += 1
else:
return ['unsupported', idx]
else:
return ['unknown-gate', idx]
return {'t_count': t, 'clifford_count': cliff}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: rz pi is Z', [['rz', 0, '1']], {'t_count': 0, 'clifford_count': 1}], ['regression: rz half pi is S', [['rz', 0, '1/2']], {'t_count': 0, 'clifford_count': 1}], ['regression: random t-count 1', [['rz', 0, '-2'], ['ccx', 0, 1, 2], ['rz', 0, '1'], ['rz', 0, '1'], ['rz', 0, '0'], ['x', 0]], {'t_count': 7, 'clifford_count': 11}], ['control: rz two pi', [['rz', 0, '2']], {'t_count': 0, 'clifford_count': 0}], ['control: rz zero', [['rz', 0, '0']], {'t_count': 0, 'clifford_count': 0}], ['control: rz quarter pi', [['rz', 0, '1/4']], {'t_count': 1, 'clifford_count': 0}], ['control: tdg', [['tdg', 0]], {'t_count': 1, 'clifford_count': 0}]], [['regression: random t-count 1', [['rz', 0, '-2'], ['ccx', 0, 1, 2], ['rz', 0, '1'], ['rz', 0, '1'], ['rz', 0, '0'], ['x', 0]], {'t_count': 7, 'clifford_count': 11}], ['regression: random t-count 3', [['rz', 0, '1/2'], ['rz', 0, '0'], ['t', 0]], {'t_count': 1, 'clifford_count': 1}], ['regression: random t-count 5', [['ccx', 0, 1, 2], ['rz', 0, '1'], ['rz', 0, '5/4'], ['tdg', 0]], {'t_count': 9, 'clifford_count': 9}], ['control: toffoli', [['ccx', 0, 1, 2]], {'t_count': 7, 'clifford_count': 8}], ['control: unsupported angle', [['h', 0], ['rz', 0, '1/8']], ['unsupported', 1]], ['control: rz four pi', [['rz', 0, '4']], {'t_count': 0, 'clifford_count': 0}], ['control: unknown gate', [['u3', 0]], ['unknown-gate', 0]]], [['regression: random t-count 7', [['rz', 0, '1/2'], ['tdg', 0], ['rz', 0, '1'], ['h', 0]], {'t_count': 1, 'clifford_count': 3}], ['regression: random t-count 11', [['s', 0], ['rz', 0, '5/4'], ['rz', 0, '-1'], ['x', 0], ['t', 0]], {'t_count': 2, 'clifford_count': 3}], ['regression: random t-count 12', [['t', 0], ['tdg', 0], ['rz', 0, '-1']], {'t_count': 2, 'clifford_count': 1}], ['control: random t-count 0', [['rz', 0, '-1/4'], ['rz', 0, '3/4'], ['rz', 0, '4']], {'t_count': 2, 'clifford_count': 0}], ['control: random t-count 2', [['sdg', 0], ['rz', 0, '1/4'], ['cx', 0]], {'t_count': 1, 'clifford_count': 2}], ['control: random t-count 4', [['ccx', 0, 1, 2]], {'t_count': 7, 'clifford_count': 8}], ['control: random t-count 6', [['ccx', 0, 1, 2], ['x', 0], ['x', 0], ['rz', 0, '0'], ['sdg', 0], ['t', 0], ['ccx', 0, 1, 2]], {'t_count': 15, 'clifford_count': 19}]], [['regression: random t-count 13', [['rz', 0, '-1/4'], ['rz', 0, '7/2'], ['rz', 0, '3/4'], ['s', 0]], {'t_count': 2, 'clifford_count': 2}], ['regression: random t-count 15', [['ccx', 0, 1, 2], ['sdg', 0], ['t', 0], ['rz', 0, '3/2']], {'t_count': 8, 'clifford_count': 10}], ['regression: random t-count 16', [['rz', 0, '3/4'], ['rz', 0, '-1'], ['tdg', 0], ['sdg', 0], ['rz', 0, '-2'], ['rz', 0, '3/2'], ['sdg', 0]], {'t_count': 2, 'clifford_count': 4}], ['control: random t-count 8', [['rz', 0, '-1/4'], ['ccx', 0, 1, 2], ['ccx', 0, 1, 2], ['ccx', 0, 1, 2], ['cx', 0]], {'t_count': 22, 'clifford_count': 25}], ['control: random t-count 9', [['rz', 0, '1/4']], {'t_count': 1, 'clifford_count': 0}], ['control: random t-count 10', [['ccx', 0, 1, 2], ['s', 0], ['ccx', 0, 1, 2], ['tdg', 0]], {'t_count': 15, 'clifford_count': 17}], ['control: random t-count 14', [['sdg', 0]], {'t_count': 0, 'clifford_count': 1}]], [['regression: random t-count 18', [['t', 0], ['rz', 0, '4'], ['rz', 0, '3/2'], ['ccx', 0, 1, 2], ['rz', 0, '3/4'], ['rz', 0, '-2']], {'t_count': 9, 'clifford_count': 9}], ['regression: random t-count 20', [['cx', 0], ['rz', 0, '-1'], ['ccx', 0, 1, 2], ['tdg', 0], ['rz', 0, '1/2'], ['t', 0]], {'t_count': 9, 'clifford_count': 11}], ['regression: random t-count 23', [['rz', 0, '-2'], ['tdg', 0], ['ccx', 0, 1, 2], ['t', 0], ['rz', 0, '4'], ['rz', 0, '-1']], {'t_count': 9, 'clifford_count': 9}], ['control: random t-count 17', [['tdg', 0]], {'t_count': 1, 'clifford_count': 0}], ['control: random t-count 19', [['rz', 0, '3/4'], ['rz', 0, '-1/4'], ['rz', 0, '5/4']], {'t_count': 3, 'clifford_count': 0}], ['control: random t-count 21', [['tdg', 0], ['rz', 0, '5/4']], {'t_count': 2, 'clifford_count': 0}], ['control: random t-count 22', [['tdg', 0], ['tdg', 0], ['tdg', 0], ['rz', 0, '-1/4'], ['x', 0]], {'t_count': 4, 'clifford_count': 1}]]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: rz pi is Z | {'clifford_count': 0, 't_count': 1} | {'clifford_count': 1, 't_count': 0} | Failed |
| regression: rz half pi is S | {'clifford_count': 1, 't_count': 0} | {'clifford_count': 1, 't_count': 0} | Passed |
| regression: random t-count 1 | {'clifford_count': 9, 't_count': 9} | {'clifford_count': 11, 't_count': 7} | Failed |
| control: rz two pi | {'clifford_count': 0, 't_count': 0} | {'clifford_count': 0, 't_count': 0} | Passed |
| control: rz zero | {'clifford_count': 0, 't_count': 0} | {'clifford_count': 0, 't_count': 0} | Passed |
| control: rz quarter pi | {'clifford_count': 0, 't_count': 1} | {'clifford_count': 0, 't_count': 1} | Passed |
| control: tdg | {'clifford_count': 0, 't_count': 1} | {'clifford_count': 0, 't_count': 1} | Passed |
SHA-256 / ca5196531b9af2bf0694cd209a5a04a03377db6b4ee34b42f462a1f3b72264cd
HELD IN THE MEMBER ARCHIVE
The verified repair and its recorded checks are member-only.
This mechanism has 7 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.
Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.
Member access is invitation-based. Sign in with your invited account to inspect the repair.
Sign in to the archive ↗Verification & scope
A deterministic bounded teaching model with a stipulated toy contract; amplitudes are rounded to fixed decimals for strict JSON output. It is not a production quantum SDK and claims no standards conformance. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:51:34.914430+00:00.
Case digest / 7710aae1d06bcb725b461213356d4148e4a7b36c577f85e1a16501848ca656e5