-
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 stage plugin interface for transpile #8305
Conversation
This commit adds a new plugin interface to qiskit for enabling external packages to write plugins that will replace a stage in the transpilation pipeline. For example, if an external package had a custom layout pass that they wanted to integrate into transpile() they could export a plugin using this new interface and then users would just need to run transpile(.., layout_method=foo) This adds long asked for extensibility to the transpiler so that to cleanly integrate new transpiler passes we're no longer required to merge the features into terra. This should hopefully make it easier for downstream pass authors to integrate their passes into terra and make it easier for the terra maintainers to evaluate new transpiler passes.
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the the following people are requested to review this:
|
Pull Request Test Coverage Report for Build 2958142026
💛 - Coveralls |
@mtreinish. This looks very useful. I am trying to better understand what we would or would not be able to do, so a few questions, if I may:
|
Yes, that's correct. One thing I'm debating is whether I want to bundle things like
Yes exactly, the idea is exactly that. A custom layout method (or any stage) that isn't part of qiskit can cleanly integrate into
Not with this, the unit of a plugin is a stage. This enables an external package to advertise that they have a custom pass manager which can be used for an optimization stage. So using this model you'd have to have your plugin return the full pass manager including the existing default stage contents. That being said in the last release we made this sort of modification easy to do. For example something like: from qiskit.transpiler.preset_passmanager import generate_preset_pass_manager
from qiskit.providers.fake_provider import FakeLagosV2
backend = FakeLagosV2()
pass_manager = generate_preset_pass_manager(3, backend)
pass_manager.optimization.append(CustomPass())
pass_manager.run(qc) You could embed something similar in your plugin but optimization is a weird case because there isn't a handy generator function like the other stages as each optimization level is custom. I guess you could have your plugin call
Unitary synthesis plugins are already handled separately with an existing (for about a year now) plugin interface. https://qiskit.org/documentation/apidoc/transpiler_plugins.html?highlight=plugin#module-qiskit.transpiler.passes.synthesis.plugin this enables synthesis method authors to hook into the existing Since the unit of the plugins added in this PR are stages the specific passes used as part of the returned
My plan for clifford synthesis was to probably add a specific plugin interface for this once the dedicated clifford synthesis pass exists. We have this mechanism specifically for unitary synthesis already so having a dual for clifford synthesis makes sense to me. You could leverage this using this interface though and write a custom plugin for the init or translation stage that used a custom synthesis pass if you wanted, but that would add a lot of boiler plate if all you're really looking for is an interface that gets a black box plugin/function that takes a clifford in and returns a dag circuit. |
This commit converts all the built-in routing method options into separate plugins and also adds a default plugin for the default behavior at each optimization level. To support using plugins for routing method adding the optimization_level to the passmanager config was necessary so that the plugin has sufficient context on how to construct the routing pass used for the routing stage. As depending on the optimization level the settings for each pass differs. For example on stochastic swap the number of stochastic trials increases for level 3 to try and find a better solution at the cost of more runtime.
This is ready for review now, I've added the pieces I thought were missing. The only open question is whether I should massage the additional built-in stages for the preset pass managers (init, layout, translation, optimization, and scheduling) into plugins. I started with just routing since it was fairly self contained. Although given the size of this PR already we can save the plugin refactor for the remaining stages into follow up PRs. |
@mtreinish, can I volunteer to review this (partly for self-educational purposes)? |
releasenotes/notes/stage-plugin-interface-47daae40f7d0ad3c.yaml
Outdated
Show resolved
Hide resolved
releasenotes/notes/stage-plugin-interface-47daae40f7d0ad3c.yaml
Outdated
Show resolved
Hide resolved
basis_gates. This will be a plugin name if an external translation stage | ||
plugin is being used. | ||
scheduling_method (str): the pass to use for scheduling instructions. This will | ||
be a plugin name if an external scheduling stage plugin is being used. |
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.
Is there any plan to replace *_method
with the plugin interface?
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 think this looks good. I would add some more testing of the included plugins (therefore, the request to change). And I'm still uncomfortable with the level being part of the PassManagerConfig
(non-blocking). The rest is good to merge for me.
Co-authored-by: Luciano Bello <[email protected]>
@1ucian0 I moved the optimization level out of the |
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.
Is there somewhere we've documented how to implement a transpiler stage from the perspective of a pass developer or backend vendor?
Documenting would be nice. Is there a way we could log a warning when the transpilation is run to log which one was selected? I think raising would be troublesome since it'd force users to uninstall something to continue. Packages could contain multiple packages, so forcing the user to uninstall might leave them in a situation where it's impossible to set up the pipeline they want. |
@mtreinish pointed me to https://github.com/Qiskit/qiskit-terra/blob/6d344c068c7e3605d735f3efa654b9f1e406a0cb/qiskit/transpiler/preset_passmanagers/plugin.py#L89 . |
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.
Thanks!
Summary
This commit adds a new plugin interface to qiskit for enabling external
packages to write plugins that will replace a stage in the transpilation
pipeline. For example, if an external package had a custom layout pass
that they wanted to integrate into transpile() they could export a
plugin using this new interface and then users would just need to run
This adds long asked for extensibility to the transpiler so that to
cleanly integrate new transpiler passes we're no longer required to
merge the features into terra. This should hopefully make it easier for
downstream pass authors to integrate their passes into terra and make it
easier for the terra maintainers to evaluate new transpiler passes.
Details and comments
TODO: