-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new passmanager.replace(index, ...) method (#3004)
* replace method * error handle * lint * changelog * lint * release note * key->index * error message * lint * release note * iamges * replace images for text
- Loading branch information
Luciano
authored
Oct 5, 2019
1 parent
00e434c
commit a934b1f
Showing
4 changed files
with
160 additions
and
9 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
47 changes: 47 additions & 0 deletions
47
releasenotes/notes/passmanager_replace-d89e2cc46517d917.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,47 @@ | ||
--- | ||
features: | ||
- | | ||
A given pass manager now can be edited with the new method `replace`. This method allows to | ||
replace a particular stage in a pass manager, which can be handy when dealing with preset | ||
pass managers. For example, let's edit the layout selector of the pass manager used at | ||
optimization level 0: | ||
.. code-block:: python | ||
from qiskit.transpiler.preset_passmanagers.level0 import level_0_pass_manager | ||
from qiskit.transpiler.transpile_config import TranspileConfig | ||
pass_manager = level_0_pass_manager(TranspileConfig(coupling_map=CouplingMap([[0,1]]))) | ||
pass_manager.draw() | ||
.. code-block:: | ||
[0] FlowLinear: SetLayout | ||
[1] Conditional: TrivialLayout | ||
[2] FlowLinear: FullAncillaAllocation, EnlargeWithAncilla, ApplyLayout | ||
[3] FlowLinear: Unroller | ||
The layout selection is set in the stage `[1]`. Let's replace it with `DenseLayout`: | ||
.. code-block:: python | ||
from qiskit.transpiler.passes import DenseLayout | ||
pass_manager.replace(1, DenseLayout(coupling_map), condition=lambda property_set: not property_set['layout']) | ||
pass_manager.draw() | ||
.. code-block:: | ||
[0] FlowLinear: SetLayout | ||
[1] Conditional: DenseLayout | ||
[2] FlowLinear: FullAncillaAllocation, EnlargeWithAncilla, ApplyLayout | ||
[3] FlowLinear: Unroller | ||
If you want to replace it without any condition, you can use set-item shortcut: | ||
.. code-block:: python | ||
pass_manager[1] = DenseLayout(coupling_map) | ||
pass_manager.draw() | ||
.. code-block:: | ||
[0] FlowLinear: SetLayout | ||
[1] FlowLinear: DenseLayout | ||
[2] FlowLinear: FullAncillaAllocation, EnlargeWithAncilla, ApplyLayout | ||
[3] FlowLinear: Unroller |
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