-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Run logical optimization passes in init stage #11354
Conversation
This commit adds Optimize1qGatesDecomposition and InverseCancellation to the init stage for optimization levels 1, 2, and 3. The optimizations these passes run are completely valid on abstract circuits and do not require target qubits to be selected to run (`Optimize1qGatesDecomposition` is noise aware and will perform target aware optimizations if one is provided, but if no target information is reported it will operate correctly for any circuit)
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.
In principle I totally agree with doing this. Personally I think that abstract optimisation is / ought to be a sufficiently important step that I'd go as far as wanting a new named stage for it between init
and layout
, but I can live with it being init
at least initially.
Are you sure this doesn't warrant a release note? It doesn't technically affect the public API, but I definitely think it's a change worth drawing attention to - if nothing else, it's a somewhat modification of the obligations of the init
stage.
@@ -88,6 +88,44 @@ def pass_manager(self, pass_manager_config, optimization_level=None) -> PassMana | |||
pass_manager_config.unitary_synthesis_plugin_config, | |||
pass_manager_config.hls_config, | |||
) | |||
elif optimization_level in {1, 2}: |
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.
Incredibly minor: there's no reason to use a set
here - optimization_level in (1, 2)
would technically be more efficient. Not important at all, though.
else: | ||
return TranspilerError(f"Invalid optimization level {optimization_level}") |
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.
Completely unrelated, but imo this should actually be a ValueError
.
Let's add a logical optimization stage. I think it's totally reasonable to break this out into a stage. FWIW, the description and expectations of the init stage is currently:
which I felt included this. But I think you're right we probably should separate this out form EDIT: But maybe as a follow up stage because I forgot this will require adding another plugin hook point and extra documentation and stuff which is larger in scope than this change. |
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.
Oh, I totally forgot that we had the bit about logical optimisation in there - I thought we only had the bit about multi-q operators. Sorry! In that case, yeah, let's merge and we can potentially split out the stages in a follow-up.
In Qiskit#11354 we added more logical optimization passes to the preset pass managers for level 1, 2, and 3 which included the Optimize1qGatesDecomposition pass. However, this had the the unintended side effect of tending to normalize circuits to use parameterized gates. This becomes an issue for discrete basis targets as the basis translator doesn't always know how to work with those. To avoid issues this commit removes the pass from the init stage and just saves it for the optimization loop. If we want to do 1q gate simplification during init in the future we can develop a different pass that does it in a manner that wouldn't interfere with discrete basis targets like Optimize1qGatesDecomposition.
In #11354 we added more logical optimization passes to the preset pass managers for level 1, 2, and 3 which included the Optimize1qGatesDecomposition pass. However, this had the the unintended side effect of tending to normalize circuits to use parameterized gates. This becomes an issue for discrete basis targets as the basis translator doesn't always know how to work with those. To avoid issues this commit removes the pass from the init stage and just saves it for the optimization loop. If we want to do 1q gate simplification during init in the future we can develop a different pass that does it in a manner that wouldn't interfere with discrete basis targets like Optimize1qGatesDecomposition.
Summary
This commit adds Optimize1qGatesDecomposition and InverseCancellation to the init stage for optimization levels 1, 2, and 3. The optimizations these passes run are completely valid on abstract circuits and do not require target qubits to be selected to run
(
Optimize1qGatesDecomposition
is noise aware and will perform target aware optimizations if one is provided, but if no target information is reported it will operate correctly for any circuit)Details and comments