forked from Qiskit/qiskit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to SabreLayout to specify starting layouts (Qiskit#10721)
* Add option to SabreLayout to specify starting layouts The SabreLayout pass typically starts with each layout trial with a random starting layout. However, in some cases starting with a specific starting layout can result in better output quality than starting with a fully random layout. To use this feature an analysis pass can set a new `sabre_starting_layout` field in the property set before `SabreLayout` with a list of layout objects that will add additional trials using each layout as a starting layout. * Fix lint * Combine random layout and partial layouts * Expand property set docs Co-authored-by: Jake Lishman <[email protected]> * Simplify branching logic for parallelism * Use a slice for starting_layout in a trial * Update releasenotes/notes/seed-sabre-with-layout-17d46e1a6f516b0e.yaml Co-authored-by: Jake Lishman <[email protected]> * Make starting layout variable names plural The starting layout is a list and can have more than one entry. To make this clearer, this commit renames starting_layout -> starting_layouts and sabre_starting_layout -> sabre_starting_layouts. * Update releasenotes/notes/seed-sabre-with-layout-17d46e1a6f516b0e.yaml Co-authored-by: Jake Lishman <[email protected]> * Update property set key in test * Update test to only use partial layout --------- Co-authored-by: Jake Lishman <[email protected]> Co-authored-by: Jake Lishman <[email protected]>
- Loading branch information
1 parent
29dddab
commit 578e109
Showing
4 changed files
with
204 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
38 changes: 38 additions & 0 deletions
38
releasenotes/notes/seed-sabre-with-layout-17d46e1a6f516b0e.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
features: | ||
- | | ||
Added support to the :class:`.SabreLayout` pass to add trials with specified | ||
starting layouts. The :class:`.SabreLayout` transpiler pass typically | ||
runs multiple layout trials that all start with fully random layouts which | ||
then use a routing pass to permute that layout instead of inserting swaps | ||
to find a layout which will result in fewer swap gates. This new feature | ||
enables running an :class:`.AnalysisPass` prior to :class:`.SabreLayout` | ||
which sets the ``"sabre_starting_layout"`` field in the property set | ||
to provide the :class:`.SabreLayout` with additional starting layouts | ||
to use in its internal trials. For example, if you wanted to run | ||
:class:`.DenseLayout` as the starting point for one trial in | ||
:class:`.SabreLayout` you would do something like:: | ||
from qiskit.providers.fake_provider import FakeSherbrooke | ||
from qiskit.transpiler import AnalysisPass, PassManager | ||
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager | ||
from qiskit.transpiler.passes import DenseLayout | ||
class SabreDenseLayoutTrial(AnalysisPass): | ||
def __init__(self, target): | ||
self.dense_pass = DenseLayout(target=target) | ||
super().__init__() | ||
def run(self, dag): | ||
self.dense_pass.run(dag) | ||
self.property_set["sabre_starting_layouts"] = [self.dense_pass.property_set["layout"]] | ||
backend = FakeSherbrooke() | ||
opt_level_1 = generate_preset_pass_manager(1, backend) | ||
pre_layout = PassManager([SabreDenseLayoutTrial(backend.target)]) | ||
opt_level_1.pre_layout = pre_layout | ||
Then when the ``opt_level_1`` :class:`.StagedPassManager` is run with a circuit the output | ||
of the :class:`.DenseLayout` pass will be used for one of the :class:`.SabreLayout` trials | ||
in addition to the 5 fully random trials that run by default in optimization level 1. |
This file contains 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