diff --git a/qiskit/transpiler/preset_passmanagers/builtin_plugins.py b/qiskit/transpiler/preset_passmanagers/builtin_plugins.py index 2da12d7da8cf..7da641c2d5fb 100644 --- a/qiskit/transpiler/preset_passmanagers/builtin_plugins.py +++ b/qiskit/transpiler/preset_passmanagers/builtin_plugins.py @@ -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`""" diff --git a/qiskit/transpiler/preset_passmanagers/level0.py b/qiskit/transpiler/preset_passmanagers/level0.py index ce8a5eedb232..caa5cbc2846c 100644 --- a/qiskit/transpiler/preset_passmanagers/level0.py +++ b/qiskit/transpiler/preset_passmanagers/level0.py @@ -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) diff --git a/qiskit/transpiler/preset_passmanagers/level1.py b/qiskit/transpiler/preset_passmanagers/level1.py index cbe63265589d..97cd5b319841 100644 --- a/qiskit/transpiler/preset_passmanagers/level1.py +++ b/qiskit/transpiler/preset_passmanagers/level1.py @@ -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) diff --git a/qiskit/transpiler/preset_passmanagers/level2.py b/qiskit/transpiler/preset_passmanagers/level2.py index ca7a515c4a43..cf4f66e1e67b 100644 --- a/qiskit/transpiler/preset_passmanagers/level2.py +++ b/qiskit/transpiler/preset_passmanagers/level2.py @@ -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) diff --git a/qiskit/transpiler/preset_passmanagers/level3.py b/qiskit/transpiler/preset_passmanagers/level3.py index 53c4f148d711..caa6cb6f48f9 100644 --- a/qiskit/transpiler/preset_passmanagers/level3.py +++ b/qiskit/transpiler/preset_passmanagers/level3.py @@ -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() diff --git a/setup.py b/setup.py index 45b9b1864539..e7ee6f893318 100644 --- a/setup.py +++ b/setup.py @@ -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",