Skip to content

Sabre layout and routing transpiler passes#4537

Merged
mergify[bot] merged 36 commits into
Qiskit:masterfrom
ajavadia:sabre
Jun 23, 2020
Merged

Sabre layout and routing transpiler passes#4537
mergify[bot] merged 36 commits into
Qiskit:masterfrom
ajavadia:sabre

Conversation

@ajavadia
Copy link
Copy Markdown
Member

@ajavadia ajavadia commented Jun 2, 2020

Adding a layout and routing method from https://arxiv.org/abs/1809.02573 (by @skywalker2012).

The initial layout selection is especially good in this method and finds high-quality initial placements very fast. I allow this layout method to be combined with any of the other available routing methods as well through selection of layout_method and routing_method. But Sabre's own routing method is also quite good - it anticipates upcoming gates via look ahead, and gives you the ability to trade off parallelism vs. number of gates.

I have not made this part of the default pipeline yet, but I think I'll do that once I do more randomized testing.

@ajavadia ajavadia requested a review from a team as a code owner June 2, 2020 18:06
@1ucian0 1ucian0 self-assigned this Jun 4, 2020
@ajavadia ajavadia added this to the 0.15 milestone Jun 18, 2020
@gushuli
Copy link
Copy Markdown
Contributor

gushuli commented Jun 18, 2020

It looks good to me.

Comment thread qiskit/circuit/bit.py Outdated
Comment thread qiskit/dagcircuit/dagcircuit.py Outdated
Comment thread qiskit/transpiler/coupling.py Outdated
Comment thread qiskit/transpiler/coupling.py Outdated
Comment thread qiskit/transpiler/layout.py Outdated
Comment thread qiskit/transpiler/passes/layout/sabre_layout.py Outdated
Comment thread qiskit/transpiler/passes/layout/sabre_layout.py Outdated
Comment thread qiskit/transpiler/passes/layout/sabre_layout.py Outdated
Comment thread test/python/transpiler/test_sabre_swap.py Outdated
Comment thread qiskit/transpiler/passes/routing/sabre_swap.py Outdated
1ucian0 and others added 4 commits June 20, 2020 15:06
Co-authored-by: Luciano Bello <luciano.bello@ibm.com>
Co-authored-by: Luciano Bello <luciano.bello@ibm.com>
Comment thread qiskit/transpiler/passes/routing/sabre_swap.py
Comment thread qiskit/transpiler/passes/routing/sabre_swap.py
@mergify mergify Bot merged commit fab61d2 into Qiskit:master Jun 23, 2020
@ajavadia ajavadia added the Changelog: Added Add an "Added" entry in the GitHub Release changelog. label Aug 3, 2020
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this pull request Aug 5, 2020
* add SABRE swap pass

* add SABRE layout bidirectional search pass

* expose sabre via preset passmanagers

* undo deprecation for Layout.combine_into_edge_map

* add Approx2qDecompose and SimplifyU3 passes

* allow synthesis_fidelity in global transpile options

* stopgap fix for circuits with regs in sabre_layout

* add test

* add tests

* clean up sabre swap

* restore lost qasm test files

* fix tests

* leave SimplifyU3 for later

* leave Approx2qDecompose for later

* Release notes

Co-authored-by: Gushu Li <Skywalker2012@users.noreply.github.com>

* lint

* update level 3

* lint

* lint relax

* regenerate mapper tests

* make set to list conversion deterministic

* cleaning the diff a bit

* test.python.transpiler.test_coupling.CouplingTest.test_make_symmetric

* make randomization of SabreSwap controllable via seed

* control randomization of SabreSwap via seed

* move imports

* test.python.transpiler.test_coupling.CouplingTest.test_neighbors

* test.python.dagcircuit.test_dagcircuit.TestDagNodeSelection.test_front_layer

* fix doc

* Update test/python/transpiler/test_sabre_swap.py

