Simulation, numerics and systems
cancel-before-synthesis
Does an exact cancellation pass save two-qubit gates when it runs before Qiskit splits multi-controlled gates?
Answer
On standard benchmark circuits, almost never. Of 209 MQT Bench circuits with 3 to 10 qubits, the pass removed gates from 28, but only 3 came out of Qiskit's level 3 with fewer two-qubit gates: 20 fewer of 29,523, or 0.07 %. None came out with more. On compute-use-uncompute programs that test the same condition in three statements, each lowered on its own the way a compiler lowers a conditional, it used 59.8 to 62.7 % fewer two-qubit gates than the best of four stock Qiskit pipelines in 10 of 12 programs. Those programs are redundant by construction: each holds six copies of its oracle, and four of them only undo each other. So the saving shows what the stock pipelines leave in; it is not a discovery of the pass.
How it was measured
- In Qiskit's level 2 and level 3, every gate on three or more qubits is split into one- and two-qubit gates first, and inverse pairs are cancelled only after that. Level 1 without a coupling map cancels first, but only neighbouring gates from a fixed list that stops at three controls. Tests in the repository pin each of these facts, so a Qiskit release that changes them fails CI.
- The pass sits at the end of Qiskit's pre_init stage, so it runs before anything else touches the gates, and everything after it is stock level 3. Each gate looks back along its own qubits, past every gate it is shown to commute with, for its inverse or for a phase on the same pattern to merge with.
- The rules are exact for X gates and phase gates with any number of controls in any control state. They read the controls bit by bit, so a check costs as much as the gate has controls, not as much as its matrix, whose side doubles with each control. A gate the rules cannot place is not moved, so a missing rule can only miss a saving, never change the result.
- Five pipelines compile the same circuits to IBM Heron's basis (cz, rz, sx, x) with all-to-all connectivity and one seed: level 1, level 2, level 3, level 3 with Qiskit's own CommutativeInverseCancellation, and level 3 with this pass.
- The programs follow how Varga, Aragonés-Soria and Oriol (arXiv:2401.15073) describe a conditional on a quantum value in the Rhyme language: compute the condition into an ancilla, run the body controlled by it, uncompute. The oracles are Qiskit's BitFlipOracleGate, the predicates come from the Rhyme tutorials. In the 2 same-condition programs without a saving, no gate acts on more than 4 qubits, and CommutativeInverseCancellation finds the same. Where the statements test two conditions in turn (3 programs), the pass removed nothing.
- The output of the pass equals its input on two random states, global phase included, for 224 of 224 circuits. 1,120 of 1,120 compiled circuits give the same state as their input from the all-zero state, the input Qiskit compiles for. The tests compare full operators on thousands of random small circuits.
Proof
Every file is pinned to the commit the numbers come from, so the links cannot drift.
Reproduce it
pip install --require-hashes -r requirements.lock
pytest -q
python -m presynth.run --config configs/full.json --results results
python scripts/make_tables.pyCPU only, a few minutes on a laptop. The last command writes the README's answer and tables from the result files. CI runs the tests, mypy and vulture, checks that the README matches the result files, and runs every pipeline on small circuits.
Limits
- The programs are a model of the paper's description, not output of Rhyme's compiler, which is not public. A compiler that joins statements on the same condition before lowering them would not need this pass for it.
- All-to-all connectivity, one basis, one seed and one Qiskit version. Routed counts on a real coupling map, where SWAP gates come on top, are not measured.
- Gate counts and depth only: no noise model, no hardware run.
- The pass only cancels and merges; it does not resynthesise. A gate it cannot move past, such as an h on the target, ends the search.