-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a default optimization level to generate_preset_pass_manager #12150
Merged
mtreinish
merged 14 commits into
Qiskit:main
from
mtreinish:default-generate-preset-pass-manager
Jul 26, 2024
Merged
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8191110
Add a default optimization level to generate_preset_pass_manager
mtreinish 439a390
Merge remote-tracking branch 'origin/main' into default-generate-pres…
mtreinish 34e9ee4
Update transpile()'s default opt level to match
mtreinish 82c776b
Update more tests expecting optimization level 1
mtreinish 6071496
Merge branch 'main' of https://github.com/Qiskit/qiskit into default-…
ElePT c64b356
* Set optimization level to 1 in test_approximation_degree.
ElePT 77ac770
Set optimization_level=1 in layout-dependent tests.
ElePT 479ac9f
Merge branch 'main' of https://github.com/Qiskit/qiskit into default-…
ElePT 8ed8d5e
Expand upgrade note explanation on benefits of level 2
mtreinish e24cd84
Merge branch 'main' into default-generate-preset-pass-manager
ElePT 4106d3d
Merge branch 'main' of https://github.com/Qiskit/qiskit into default-…
ElePT 8eed81b
Merge branch 'main' of https://github.com/Qiskit/qiskit into default-…
ElePT ae3523f
Merge branch 'default-generate-preset-pass-manager' of https://github…
ElePT 8198182
Apply Elena's reno suggestions
ElePT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
41 changes: 41 additions & 0 deletions
41
releasenotes/notes/default-level-2-generate-preset-passmanager-ec758ddc896ae2d6.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,41 @@ | ||
--- | ||
features_transpiler: | ||
- | | ||
The ``optimization_level`` argument for the :func:`.generate_preset_pass_manager` function is | ||
now optional. If it's not specified it will default to using optimization level 2. As the argument | ||
is now optional, the first positional argument has been expanded to enable passing a :class:`.Target` | ||
or a :class:`.BackendV2` as the first argument for more convenient construction. For example:: | ||
|
||
from qiskit.transpiler.preset_passmanager import generate_preset_pass_manager | ||
from qiskit.providers.fake_provider import GenericBackendV2 | ||
|
||
backend = GenericBackendV2(100) | ||
|
||
generate_preset_pass_manager(backend.Target) | ||
|
||
will construct a default pass manager for the 100 qubit :class`.GenericBackendV2` instance. | ||
upgrade_transpiler: | ||
- | | ||
The default ``optimization_level`` used by the :func:`.transpile` function when one is not | ||
specified has been changed to level 2. This makes it consistent with the default used | ||
by :func:`.generate_preset_pass_manager` which is used internally by :func:`.transpile`. If | ||
you were previously relying on the implicit default of level 1, you can simply set | ||
the argument ``optimization_level=1`` when you call :func:`.transpile`. There isn't an API | ||
change though because fundamentally level 2 and level 1 have the same semantics. Similarly you | ||
can change the default back in your local environment by using a user config file and setting | ||
the ``transpile_optimization_level`` field to 1. | ||
|
||
The only potential issue is that if you were relying on an implicit trivial layout (where qubit 0 | ||
in the circuit passed to :func:`.transpile` is mapped to qubit 0 on the target backend/coupling, | ||
1->1, 2->2, etc.) without specifying ``optimization_level=1``, ``layout_method="trivial"``, or | ||
explicitly setting ``initial_layout`` when calling :func:`.transpile`. This behavior was a side | ||
ElePT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
effect of the preset pass manager construction in optimization level 1 and is not mirrored in | ||
level 2. If you need this behavior you can use any of the three options list previously to make | ||
ElePT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this behavior explicit. | ||
|
||
Similarly if you were targeting a discrete basis gate set you may encounter an issue using the | ||
new default with optimization level 2 (or 3) as the additional optimization passes that run in | ||
ElePT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
level 2 and 3 don't work in all cases with a discrete basis. You can explicitly set | ||
``optimization_level=1`` manually in this case. In general the transpiler does not currently | ||
fully support discrete basis sets and if you're relying on this you should likely construct a | ||
pass manager manually to build a compilation pipeline that will work with your target. |
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I'd rather this function not support any positional arguments.
I think we want a more ergonomic API on top of this function eventually anyways, e.g. #12161, so it seems too kludgy to me to try and make this accept a target positionally here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#12161 is actually what I'm not sure we want to do. Adding a 3rd API with different semantics to do what we already have two interfaces for seems like a mistake to me. If people really want a different name I feel like we really should just alias it (but I still don't think it's worth it). But adding yet another entrypoint to accomplish the same thing feels like a mistake. If people are complaining about the ergonomics of the existing interface I feel like we should just evolve it in-place instead of diverging it again and requiring people to learn yet another thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's unfortunate that we've ended up here, but I think the right thing to do for users is to make it so the common patterns
{transpile,generate_preset_pass_manager}({backend,target}, optimization_level=2)
work the same in both forms. It ends up in an ugly signature for us, but we can tidy that up in place and potentially fix the signature properly for Qiskit 2.0+.