Co-authored-by: Luciano Bello <luciano.bello@ibm.com>

* Update qiskit/transpiler/passes/routing/sabre_swap.py

Co-authored-by: Luciano Bello <luciano.bello@ibm.com>

* add note and test for neighbors

* lint

* release note

Co-authored-by: Gushu Li <Skywalker2012@users.noreply.github.com>
Co-authored-by: Luciano Bello <luciano.bello@ibm.com>
jakelishman added a commit to jakelishman/qiskit-terra that referenced this pull request Sep 1, 2023
The custom `decay` heuristic is supposed to penalise increases in depth
in the output.  The output space of qubits are the physical qubits, so
the depth is defined in relation to those.  Since its introduction in
Qiskitgh-4537, this heuristic has instead been tracking the depth on the
virtual qubits, which due to the swaps is not necessarily related to the
depth in the output.

Notably, this commit actually makes the depth for routing large
volumetric circuits slightly _worse_ on average (at least for heavy-hex
topologies).  This may be because the effect on the heuristic is
overweighted, or that the depth tracking resets after each gate is
routed (and occasionally in between) to be flat across all qubits,
rather than reflecting the actual depth each qubit is subject to.
jakelishman added a commit to jakelishman/qiskit-terra that referenced this pull request Sep 5, 2023
The custom `decay` heuristic is supposed to penalise increases in depth
in the output.  The output space of qubits are the physical qubits, so
the depth is defined in relation to those.  Since its introduction in
Qiskitgh-4537, this heuristic has instead been tracking the depth on the
virtual qubits, which due to the swaps is not necessarily related to the
depth in the output.

Notably, this commit actually makes the depth for routing large
volumetric circuits slightly _worse_ on average (at least for heavy-hex
topologies).  This may be because the effect on the heuristic is
overweighted, or that the depth tracking resets after each gate is
routed (and occasionally in between) to be flat across all qubits,
rather than reflecting the actual depth each qubit is subject to.
jakelishman added a commit to jakelishman/qiskit-terra that referenced this pull request Sep 5, 2023
The custom `decay` heuristic is supposed to penalise increases in depth
in the output.  The output space of qubits are the physical qubits, so
the depth is defined in relation to those.  Since its introduction in
Qiskitgh-4537, this heuristic has instead been tracking the depth on the
virtual qubits, which due to the swaps is not necessarily related to the
depth in the output.

Notably, this commit actually makes the depth for routing large
volumetric circuits slightly _worse_ on average (at least for heavy-hex
topologies).  This may be because the effect on the heuristic is
overweighted, or that the depth tracking resets after each gate is
routed (and occasionally in between) to be flat across all qubits,
rather than reflecting the actual depth each qubit is subject to.
github-merge-queue Bot pushed a commit that referenced this pull request Sep 7, 2023
The custom `decay` heuristic is supposed to penalise increases in depth
in the output.  The output space of qubits are the physical qubits, so
the depth is defined in relation to those.  Since its introduction in
gh-4537, this heuristic has instead been tracking the depth on the
virtual qubits, which due to the swaps is not necessarily related to the
depth in the output.

Notably, this commit actually makes the depth for routing large
volumetric circuits slightly _worse_ on average (at least for heavy-hex
topologies).  This may be because the effect on the heuristic is
overweighted, or that the depth tracking resets after each gate is
routed (and occasionally in between) to be flat across all qubits,
rather than reflecting the actual depth each qubit is subject to.
jakelishman added a commit to jakelishman/qiskit-terra that referenced this pull request Aug 14, 2025
Ever since Sabre was first introduced to Qiskit (in [1]), the extended
set has been recalculated from the front layer, every time the front
layer is updated.  Now that the extended set is tracked as a series of
layers, it is easily possible to keep the layer structure updated in the
same way as the front layer, by tracking separate points in the
topological iteration through the interaction graph.

To speed up synchronisation of the layers during updates, a new outer
tracker, `Layers`, now means that a removal can jump immediately to the
correct layer, without having to test multiples.  This outer structure
co-operates with the individual layers to effect faster lookups and
removals; rather than each layer storing its own `IndexMap`, they
instead store only a `Vec`, and the outer `Layers` tracks _where_ in the
`Vec` any given gate is.  On removal, the layer returns which, if any,
gate has moved to occupy the otherwise empty slot (since removals are by
swap, not shift).  This avoids all hash lookups in the layer structures;
everything is simple contiguous indexed access.

With the tracking done elsewhere, and with `VecMap` providing type-safe
indexing, each individual `Layer` now stores its contained gates in
terms of `[VirtualQubit; 2]`; this minimises the amount of data that
needs to be modified on a swap, at the cost that actions that need to
associate actual gates with the current physical qubits (like iterating
over active swaps) now need access to the `NLayout`, rather than the
layout being (implicitly) tracked by each `Layer` via `apply_swap`.
This is a performance improvement; as more overhead is reduced, the cost
of the hash lookups in swap application was ever more visible.

[1]: fab61d2: Sabre layout and routing transpiler passes (Qiskitgh-4537)
jakelishman added a commit to jakelishman/qiskit-terra that referenced this pull request Mar 11, 2026
Ever since Sabre was first introduced to Qiskit (in [1]), the extended
set has been recalculated from the front layer, every time the front
layer is updated.  Now that the extended set is tracked as a series of
layers, it is easily possible to keep the layer structure updated in the
same way as the front layer, by tracking separate points in the
topological iteration through the interaction graph.

To speed up synchronisation of the layers during updates, a new outer
tracker, `Layers`, now means that a removal can jump immediately to the
correct layer, without having to test multiples.  This outer structure
co-operates with the individual layers to effect faster lookups and
removals; rather than each layer storing its own `IndexMap`, they
instead store only a `Vec`, and the outer `Layers` tracks _where_ in the
`Vec` any given gate is.  On removal, the layer returns which, if any,
gate has moved to occupy the otherwise empty slot (since removals are by
swap, not shift).  This avoids all hash lookups in the layer structures;
everything is simple contiguous indexed access.

With the tracking done elsewhere, and with `VecMap` providing type-safe
indexing, each individual `Layer` now stores its contained gates in
terms of `[VirtualQubit; 2]`; this minimises the amount of data that
needs to be modified on a swap, at the cost that actions that need to
associate actual gates with the current physical qubits (like iterating
over active swaps) now need access to the `NLayout`, rather than the
layout being (implicitly) tracked by each `Layer` via `apply_swap`.
This is a performance improvement; as more overhead is reduced, the cost
of the hash lookups in swap application was ever more visible.

[1]: fab61d2: Sabre layout and routing transpiler passes (Qiskitgh-4537)
jakelishman added a commit to jakelishman/qiskit-terra that referenced this pull request Mar 11, 2026
Ever since Sabre was first introduced to Qiskit (in [1]), the extended
set has been recalculated from the front layer, every time the front
layer is updated.  Now that the extended set is tracked as a series of
layers, it is easily possible to keep the layer structure updated in the
same way as the front layer, by tracking separate points in the
topological iteration through the interaction graph.

To speed up synchronisation of the layers during updates, a new outer
tracker, `Layers`, now means that a removal can jump immediately to the
correct layer, without having to test multiples.  This outer structure
co-operates with the individual layers to effect faster lookups and
removals; rather than each layer storing its own `IndexMap`, they
instead store only a `Vec`, and the outer `Layers` tracks _where_ in the
`Vec` any given gate is.  On removal, the layer returns which, if any,
gate has moved to occupy the otherwise empty slot (since removals are by
swap, not shift).  This avoids all hash lookups in the layer structures;
everything is simple contiguous indexed access.

