Skip to content

Scan one wire when reserving existing SWAP neighbors - #3

Merged
ophirazulai merged 1 commit into
absorb-into-swaps-lean-commutation-checker-refactoredfrom
swap-absorption-one-wire-reservation
Oct 27, 2026
Merged

ophirazulai merged 1 commit into
absorb-into-swaps-lean-commutation-checker-refactoredfrom
swap-absorption-one-wire-reservation

Conversation

@masterFoad

Copy link
Copy Markdown
Owner

Follow-up to the refactor in ab28929: one change to the reservation loop in _select_moves.

Change

Before choosing moves, every SWAP reserves the same-pair units that already sit next to it on both of its wires. The loop scanned the neighbors on both wires. A unit that is next to the SWAP on both wires is, in particular, a neighbor on the first wire, so the second scan could only find the same units again (touching is only used through taken.update and a truth test, so the duplicates never changed anything). The loop now scans the first wire and checks adjacency on the second. Adjacency on the first wire holds by construction: a same-pair unit found at at - 1 or at + 1 on that wire has position_on_wire(qubit_a, unit) equal to that index.

Output identity

Checked on 9 large routed circuits (O2 init+layout+routing on a line coupling map, seed 11): the unit index (node_to_unit, first_node, groups, labels, pair_keys, swaps), the selected moves, and the full pass output (QPY hash) are identical to ab28929 on every case, including cases with many moves (qft_n320: 4,901 moves; square_root_n60: 6,740; bwt_n37: 3,637).

The pass's unit tests in test_swap_absorption.py give the same results with and without the change (pass-level tests pass; the preset-pipeline tests could not run against the local build used, which predates this branch's preset wiring, so they fail identically on both). CI here should run the full suite.

Speed

Time of _select_moves, median of 9 runs interleaved with the original, one pinned core, CPython 3.13 (pure-Python code, so the Rust build profile does not affect it):

circuit ops SWAPs before (ms) after (ms) change
100 (QASMBench large) 165,497 111,553 463 335 -28%
qft_n320 85,263 60,743 270 206 -24%
qv_N100 115,296 110,344 363 278 -23%
vqe_uccsd_n28 372,886 12,155 82 64 -22%
multiplier_n400 921,886 425,890 2,327 1,839 -21%
square_root_n45 235,564 85,038 496 391 -21%
multiplier_n350 670,714 291,314 1,616 1,286 -20%
square_root_n60 2,142,907 990,802 3,376 2,726 -19%
bwt_n37 2,636,929 956,848 3,466 2,817 -19%

On SWAP-heavy circuits _select_moves is roughly a quarter to a third of the pass, so the whole pass is a few percent faster; end-to-end pass times were too noisy in this run to state a figure.

Two other cleanups were measured and left out: extracting the CX-diagonal-CX match into a helper (no gain, up to 6% slower on vqe_uccsd_n28, which has 11,480 such groups) and extracting the candidate scan into a helper (3-12% slower in _select_moves).

A unit next to a SWAP on both of its wires is a neighbor on the first
wire, so the second wire's scan only found the same units again.
Scan the first wire and check adjacency on the second.

Signed-off-by: Foad Abo Dahood <[email protected]>
@masterFoad

Copy link
Copy Markdown
Owner Author

One more case finished: the earlier routed capture of bwt_n37 (4,464,501 ops, 960,720 SWAPs, 1,036 moves). Unit index, moves and pass output identical; _select_moves 4,194 ms -> 3,475 ms (-17%). That makes 10 of 10 cases identical, with _select_moves 17-28% faster.

@ophirazulai
ophirazulai merged commit bbe9c99 into absorb-into-swaps-lean-commutation-checker-refactored Oct 27, 2026
2 checks passed
@ophirazulai
ophirazulai deleted the swap-absorption-one-wire-reservation branch October 27, 2026 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants