-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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 11 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 |
|---|---|---|
|
|
@@ -84,6 +84,7 @@ def transpile( | |
| hls_config: Optional[HLSConfig] = None, | ||
| init_method: str = None, | ||
| optimization_method: str = None, | ||
| ignore_backend_default_methods: bool = False, | ||
| ) -> Union[QuantumCircuit, List[QuantumCircuit]]: | ||
| """Transpile one or more circuits, according to some desired transpilation targets. | ||
|
|
||
|
|
@@ -276,6 +277,11 @@ def callback_func(**kwargs): | |
| plugin is not used. You can see a list of installed plugins by | ||
| using :func:`~.list_stage_plugins` with ``"optimization"`` for the | ||
| ``stage_name`` argument. | ||
| ignore_backend_default_methods: If set to ``True`` any default methods specified by | ||
| a backend will be ignored. Some backends specify alternative default methods | ||
| to support custom compilation target passes/plugins which support backend | ||
| specific compilation techniques. If you'd prefer that these did not run and | ||
| use the defaults for a given optimization level this can be used. | ||
|
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. Is there a more descriptive name that we can use here? I'm not sure that "backend default methods" will be clear to a user without context. Maybe something like
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'm open to changing the name, what about
Contributor
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.
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. In the context of
Contributor
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. Ok. I see that it's also clear in the doc that it means "instance method". It makes sense to me that whatever the name of the method in question here (eg
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 renamed it to |
||
|
|
||
| Returns: | ||
| The transpiled circuit(s). | ||
|
|
@@ -344,6 +350,7 @@ def callback_func(**kwargs): | |
| hls_config, | ||
| init_method, | ||
| optimization_method, | ||
| ignore_backend_default_methods, | ||
| ) | ||
| # Get transpile_args to configure the circuit transpilation job(s) | ||
| if coupling_map in unique_transpile_args: | ||
|
|
@@ -426,7 +433,7 @@ def _log_transpile_time(start_time, end_time): | |
| def _combine_args(shared_transpiler_args, unique_config): | ||
| # Pop optimization_level to exclude it from the kwargs when building a | ||
| # PassManagerConfig | ||
| level = shared_transpiler_args.get("optimization_level") | ||
| level = shared_transpiler_args.pop("optimization_level") | ||
| pass_manager_config = shared_transpiler_args | ||
| pass_manager_config.update(unique_config.pop("pass_manager_config")) | ||
| pass_manager_config = PassManagerConfig(**pass_manager_config) | ||
|
|
@@ -597,6 +604,7 @@ def _parse_transpile_args( | |
| hls_config, | ||
| init_method, | ||
| optimization_method, | ||
| ignore_backend_default_methods, | ||
| ) -> Tuple[List[Dict], Dict]: | ||
| """Resolve the various types of args allowed to the transpile() function through | ||
| duck typing, overriding args, etc. Refer to the transpile() docstring for details on | ||
|
|
@@ -669,6 +677,12 @@ def _parse_transpile_args( | |
| } | ||
|
|
||
| list_transpile_args = [] | ||
| if not ignore_backend_default_methods: | ||
| if scheduling_method is None and hasattr(backend, "get_scheduling_stage_method"): | ||
|
Contributor
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. This seems to me like restricting the flexibility of
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 think there are 2 pieces here, for the preset passmanagers/ The second part is what the plugin usage. If you look at earlier iterations of this PR, I had this interface be a bit more generic similar to what you're describing here. Instead of working with plugins backends would return
Contributor
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. Okey, so we think current default stages of qiskit transpiler is sort of stable in future. My only concern was the stability of new API. To me current mechanism based off of #8305 seems reasonable. |
||
| scheduling_method = backend.get_scheduling_stage_method() | ||
| if translation_method is None and hasattr(backend, "get_translation_stage_method"): | ||
| translation_method = backend.get_translation_stage_method() | ||
|
|
||
|
jlapeyre marked this conversation as resolved.
|
||
| for key, value in { | ||
| "inst_map": inst_map, | ||
| "coupling_map": coupling_map, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -287,6 +287,26 @@ class BackendV2(Backend, ABC): | |
| will build a :class:`~qiskit.providers.models.BackendConfiguration` object | ||
| and :class:`~qiskit.providers.models.BackendProperties` from the attributes | ||
| defined in this class for backwards compatibility. | ||
|
|
||
| A backend object can optionally contain methods named | ||
| ``get_translation_stage_method`` and ``get_scheduling_stage_method``. If these | ||
|
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. Should these be renamed to
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. Good catch, I'll update this now
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. Actually I misread what you wrote here, I'm not sure we want to rename this. I had standardized on method because it's not actually restricted to plugins. It basically is the return of these methods are for changing the default for
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. Agree, I think this is clearer post- #8661 . I was trying to avoid the confusion between method as in I think either
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 renamed it |
||
| methods are present on a backend object and this object is used for | ||
| :func:`~.transpile` or :func:`~.generate_preset_pass_manager` the | ||
| transpilation process will default to using the output from those methods | ||
| as the scheduling stage and the translation compilation stage. This | ||
| enables a backend which has custom requirements for compilation to specify a | ||
| stage plugin for these stages to enable custom transformation of | ||
| the circuit to ensure it is runnable on the backend. These hooks are enabled | ||
| by default and should only be used to enable extra compilation steps | ||
| if they are **required** to ensure a circuit is executable on the backend or | ||
| have the expected level of performance. These methods are passed no input | ||
| arguments and are expected to return a ``str`` representing the method name | ||
| which is should be a stage plugin (see: :mod:`qiskit.transpiler.preset_passmanagers.plugin` | ||
|
mtreinish marked this conversation as resolved.
Outdated
|
||
| for more details on plugins). The typical expected use case is for a backend | ||
| provider to implement a stage plugin for ``translation`` or ``scheduling`` | ||
| that contains the custom compilation passes and then for the hook methods on | ||
| the backend object to return the plugin name so that :func:`~.transpile` will | ||
| use it by default when targetting the backend. | ||
| """ | ||
|
|
||
| version = 2 | ||
|
|
||
| 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_method()`` or ``get_translation_stage_method()`` 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`. | ||
|
mtreinish marked this conversation as resolved.
|
||
| - | | ||
| Added a new keyword argument, ``ignore_backend_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. | ||
Uh oh!
There was an error while loading. Please reload this page.