With the tracking done elsewhere, and with `VecMap` providing type-safe
indexing, each individual `Layer` now stores its contained gates in
terms of `[VirtualQubit; 2]`; this minimises the amount of data that
needs to be modified on a swap, at the cost that actions that need to
associate actual gates with the current physical qubits (like iterating
over active swaps) now need access to the `NLayout`, rather than the
layout being (implicitly) tracked by each `Layer` via `apply_swap`.
This is a performance improvement; as more overhead is reduced, the cost
of the hash lookups in swap application was ever more visible.

[1]: fab61d2: Sabre layout and routing transpiler passes (Qiskitgh-4537)
jakelishman added a commit to jakelishman/qiskit-terra that referenced this pull request Mar 24, 2026
Ever since Sabre was first introduced to Qiskit (in [1]), the extended
set has been recalculated from the front layer, every time the front
layer is updated.  Now that the extended set is tracked as a series of
layers, it is easily possible to keep the layer structure updated in the
same way as the front layer, by tracking separate points in the
topological iteration through the interaction graph.

To speed up synchronisation of the layers during updates, a new outer
tracker, `Layers`, now means that a removal can jump immediately to the
correct layer, without having to test multiples.  This outer structure
co-operates with the individual layers to effect faster lookups and
removals; rather than each layer storing its own `IndexMap`, they
instead store only a `Vec`, and the outer `Layers` tracks _where_ in the
`Vec` any given gate is.  On removal, the layer returns which, if any,
gate has moved to occupy the otherwise empty slot (since removals are by
swap, not shift).  This avoids all hash lookups in the layer structures;
everything is simple contiguous indexed access.

With the tracking done elsewhere, and with `VecMap` providing type-safe
indexing, each individual `Layer` now stores its contained gates in
terms of `[VirtualQubit; 2]`; this minimises the amount of data that
needs to be modified on a swap, at the cost that actions that need to
associate actual gates with the current physical qubits (like iterating
over active swaps) now need access to the `NLayout`, rather than the
layout being (implicitly) tracked by each `Layer` via `apply_swap`.
This is a performance improvement; as more overhead is reduced, the cost
of the hash lookups in swap application was ever more visible.

[1]: fab61d2: Sabre layout and routing transpiler passes (Qiskitgh-4537)
jakelishman added a commit to jakelishman/qiskit-terra that referenced this pull request Apr 8, 2026
Ever since Sabre was first introduced to Qiskit (in [1]), the extended
set has been recalculated from the front layer, every time the front
layer is updated.  Now that the extended set is tracked as a series of
layers, it is easily possible to keep the layer structure updated in the
same way as the front layer, by tracking separate points in the
topological iteration through the interaction graph.

To speed up synchronisation of the layers during updates, a new outer
tracker, `Layers`, now means that a removal can jump immediately to the
correct layer, without having to test multiples.  This outer structure
co-operates with the individual layers to effect faster lookups and
removals; rather than each layer storing its own `IndexMap`, they
instead store only a `Vec`, and the outer `Layers` tracks _where_ in the
`Vec` any given gate is.  On removal, the layer returns which, if any,
gate has moved to occupy the otherwise empty slot (since removals are by
swap, not shift).  This avoids all hash lookups in the layer structures;
everything is simple contiguous indexed access.

With the tracking done elsewhere, and with `VecMap` providing type-safe
indexing, each individual `Layer` now stores its contained gates in
terms of `[VirtualQubit; 2]`; this minimises the amount of data that
needs to be modified on a swap, at the cost that actions that need to
associate actual gates with the current physical qubits (like iterating
over active swaps) now need access to the `NLayout`, rather than the
layout being (implicitly) tracked by each `Layer` via `apply_swap`.
This is a performance improvement; as more overhead is reduced, the cost
of the hash lookups in swap application was ever more visible.

[1]: fab61d2: Sabre layout and routing transpiler passes (Qiskitgh-4537)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: Added Add an "Added" entry in the GitHub Release changelog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants