Skip to content

Commit

Permalink
Rename hook methods backend_
Browse files Browse the repository at this point in the history
  • Loading branch information
mtreinish committed Oct 3, 2022
1 parent d004080 commit 214d9f7
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
8 changes: 4 additions & 4 deletions qiskit/compiler/transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,10 +678,10 @@ def _parse_transpile_args(

list_transpile_args = []
if not ignore_backend_supplied_default_methods:
if scheduling_method is None and hasattr(backend, "get_scheduling_stage_method"):
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()
if scheduling_method is None and hasattr(backend, "get_scheduling_stage_plugin"):
scheduling_method = backend.get_scheduling_stage_plugin()
if translation_method is None and hasattr(backend, "get_translation_stage_plugin"):
translation_method = backend.get_translation_stage_plugin()

for key, value in {
"inst_map": inst_map,
Expand Down
6 changes: 3 additions & 3 deletions qiskit/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def _define(self):
The transpiler supports the ability for backends to provide custom transpiler
stage implementations to facilitate hardware specific optimizations and
circuit transformations. Currently there are two stages supported,
``get_translation_stage_method()`` and ``get_scheduling_stage_method()``
``get_translation_stage_plugin()`` and ``get_scheduling_stage_plugin()``
which allow a backend to specify string plugin names to be used as the default
translation and scheduling stages, respectively. These
hook points in a :class:`~.BackendV2` class can be used if your
Expand All @@ -430,10 +430,10 @@ def _define(self):
class Mybackend(BackendV2):
def get_scheduling_stage_method(self):
def get_scheduling_stage_plugin(self):
return "SpecialDD"
def get_translation_stage_method(self):
def get_translation_stage_plugin(self):
return "BasisTranslatorWithCustom1qOptimization"
This snippet of a backend implementation will now have the :func:`~.transpile`
Expand Down
2 changes: 1 addition & 1 deletion qiskit/providers/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class BackendV2(Backend, ABC):
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
``get_translation_stage_plugin`` and ``get_scheduling_stage_plugin``. If these
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
Expand Down
8 changes: 4 additions & 4 deletions qiskit/transpiler/passmanager_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ def from_backend(cls, backend, **pass_manager_options):
if res.target is None:
if backend_version >= 2:
res.target = backend.target
if res.scheduling_method is None and hasattr(backend, "get_scheduling_stage_method"):
res.scheduling_method = backend.get_scheduling_stage_method()
if res.translation_method is None and hasattr(backend, "get_translation_stage_method"):
res.translation_method = backend.get_translation_stage_method()
if res.scheduling_method is None and hasattr(backend, "get_scheduling_stage_plugin"):
res.scheduling_method = backend.get_scheduling_stage_plugin()
if res.translation_method is None and hasattr(backend, "get_translation_stage_plugin"):
res.translation_method = backend.get_translation_stage_plugin()
return res

def __str__(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ features:
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
``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
Expand Down
20 changes: 10 additions & 10 deletions test/python/transpiler/test_preset_passmanagers.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,11 @@ def test_backend_with_custom_stages(self, _plugin_manager_mock):
class TargetBackend(FakeLagosV2):
"""Fake lagos subclass with custom transpiler stages."""

def get_scheduling_stage_method(self):
def get_scheduling_stage_plugin(self):
"""Custom scheduling stage."""
return "custom_stage_for_test"

def get_translation_stage_method(self):
def get_translation_stage_plugin(self):
"""Custom post translation stage."""
return "custom_stage_for_test"

Expand Down Expand Up @@ -1104,11 +1104,11 @@ def test_backend_with_custom_stages_level2(self, _plugin_manager_mock):
class TargetBackend(FakeLagosV2):
"""Fake lagos subclass with custom transpiler stages."""

def get_scheduling_stage_method(self):
def get_scheduling_stage_plugin(self):
"""Custom scheduling stage."""
return "custom_stage_for_test"

def get_translation_stage_method(self):
def get_translation_stage_plugin(self):
"""Custom post translation stage."""
return "custom_stage_for_test"

Expand Down Expand Up @@ -1138,11 +1138,11 @@ def test_backend_with_custom_stages_level1(self, _plugin_manager_mock):
class TargetBackend(FakeLagosV2):
"""Fake lagos subclass with custom transpiler stages."""

def get_scheduling_stage_method(self):
def get_scheduling_stage_plugin(self):
"""Custom scheduling stage."""
return "custom_stage_for_test"

def get_translation_stage_method(self):
def get_translation_stage_plugin(self):
"""Custom post translation stage."""
return "custom_stage_for_test"

Expand Down Expand Up @@ -1172,11 +1172,11 @@ def test_backend_with_custom_stages_level3(self, _plugin_manager_mock):
class TargetBackend(FakeLagosV2):
"""Fake lagos subclass with custom transpiler stages."""

def get_scheduling_stage_method(self):
def get_scheduling_stage_plugin(self):
"""Custom scheduling stage."""
return "custom_stage_for_test"

def get_translation_stage_method(self):
def get_translation_stage_plugin(self):
"""Custom post translation stage."""
return "custom_stage_for_test"

Expand Down Expand Up @@ -1206,11 +1206,11 @@ def test_backend_with_custom_stages_level0(self, _plugin_manager_mock):
class TargetBackend(FakeLagosV2):
"""Fake lagos subclass with custom transpiler stages."""

def get_scheduling_stage_method(self):
def get_scheduling_stage_plugin(self):
"""Custom scheduling stage."""
return "custom_stage_for_test"

def get_translation_stage_method(self):
def get_translation_stage_plugin(self):
"""Custom post translation stage."""
return "custom_stage_for_test"

Expand Down

0 comments on commit 214d9f7

Please sign in to comment.