-
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
Add a default optimization level to generate_preset_pass_manager #12150
Conversation
This commit adds a default value to the generate_preset_pass_manager's optimization_level argument. If it's not specified optimization level 2 will be used. After Qiskit#12148 optimization level 2 is a better fit for an optimal tradeoff between heuristic effort and runtime that makes it well suited as a default optimization level.
One or more of the the following people are requested to review this:
|
d263471
to
8191110
Compare
Pull Request Test Coverage Report for Build 10114185659Details
💛 - Coveralls |
# Handle positional arguments for target and backend. This enables the usage | ||
# pattern `generate_preset_pass_manager(backend.target)` to generate a default | ||
# pass manager for a given target. | ||
if isinstance(optimization_level, Target): |
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+.
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.
This looks fine in principle to me, I'm just concerned about how we're setting this to have a different default optimisation level to transpile
. We already get complaints whenever the interfaces of transpile
and this diverge around type inference / whatever, and I guess I'd roughly rather we moved the two in step?
I can live with the split if it was already discussed more in the team, though.
# Handle positional arguments for target and backend. This enables the usage | ||
# pattern `generate_preset_pass_manager(backend.target)` to generate a default | ||
# pass manager for a given target. | ||
if isinstance(optimization_level, Target): |
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+.
This commit updates the transpile() function's optimization_level argument default value to match generate_preset_pass_manager's new default to use 2 instead of 1. This is arguably a breaking API change, but since the semantics are equivalent with two minor edge cases with implicit behavior that were a side effect of the level 1 preset pass manager's construction (which are documented in the release notes) we're ok making it in this case. Some tests which we're relying on the implicit behavior of optimization level 1 are updated to explicitly set the optimization level argument which will retain this behavior.
I updated the |
I'm thinking that if we want to do this for 1.1.0 we should drop 34e9ee4 and save that for 1.2. There seem to be a lot of issues with using level2 as the default in testing. There might be some more implicit assumptions I didn't think of that the tests are flagging. FWIW, every commit I've pushed up I ran the tests locally with and everything passed I assume it's either the presence of optional dependencies or py3.8 vs 3.12 that's causing the failures. But it's making me uneasy about making a potentially breaking change at the last minute before a release. |
An alternative to moving I'd like to see them stay in step at all times, but I can live with it if the decision is to go with O2 for this and move |
…generate-preset-pass-manager
* Replace use of transpile with specific pass in HLS tests.
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.
The PR looks good to me, I went in and fixed a couple of missing tests that were optimization-level dependant, or were using the full pipeline to only test the effect of a single transpiler pass (and that made them optimization-level dependant). Before approving, I want to confirm that we want to move on with the optimization level 2 default in both transpile
and generate_ppm
(I am going to call it like this from now on) for 1.2. Thoughts? @jakelishman @mtreinish @1ucian0
d935ae9
to
3e987cd
Compare
…generate-preset-pass-manager
3e987cd
to
479ac9f
Compare
I'm good with doing this for 1.2, if there are no objections from anyone else. I'm personally still a bit apprehensive about the API implications on changing I will push up a small tweak to the upgrade release note though to elaborate a bit more on the benefits of the change to |
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.
I left a few suggestions for the reno.
releasenotes/notes/default-level-2-generate-preset-passmanager-ec758ddc896ae2d6.yaml
Outdated
Show resolved
Hide resolved
releasenotes/notes/default-level-2-generate-preset-passmanager-ec758ddc896ae2d6.yaml
Outdated
Show resolved
Hide resolved
releasenotes/notes/default-level-2-generate-preset-passmanager-ec758ddc896ae2d6.yaml
Outdated
Show resolved
Hide resolved
releasenotes/notes/default-level-2-generate-preset-passmanager-ec758ddc896ae2d6.yaml
Outdated
Show resolved
Hide resolved
…generate-preset-pass-manager
…generate-preset-pass-manager
….com/mtreinish/qiskit-core into default-generate-preset-pass-manager
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.
I commited the reno suggestions and will approve the PR, @mtreinish, feel free to add it to the merge queue if you agree with the changes or modify them if you don't.
…kit#12150) * Add a default optimization level to generate_preset_pass_manager This commit adds a default value to the generate_preset_pass_manager's optimization_level argument. If it's not specified optimization level 2 will be used. After Qiskit#12148 optimization level 2 is a better fit for an optimal tradeoff between heuristic effort and runtime that makes it well suited as a default optimization level. * Update transpile()'s default opt level to match This commit updates the transpile() function's optimization_level argument default value to match generate_preset_pass_manager's new default to use 2 instead of 1. This is arguably a breaking API change, but since the semantics are equivalent with two minor edge cases with implicit behavior that were a side effect of the level 1 preset pass manager's construction (which are documented in the release notes) we're ok making it in this case. Some tests which we're relying on the implicit behavior of optimization level 1 are updated to explicitly set the optimization level argument which will retain this behavior. * Update more tests expecting optimization level 1 * * Set optimization level to 1 in test_approximation_degree. * Replace use of transpile with specific pass in HLS tests. * Set optimization_level=1 in layout-dependent tests. * Expand upgrade note explanation on benefits of level 2 * Apply Elena's reno suggestions --------- Co-authored-by: Elena Peña Tapia <[email protected]> Co-authored-by: Elena Peña Tapia <[email protected]>
Summary
This commit adds a default value to the generate_preset_pass_manager's optimization_level argument. If it's not specified optimization level 2 will be used. After #12148 optimization level 2 is a better fit for an optimal tradeoff between heuristic effort and runtime that makes it well suited as a default optimization level.
Details and comments