Metadata-Version: 2.4
Name: qoptct
Version: 0.4.0
Summary: qopt: verified Clifford+T circuit optimizer (T and CNOT counts) with a Qiskit transpiler plugin
Author: Maksym Shchehlov
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/seglovmaksim695-creator/qopt
Project-URL: Repository, https://github.com/seglovmaksim695-creator/qopt
Project-URL: Issues, https://github.com/seglovmaksim695-creator/qopt/issues
Project-URL: Changelog, https://github.com/seglovmaksim695-creator/qopt/blob/main/CHANGELOG.md
Project-URL: DOI, https://doi.org/10.5281/zenodo.24182059
Keywords: quantum computing,circuit optimization,Clifford+T,T-count,CNOT count,verification,qiskit,transpiler plugin
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Topic :: Scientific/Engineering :: Physics
Classifier: Intended Audience :: Science/Research
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: numpy>=2.0
Requires-Dist: qiskit>=2.0
Requires-Dist: pyzx>=0.10
Provides-Extra: net
Requires-Dist: torch>=2.4; extra == "net"
Provides-Extra: qcec
Requires-Dist: mqt.qcec>=3.0; extra == "qcec"
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"
Requires-Dist: qiskit-qasm3-import>=0.5; extra == "test"
Dynamic: license-file

# qopt — a verified Clifford+T circuit optimizer

