-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for custom backend transpiler stages (#8648)
* Add support for custom backend transpiler stages This commit adds initial support to the transpiler and backend interfaces for backends to specify custom transpiler stages. There are often specific hardware compilation requirements that a general purpose transpiler's preset pass manager can't account for. While we strive to provide interfaces to outline all the hardware constraints via the Target class and general purposes passes to fit and optimize an input circuit to the target backend there are some constraints that aren't easily addressed in a general purpose way. For such cases having an interface for a specific backend which has the necessary context of its own constraints to provide custom compilation steps to integrate into the pipeline is a necessary feature. The two initial examples of this are custom basis gate translation and custom scheduling. This commit adds two new hook point methods for BackendV2 objects, get_post_translation_stage() and get_scheduling_stage(). These allow for backends to specify custom PassManager objects that will run after the translation stage and for the scheduling stage by default when compilation is targetting the backend. This should enable backends with custom hardware specific requirements to influence the compilation process so that any required custom steps to ensure the output circuit is executable. In the future we may add additional hook points in a similar manner to enable backends to assert more hardware-specific compilation where the need arises. Closes #8329 * Remove stray optimization level args from pm config * Fix tests * Apply suggestions from code review Co-authored-by: Jake Lishman <jake@binhbar.com> * Pivot backend transpiler hook points to leverage plugins Since in qiskit-terra 0.22.0 we're adding a plugin interface for transpiler stages already, the more natural fit for enabling backends to inject custom passes into a pass maanger is via that plugin interface. This commit updates the hook points to return a plugin method name that a backend should use by default. This will provide the same level of flexibility but also export any custom stages as standalone methods that users can call into if they need to and also advertise the custom stage methods along with all other installed methods. * Apply suggestions from code review Co-authored-by: Kevin Krsulich <kevin@krsulich.net> * Update qiskit/providers/__init__.py Co-authored-by: Kevin Krsulich <kevin@krsulich.net> * Update release note * Update qiskit/providers/backend.py Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com> * Rename transpile() option and reword doc * Rename hook methods backend_ * Update qiskit/compiler/transpiler.py Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com> Co-authored-by: Jake Lishman <jake@binhbar.com> Co-authored-by: Kevin Krsulich <kevin@krsulich.net> Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>
- Loading branch information
1 parent
53e215c
commit 86fb555
Showing
9 changed files
with
310 additions
and
22 deletions.
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
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
18 changes: 18 additions & 0 deletions
18
releasenotes/notes/add-backend-custom-passes-cddfd05c8704a4b1.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,18 @@ | ||
--- | ||
features: | ||
- | | ||
The :class:`~.BackendV2` class now has support for two new optional hook | ||
points enabling backends to inject custom compilation steps as part of | ||
:func:`~.transpile` and :func:`~.generate_preset_pass_manager`. If a | ||
:class:`~.BackendV2` implementation includes the methods | ||
``get_scheduling_stage_plugin()`` or ``get_translation_stage_plugin()`` the | ||
transpiler will use the returned string as the default value for | ||
the ``scheduling_method`` and ``translation_method`` arguments. This enables | ||
backends to run additional custom transpiler passes when targetting that | ||
backend by leveraging the transpiler stage | ||
:mod:`~qiskit.transpiler.preset_passmanagers.plugin` interface. | ||
For more details on how to use this see :ref:`custom_transpiler_backend`. | ||
- | | ||
Added a new keyword argument, ``ignore_backend_supplied_default_methods``, to the | ||
:func:`~.transpile` function can be used to disable a backend's custom | ||
default method if the target backend has one set. |
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.