Repository navigation
Scan one wire when reserving existing SWAP neighbors - #3
Merged
ophirazulai merged 1 commit intoOct 27, 2026
Conversation
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]>
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
merged commit Oct 27, 2026
bbe9c99
into
absorb-into-swaps-lean-commutation-checker-refactored
2 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 (
touchingis only used throughtaken.updateand 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 atat - 1orat + 1on that wire hasposition_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):On SWAP-heavy circuits
_select_movesis 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).