Skip to content

Commit

Permalink
Migrate translation stage to plugins (Qiskit#10621)
Browse files Browse the repository at this point in the history
This commit updates the preset pass manager construction to only use
plugins for the translation stage. To accomplish this the previously
hard coded built-in translation methods, unroller, translator, and
synthesis are migrated to be exposed as built-in plugins. This
simplifies the preset pass manager construction as now the translation
stage is solely built via plugins.

Fixes Qiskit#9456
  • Loading branch information
mtreinish authored and SamD-1998 committed Sep 7, 2023
1 parent 067ec05 commit 10fcf6e
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 64 deletions.
51 changes: 51 additions & 0 deletions qiskit/transpiler/preset_passmanagers/builtin_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,57 @@
from qiskit.transpiler.timing_constraints import TimingConstraints


class BasisTranslatorPassManager(PassManagerStagePlugin):
"""Plugin class for translation stage with :class:`~.BasisTranslator`"""

def pass_manager(self, pass_manager_config, optimization_level=None) -> PassManager:
return common.generate_translation_passmanager(
pass_manager_config.target,
basis_gates=pass_manager_config.basis_gates,
method="translator",
approximation_degree=pass_manager_config.approximation_degree,
coupling_map=pass_manager_config.coupling_map,
backend_props=pass_manager_config.backend_properties,
unitary_synthesis_method=pass_manager_config.unitary_synthesis_method,
unitary_synthesis_plugin_config=pass_manager_config.unitary_synthesis_plugin_config,
hls_config=pass_manager_config.hls_config,
)


class UnrollerPassManager(PassManagerStagePlugin):
"""Plugin class for translation stage with :class:`~.BasisTranslator`"""

def pass_manager(self, pass_manager_config, optimization_level=None) -> PassManager:
return common.generate_translation_passmanager(
pass_manager_config.target,
basis_gates=pass_manager_config.basis_gates,
method="unroller",
approximation_degree=pass_manager_config.approximation_degree,
coupling_map=pass_manager_config.coupling_map,
backend_props=pass_manager_config.backend_properties,
unitary_synthesis_method=pass_manager_config.unitary_synthesis_method,
unitary_synthesis_plugin_config=pass_manager_config.unitary_synthesis_plugin_config,
hls_config=pass_manager_config.hls_config,
)


class UnitarySynthesisPassManager(PassManagerStagePlugin):
"""Plugin class for translation stage with :class:`~.BasisTranslator`"""

def pass_manager(self, pass_manager_config, optimization_level=None) -> PassManager:
return common.generate_translation_passmanager(
pass_manager_config.target,
basis_gates=pass_manager_config.basis_gates,
method="synthesis",
approximation_degree=pass_manager_config.approximation_degree,
coupling_map=pass_manager_config.coupling_map,
backend_props=pass_manager_config.backend_properties,
unitary_synthesis_method=pass_manager_config.unitary_synthesis_method,
unitary_synthesis_plugin_config=pass_manager_config.unitary_synthesis_plugin_config,
hls_config=pass_manager_config.hls_config,
)


class BasicSwapPassManager(PassManagerStagePlugin):
"""Plugin class for routing stage with :class:`~.BasicSwap`"""

Expand Down
20 changes: 4 additions & 16 deletions qiskit/transpiler/preset_passmanagers/level0.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,10 @@ def _swap_mapped(property_set):
else:
layout = None
routing = None
if translation_method not in {"translator", "synthesis", "unroller"}:
translation = plugin_manager.get_passmanager_stage(
"translation", translation_method, pass_manager_config, optimization_level=0
)
else:
translation = common.generate_translation_passmanager(
target,
basis_gates,
translation_method,
approximation_degree,
coupling_map,
backend_properties,
unitary_synthesis_method,
unitary_synthesis_plugin_config,
hls_config,
)

translation = plugin_manager.get_passmanager_stage(
"translation", translation_method, pass_manager_config, optimization_level=0
)

if (coupling_map and not coupling_map.is_symmetric) or (
target is not None and target.get_non_global_operation_names(strict_direction=True)
Expand Down
19 changes: 3 additions & 16 deletions qiskit/transpiler/preset_passmanagers/level1.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,22 +207,9 @@ def _swap_mapped(property_set):
layout = None
routing = None

if translation_method not in {"translator", "synthesis", "unroller"}:
translation = plugin_manager.get_passmanager_stage(
"translation", translation_method, pass_manager_config, optimization_level=1
)
else:
translation = common.generate_translation_passmanager(
target,
basis_gates,
translation_method,
approximation_degree,
coupling_map,
backend_properties,
unitary_synthesis_method,
unitary_synthesis_plugin_config,
hls_config,
)
translation = plugin_manager.get_passmanager_stage(
"translation", translation_method, pass_manager_config, optimization_level=1
)

if (coupling_map and not coupling_map.is_symmetric) or (
target is not None and target.get_non_global_operation_names(strict_direction=True)
Expand Down
19 changes: 3 additions & 16 deletions qiskit/transpiler/preset_passmanagers/level2.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,22 +196,9 @@ def _swap_mapped(property_set):
else:
layout = None
routing = None
if translation_method not in {"translator", "synthesis", "unroller"}:
translation = plugin_manager.get_passmanager_stage(
"translation", translation_method, pass_manager_config, optimization_level=2
)
else:
translation = common.generate_translation_passmanager(
target,
basis_gates,
translation_method,
approximation_degree,
coupling_map,
backend_properties,
unitary_synthesis_method,
unitary_synthesis_plugin_config,
hls_config,
)
translation = plugin_manager.get_passmanager_stage(
"translation", translation_method, pass_manager_config, optimization_level=2
)

if (coupling_map and not coupling_map.is_symmetric) or (
target is not None and target.get_non_global_operation_names(strict_direction=True)
Expand Down
20 changes: 4 additions & 16 deletions qiskit/transpiler/preset_passmanagers/level3.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,22 +234,10 @@ def _swap_mapped(property_set):
else:
layout = None
routing = None
if translation_method not in {"translator", "synthesis", "unroller"}:
translation = plugin_manager.get_passmanager_stage(
"translation", translation_method, pass_manager_config, optimization_level=3
)
else:
translation = common.generate_translation_passmanager(
target,
basis_gates,
translation_method,
approximation_degree,
coupling_map,
backend_properties,
unitary_synthesis_method,
unitary_synthesis_plugin_config,
hls_config,
)

translation = plugin_manager.get_passmanager_stage(
"translation", translation_method, pass_manager_config, optimization_level=3
)

if optimization_method is None:
optimization = PassManager()
Expand Down
5 changes: 5 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@
"permutation.basic = qiskit.transpiler.passes.synthesis.high_level_synthesis:BasicSynthesisPermutation",
"permutation.acg = qiskit.transpiler.passes.synthesis.high_level_synthesis:ACGSynthesisPermutation",
],
"qiskit.transpiler.translation": [
"translator = qiskit.transpiler.preset_passmanagers.builtin_plugins:BasisTranslatorPassManager",
"unroller = qiskit.transpiler.preset_passmanagers.builtin_plugins:UnrollerPassManager",
"synthesis = qiskit.transpiler.preset_passmanagers.builtin_plugins:UnitarySynthesisPassManager",
],
"qiskit.transpiler.routing": [
"basic = qiskit.transpiler.preset_passmanagers.builtin_plugins:BasicSwapPassManager",
"stochastic = qiskit.transpiler.preset_passmanagers.builtin_plugins:StochasticSwapPassManager",
Expand Down

0 comments on commit 10fcf6e

Please sign in to comment.