[![PyPI](https://img.shields.io/pypi/v/qoptct.svg)](https://pypi.org/project/qoptct/)
[![tests](https://github.com/seglovmaksim695-creator/qopt/actions/workflows/tests.yml/badge.svg)](https://github.com/seglovmaksim695-creator/qopt/actions/workflows/tests.yml)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.24182059.svg)](https://doi.org/10.5281/zenodo.24182059)

> **Package name:** the project is called *qopt*, but on PyPI the name `qopt` belongs to an unrelated project.
> Since version 0.3.0 the package is therefore installed and imported as **`qoptct`**:
> `pip install qoptct`, `import qoptct`, command `qoptct`.

`qopt` reduces the **T count** and the **CNOT (CX) count** of Clifford+T circuits given as Toffoli networks
(Feynman `.qc` format). It has a unitary mode and measurement-based modes, and it **never reports a circuit that
has not been checked**: unitary outputs are proven equal to the input (or the input is returned), and every
measurement-based output is proven equal by the exact prover `qoptct.verify` or, when a proof is out of reach,
re-checked by independent simulators over many sampled inputs and measurement outcomes before it is written
(the JSON report says which).

Repository: <https://github.com/seglovmaksim695-creator/qopt>  · Version 0.4.0 · License Apache-2.0 (benchmark files: see `bench_qc/SOURCES.md`) · Author: Maksym Shchehlov

## Installation

```bash
pip install qoptct              # Python 3.11+, macOS or Linux; provides the `qoptct` command and the Qiskit plugin
pip install "qoptct[net]"       # optional: + PyTorch for the neural mode --net
pip install "qoptct[qcec]"      # optional: + MQT QCEC as an extra equivalence checker for unitary circuits
```

Dependencies: numpy, qiskit ≥ 2.0, pyzx. PyTorch is needed only for `--net`; without it every other mode works
and `--net` stops with a message that says what to install.

From the repository (to run the tests, the benchmarks and the scripts):

```bash
git clone https://github.com/seglovmaksim695-creator/qopt.git && cd qopt
python3 -m venv .venv && . .venv/bin/activate
pip install -r requirements.txt                      # exact versions used for the results (incl. torch)
pip install -e ".[test]"
pytest -q tests                                      # a few minutes
```

`requirements-lock.txt` pins the full environment used for testing. Caches are written to `$QOPT_CACHE`
(default `~/.cache/qopt`).

## Usage

```bash
qoptct optimize bench_qc/tof_3.qc -o tof_3_opt.qc                          # unitary, minimum CX (default --mode cx)
qoptct optimize bench_qc/tof_3.qc -o tof_3_opt.qc --net --post             # + neural block resynthesis + CX post-pass
qoptct optimize bench_qc/tof_3.qc -o tof_3.qasm --mode balanced            # fewer T, CX <= 1.5x unitary CX
qoptct optimize bench_qc/mod_red_21.qc -o m.qasm --mode t --clean          # minimum T, clean-ancilla model
qoptct optimize X.qc --report report.json                                  # JSON report (also printed to stdout)
qoptct optimize X.qc -o x.qasm --mode t --prove                            # + exact proof of the written result
qoptct prove x.qasm X.qc                                                   # exact proof of any output against its input
```

Python: `import qoptct; names, ref, best, how = qoptct.optimize("X.qc")`.

| option | meaning |
|---|---|
| `--mode cx` (default) | unitary output, minimum CX; proven equal to the input, otherwise the input is returned. Written as `.qc`, or as OpenQASM 3 if the `-o` file name ends in `.qasm` |
| `--mode balanced` | measurement-based output (OpenQASM 3) with lower T and CX ≤ `--cx-factor` (1.5) × unitary CX, if one is found and verified |
| `--mode t` | lowest T found (measurement-based), CX may grow |
| `--clean` | clean-ancilla model (see below) for the measurement-based modes |
| `--net` | neural block resynthesis (models in `qoptct/models/`; needs `pip install "qoptct[net]"`) |
| `--post` | CX post-pass on H-free regions (slow) |
| `--meas` | older Gidney transformation (clean-ancilla model), kept for compatibility |
| `--tgad`, `--vartodd` | Hadamard gadgets + TODD; `--vartodd` also tries an external VarTODD binary given by `QOPT_VARTODD_BIN` |
| `--prove` | prove the written result exactly with `qoptct.verify` (also for unitary results); the status is in the report |
| `--no-arith`, `--no-bandc`, `--no-gf2m`, `--no-cxpass` | switch off one optional module (see below) |
| `--no-contrib` | switch off all optional modules (0.3 behaviour) |
| `--budget S` | total seconds for all optional-module stages (default 1500; 0 = unlimited) |
| `--time-limit S` | overall seconds of a run (default 3600; 0 = none): all searches — the unitary portfolio, its proofs, the module stages and the measurement-based searches — stop there and the best result checked so far is written (in the worst case the input itself). Only the final check of a written measurement-based result (or `--prove`) may follow: usually under a minute, at most ~15 min |
| `--and-sec S` | seconds for the variant search of the logical-AND compiler in balanced/t modes (default 1800; 0 = unlimited) |
| `--contrib-sec S`, `--source-sec NAME=S` | time limit of one module call (default 240 s; `bandc` gets more on large circuits) |
| `--require-proof` | accept module results above 22 qubits only with an exact proof |
| `--keep-temp` | keep the work directory with the intermediate files of the stages (path in the report: `temp_dir`) |

Measurement-based outputs are written only if they pass the checks described below; otherwise the unitary result is
written. The JSON report (`final`) says which candidate was used, how it was checked and its T/CX/qubit counts
(`final.file`: `qc` or `openqasm3`; `search_seconds`: time until the searches ended). The written OpenQASM 3 is
readable by `qiskit.qasm3.loads` (with `qiskit-qasm3-import`): conditions are single measured bits or their negation,
possibly nested. Where a stage produced an XOR (`^`) or AND (`&&`) condition, the result is rewritten — the condition
is computed into an idle measured qubit and measured once more (same T and CX, one more measurement), or the
correction is repeated per term — and proven again; `final.qiskit_rewrite` gives the counts before and after. If no
rewritten form can be proven, the previous readable result is written. Intermediate files are kept in a private
temporary directory (removed at the end unless `--keep-temp`), and `-o` is written atomically (temporary file +
rename), so it never holds a partial or intermediate circuit.

Exit codes of `qoptct optimize`: 0 — a result was written; 3 — usage or input error (missing or unreadable file,
malformed circuit, unknown gate, undeclared wire, missing output directory), reported as one `error: ...` line on
stderr. `qoptct prove`: 0 PROVED, 1 REFUTED, 2 UNKNOWN, 3 usage or input error (an input error is never reported as
REFUTED). `python -m qoptct.verify` uses the same codes.

## Optional modules and exact proofs (new in 0.4)

All modules are part of the package; each one can be switched off, and none of them can break a run: every call
runs in a child process with a hard time limit, an error or a timeout only skips the module, and **every circuit a
module returns is checked again by the core** before it is compared with the other candidates.

| module | what it does | used in |
|---|---|---|
| `qoptct.contrib.arith` | recognizes classical arithmetic (adders, comparators, addition mod 2^n−1, hidden weighted bit) by its truth table and rebuilds it on logical ANDs | `--mode balanced`, `--mode t` |
| `qoptct.contrib.bandc` | logical-AND compiler for large classical circuits (hundreds to 1600 wires) with exact wire-value tracking | `--mode balanced`, `--mode t` |
| `qoptct.contrib.gf2m` | GF(2^m) multipliers from low-rank bilinear decompositions (tables shipped with the package) | `--mode balanced`, `--mode t` |
| `qoptct.contrib.cxpass` | CX post-pass: block re-synthesis of CX/phase regions, merged and XOR-conditioned corrections | all modes |
| `qoptct.verify` | exact prover and fast checkers (below) | checks of all measurement-based results |

How a candidate is accepted:

* ≤ 22 qubits in total: the state-vector checker (30 random inputs), then the exact proof; if the proof does not
  finish in time, a stronger sampled check with 64–256 random inputs and freshly sampled measurement outcomes.
* > 22 qubits: the exact proof; if it ends UNKNOWN (time or width), the sparse-state / path-sum sampled checks of
  `qoptct.verify` (not a proof; the report says so). `--require-proof` accepts only proven results.
* A REFUTED result is never written; the optimizer falls back to the proven unitary result.

`qoptct prove CIRCUIT REF.qc [--clean] [--budget S]` proves that an output (OpenQASM 3 as written by qoptct, or a
`.qc` file) implements the input in the unitary, strict or clean model. It prints JSON and exits with 0 (PROVED),
1 (REFUTED), 2 (UNKNOWN) or 3 (usage or input error). The proof covers every basis input and every combination of measurement outcomes
(sum-over-paths normal form or a trace miter over Z[ω]); unitary circuits can also be handed to MQT QCEC when
`qoptct[qcec]` is installed. From Python:

```python
from qoptct.verify import prove, check_dense, check_sparse, quick_check
r = prove("x.qasm", "X.qc", clean=False, budget_sec=120)    # {"status": "PROVED"|"REFUTED"|"UNKNOWN", "method", "detail", ...}
```

The prover runs in its own process (`python -m qoptct.verify._worker`), so it can be called from scripts without an
`if __name__ == "__main__":` guard and from the Qiskit plugin. `QoptPass(cxpass=True)` also applies the CX post-pass
to every optimized run (a post-pass result is used only if it is proven equal again).

## Qiskit plugin

`pip install qoptct` registers two stage plugins for the Qiskit transpiler, both named `qoptct`:

* `optimization_method="qoptct"` — Qiskit's own optimization stage of the chosen level, then `QoptPass` on the
  Clifford+T parts of the (already translated and routed) circuit;
* `init_method="qoptct"` (optional, recommended for Toffoli circuits) — `QoptPass` on the circuit as written,
  while the Toffolis are still Toffolis, before Qiskit's own init stage. Most of the savings come from here.

```python
from qiskit import QuantumCircuit, transpile
from qiskit.quantum_info import Operator

qc = QuantumCircuit(5)                                                 # tof_3 from bench_qc/
qc.ccx(0, 1, 4); qc.ccx(2, 4, 3); qc.ccx(0, 1, 4)

basis = ["h", "x", "z", "s", "sdg", "t", "tdg", "cx"]                 # Clifford+T
plain = transpile(qc, basis_gates=basis, optimization_level=3)
ours = transpile(qc, basis_gates=basis, optimization_level=3,
                 init_method="qoptct", optimization_method="qoptct")
print(plain.count_ops(), ours.count_ops())
assert Operator(ours).equiv(Operator(qc))                              # same operator up to a global phase
```

CX/T after `transpile` with a Clifford+T basis (Qiskit 2.6.2, levels 1–3 gave the same numbers):

| circuit | Qiskit level 3 | `optimization_method="qoptct"` | `+ init_method="qoptct"` |
|---|---|---|---|
| tof_3 | 18 / 19 | 16 / 15 | 12 / 15 |
| mod5_4 | 28 / 22 | 25 / 16 | 11 / 8 |
| barenco_tof_3 | 24 / 24 | 20 / 16 | 16 / 16 |

A part of the circuit is replaced only if the new version is **proven** equal, strictly cheaper (CX, then T),
and uses only gates and qubit pairs allowed by the basis / coupling map / target; everything else
(measurements, rotations, other gates) is left as it is. With a coupling map, compare with
`Operator.from_circuit(out)`. On circuits with up to 10 qubits per part the global phase is kept exactly.
The "strictly cheaper" rule holds for each replaced part; the later stages of `transpile` (for example the
synthesis of rotations) can still change the totals, so on circuits with rotations compare the final counts
with and without the plugin.

The pass can also be used directly:

```python
from qiskit.transpiler import PassManager
from qoptct.qiskit_qopt import QoptPass
p = QoptPass(); out = PassManager([p]).run(qc); print(p.last)   # runs, replaced, CX/T before and after
```

`QoptMeasPass(ancillas=[...])` is the measurement-based variant (logical AND, needs qubits known to start in |0>).

## Cost models — read this before comparing numbers

The same benchmark has different "best" numbers in different models. All tables say which model they use.

| model | allowed in the output | input wires | ancillas | checked by |
|---|---|---|---|---|
| **unitary** | Clifford+T gates only, same wires | arbitrary state | none | full unitary / PyZX / numerical |
| **strict** (measurement-based) | + fresh ancillas in \|0>, mid-circuit measurements, classically controlled Clifford gates | **all** `.qc` wires are data in an arbitrary state, including wires the benchmark intends as ancillas | fresh ones must end in a basis state, unentangled | `verify_qasm` (strict), `verify_big` |
| **clean** (clean ancillas) | as strict | wires listed in the `.i` line are data; **the other `.qc` wires start in \|0> and must end in \|0>** (the intended use of e.g. `tof_n`, `mod_red_21`) | as strict | `verify_qasm(clean=True)` |

* *unitary* is the model of most circuit-optimization papers (Nam et al., PyZX, GUOQ, Quarl, …).
* *strict* is stronger than *clean*: a strict circuit is valid in the clean model, not vice versa.
* In both measurement-based models the logical AND costs 4 T and its uncomputation 0 T (Gidney 2018); that is
  why T counts there are far below unitary ones. They must not be compared with unitary T-count records.
* Published H-gadget T-count records (TODD/FastTODD, AlphaTensor-Quantum) use yet another model (gadget ancillas,
  no classical feed-forward on the output). They are listed for orientation only.

## Results (23 benchmarks)

| circuit | qubits | Toffolis | input T/CX | unitary T/CX | strict T/CX (+extra) | clean T/CX (+extra) |
|---|---|---|---|---|---|---|
| adder_8 | 24 | 57 | 399/409 | 193/223 | — | — |
| barenco_tof_10 | 19 | 32 | 224/192 | 72/72 | 59/48 (+3) | 59/48 (+3) |
| barenco_tof_3 | 5 | 4 | 28/24 | 16/14 | 8/9 (+2) | 8/9 (+2) |
| barenco_tof_4 | 7 | 8 | 56/48 | 24/24 | 12/13 (+3) | 12/13 (+3) |
| barenco_tof_5 | 9 | 12 | 84/72 | 32/32 | 16/17 (+4) | 16/17 (+4) |
| csla_mux_3 | 15 | 10 | 70/80 | 64/64 | 40/70 (+1) | 28/84 (+3) |
| csum_mux_9 | 30 | 28 | 196/168 | 84/112 | — | — |
| gf2^4_mult | 12 | 16 | 112/99 | 68/86 | 58/115 (+0) | 36/79 (+1) |
| gf2^5_mult | 15 | 25 | 175/154 | 115/132 | 90/183 (+0) | 56/124 (+1) |
| grover_5 | 9 | 48 | 336/288 | 166/160 | 124/155 (+4) | 124/155 (+4) |
| ham15-low | 17 | 23 | 161/236 | 97/179 | — | 68/177 (+1) |
| mod5_4 | 5 | 4 | 28/28 | 7/10 | 4/11 (+1) | 4/11 (+0) |
| mod_mult_55 | 9 | 7 | 49/48 | 35/39 | 20/35 (+2) | 12/24 (+1) |
| mod_red_21 | 11 | 17 | 119/105 | 73/61 | 44/58 (+5) | 28/48 (+0) |
| qcla_com_7 | 24 | 29 | 203/186 | 95/111 | 59/565 (+37) | 59/565 (+37) |
| qcla_mod_7 | 26 | 59 | 413/382 | 237/256 | — | — |
| qft_4 | 5 | 2 | 69/46 | 67/37 | 53/265 (+42) | 53/265 (+42) |
| rc_adder_6 | 14 | 11 | 77/93 | 47/65 | 24/54 (+6) | 24/53 (+6) |
| tof_10 | 19 | 17 | 119/102 | 71/54 | 59/71 (+3) | 36/37 (+1) |
| tof_3 | 5 | 3 | 21/18 | 15/12 | 8/10 (+2) | 8/9 (+1) |
| tof_4 | 7 | 5 | 35/30 | 23/18 | 12/15 (+3) | 12/13 (+1) |
| tof_5 | 9 | 7 | 49/42 | 31/24 | 16/20 (+4) | 16/17 (+1) |
| vbe_adder_3 | 10 | 10 | 70/70 | 24/28 | 12/33 (+3) | 12/33 (+3) |

Best point per model: unitary = minimum CX; strict and clean = minimum T (then CX, then extra qubits). Other Pareto points (e.g. fewer extra qubits) are in results/TABLE.md.

Totals over the circuits that have a result in the model: unitary: 23 circuits, T 3093→1656, CX 2920→1813; strict: 19 circuits, T 1924→718, CX 1725→1747; clean: 20 circuits, T 2085→671, CX 1961→1781

Full tables with Pareto fronts and provenance: `results/TABLE.md`, machine-readable `results/table.csv`;
circuits: `results/best/<model>/<name>.qasm` and `results/pareto/<model>/`.

## Hardware check (IBM Quantum)

On `ibm_marrakesh`, the unitary `qopt` circuits returned the correct answer more often than the input circuits on all
five benchmarks tried (+2 to +10 percentage points), while the measurement-based circuits were worse on current
hardware (mid-circuit measurement latency). Details: `results/hardware/README.md`.

## Comparison with nine tools (summary; details in `results/COMPARISON.md`)

Tools run on the same files: Qiskit 2.6.1, PyZX 0.10.8, pytket 2.18.5, Cirq 1.7, Q# Resource Estimator 1.31,
Qualtran 0.7.0, pyLIQTR 1.0.1, Qrisp 0.9.10, PennyLane 0.45.1. All produced circuits were verified with the same
checker; estimates without circuits are marked as such.

| circuit | best tool circuit by T (as-is or MCX rewrite) | best tool circuit by CX | qopt unitary | qopt strict | qopt clean |
|---|---|---|---|---|---|
| barenco_tof_3 | 8/9 +2 (PennyLane 0.45.1, and_ladder; strict) | 8/9 +2 (PennyLane 0.45.1, and_ladder; strict) | 16/14 | 8/9 (+2) | 8/9 (+2) |
| barenco_tof_4 | 12/13 +3 (PennyLane 0.45.1, and_ladder; strict) | 12/13 +3 (PennyLane 0.45.1, and_ladder; strict) | 24/24 | 12/13 (+3) | 12/13 (+3) |
| barenco_tof_5 | 16/17 +4 (PennyLane 0.45.1, and_ladder; strict) | 16/17 +4 (PennyLane 0.45.1, and_ladder; strict) | 32/32 | 16/17 (+4) | 16/17 (+4) |
| csla_mux_3 | 62/161 +0 (PyZX 0.10.8, full_reduce; strict) | 64/72 +0 (Qiskit 2.6.1, as-is; strict) | 64/64 | 40/70 (+1) | 28/84 (+3) |
| gf2^4_mult | 68/274 +0 (PyZX 0.10.8, full_reduce; strict) | 96/99 +0 (Qiskit 2.6.1, as-is; strict) | 68/86 | 58/115 (+0) | 36/79 (+1) |
| gf2^5_mult | 115/509 +0 (pytket 2.18.5, zxperm_fpo; strict) | 155/154 +0 (Qiskit 2.6.1, as-is; strict) | 115/132 | 90/183 (+0) | 56/124 (+1) |
| grover_5 | 166/301 +0 (PyZX 0.10.8, full_reduce; strict) | 296/288 +0 (Qiskit 2.6.1, as-is; strict) | 166/160 | 124/155 (+4) | 124/155 (+4) |
| ham15-low | 97/322 +0 (PyZX 0.10.8, full_reduce; strict) | 147/236 +0 (Qiskit 2.6.1, as-is; strict) | 97/179 | — | 68/177 (+1) |
| mod5_4 | 8/20 +0 (PyZX 0.10.8, full_reduce; strict) | 8/20 +0 (PyZX 0.10.8, full_reduce; strict) | 7/10 | 4/11 (+1) | 4/11 (+0) |
| mod_mult_55 | 35/89 +0 (PyZX 0.10.8, full_reduce; strict) | 45/48 +0 (Qiskit 2.6.1, as-is; strict) | 35/39 | 20/35 (+2) | 12/24 (+1) |
| mod_red_21 | 73/149 +0 (PyZX 0.10.8, full_reduce; strict) | 107/105 +0 (Qiskit 2.6.1, as-is; strict) | 73/61 | 44/58 (+5) | 28/48 (+0) |
| qft_4 | 67/55 +0 (PyZX 0.10.8, full_reduce; strict) | 409/45 +0 (Qiskit 2.6.1, as-is; strict) | 67/37 | 53/265 (+42) | 53/265 (+42) |
| rc_adder_6 | 47/103 +0 (PyZX 0.10.8, full_reduce; strict) | 67/83 +0 (Qiskit 2.6.1, as-is; strict) | 47/65 | 24/54 (+6) | 24/53 (+6) |
| tof_10 | 36/37 +1 (PennyLane 0.45.1, and_ladder; clean) | 36/37 +1 (PennyLane 0.45.1, and_ladder; clean) | 71/54 | 59/71 (+3) | 36/37 (+1) |
| tof_3 | 8/9 +1 (PennyLane 0.45.1, and_ladder; clean) | 8/9 +1 (PennyLane 0.45.1, and_ladder; clean) | 15/12 | 8/10 (+2) | 8/9 (+1) |
| tof_4 | 12/13 +1 (PennyLane 0.45.1, and_ladder; clean) | 12/13 +1 (PennyLane 0.45.1, and_ladder; clean) | 23/18 | 12/15 (+3) | 12/13 (+1) |
| tof_5 | 16/17 +1 (PennyLane 0.45.1, and_ladder; clean) | 16/17 +1 (PennyLane 0.45.1, and_ladder; clean) | 31/24 | 16/20 (+4) | 16/17 (+1) |
| vbe_adder_3 | 24/71 +0 (PyZX 0.10.8, full_reduce; strict) | 56/58 +0 (Qiskit 2.6.1, as-is; strict) | 24/28 | 12/33 (+3) | 12/33 (+3) |

Each tool cell: T/CX extra-qubits (tool, variant; model in which the circuit passed verification).

Honest caveats:

* **Given the gate list "as is", no tool replaces Toffolis by logical ANDs with measurement-based uncomputation
  automatically.** Unitary tools give ~7 T per Toffoli minus phase folding; Q#/Qualtran give only estimates
  (4 T per Toffoli) without a circuit.
* **When a human rewrites the circuit as a multi-controlled X** (tof_n, barenco_tof_n), tools reach our numbers or
  beat them: PennyLane's `TemporaryAND` ladder equals our clean-model tof_n points; on barenco_tof_n Qiskit's
  Khattar–Gidney syntheses with one ancilla were better than our general compiler until the MCX recognition
  (`contrib/c12`) was added. Our advantage is automatic discovery in arbitrary networks, not better gadgets.
* Third-party pitfalls and one wrong circuit of a tool are documented in `docs/FINDINGS.md`.

## How to check the results yourself

```bash
python scripts/verify_all.py --jobs 2          # re-verifies all 200 rows of results/table.csv (~40 min)
python scripts/verify_all.py --only tof_3       # one circuit
sh scripts/reproduce.sh cx out                  # re-run the optimizer on all benchmarks (see script header)
```

Every qasm in `results/` is self-contained OpenQASM 3 using `h x z s sdg t tdg cx cz`, `measure`, and `if` on
classical bits (eight files from 0.3.0 — best and Pareto points of qft_4 and qcla_com_7 — use `&&` in conditions, which
`qiskit.qasm3.loads` does not read; `qoptct prove` and `qoptct.verify` read them); data qubits are `q[0..n-1]` in the order of the `.v` line of the `.qc` file, extra qubits follow
and start in |0>.

## Limitations

* Not every result is proven: when the exact prover ends UNKNOWN (deep classical logic such as hwb, very wide
  circuits), measurement-based results rely on sampled checks (many random inputs and measurement outcomes); the
  report's `final.check` / `final.proof` say which. Use `--require-proof` (modules) or `qoptct prove` to insist on a
  proof. Unitary results ≤ 10 qubits are proven exactly; larger ones rely on PyZX, a numerical check (≤ 26 qubits)
  or the exact path-sum prover of `qoptct.verify`.
* Above 22 qubits in total only the module results (arith, bandc, gf2m, cxpass) are available in the
  measurement-based modes; the older H-gadget and AND stages need the state-vector check and are skipped there.
* The neural models were trained on random circuits of 2–4 qubits; `--net` gives small gains (≈ 1–2 % CX).
* Runtime: unitary mode takes seconds for small circuits and up to an hour for the largest benchmarks; the
  measurement-based modes take minutes (with the optional modules up to `--budget` seconds more). Several rewriting programs have internal time limits, so results can
  depend on machine speed.
* Some numbers in `results/` come from longer development searches than a single default run (column `source`
  in `results/TABLE.md`); a default run may give slightly worse points.
* The hand-made clean-model constructions (`contrib/c1/best_clean`) apply only to the exact benchmark files.
* hwb6 is not included (license of the benchmark file).

## Citation

See `CITATION.cff`. A preprint draft is in `paper/preprint.md`.

## Acknowledgements

Benchmarks from the Feynman repository (M. Amy). Logical AND construction: C. Gidney, *Halving the cost of quantum
addition*, Quantum 2, 74 (2018). Sum-over-paths verification: M. Amy, arXiv:1805.06908.
