Phase folding published
Every wire carries a parity of the circuit's inputs: CNOTs XOR parities, X gates flip them, and other gates start new ones. Diagonal rotations on the same parity merge into one, however many gates lie between them, and the CNOTs they kept apart then cancel.
Adders: 19% fewer CNOTs than Qiskit at level 3 (196 against 241 at 32 qubits; 181 since 0.4.13, with gathering and Pauli pairs); QFT, QAOA and Heisenberg chains: 7–25% fewer gates in all; compiling through CNOTs first does the same for CZ devices (adders: 40 CZs instead of 49).
Amy, Maslov and Mosca, IEEE TCAD 2014; Nam, Ross, Su, Childs and Maslov, npj QI 2018 · phase_folding.rs
Rotation merging through Cliffords published
Phase folding stops at Hadamards. Moved through every Clifford gate before it with a stabilizer tableau, each Z rotation is a rotation about a Pauli string, and rotations about the same string merge whenever everything between them commutes with it.
Since 0.4.12 the tableau takes each gate in one update, where a √X, a CZ or an X used to be three or four (H S H, H CX H, H S S H): the same outputs, byte for byte, with rotation merging 41% cheaper on a CZ chip compilation of the 16-qubit Hamiltonian (1.37 → 0.81 billion instructions). That made CZ compilations 0.97–0.98× the time; the 16-qubit Hamiltonian on a heavy-hex chip still takes 2.6 s, against Qiskit's 0.11–0.15 s, most of it in rounds of the whole pipeline.
Zhang and Chen, arXiv:1903.12456 · pauli_network.rs (apply_all_to_map)
Pauli networks extended
A Hamiltonian simulation step is a list of Pauli rotations, each conventionally written with its own CNOT ladders. QCC reads the circuit back as rotations and one Clifford, and builds it again greedily: each controlled-Pauli gate is the one that most lowers the weights of the rotations coming next, so commuting rotations share their CNOTs. It is kept only when it needs no more two-qubit gates and no more gates in all.
One Trotter step of random Hamiltonians: 47% fewer CNOTs than Qiskit at 8 qubits (101 against 191), 20% at 16 (313 against 393) and 7% at 32 (687 against 740), with 39%, 18% and 15% fewer gates in all (286, 790 and 1511 against 474, 972 and 1789).
After Rustiq: Goubault de Brugière and Martiel, arXiv:2404.03280, and pytket's GreedyPauliSimp, whose seeded trials QCC also runs; Clifford synthesis after Bravyi et al., arXiv:2105.02291 · pauli_network.rs
Pauli networks on the chip's couplings extended
A Pauli network synthesized as if every qubit were coupled puts its CNOTs on pairs far apart, and routing them costs more than the network saves. On a chip QCC also synthesizes it on the physical qubits, from each initial layout its routings found: every CNOT that sets up a rotation is on a coupled pair, and each candidate is scored by what it does to every rotation's spanning tree on the chip (the minimum spanning tree of its qubits under the chip's distances) rather than to its weight, so commuting rotations still share CNOTs. The Clifford left at the end is synthesized on the chip too, or routed (next entry), and the best trial of each is optimized as one more candidate, kept only if it is the cheapest.
Since 0.4.15, on a 19-qubit heavy-hex chip: Hamiltonians at 8 and 16 qubits 335 → 189 and 1321 → 1078 CNOTs (Qiskit 425 and 1463), with CZ 307 → 184 and 1231 → 1095; on 24 held-out random Hamiltonians 15–35% fewer two-qubit gates, every one. Two-qubit gates against Qiskit on the chip 0.924× → 0.880× with CX, 0.897× → 0.862× with CZ. The 16-qubit Hamiltonian takes 2.8× the time with CX (1.4 s) and 1.5× with CZ (3.0 s).
Architecture-aware Pauli synthesis as in Paulihedral (Li et al., ASPLOS 2022, arXiv:2109.03371) and Tetris (Jin et al., ISCA 2024, arXiv:2309.01905), here inside the Rustiq-style greedy network · pauli_network.rs (synthesize_on) · device.rs (networks_on_chip)
Clifford synthesis on the chip's couplings published
A Pauli network on a chip ends with a Clifford, what is left of the rotations' frame. Synthesized as if every qubit were coupled and then routed, it cost about a tenth of the network's CNOTs. QCC also synthesizes it with every CNOT on a coupled pair: one row of its tableau at a time, the row's two Pauli images are gathered onto one qubit along Steiner trees of the qubits still free (whichever image first needs fewer CNOTs), and that qubit is taken out; the row and qubit needing fewest CNOTs go first, and never a qubit whose removal would split the free ones. Both endings are kept and the best of each optimized, so no circuit gets costlier.
Since 0.4.16, on a 19-qubit heavy-hex chip: Hamiltonians at 8 and 16 qubits 189 → 187 and 1078 → 1063 CNOTs, with CZ 184 → 181 and 1095 → 1030; on 22 held-out random Hamiltonians of 6–16 qubits 10874 → 10463 CNOTs (−3.8%) and 10589 → 10214 CZs (−3.5%), none with more two-qubit gates. Dropping the Clifford altogether would give 9601 CNOTs there, so most of its cost remains. The chip Hamiltonians take 1.10–1.38× the time.
Winderl et al., "Architecture-Aware Synthesis of Stabilizer Circuits from Clifford Tableaus", arXiv:2309.08972; Steiner trees by the heuristic of Takahashi and Matsuyama · pauli_network.rs (clifford_on)
Cheap frames for Pauli networks ours
Single-qubit gates are most of what a Pauli network costs. The basis changes that set up each CNOT are not undone after it: the rotations still to come are read in the new frame, which leaves their weights alone, and the frame is paid for once, at the end. Each CNOT is placed whichever way round needs fewer basis changes, and those use √X, native on IBM devices, rather than Hadamards.
About half the network's single-qubit gates: on a 16-qubit Hamiltonian, 792 gates in all instead of 1285, against Qiskit's 972 and pytket's 887.
pauli_network.rs
A charge for local Cliffords, and trials judged one by one ours
The greedy synthesis of a Pauli network charges each candidate CNOT for the single-qubit Cliffords it needs; a hundredth of a weight only breaks ties. Besides its eight seeded trials at that charge, QCC runs four at a tenth of a weight, which give up a few CNOTs for fewer single-qubit gates, and compares every trial with the direct compilation on its own, keeping the first of the cheapest that needs no more two-qubit gates and no more gates in all. Before, only the trial with the fewest CNOTs was compared, and on a 32-qubit Hamiltonian it needed more gates in all, so no network was kept. The usual trials still run, so no circuit can get worse.
32-qubit Hamiltonian: 740 → 687 CNOTs and 1555 → 1511 gates (Qiskit 740 and 1789, pytket 737 and 1681); 8 qubits 107 / 293 → 101 / 286; on a heavy-hex chip at 8 qubits 349 / 713 → 345 / 648 with CX and 331 / 1333 → 310 / 1119 with CZ. On 15 held-out random Hamiltonians, 0.981× the CNOTs and 0.980× the gates, worse on none. It costs 1.3–1.5× the time on Hamiltonians (32 qubits 0.33 s → 0.40–0.45 s); nothing else changes.
passes.rs (network_trials, paying_network) · pauli_network.rs
Gate counts without Euler angles ours
Two-qubit synthesis prices every way of moving a rotation across a gate by the single-qubit gates it leaves, hundreds of thousands of counts on a large circuit. A count only asks whether some Euler angles are multiples of 2π, and those angles are the phases of products of the unitary's entries, so QCC tests the products directly instead of computing the angles with arctangents. With sparse parities in phase folding and cheaper Clifford tracking in rotation merging, every benchmark circuit compiles faster and to the same gates.
0.73× the time of the previous version in geometric mean over 24 circuits, identical outputs; the 32-qubit Quantum Volume circuit 230 ms → 155 ms (Qiskit: 69 ms).
one_qubit.rs
Two-qubit synthesis in context ours
Runs of gates on one pair of qubits are resynthesized from their 4×4 unitary with the fewest two-qubit gates (KAK). Many syntheses use that many; they differ in their single-qubit gates. A block's outer gates merge with its neighbours' afterwards, so QCC picks the one with the fewest gates between its first and last two-qubit gate, not the fewest in isolation.
Quantum Volume: 1% fewer gates than synthesizing each block alone, which brings QCC level with Qiskit there.
KAK and templates after Vatan and Williams, PRA 2004 · two_qubit.rs
Moving gates through symmetric blocks ours
An XX + YY + ZZ interaction, as in Heisenberg models, commutes with the same rotation on both qubits, so the single-qubit gates around such a block are not fixed: a factor can pass through it from one side to the other. Blocks are synthesized one at a time, so QCC then picks, for each symmetric block, the factor that leaves the gates between it and its neighbours cheapest.
Heisenberg chains: 8–9% fewer gates with CX (1173 against Qiskit's 1568 at 32 qubits; 1143 with Pauli pairs), and with CZ 7–13% fewer than Qiskit instead of a fifth more.
symmetric_blocks.rs
Optimizing to a fixed point for CZ devices extended
For a CZ device QCC reads the circuit through CX, each CZ as H·CX·H, so that phase folding sees parities, then translates it back. Every translation leaves single-qubit gates where the next reading finds more to fold, so one run of the pipeline is far from a fixed point (for CX it nearly is one). QCC runs the pipeline again on its own result while it gets cheaper, up to eight rounds, keeping a round only when it is strictly cheaper. Qiskit's level 3 loops its optimizations the same way, and GUOQ alternates rewriting and resynthesis until nothing improves.
On a heavy-hex chip with CZ: 0.908× Qiskit's two-qubit gates and 0.848× its gates, from 0.917× and 0.868×; the 16-qubit Hamiltonian 1379 → 1292 CZs, 5372 → 4572 gates (Qiskit: 1477, 5357). No circuit got worse; compiling for CZ took 1.65× as long, of which 0.4.5 won back most by running candidates side by side (below).
Xu, Molavi, Tannu and Albarghouthi, Optimizing Quantum Circuits, Fast and Slow, ASPLOS 2025; passes.rs
Independent candidates side by side ours
Much of compiling is several candidates worked out from the same input and compared at the end: SABRE's 32 layout trials, the direct compilation and the one through CX for a CZ device (in every round of the fixed point above), the Pauli networks, and on a chip the routing of the logical circuit with and without a network. QCC runs them on all cores and takes the results back in the order a loop would produce them, so the first of the cheapest is kept as before and the output does not depend on the threads; the direct candidates, which were compiled twice to try a network, are compiled once. Under 64 instructions everything stays on one thread.
The 112 compilations of the benchmark circuits give byte-identical outputs. On 4 vCPUs, against 0.4.4: 0.51× the time on a heavy-hex chip with CX and 0.62× with CZ (the 16-qubit Hamiltonian with CZ 5.6 s → 2.2 s, still slower than Qiskit's 0.15 s), 0.82× inside Qiskit with CZ; unchanged with CX without a chip.
parallel.rs
Syntheses shared across a compilation ours
A compilation for a CZ device runs the pipeline many times on circuits that differ little: the direct pipeline and the one through CX, round after round, on each candidate's qubits. Most blocks come back with the same unitary to the bit, and each pipeline synthesized them again. QCC keeps one compilation's two-qubit syntheses, for each set of native gates, shared by every pipeline on every thread. A synthesis depends only on the unitary, its objective and the native gates, so this changes no output.
On the 16-qubit Hamiltonian on a heavy-hex chip with CZ, 66% of the synthesis requests had been made before in the same compilation. With block gathering that no longer copies what it tries: 0.83× the time of 0.4.5 on the chip with CZ (the Hamiltonian 2.1 s → 1.6 s, still slower than Qiskit's 0.15 s) and 0.82× inside Qiskit with CZ, byte-identical outputs; unchanged with CX.
lower.rs (SynthesisCache)
Gathering blocks through commuting gates extended
Two gates on the same pair of qubits fall in different blocks when a gate on one of them and a third qubit lies between, even if that gate commutes with one of them: cx a,b; cx a,c; cx b,a is a SWAP and one CNOT once cx a,c moves aside. QCC moves such gates out of the way when they commute exactly with what they cross (single-qubit gates counted together), taking along the gates that depend on them, and only where the gathered block needs fewer CNOTs; the circuit is kept only when it needs no more two-qubit gates and no more gates in all.
Random Clifford+T: 150 CNOTs instead of 154 at 16 qubits, and 310 at 32, as many as pytket with fewer gates in all (1034 against 1039). On a heavy-hex chip: the 16-qubit QFT 353 CNOTs instead of 357 (Qiskit 356), the 16-qubit QAOA 180 instead of 188, both with CX; four of the 32 chip results got worse in one count or both.
As tket's Clifford simplification: Fagan and Duncan, arXiv:1901.10114; Sivarajah et al., arXiv:2003.10611 · commuting_blocks.rs
Carrying gates between blocks extended
When the gates between two blocks on a pair do not commute with them, part of a block may still commute with them once moved through the single-qubit gates between: in cx a,b; h b; cx b,c; cx a,b, h b · cx a,b is cz a,b · h b, and the CZ commutes with the control of cx b,c, so it joins the last CNOT and the pair needs one CNOT instead of two. QCC carries the end of a block (from one of its last three two-qubit gates) forward into the next block on its pair, or the start of one back: across a single-qubit gate g the carried part D becomes g D g†, across any other gate it must commute exactly. A move is made only where the two blocks then need fewer CNOTs, on results that will not be optimized again, and the circuit is kept only when it needs no more two-qubit gates and no more gates in all. Gates stay on their pairs, so it is safe on a chip.
On a heavy-hex chip: the 16-qubit Hamiltonian 1336 → 1321 CNOTs, and with CZ 1256 / 4454 → 1231 / 4208 CZs / gates; the 8-qubit one 345 → 335 CNOTs; QAOA 8 94 → 92; the 16-qubit adder 148 → 146. Without a chip, random Clifford+T 150 / 505 → 148 / 499 at 16 qubits (pytket 148 / 495) and 310 / 1034 → 308 / 1030 at 32. No benchmark circuit got more two-qubit gates, and on 82 held-out compilations 22 got fewer and none more. It costs 1.05× the time without a chip and 1.07× on it; the 16-qubit Hamiltonian with CZ on the chip 1.5 → 2.4 s. The largest wins (733 → 704 CNOTs on the 16-qubit Clifford+T circuit on the chip) need more single-qubit gates, and are refused.
Rewrites of this kind appear in ZX-calculus Clifford simplification: Fagan and Duncan, arXiv:1901.10114; extended here to any gates of a block with exact checks · commuting_blocks.rs · device.py
Single-qubit trades through CNOTs ours
A CNOT commutes with a Z rotation on its control and an X rotation on its target, so the runs of single-qubit gates on either side can hand such a rotation across. QCC chooses the angles that make both runs cheapest. It hides Z rotations from phase folding, so it runs only on a circuit that will not be optimized again.
With gathering, random Clifford+T: 278, 505 and 1034 gates in all at 8, 16 and 32 qubits, instead of 293, 525 and 1074.
symmetric_blocks.rs
Pauli and rotation pairs around two-qubit gates extended
A Pauli that commutes with a two-qubit gate (X with a CNOT's target, Z with its control or with a CZ) can be put on both sides of it without changing the circuit, each copy merging into the single-qubit gates on its side. Along a wire this carries a stray X, left by a synthesis between two CNOTs, to gates further on that absorb it for free, or to another X. Qiskit's Optimize1qGatesSimpleCommutation moves gates one commutation at a time into existing runs; QCC solves each wire exactly, across any number of gates, with a dynamic programme over its runs. Since 0.4.14 the last pass also pairs rotations: a whole axis commutes with a CNOT's target (X), its control and a CZ (Z), so at each gate the programme may choose a rotation about it, at an angle that removes an outer rotation of a nearby run, as well as the Pauli. A Z rotation at the end of one run can then join the start of another through several CNOT controls or CZs. It runs once on the final result, after every choice between circuits, so it never changes a two-qubit gate count.
Since 0.4.13: no two-qubit gate added and no circuit costlier; Clifford+T at 16 qubits 499 → 484 gates (pytket 495), QAOA at 32 634 → 615, Heisenberg at 32 1173 → 1143; on adders the gathered blocks, refused before for a few more gates in all, now pay: 40 / 105 → 37 / 104, 92 / 245 → 85 / 244, 196 / 525 → 181 / 524 CNOTs / gates. 1% fewer gates over the benchmark, at 1.04× the time. Rotation pairs (0.4.14): Clifford+T at 32 qubits 1009 → 988 gates (pytket 1039), at 16 484 → 476; on the heavy-hex chip the 16-qubit adder 402 → 395 with CX; 0.866× → 0.863× Qiskit's gates without a chip; 67 of 234 compilations fewer gates, none more; 1.03× the time without a chip, 1.00× on it.
After Qiskit's Optimize1qGatesSimpleCommutation · pauli_pairs.rs
SWAP elision and permutation-aware synthesis extended
A SWAP costs three CNOTs; relabelling the qubits after it costs nothing. The same holds for a SWAP hidden in a block: a CNOT each way is a SWAP and one CNOT, so a block that is a SWAP away from fewer CNOTs is synthesized that way. QCC relabels whenever the moved qubits are measured last, so the output is exactly equivalent, and otherwise when asked to, reporting where each qubit's state ends.
QFT: 12, 24 and 48 fewer CNOTs at 8, 16 and 32 qubits; random Clifford+T: up to 5% fewer.
As Qiskit's ElidePermutations and pytket's implicit wire swaps · permutation.rs
Numerical synthesis for any entangling gate ours
For native gates without a known template (iSWAP, √iSWAP, √SWAP, …), the fewest uses are found numerically: first matching the target's Makhlin invariants, then the single-qubit gates around them, both by Levenberg–Marquardt from seeded starts.
Try it in the decomposition playground · numeric.rs