-
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
Migrate init stage to plugins #10689
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,34 +46,21 @@ def level_0_pass_manager(pass_manager_config: PassManagerConfig) -> StagedPassMa | |
basis_gates = pass_manager_config.basis_gates | ||
coupling_map = pass_manager_config.coupling_map | ||
initial_layout = pass_manager_config.initial_layout | ||
init_method = pass_manager_config.init_method | ||
init_method = pass_manager_config.init_method or "default" | ||
layout_method = pass_manager_config.layout_method or "default" | ||
routing_method = pass_manager_config.routing_method or "stochastic" | ||
translation_method = pass_manager_config.translation_method or "translator" | ||
optimization_method = pass_manager_config.optimization_method or "default" | ||
scheduling_method = pass_manager_config.scheduling_method or "default" | ||
approximation_degree = pass_manager_config.approximation_degree | ||
unitary_synthesis_method = pass_manager_config.unitary_synthesis_method | ||
unitary_synthesis_plugin_config = pass_manager_config.unitary_synthesis_plugin_config | ||
target = pass_manager_config.target | ||
hls_config = pass_manager_config.hls_config | ||
|
||
# Choose routing pass | ||
routing_pm = plugin_manager.get_passmanager_stage( | ||
"routing", routing_method, pass_manager_config, optimization_level=0 | ||
) | ||
|
||
unroll_3q = None | ||
# Build pass manager | ||
if coupling_map or initial_layout: | ||
unroll_3q = common.generate_unroll_3q( | ||
target, | ||
basis_gates, | ||
approximation_degree, | ||
unitary_synthesis_method, | ||
unitary_synthesis_plugin_config, | ||
hls_config, | ||
) | ||
layout = plugin_manager.get_passmanager_stage( | ||
"layout", layout_method, pass_manager_config, optimization_level=0 | ||
) | ||
|
@@ -98,7 +85,7 @@ def level_0_pass_manager(pass_manager_config: PassManagerConfig) -> StagedPassMa | |
"scheduling", scheduling_method, pass_manager_config, optimization_level=0 | ||
) | ||
|
||
init = common.generate_control_flow_options_check( | ||
pre_init = common.generate_control_flow_options_check( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The whole concept of a pre-initialisation stage is funny to me, but this does seem like an ok compromise. |
||
layout_method=layout_method, | ||
routing_method=routing_method, | ||
translation_method=translation_method, | ||
|
@@ -107,17 +94,15 @@ def level_0_pass_manager(pass_manager_config: PassManagerConfig) -> StagedPassMa | |
basis_gates=basis_gates, | ||
target=target, | ||
) | ||
if init_method is not None: | ||
init += plugin_manager.get_passmanager_stage( | ||
"init", init_method, pass_manager_config, optimization_level=0 | ||
) | ||
elif unroll_3q is not None: | ||
init += unroll_3q | ||
init = plugin_manager.get_passmanager_stage( | ||
"init", init_method, pass_manager_config, optimization_level=0 | ||
) | ||
optimization = plugin_manager.get_passmanager_stage( | ||
"optimization", optimization_method, pass_manager_config, optimization_level=0 | ||
) | ||
|
||
return StagedPassManager( | ||
pre_init=pre_init, | ||
init=init, | ||
layout=layout, | ||
routing=routing, | ||
|
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
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.
Pre-existing, but is this definitely an "initialisation" action and not just a shared requirement of most of our routing plugins?
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.
It is, since almost all layout and routing stages only work with 1 and 2 qubit gates this is why it's in the default. You could argue it's a better fit for the
pre_layout
stage, but I thinkinit
works better here because it allows for plugins to override it. So in a hypothetical case where there is a layout and routing pass for hardware that has native 3q gates they can have users do something liketranspile(..., routing_method="toffoli", init_method="only_opt")
.I guess there is an argument that the
init
stage should be more granular. We do have an issue for adding a dedicated synthesis stage #8936. But, at the end of the day there isn't very much in there and I worry about having too many stages that all only do one or two passes.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, that's fine. I'd originally written "layout" in my comment, then mistakenly changed it because I thought it was only Sabre that really had a problem (which is via Sabre routing anyway - the Sabre layout logic itself doesn't care), but that's not true - noise aware, CSP and VF2 all have issues with 3q.