-
Notifications
You must be signed in to change notification settings - Fork 3k
Add support for custom backend transpiler stages #8648
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
Changes from 6 commits
77d717f
061ebc4
d7c479d
5eae0ee
caa9c49
69e5b25
cf6a7ec
b845ac3
3870356
ccbbe55
e7b2e8b
f8e8fde
bb45d9d
d004080
214d9f7
4eb107b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -404,6 +404,54 @@ def _define(self): | |
| transpiler will ensure that it continues to be well supported by Qiskit | ||
| moving forward. | ||
|
|
||
| .. _custom_transpiler_backend: | ||
|
|
||
| Custom Transpiler Passes | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| As part of the transpiler there is a provision for backends to provide custom | ||
| stage implementation to facilitate hardware specific optimizations and | ||
|
mtreinish marked this conversation as resolved.
Outdated
|
||
| circuit transformations. Currently there are two hook points supported, | ||
|
mtreinish marked this conversation as resolved.
Outdated
|
||
| ``get_post_translation_stage()`` which is used for a backend to specify a | ||
| :class:`~PassManager` which will be run after basis translation stage in the | ||
| compiler and ``get_scheduling_stage()`` which is used for a backend to | ||
| specify a :class:`~PassManager` which will be run for the scheduling stage | ||
| by default (which is the last defined stage in a default compilation). These | ||
| hook points in a :class:`~.BackendV2` class should only be used if your | ||
| backend has special requirements for compilation that are not met by the | ||
| default backend. | ||
|
|
||
| To leverage these hook points you just need to add the methods to your | ||
| :class:`~.BackendV2` implementation and have them return a | ||
| :class:`~.PassManager` object. For example:: | ||
|
|
||
| from qiskit.circuit.library import XGate | ||
| from qiskit.transpiler.passes import ( | ||
| ALAPScheduleAnalysis, | ||
| PadDynamicalDecoupling, | ||
| ResetAfterMeasureSimplification | ||
| ) | ||
|
|
||
| class Mybackend(BackendV2): | ||
|
|
||
| def get_scheduling_stage(self): | ||
| dd_sequence = [XGate(), XGate()] | ||
| pm = PassManager([ | ||
| ALAPScheduleAnalysis(self.instruction_durations), | ||
| PadDynamicalDecoupling(self.instruction_durations, dd_sequence) | ||
| ]) | ||
| return pm | ||
|
|
||
| def get_post_translation_stage(self): | ||
| pm = PassManager([ResetAfterMeasureSimplification()]) | ||
| return pm | ||
|
|
||
| This snippet of a backend implementation will now have the :func:`~.transpile` | ||
| function run a custom stage for scheduling (unless the user manually requests a | ||
| different one explicitly) which will insert dynamical decoupling sequences and | ||
| also simplify resets after measurements after the basis translation stage. This | ||
| way if these two compilation steps are **required** for running on ``Mybackend`` | ||
| the transpiler will be able to perform these steps without any manual user input. | ||
|
Member
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. Are we planning to add a different interface for passes that are suggested but not required? For example,
Member
Author
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. I guess required is probably too strong a word. I was trying to reinforce here that these passes will be run by default for every But, writing this I just realize that I think we should add an optimization level kwarg to the hook method. Because, I realize to really support using |
||
|
|
||
| Run Method | ||
| ---------- | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| 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()`` or ``get_post_translation_stage()`` the | ||
| transpiler will use the returned :class:`~.PassManager` object to run | ||
| additional custom transpiler passes when targetting that backend. | ||
| For more details on how to use this see :ref:`custom_transpiler_backend`. | ||
|
mtreinish marked this conversation as resolved.
|
||
Uh oh!
There was an error while loading. Please reload this page.