WAI Extension: Quantum Compile Certificates
Mirrored from the canonical text at commit c5e7133e ().
Status: Draft. Defines the certificate of a compile,
wai.quantum.compile/1: one record for each compile that names every pass with the digest of the circuit it was given and of the circuit it gave, the layer its check stands on and the distance it adds, so that the whole is one chain from the program’s text to the compiled program’s text; the rules any reader holds that record to without running anything; what a verifier does with a sealed one; and what each synthesis method the passes use guarantees. A job that ran compiled carries the chain in its result. Reference implementation:wai_quantum::engine::compile,engine::certificateandengine::synth; vectors:quantum-conformance/compile/.
Keywords MUST, MUST NOT, SHOULD, MAY are RFC 2119/8174.
1. Scope and model
A compile takes an OpenQASM program whose measurements all come at the end and writes it in another gate set (its basis) through an ordered list of named passes. Every pass is checked where it acts before its output is used; a pass whose check does not hold is left out, and the program goes on as it was. The compile’s certificate records all of it.
The claim a certificate makes is one sentence: the output text is the
program text, up to a global phase, to within epsilon.bound in the operator
norm, and here is each step with how it was checked. It is not a proof
object that a small checker replays: it is a chain of digests that fixes
which circuits the claim is about, a statement for each step of what kind of
check stood behind it, and a compile that gives the same bytes on every host,
so that a verifier holding the request can make the certificate again and
compare.
A compile does not place a program on a device’s qubits or route it; the exact compile to a device’s own gates and connectivity for a provider’s job is the provider protocol’s (quantum-providers §4), and its program is checked there before it is sent.
2. The request
{"qasm", "epsilon", "level", "basis", "stages", "twirl", "dd", "passes"},
all but qasm optional:
| Member | Meaning | Default |
|---|---|---|
qasm | the program | |
epsilon | the most the output may differ from the program in the operator norm, up to a global phase: a number greater than 0, and at most 0.5 for the basis clifford_t | 1e-6 |
level | 0, 1 or 2: which passes run (§3); above 0, the best on the basis’s objective of this level’s output and every lower level’s (§3.1) | 1 |
basis | the gate set the output is written in (below) | clifford_t |
stages | true: the result also holds the circuit after each pass | false |
twirl | true or {"seed": N}: frame each two-qubit Clifford gate with seeded Paulis | off |
dd | "xx" or "xy4": a decoupling sequence in each idle window | off |
passes | names of passes the host holds, built in (§3) or its own, run after the level’s | none |
The bases:
basis | The output’s gates | Approximates |
|---|---|---|
clifford_t | h x y z s sdg t tdg cx cz swap: every rotation off the multiples of π/4 written as a Clifford+T word | within epsilon |
standard | the reader’s standard gates at any angle | nothing |
cz | one-qubit gates at any angle around cz, the two-qubit gate of the device bases rzsxxcz and prxcz | nothing |
zz | one-qubit gates around rzz(θ), 0 ≤ θ ≤ π/2: the zz gate of the device basis gpizz at θ/2π of a turn | nothing |
xx | one-qubit gates around rxx(θ), 0 ≤ θ ≤ π/2: the xx gate of the device basis prxrzxx at θ/2π of a turn | nothing |
A request MUST be refused, and nothing compiled, when its program
measures in the middle, resets after a gate or acts on a measured bit; when
it holds more than 200 000 gates; when basis, level, epsilon, twirl
or dd is not one of the values above; when it gives target (a device’s
name, which a compile does not take); when it names a pass the host does not
hold; or when epsilon, shared by the program’s rotations, leaves one of
them less than 1e-15. A compile MUST also be refused when a pass writes
more than 2 000 000 gates, the most a program is read with: its output would
not read back. The pass that passes it is named, and approximate stops as
soon as it does.
3. The passes
| Pass | What it does | The layer its check stands on (§5) |
|---|---|---|
lower | every gate in h x y z s sdg t tdg cx cz swap rz, a rz at a multiple of π/4 as the named gates it is | exact_arithmetic when every decomposition used is of a gate whose own entries, and its decomposition’s, are in Z[ω]/√2ᵏ (§7.1); else exact_simulation |
simplify | checked rewrites: a gate and its inverse cancel, rotations merge, a gate is carried past what it commutes with; each rewrite’s gates held to the gates they replace by a tableau or on every basis state of their qubits, the two unitaries at most 1e-12 apart at one global phase (in the Frobenius norm), so a rewrite moves nothing past the rounding of doubles | exact_simulation |
phase_fold | phase gates on one parity of the path variables merged into one (§7.5) | exact_arithmetic when every angle is a multiple of π/4; else exact_simulation |
phase_resynth | each region of cx cz swap, Pauli and phase gates written again with the fewest T terms its phase polynomial’s signature allows that the search finds (§7.5) | exact_arithmetic |
resynth_1q | each run of one-qubit gates written again when that is cheaper (§7.2) | exact_arithmetic when every run rewritten was a Clifford+T word; else exact_simulation |
resynth_2q | each block on one pair of qubits written with at most three CNOTs when that uses fewer (§7.4) | exact_simulation |
approximate | every rz off the multiples of π/4 as a Clifford+T word within its share of the budget (§7.3) | bounded; exact_arithmetic when there was none to write |
native_2q | each block on one pair written around the basis’s own two-qubit gate, at most three of it (§7.4) | exact_simulation |
twirl | each cx, cz and swap between a seeded Pauli and its image through the gate | stabilizer |
dd | the decoupling sequence in each window where a qubit idles for as many layers as it has pulses | stabilizer |
The passes a level runs, in order:
| Level | clifford_t | standard | cz, zz, xx |
|---|---|---|---|
| 0 | lower, approximate | lower | lower, native_2q (each two-qubit gate by its own fixed identity) |
| 1 | simplify, lower, simplify, phase_fold, lower, approximate, phase_fold, simplify, lower | simplify, lower, simplify, phase_fold, simplify | simplify, lower, simplify, phase_fold, simplify, lower, native_2q, resynth_1q |
| 2 | simplify, lower, simplify, resynth_2q, lower, resynth_1q, phase_fold, simplify, lower, approximate, resynth_1q, phase_fold, phase_resynth, simplify, lower | simplify, lower, simplify, resynth_2q, lower, phase_fold, resynth_1q, simplify | as level 1 |
Then the request’s passes, then twirl, then dd. A request’s passes may
name a built-in pass too: "passes": ["phase_resynth"] lowers the T count
past phase folding at any level and in any basis.
3.1 Each level against the levels below it
A basis’s objective is what its compiles are held to: the output’s counts (§4) compared in this order, fewer first.
| Basis | Objective |
|---|---|
clifford_t | t_count, then cnots, then gates |
standard | cnots, then gates |
cz, zz, xx | two_qubit, then gates |
A pass that writes a part of the circuit again (resynth_1q, resynth_2q)
keeps the new part only when it is better on the same counts in the same
order, with the rotations off the multiples of π/4 weighed before them in
clifford_t, since each becomes a word of about 3·log₂(1/ε) T gates.
A pass’s gain can still cost a later pass more: two-qubit blocks written
again with fewer CNOTs can leave phase folding fewer T gates to merge. So a
compile at level 1 or 2 also compiles the program at each level below it,
under the same options (the request’s passes, twirl and dd too), and
gives the output that is best on the objective, of those that tie the
highest level’s: a level MUST NOT give an output worse on its objective
than a lower level gives for the same request. The certificate is the kept
compile’s (its passes, its bound and its check of the whole output), under
the level asked for, and its guard records the comparison (here of
clifford_t_n8_d40, §7.5, at level 2, whose own passes give two T gates
more than level 1’s):
"guard": {
"how": "…",
"objective": ["t_count", "cnots", "gates"],
"candidates": [
{ "level": 2, "output": "<64 hex>", "counts": { "t_count": 36, "cnots": 150, "gates": 287 } },
{ "level": 1, "output": "<64 hex>", "counts": { "t_count": 34, "cnots": 156, "gates": 287 } },
{ "level": 0, "output": "<64 hex>", "counts": { "t_count": 72, "cnots": 160, "gates": 374 } }
],
"kept": 1
}
A lower level that refuses the program is a candidate with the reason
(refused) and is not kept; a refusal of the level asked for is the
compile’s. A compile at level 0 has no guard.
4. The certificate
{
"format": "wai.quantum.compile/1",
"basis": "clifford_t",
"level": 0,
"source": { "hash": "<64 hex>", "qubits": 2, "counts": { "…": "…" } },
"output": { "hash": "<64 hex>", "counts": { "…": "…" } },
"epsilon": { "budget": 0.0001, "rotations": 2, "each": 5e-05, "bound": 7.4e-05 },
"passes": [
{ "pass": "lower", "input": "<64 hex>", "output": "<64 hex>",
"layer": "exact_simulation", "bound": 0.0,
"before": { "…": "…" }, "after": { "…": "…" },
"check": { "how": "…", "verdict": "exact", "checked": 1, "proved": 0, "distance": 5.6e-17 } },
{ "pass": "approximate", "input": "<64 hex>", "output": "<64 hex>",
"layer": "bounded", "bound": 7.4e-05,
"before": { "…": "…" }, "after": { "…": "…" },
"check": { "how": "…", "verdict": "approximate", "rotations": 2, "epsilon_each": 5e-05, "t_count": 76, "distance": 7.4e-05 } }
],
"rotations": [ { "angle": 0.3, "t_count": 38, "distance": 3.8e-05, "k": 20 }, { "…": "…" } ],
"whole": { "how": "…", "distance": 7.3e-05, "verdict": "approximate", "layer": "exact_simulation" },
"verdict": "approximate",
"layer": "exact_simulation",
"weakest": "bounded",
"reading": "…"
}
- A digest is the BLAKE3 of a circuit’s text, in 64 lower-case hex
digits. The text is the circuit written as OpenQASM 3 by the engine’s
writer: the line
OPENQASM 3.0;,qubit[n] q;,bit[m] c;when the program has bits, one gate a line with each angle written as the shortest decimal that reads back to the same double, and the final measurements.source.hashis the digest of the program as read, in standard gates;output.hashis the digest of the compiled program’s text, which is the text the result gives. passeslists every pass that ran, in order, applied or not.inputis the digest of the circuit the pass was given andoutputof the circuit it gave;layeris the layer its check stands on (§5);boundis the distance it adds toepsilon.bound;beforeandafterare the circuit’s counts;checkis the check’s own record, itsverdictone ofproof,exact,approximate,rejectedandskipped. A pass a host registered also carriescomponent, its identity.epsilon.boundis the sum of the passes’bound, in their order, in double precision. By the triangle inequality the output is within it of the program, up to a global phase, in the operator norm; on any input the output distribution is then within it in total variation, and an observable’s expectation within twice it times the observable’s norm.verdictis the weakest of the applied passes’ verdicts:approximateif any is, elseexactif any is, elseproof.weakestis the weakest layer among the applied passes, ornullwhen none was applied.wholeis the check of the whole output against the whole program, andlayeris its layer (§5.2): the strongest check the whole compile passed.rotationslists the first 64 rotations the approximation wrote: the angle, the word’sTcount, its distance and the denominator exponentkof the operator found.guard, at a level above 0, is the comparison of §3.1: the objective, each level’s output digest and counts on it (or why that level refused), and the level kept. The passes are the kept level’s, andlevelis the request’s.
A certificate sealed before certificates carried input, output, layer
and bound holds none of them, nor layer and weakest. It is of the
earlier form, and is held to its format and its budget alone (§6).
5. Layers
5.1 A pass’s layer
Weakest first:
| Layer | What the engine did | What that does not show |
|---|---|---|
unchecked | nothing: the pass was skipped, or its check did not hold and it was left out | the pass changed nothing: its output is its input |
bounded | computed the output’s operator-norm distance from the input, up to a global phase, from the output itself in fixed point, and rounded it up | equality: the two differ by at most the bound |
exact_simulation | compared in double precision: dense matrices or every basis state of the qubits a step touches, or a phase polynomial’s sums | a proof: the two are equal to the rounding of doubles |
exact_arithmetic | established an identity in integers: a word multiplied out over Z[ω]/√2ᵏ, a phase polynomial in whole eighths of a turn, or two unitaries proportional entry by entry (§7.1) | anything of gates whose angles are not whole eighths of a turn |
stabilizer | compared stabilizer tableaus | anything of a circuit that is not Clifford |
exact_arithmetic and stabilizer are proofs, and a pass checked by either
adds no distance. exact_simulation is a numeric check: the pass’s record
says exact, never proof, unless every step of it was also proved (a host’s
registered pass proved by a chain of checked rewrites says proof with this
layer, since each rewrite’s window is compared on a tableau or on basis
states). stabilizer, exact_simulation and unchecked are the layers of
those names in a job’s verdict (quantum-providers §8); exact_arithmetic and
bounded are a compile’s own.
5.2 The whole compile’s layer
The whole output is held to the whole program by the first of these that decides it, and a compile whose output any of them finds is not the program MUST be refused:
| Layer | The check | Asked when |
|---|---|---|
stabilizer | both are Clifford circuits with the same tableau | no pass approximated, up to 4096 qubits |
exact_arithmetic | both multiplied out over Z[ω]/√2ᵏ and found proportional (§7.1) | no pass approximated, every gate of both in the ring, up to 6 qubits and 2²² gate-entry updates |
exact_simulation | their dense unitaries, the distance at most epsilon.bound plus 1e-9 for the rounding of doubles | up to 8 qubits |
pass_equivalence | none: the passes’ own checks stand, composed | otherwise |
So a compile that approximates never has a proof’s layer; a wide program that is not Clifford stands on its passes’ checks, and its certificate says so.
6. Holding a certificate to its form, and to its request
6.1 The form
These hold of every certificate of the chained form (one whose passes carry
input or layer), and a reader can check each without running anything.
A certificate that breaks one MUST NOT be accepted.
formatiswai.quantum.compile/1.- Every digest is 64 lower-case hex digits.
- The digests chain: the first pass’s
inputissource.hash, each pass’sinputis theoutputof the pass before it, and the last pass’soutputisoutput.hash. - Every
layeris one of §5.1’s, and everyboundis a finite number that is not negative. - A pass whose layer is
unchecked,exact_arithmeticorstabilizerhasbound0, and one whose layer isuncheckedhasoutputequal toinput. - A pass’s layer is one its check’s verdict gives:
rejectedandskippedgiveunchecked;approximategivesbounded;exactgivesexact_simulation;proofgivesexact_arithmetic,stabilizeror (a registered pass)exact_simulation. epsilon.boundis the sum of the passes’bound, in order, in double precision, and is at mostepsilon.budget.verdictandweakestare what the passes conclude (§4).layeris one of §5.2’s and iswhole.layer; it is notstabilizerorexact_arithmeticwhenverdictisapproximate.whole.distance, where there is one, is at mostepsilon.boundplus1e-9.- Where it holds
guard: the guard’sobjectiveis its basis’s (§3.1); itscandidatesareleveland each level below it, highest first, each with anoutputdigest and a whole number for each count of the objective and nothing else, or withrefused, the first never refused;keptis the level of a candidate not refused whoseoutputisoutput.hashand whose counts areoutput.counts’; and no candidate not refused has fewer counts, compared in the objective’s order, nor the same counts at a higher level thankept. A certificate sealed before the guard has none, and is not held to this rule.
A certificate of the earlier form is held to rule 1 and to
epsilon.bound ≤ epsilon.budget. In §6.2 it is held to its output’s digest
and to the check of the whole output, and to nothing that depends on the
engine that wrote it (its program’s digest, the names of its options): it is
never answered differs for not being reproduced.
6.2 A sealed compile
A compile is returned as {"request", "result"}, the result holding
qasm (the compiled program), certificate, options, with stages when
asked, the engine that made it and its schema, sealed by a receipt in the
form every job’s takes (quantum-providers §8). A verifier checks the receipt
first; when it holds, it looks at the compile again and reports what it finds
under compile:
{ "again": "reproduced", "form": "chained", "layer": "exact_simulation",
"weakest": "bounded", "passes": 2, "differences": [], "why": "…" }
It MUST answer differs, and the job is then not valid though its seal
holds, when any of these is so (differences names each):
- the certificate breaks a rule of §6.1;
output.hashis not the digest ofresult.qasm;- of the chained form:
source.hashis not the digest of the request’s program as read, or the certificate’sbasis,levelorepsilon.budgetis not the request’s; - the result holds
stagesand they are not, in order, the circuits whose digests the passes name as their outputs; - the engine that sealed it is the verifier’s own (its name and version, the certificate of the chained form, no registered component taking part) and, compiling the request again, the verifier gets another certificate or a refusal;
- the output, held to the program by the checks of §5.2, is not the program within the bound.
Otherwise its answer is:
reproduced: compiled again by the verifier, the request gives this certificate and this output, byte for byte. Every pass’s check ran again.partly: not reproduced (another engine sealed it, a registered component took part, or the program is past what a verifier compiles again), and the output was held to the program by a check of §5.2 that decides it;wholeis that check.host_statement: not reproduced, and wider than any check of §5.2 decides: the passes’ checks are the host’s statement under its seal.
A verifier compiles a request again only when its program holds at most
50 000 gates and at most 2 000 rotations off the multiples of π/4 once
lowered (each is a synthesis); past that it does not, and says so in why.
6.3 A job that ran compiled
A job whose request holds compile runs its program compiled, and its
result’s compiled holds, beside the summary (basis, level, budget,
distance, the bound, verdict, counts and certificate, the BLAKE3 of the
certificate’s RFC 8785 canonical JSON), the certificate’s chain:
"chain": { "source": "<64 hex>", "output": "<64 hex>",
"layer": "exact_simulation", "weakest": "bounded",
"passes": [ { "pass": "lower", "input": "<64 hex>", "output": "<64 hex>",
"layer": "exact_simulation", "bound": 0.0 }, { "…": "…" } ] }
The chain is held to rules 2 to 5 and 7 of §6.1 (with compiled.distance as
the bound and compiled.epsilon as the budget), to weakest, and to a
layer of §5.2. A verifier then reads the request again, which compiles its
program: reproduced when that gives this compiled byte for byte;
differs when the chain breaks a rule, the request asks for no compile, or
the verifier’s own engine gives another; otherwise host_statement.
7. What each method guarantees
7.1 Exact arithmetic
A gate whose angles are whole eighths of a turn has a matrix with entries in
D[ω] = Z[ω][1/√2], ω = e^{iπ/4}: the Paulis, h s sdg t tdg sx sxdg, the
rotations and u at multiples of π/4 (each up to a global phase), cx cy cz ch swap iswap, cp at multiples of π/4, crx cry crz at multiples of π/2
(under a control the rotation’s own phase counts, and its half angle must be
a whole eighth), rxx ryy rzz at multiples of π/4, ccx ccz cswap. A
circuit of such gates on up to 6 qubits is multiplied out as one matrix of
elements of Z[ω] over a common power of √2, with integers of any size and
no rounding. Two such unitaries are equal up to a global phase exactly when
they are proportional: Aᵢ·Bₚ = Bᵢ·Aₚ for every entry i, for one entry p
where B is not zero.
Guarantee: a proof, the same bits on every host, of the circuit as the
engine reads it: an angle within 10⁻¹² eighths of a whole eighth of a turn
is read as that eighth, here as everywhere in the engine. Limits: 6
qubits, 2²² gate-entry updates for the pair, and no gate outside the ring;
past any of them nothing is concluded and the next check is asked.
A gate in the ring may lower to gates outside it (a controlled phase at an
odd eighth lowers through sixteenths of a turn): that decomposition is
compared in doubles, and lower’s layer is then exact_simulation.
7.2 One-qubit synthesis
- A Clifford+T word is multiplied out over
Z[ω]/√2ᵏand written again in its normal form, which has the fewestTgates of any word for that operator. The word is checked to multiply back to the operator, exactly. Guarantee: a proof (exact_arithmetic), and theTcount is optimal for the operator. - Any other run is one unitary, written as
Rz(β)·Ry(γ)·Rz(δ)(its Euler angles, read from the matrix with the crate’s own arctangent) and so as oneugate; forclifford_tasRz·H·Rz·H·Rz, at most three rotations for the approximation. Guarantee: compared with the run on their 2×2 matrices and kept only within1e-12;exact_simulation.
7.3 A rotation in Clifford+T
rz(θ) at an angle off the multiples of π/4 is written as a Clifford+T word
by the published grid-problem method: for the denominator exponent
k = 0, 1, 2, …, the elements u of Z[ω] with u/√2ᵏ in the part of the
unit disk within ε of the rotation and with its conjugate in the unit disk
are enumerated as a two-dimensional grid problem; for each, t†t = 2ᵏ − |u|²
is solved in Z[ω] by factoring; the first k with a solution gives the
operator, and of the operators found at that k the one whose word has the
fewest T gates is taken, then the nearest. All of it is integer and
fixed-point arithmetic (320 fractional bits).
Guarantee. The word is Clifford+T exactly; it multiplies back, in the
ring, to the operator found; and its distance to rz(θ), up to a global
phase, is computed again from the word itself in fixed point and rounded up.
That recomputed distance is the pass’s bound and each rotation’s
distance, and it is at most the rotation’s share of the budget, or the
compile is refused. The same angle and ε give the same word on every host.
What is not guaranteed. The word is not proved the shortest. At each k
at most 64 candidates have their norm equation tried, and a candidate whose
factoring passes 2¹⁴ steps is passed over; a shorter word behind such a
candidate is missed. Measured: against every Clifford+T operator of at most
11 T gates, the word’s T count is the optimum in 21 of 24 cases and one
more in 3; over 1 192 angles and precisions from 10⁻¹ to 10⁻¹³ it is
never more than a reference implementation’s of the same method. The count
is close to 3·log₂(1/ε).
Measured. The T count of the word for rz(θ) against ε (the engine’s
test the_t_count_against_epsilon_is_the_table_the_specification_gives
pins every entry and its k; every word’s distance, recomputed from the word,
is within its ε). Each synthesis took under a tenth of a second, measured
on one core of an arm64 host in a release build.
θ \ ε | 10⁻² | 10⁻³ | 10⁻⁴ | 10⁻⁵ | 10⁻⁶ | 10⁻⁷ | 10⁻⁸ | 10⁻⁹ | 10⁻¹⁰ |
|---|---|---|---|---|---|---|---|---|---|
π/7 | 20 | 27 | 35 | 51 | 56 | 72 | 78 | 89 | 98 |
1 | 14 | 29 | 38 | 48 | 61 | 71 | 80 | 89 | 100 |
0.123 | 17 | 29 | 35 | 47 | 56 | 72 | 80 | 87 | 97 |
3·log₂(1/ε) | 19.9 | 29.9 | 39.9 | 49.8 | 59.8 | 69.8 | 79.7 | 89.7 | 99.7 |
The rotations vectors (§9) pin five of these words, and the second
implementation (§9) multiplies each pinned word out again in integers and
computes its distance in 90-digit decimals: every pinned distance is the
word’s own, rounded up, and within its ε.
7.4 Two-qubit synthesis
Any two-qubit unitary is (A₁⊗A₂)·exp(i(a·XX + b·YY + c·ZZ))·(B₁⊗B₂) up to a
phase (the KAK decomposition), with a, b, c reduced to (−π/4, π/4].
- Around CNOTs (
resynth_2q, and the basisczwith eachcxwrittenh·cz·h): three, or two when a coordinate is zero, none when all are. - Around
rzzorrxx(the baseszzandxx): the three terms commute, so the middle is one gate for each coordinate that is not zero, between the one-qubit Cliffords that turn the term’s axis into the gate’s own. A coordinate of the sign that would give a negative angle is the gate between a Pauli on the first qubit that anticommutes with the term. So a controlled phase or a CNOT takes onerzzor onerxx, where it takes twocz; a swap takes three of any.
A block is also written gate by gate through fixed identities (cx as
h·cz·h; cz as one rzz(π/2) or rxx(π/2) with quarter turns undone),
and that is kept where it spends no more two-qubit gates.
Guarantee and accuracy class. The decomposition is numeric: a
fixed-order Jacobi eigen-solver using only + − × ÷ √ and the crate’s own
trigonometric functions, in doubles. It is deterministic, the same bits on
every host, but it is not exact arithmetic. Every block written is compared
with the block it replaces on their 4×4 matrices and kept only within 1e-9;
the measured distances add to the pass’s bound. The layer is
exact_simulation, the verdict exact, never proof. A job that runs such
an output does not gain the bit-exact class from it: the bit-exact method
takes dyadic angles only.
7.5 T-count reduction
Three passes lower the T count, and all are proofs when the circuit is
Clifford+T:
phase_foldfollows the circuit as a sum over paths: a wire holds an affine function of the path variables (one for each input qubit, a fresh one where a gate that is not a permutation of basis states writes the wire), and a phase gate on a wire holding the parityfmultiplies the path’s amplitude bye^{iθf}. Phases on one parity add, across Hadamards too. The check recomputes the phase polynomial of the input and the output: the same circuit once the phases are taken out, and the same angle on every parity, in whole eighths of a turn. Where the pass changed the circuit, the circuit before and after are also multiplied out overZ[ω]/√2ᵏwithin §7.1’s limits: the check’sringisproved, ornot decidedpast the limits or off the ring, and a pass the ring finds changed the unitary is rejected.resynth_1qwrites each run of one-qubit Clifford+T gates in its normal form (§7.2).phase_resynthsearches for identities among phase polynomials:- Regions. The circuit is cut into regions of
cx cz swap x y z s sdg t tdg(andrz,pat multiples of π/4); any other gate ends the regions on its qubits. A region gate goes to the highest level its qubits have reached and any other gate after the regions of its level, which moves gates only past gates on other qubits; that is checked so: every qubit’s gates in their order. - What a region is. On
w ≤ 64wires a region is|x⟩ ↦ ω^{f(x)}·|A·x ⊕ b⟩,f(x) = Σₚ cₚ·(p·x)summed over paritiespof its inputs with coefficients modulo 8. A term with an odd coefficient is aTgate. Two sets ofTterms differ by a Clifford (S,ZandCZon parities) exactly when they have the same signature, the parity, for everyα ≤ β ≤ γ, of the terms holding all three variables; the sets with the signature of the region’s are a coset of the punctured Reed–Muller codeRM(r−4, r)*,rthe dimension the terms span. - The search. Where
r ≤ 6every word of the code (at most2²²) is tried in Gray-code order and the first lightest word of the coset is taken: the fewestTgates any rewriting of that region’s polynomial can take. Wider, third-order duplicate-and-destroy: forzthe sum of two terms and aythat keeps the signature, addingzto the termsynames makes the two one, which cancel; the pairs are tried in order until none has such ay. That finds fewer, not always the fewest. - The region written again. The Clifford left between the region’s
polynomial and the new
Tterms is read from its coefficients and written asSandZon parities; each term is put on one wire by CNOTs and its phase gates applied there, then the wires are taken toA·x ⊕ bby Gaussian elimination. A region is replaced only when that takes fewerTgates. - The check. Each region written again has the same affine map and
the same coefficient, modulo 8, on every product of one, two and three of
its variables as the region it replaces. A parity is the multilinear
polynomial
⊕_{i∈S} xᵢ = Σ_{∅≠T⊆S} (−2)^{|T|−1}·Π_{i∈T} xᵢ, whose terms of four variables or more vanish modulo 8, and a multilinear polynomial is fixed by its values on{0,1}ʷ: so this is equality up to a global phase, an identity in integers at any width. Where the circuit is within §7.1’s limits the circuit before and after are also multiplied out overZ[ω]/√2ᵏ(ring, as forphase_fold). The layer isexact_arithmetic, the verdictproof. The check also recordsregions(those with twoTgates or more),rewrittenandt_removed. - Limits. A region ends at every gate that is not one of these, so
identities that need a Hadamard taken out of the way (by an ancilla) are
not searched; a region wider than 64 qubits is kept; the polynomials and
searches of one pass share
2²⁸word operations; past them a search stops with what it has found and the regions left are kept, which the check’sbudgetsays. A region written again can take more CNOTs:Tgates are what it lowers.
- Regions. The circuit is cut into regions of
phase_resynth runs at level 2 of clifford_t, after the last
phase_fold, and in any basis and level when a request names it in
passes.
Where the whole circuit is Clifford+T on up to 6 qubits, the whole output is also proved the whole program in exact arithmetic (§5.2), whatever the passes did.
Measured. The T count of Clifford+T programs: as written (each gate
lowered as lower writes it), the output of level 1, the output of level
2’s own passes and of level 2 (the best of that and the levels below it,
§3.1), and the T gates phase_resynth removed in level 2’s passes; then
the CNOTs of the outputs of levels 1 and 2. The first four are of the
cross-simulator’s corpus (quantum-cross-simulator/corpus/qasm/), the rest
of quantum-conformance/compile/benchmarks/. The engine’s test
the_t_count_reductions_are_the_table_the_specification_gives pins every
entry; no compile approximates a rotation, and each within six qubits is
proved the program in exact arithmetic.
| Program | Qubits | As written | Level 1 | Level 2’s passes | Level 2 | phase_resynth | CNOTs, level 1 | CNOTs, level 2 |
|---|---|---|---|---|---|---|---|---|
clifford_t_n4_d20 | 4 | 19 | 11 | 11 | 11 | 0 | 34 | 31 |
clifford_t_n8_d40 | 8 | 72 | 34 | 36 | 34 (level 1’s) | 0 | 156 | 156 |
clifford_t_n12_d40 | 12 | 96 | 46 | 46 | 46 | 0 | 232 | 230 |
grover_n3 | 3 | 28 | 28 | 28 | 28 | 0 | 24 | 24 |
ccz_triples_n4 | 4 | 28 | 8 | 7 | 7 | 1 | 16 | 13 |
ccz_line_n6 | 6 | 28 | 14 | 13 | 13 | 1 | 18 | 31 |
cccz_ancilla_n5 | 5 | 21 | 15 | 15 | 15 | 0 | 16 | 16 |
toffoli_chain_n7 | 7 | 35 | 23 | 23 | 23 | 0 | 26 | 26 |
adder_n8 | 8 | 42 | 24 | 24 | 24 | 0 | 43 | 43 |
What it shows: phase folding takes most of what there is to take, and
phase_resynth finds more where several Toffolis share variables inside
one region (ccz_triples_n4: 4·Σ xᵢxⱼxₖ over the four triples is seven
T gates, not eight; ccz_line_n6, at 13 more CNOTs). On the random
circuits, the Toffoli chain and the adder no region phase folding leaves
takes fewer by the search (where its terms span six variables or fewer,
none can); what more there is needs the Hadamards between regions taken out
of the way, which no pass here does. On clifford_t_n8_d40 level 2’s own
passes write two-qubit blocks again with six fewer CNOTs and no more T
gates, but phase folding, after them, then has two T gates fewer to merge:
36 against level 1’s 34. Each block is better on the objective where it is
written; the loss shows only in the whole, so the guard (§3.1) keeps level
1’s output, and level 2 is never worse than level 1. Running phase folding
before resynth_2q gives 34 T gates and 150 CNOTs here, but more T
gates on five of the corpus’s rotation-heavy programs (dyadic_n6_k20,
gate_c2ry, gate_c2rz, rotations_wide_n20, tn_shallow_n26, from 2 to
28 more) and fewer on two (rotations_n6, rotations_counts_n6, 12 fewer),
so the order stays as it is.
8. Determinism
A compile is the same bytes on every host: the synthesis of rotations is
integer and fixed-point arithmetic; the numeric decompositions use only
+ − × ÷ √ and the crate’s own trigonometric functions, with fixed-order
eigen-solvers; no output depends on a map’s order, a clock or a thread.
That is what lets a verifier compile again and compare (§6.2). The
conformance vectors pin the digest of each certificate; they are held on
macOS arm64, Linux x86-64, Linux arm64 and wasm32.
9. Conformance
quantum-conformance/compile/vectors.json holds:
compile: requests in every basis, each pinned to its certificate’s digest, its program’s and output’s digests, its layers and its bound; every layer of §5.1 and §5.2 is stood on by one of them, andphase_resynthlowers theTcount in two (one at level 2, one asked for by name);rotations: angles and precisions with the word, itsTcount,kand its distance;blocks: two-qubit blocks and how many of each device basis’s gate each takes;refuse: requests that are refused (§2), with words the refusal holds;forged: sealed compiles changed and sealed again, each breaking one rule of §6, and what a verifier must answer; and certificates another engine sealed, answeredreproduced,partlyandhost_statement. A vector whose edit breaks the form names the rule of §6.1 it breaks; each rule a changed member can break (2 to 9, and 11, the guard’s) has one.
quantum-conformance/compile/benchmarks/ holds the Clifford+T programs of
§7.5’s table that are not the cross-simulator’s.
quantum-conformance/tools/compile_form.py is a second implementation of
§6.1 and of §7.3’s guarantee, in Python, from this text alone. It holds the
set’s pinned certificates to the eleven rules (certificate.json, of the
forged vectors’ first request, and guarded.json, a level-2 compile’s with
its guard) and makes the forged vectors’ edits to the certificate of their
request: each must break the rule its vector names, and a vector that names
none must leave the form holding. And it multiplies each rotations vector’s
word out over Z[ω]/√2ᵏ in integers: the word must be Clifford+T with the
T count pinned, unitary, and no farther from its rotation, computed in
90-digit decimals, than its pinned distance, which must be that distance
rounded up and within ε.
10. What it leaves out
- Placing and routing on a device, and the device bases’ one-qubit forms
(
prx,gpi,gpi2withZrotations carried in their phases): a compile tocz,zzorxxwrites standard one-qubit gates around the two-qubit gate. A provider’s job is compiled exactly, from dyadic angles, by quantum-providers §4, and carries no certificate of this form. - A proof of equivalence at any angle and any width: past the limits of §5.2 a compile stands on its passes’ checks.
- A shortest Clifford+T word for a rotation (§7.3), and the approximation of a general one-qubit unitary as one word: it is written as at most three rotations, its Euler angles read in doubles, each angle that is a whole eighth of a turn written as the gates it is and each other one approximated (§7.2).
- The fewest
Tgates of a whole Clifford+T circuit:phase_resynthfinds the fewest for each region’s phase polynomial where its terms span six variables or fewer (§7.5), but a region ends at every Hadamard, and taking Hadamards out of the way with ancillas, which lowers the count of arithmetic circuits further, is not done. - Programs that measure in the middle.