diff --git a/qiskit/transpiler/preset_passmanagers/builtin_plugins.py b/qiskit/transpiler/preset_passmanagers/builtin_plugins.py index c123ebab60c6..d1fc2b5e67c7 100644 --- a/qiskit/transpiler/preset_passmanagers/builtin_plugins.py +++ b/qiskit/transpiler/preset_passmanagers/builtin_plugins.py @@ -12,7 +12,6 @@ """Built-in transpiler stage plugins for preset pass managers.""" -from qiskit.transpiler.passmanager_config import PassManagerConfig from qiskit.transpiler.passmanager import PassManager from qiskit.transpiler.exceptions import TranspilerError from qiskit.transpiler.passes import BasicSwap @@ -27,18 +26,19 @@ class BasicSwapPassManager(PassManagerStagePlugin): """Plugin class for routing stage with :class:`~.BasicSwap`""" - def pass_manager(self, pass_manager_config: PassManagerConfig) -> PassManager: + def pass_manager(self, pass_manager_config, optimization_level=None) -> PassManager: """Build routing stage PassManager.""" - opt_level = pass_manager_config.optimization_level seed_transpiler = pass_manager_config.seed_transpiler target = pass_manager_config.target coupling_map = pass_manager_config.coupling_map backend_properties = pass_manager_config.backend_properties routing_pass = BasicSwap(coupling_map) vf2_call_limit = common.get_vf2_call_limit( - opt_level, pass_manager_config.layout_method, pass_manager_config.initial_layout + optimization_level, + pass_manager_config.layout_method, + pass_manager_config.initial_layout, ) - if opt_level == 0: + if optimization_level == 0: return common.generate_routing_passmanager( routing_pass, target, @@ -46,7 +46,7 @@ def pass_manager(self, pass_manager_config: PassManagerConfig) -> PassManager: seed_transpiler=seed_transpiler, use_barrier_before_measurement=True, ) - if opt_level == 1: + if optimization_level == 1: return common.generate_routing_passmanager( routing_pass, target, @@ -57,7 +57,7 @@ def pass_manager(self, pass_manager_config: PassManagerConfig) -> PassManager: check_trivial=True, use_barrier_before_measurement=True, ) - if opt_level == 2: + if optimization_level == 2: return common.generate_routing_passmanager( routing_pass, target, @@ -67,7 +67,7 @@ def pass_manager(self, pass_manager_config: PassManagerConfig) -> PassManager: seed_transpiler=seed_transpiler, use_barrier_before_measurement=True, ) - if opt_level == 3: + if optimization_level == 3: return common.generate_routing_passmanager( routing_pass, target, @@ -77,28 +77,29 @@ def pass_manager(self, pass_manager_config: PassManagerConfig) -> PassManager: seed_transpiler=seed_transpiler, use_barrier_before_measurement=True, ) - raise TranspilerError(f"Invalid optimization level specified: {opt_level}") + raise TranspilerError(f"Invalid optimization level specified: {optimization_level}") class StochasticSwapPassManager(PassManagerStagePlugin): """Plugin class for routing stage with :class:`~.StochasticSwap`""" - def pass_manager(self, pass_manager_config: PassManagerConfig) -> PassManager: + def pass_manager(self, pass_manager_config, optimization_level=None) -> PassManager: """Build routing stage PassManager.""" - opt_level = pass_manager_config.optimization_level seed_transpiler = pass_manager_config.seed_transpiler target = pass_manager_config.target coupling_map = pass_manager_config.coupling_map backend_properties = pass_manager_config.backend_properties vf2_call_limit = common.get_vf2_call_limit( - opt_level, pass_manager_config.layout_method, pass_manager_config.initial_layout + optimization_level, + pass_manager_config.layout_method, + pass_manager_config.initial_layout, ) - if opt_level == 3: + if optimization_level == 3: routing_pass = StochasticSwap(coupling_map, trials=200, seed=seed_transpiler) else: routing_pass = StochasticSwap(coupling_map, trials=20, seed=seed_transpiler) - if opt_level == 0: + if optimization_level == 0: return common.generate_routing_passmanager( routing_pass, target, @@ -106,7 +107,7 @@ def pass_manager(self, pass_manager_config: PassManagerConfig) -> PassManager: seed_transpiler=seed_transpiler, use_barrier_before_measurement=True, ) - if opt_level == 1: + if optimization_level == 1: return common.generate_routing_passmanager( routing_pass, target, @@ -117,7 +118,7 @@ def pass_manager(self, pass_manager_config: PassManagerConfig) -> PassManager: check_trivial=True, use_barrier_before_measurement=True, ) - if opt_level in {2, 3}: + if optimization_level in {2, 3}: return common.generate_routing_passmanager( routing_pass, target, @@ -127,23 +128,24 @@ def pass_manager(self, pass_manager_config: PassManagerConfig) -> PassManager: seed_transpiler=seed_transpiler, use_barrier_before_measurement=True, ) - raise TranspilerError(f"Invalid optimization level specified: {opt_level}") + raise TranspilerError(f"Invalid optimization level specified: {optimization_level}") class LookaheadSwapPassManager(PassManagerStagePlugin): """Plugin class for routing stage with :class:`~.LookaheadSwap`""" - def pass_manager(self, pass_manager_config: PassManagerConfig) -> PassManager: + def pass_manager(self, pass_manager_config, optimization_level=None) -> PassManager: """Build routing stage PassManager.""" - opt_level = pass_manager_config.optimization_level seed_transpiler = pass_manager_config.seed_transpiler target = pass_manager_config.target coupling_map = pass_manager_config.coupling_map backend_properties = pass_manager_config.backend_properties vf2_call_limit = common.get_vf2_call_limit( - opt_level, pass_manager_config.layout_method, pass_manager_config.initial_layout + optimization_level, + pass_manager_config.layout_method, + pass_manager_config.initial_layout, ) - if opt_level == 0: + if optimization_level == 0: routing_pass = LookaheadSwap(coupling_map, search_depth=2, search_width=2) return common.generate_routing_passmanager( routing_pass, @@ -152,7 +154,7 @@ def pass_manager(self, pass_manager_config: PassManagerConfig) -> PassManager: seed_transpiler=seed_transpiler, use_barrier_before_measurement=True, ) - if opt_level == 1: + if optimization_level == 1: routing_pass = LookaheadSwap(coupling_map, search_depth=4, search_width=4) return common.generate_routing_passmanager( routing_pass, @@ -164,7 +166,7 @@ def pass_manager(self, pass_manager_config: PassManagerConfig) -> PassManager: check_trivial=True, use_barrier_before_measurement=True, ) - if opt_level == 2: + if optimization_level == 2: routing_pass = LookaheadSwap(coupling_map, search_depth=5, search_width=6) return common.generate_routing_passmanager( routing_pass, @@ -175,7 +177,7 @@ def pass_manager(self, pass_manager_config: PassManagerConfig) -> PassManager: seed_transpiler=seed_transpiler, use_barrier_before_measurement=True, ) - if opt_level == 3: + if optimization_level == 3: routing_pass = LookaheadSwap(coupling_map, search_depth=5, search_width=6) return common.generate_routing_passmanager( routing_pass, @@ -186,23 +188,24 @@ def pass_manager(self, pass_manager_config: PassManagerConfig) -> PassManager: seed_transpiler=seed_transpiler, use_barrier_before_measurement=True, ) - raise TranspilerError(f"Invalid optimization level specified: {opt_level}") + raise TranspilerError(f"Invalid optimization level specified: {optimization_level}") class SabreSwapPassManager(PassManagerStagePlugin): """Plugin class for routing stage with :class:`~.SabreSwap`""" - def pass_manager(self, pass_manager_config: PassManagerConfig) -> PassManager: + def pass_manager(self, pass_manager_config, optimization_level=None) -> PassManager: """Build routing stage PassManager.""" - opt_level = pass_manager_config.optimization_level seed_transpiler = pass_manager_config.seed_transpiler target = pass_manager_config.target coupling_map = pass_manager_config.coupling_map backend_properties = pass_manager_config.backend_properties vf2_call_limit = common.get_vf2_call_limit( - opt_level, pass_manager_config.layout_method, pass_manager_config.initial_layout + optimization_level, + pass_manager_config.layout_method, + pass_manager_config.initial_layout, ) - if opt_level == 0: + if optimization_level == 0: routing_pass = SabreSwap(coupling_map, heuristic="basic", seed=seed_transpiler) return common.generate_routing_passmanager( routing_pass, @@ -211,7 +214,7 @@ def pass_manager(self, pass_manager_config: PassManagerConfig) -> PassManager: seed_transpiler=seed_transpiler, use_barrier_before_measurement=True, ) - if opt_level == 1: + if optimization_level == 1: routing_pass = SabreSwap(coupling_map, heuristic="lookahead", seed=seed_transpiler) return common.generate_routing_passmanager( routing_pass, @@ -223,7 +226,7 @@ def pass_manager(self, pass_manager_config: PassManagerConfig) -> PassManager: check_trivial=True, use_barrier_before_measurement=True, ) - if opt_level == 2: + if optimization_level == 2: routing_pass = SabreSwap(coupling_map, heuristic="decay", seed=seed_transpiler) return common.generate_routing_passmanager( routing_pass, @@ -234,7 +237,7 @@ def pass_manager(self, pass_manager_config: PassManagerConfig) -> PassManager: seed_transpiler=seed_transpiler, use_barrier_before_measurement=True, ) - if opt_level == 3: + if optimization_level == 3: routing_pass = SabreSwap(coupling_map, heuristic="decay", seed=seed_transpiler) return common.generate_routing_passmanager( routing_pass, @@ -245,13 +248,13 @@ def pass_manager(self, pass_manager_config: PassManagerConfig) -> PassManager: seed_transpiler=seed_transpiler, use_barrier_before_measurement=True, ) - raise TranspilerError(f"Invalid optimization level specified: {opt_level}") + raise TranspilerError(f"Invalid optimization level specified: {optimization_level}") class NoneRoutingPassManager(PassManagerStagePlugin): """Plugin class for routing stage with error on routing.""" - def pass_manager(self, pass_manager_config: PassManagerConfig) -> PassManager: + def pass_manager(self, pass_manager_config, optimization_level=None) -> PassManager: """Build routing stage PassManager.""" seed_transpiler = pass_manager_config.seed_transpiler target = pass_manager_config.target diff --git a/qiskit/transpiler/preset_passmanagers/level0.py b/qiskit/transpiler/preset_passmanagers/level0.py index 84dd2d810aaf..bd52ae54d429 100644 --- a/qiskit/transpiler/preset_passmanagers/level0.py +++ b/qiskit/transpiler/preset_passmanagers/level0.py @@ -72,11 +72,6 @@ def level_0_pass_manager(pass_manager_config: PassManagerConfig) -> StagedPassMa unitary_synthesis_method = pass_manager_config.unitary_synthesis_method unitary_synthesis_plugin_config = pass_manager_config.unitary_synthesis_plugin_config target = pass_manager_config.target - # Override an unset optimization_level for stage plugin use. - # it will be restored to None before this is returned - optimization_level = pass_manager_config.optimization_level - if optimization_level is None: - pass_manager_config.optimization_level = 0 # Choose an initial layout if not set by user (default: trivial layout) _given_layout = SetLayout(initial_layout) @@ -123,7 +118,7 @@ def _choose_layout_condition(property_set): ) else: routing_pm = plugin_manager.get_passmanager_stage( - "routing", routing_method, pass_manager_config + "routing", routing_method, pass_manager_config, optimization_level=0 ) unroll_3q = None @@ -138,7 +133,7 @@ def _choose_layout_condition(property_set): ) if layout_method not in {"trivial", "dense", "noise_adaptive", "sabre"}: layout = plugin_manager.get_passmanager_stage( - "layout", layout_method, pass_manager_config + "layout", layout_method, pass_manager_config, optimization_level=0 ) else: layout = PassManager() @@ -151,7 +146,7 @@ def _choose_layout_condition(property_set): routing = None if translation_method not in {"translator", "synthesis", "unroller"}: translation = plugin_manager.get_passmanager_stage( - "translation", translation_method, pass_manager_config + "translation", translation_method, pass_manager_config, optimization_level=0 ) else: translation = common.generate_translation_passmanager( @@ -181,21 +176,20 @@ def _choose_layout_condition(property_set): ) else: sched = plugin_manager.get_passmanager_stage( - "scheduling", scheduling_method, pass_manager_config + "scheduling", scheduling_method, pass_manager_config, optimization_level=0 ) if init_method is not None: - init = plugin_manager.get_passmanager_stage("init", init_method, pass_manager_config) + init = plugin_manager.get_passmanager_stage( + "init", init_method, pass_manager_config, optimization_level=0 + ) else: init = unroll_3q optimization = None if optimization_method is not None: optimization = plugin_manager.get_passmanager_stage( - "optimization", optimization_method, pass_manager_config + "optimization", optimization_method, pass_manager_config, optimization_level=0 ) - # Restore PassManagerConfig optimization_level override - pass_manager_config.optimization_level = optimization_level - return StagedPassManager( init=init, layout=layout, diff --git a/qiskit/transpiler/preset_passmanagers/level1.py b/qiskit/transpiler/preset_passmanagers/level1.py index fc1c0a5c820c..cd3151b2a229 100644 --- a/qiskit/transpiler/preset_passmanagers/level1.py +++ b/qiskit/transpiler/preset_passmanagers/level1.py @@ -83,11 +83,6 @@ def level_1_pass_manager(pass_manager_config: PassManagerConfig) -> StagedPassMa unitary_synthesis_plugin_config = pass_manager_config.unitary_synthesis_plugin_config timing_constraints = pass_manager_config.timing_constraints or TimingConstraints() target = pass_manager_config.target - # Override an unset optimization_level for stage plugin use. - # it will be restored to None before this is returned - optimization_level = pass_manager_config.optimization_level - if optimization_level is None: - pass_manager_config.optimization_level = 1 # Use trivial layout if no layout given _given_layout = SetLayout(initial_layout) @@ -187,7 +182,10 @@ def _vf2_match_not_found(property_set): ) else: routing_pm = plugin_manager.get_passmanager_stage( - "routing", routing_method, pass_manager_config + "routing", + routing_method, + pass_manager_config, + optimization_level=1, ) # Build optimization loop: merge 1q rotations and cancel CNOT gates iteratively @@ -212,7 +210,7 @@ def _opt_control(property_set): ) if layout_method not in {"trivial", "dense", "noise_adaptive", "sabre"}: layout = plugin_manager.get_passmanager_stage( - "layout", layout_method, pass_manager_config + "layout", layout_method, pass_manager_config, optimization_level=1 ) else: layout = PassManager() @@ -229,7 +227,7 @@ def _opt_control(property_set): routing = None if translation_method not in {"translator", "synthesis", "unroller"}: translation = plugin_manager.get_passmanager_stage( - "translation", translation_method, pass_manager_config + "translation", translation_method, pass_manager_config, optimization_level=1 ) else: translation = common.generate_translation_passmanager( @@ -262,7 +260,7 @@ def _opt_control(property_set): optimization.append(opt_loop, do_while=_opt_control) else: optimization = plugin_manager.get_passmanager_stage( - "optimization", optimization_method, pass_manager_config + "optimization", optimization_method, pass_manager_config, optimization_level=1 ) if scheduling_method is None or scheduling_method in {"alap", "asap"}: sched = common.generate_scheduling( @@ -270,14 +268,14 @@ def _opt_control(property_set): ) else: sched = plugin_manager.get_passmanager_stage( - "scheduling", scheduling_method, pass_manager_config + "scheduling", scheduling_method, pass_manager_config, optimization_level=1 ) if init_method is not None: - init = plugin_manager.get_passmanager_stage("init", init_method, pass_manager_config) + init = plugin_manager.get_passmanager_stage( + "init", init_method, pass_manager_config, optimization_level=1 + ) else: init = unroll_3q - # Restore PassManagerConfig optimization_level override - pass_manager_config.optimization_level = optimization_level return StagedPassManager( init=init, diff --git a/qiskit/transpiler/preset_passmanagers/level2.py b/qiskit/transpiler/preset_passmanagers/level2.py index 20082b4e85e2..dad5b75cde5b 100644 --- a/qiskit/transpiler/preset_passmanagers/level2.py +++ b/qiskit/transpiler/preset_passmanagers/level2.py @@ -85,11 +85,6 @@ def level_2_pass_manager(pass_manager_config: PassManagerConfig) -> StagedPassMa timing_constraints = pass_manager_config.timing_constraints or TimingConstraints() unitary_synthesis_plugin_config = pass_manager_config.unitary_synthesis_plugin_config target = pass_manager_config.target - # Override an unset optimization_level for stage plugin use. - # it will be restored to None before this is returned - optimization_level = pass_manager_config.optimization_level - if optimization_level is None: - pass_manager_config.optimization_level = 2 # Search for a perfect layout, or choose a dense layout, if no layout given _given_layout = SetLayout(initial_layout) @@ -169,7 +164,7 @@ def _vf2_match_not_found(property_set): ) else: routing_pm = plugin_manager.get_passmanager_stage( - "routing", routing_method, pass_manager_config + "routing", routing_method, pass_manager_config, optimization_level=2 ) # Build optimization loop: 1q rotation merge and commutative cancellation iteratively until @@ -197,7 +192,7 @@ def _opt_control(property_set): ) if layout_method not in {"trivial", "dense", "noise_adaptive", "sabre"}: layout = plugin_manager.get_passmanager_stage( - "layout", layout_method, pass_manager_config + "layout", layout_method, pass_manager_config, optimization_level=2 ) else: layout = PassManager() @@ -211,7 +206,7 @@ def _opt_control(property_set): routing = None if translation_method not in {"translator", "synthesis", "unroller"}: translation = plugin_manager.get_passmanager_stage( - "translation", translation_method, pass_manager_config + "translation", translation_method, pass_manager_config, optimization_level=2 ) else: translation = common.generate_translation_passmanager( @@ -241,7 +236,7 @@ def _opt_control(property_set): optimization.append(opt_loop, do_while=_opt_control) else: optimization = plugin_manager.get_passmanager_stage( - "optimization", optimization_method, pass_manager_config + "optimization", optimization_method, pass_manager_config, optimization_level=2 ) if scheduling_method is None or scheduling_method in {"alap", "asap"}: sched = common.generate_scheduling( @@ -249,16 +244,15 @@ def _opt_control(property_set): ) else: sched = plugin_manager.get_passmanager_stage( - "scheduling", scheduling_method, pass_manager_config + "scheduling", scheduling_method, pass_manager_config, optimization_level=2 ) if init_method is not None: - init = plugin_manager.get_passmanager_stage("init", init_method, pass_manager_config) + init = plugin_manager.get_passmanager_stage( + "init", init_method, pass_manager_config, optimization_level=2 + ) else: init = unroll_3q - # Restore PassManagerConfig optimization_level override - pass_manager_config.optimization_level = optimization_level - return StagedPassManager( init=init, layout=layout, diff --git a/qiskit/transpiler/preset_passmanagers/level3.py b/qiskit/transpiler/preset_passmanagers/level3.py index c579cc5038b6..2bc560282f4f 100644 --- a/qiskit/transpiler/preset_passmanagers/level3.py +++ b/qiskit/transpiler/preset_passmanagers/level3.py @@ -174,7 +174,7 @@ def _vf2_match_not_found(property_set): ) else: routing_pm = plugin_manager.get_passmanager_stage( - "routing", routing_method, pass_manager_config + "routing", routing_method, pass_manager_config, optimization_level=3 ) # 8. Optimize iteratively until no more change in depth. Removes useless gates @@ -203,7 +203,9 @@ def _opt_control(property_set): # Build pass manager if init_method is not None: - init = plugin_manager.get_passmanager_stage("init", init_method, pass_manager_config) + init = plugin_manager.get_passmanager_stage( + "init", init_method, pass_manager_config, optimization_level=3 + ) else: init = common.generate_unroll_3q( target, @@ -218,7 +220,7 @@ def _opt_control(property_set): if coupling_map or initial_layout: if layout_method not in {"trivial", "dense", "noise_adaptive", "sabre"}: layout = plugin_manager.get_passmanager_stage( - "layout", layout_method, pass_manager_config + "layout", layout_method, pass_manager_config, optimization_level=3 ) else: layout = PassManager() @@ -232,7 +234,7 @@ def _opt_control(property_set): routing = None if translation_method not in {"translator", "synthesis", "unroller"}: translation = plugin_manager.get_passmanager_stage( - "translation", translation_method, pass_manager_config + "translation", translation_method, pass_manager_config, optimization_level=3 ) else: translation = common.generate_translation_passmanager( @@ -280,7 +282,7 @@ def _opt_control(property_set): optimization.append(opt_loop, do_while=_opt_control) else: optimization = plugin_manager.get_passmanager_stage( - "optimization", optimization_method, pass_manager_config + "optimization", optimization_method, pass_manager_config, optimization_level=3 ) if (coupling_map and not coupling_map.is_symmetric) or ( target is not None and target.get_non_global_operation_names(strict_direction=True) @@ -295,7 +297,7 @@ def _opt_control(property_set): ) else: sched = plugin_manager.get_passmanager_stage( - "scheduling", scheduling_method, pass_manager_config + "scheduling", scheduling_method, pass_manager_config, optimization_level=3 ) # Restore PassManagerConfig optimization_level override diff --git a/qiskit/transpiler/preset_passmanagers/plugin.py b/qiskit/transpiler/preset_passmanagers/plugin.py index 607ef0567187..a442bbb49383 100644 --- a/qiskit/transpiler/preset_passmanagers/plugin.py +++ b/qiskit/transpiler/preset_passmanagers/plugin.py @@ -160,7 +160,7 @@ def pass_manager(self, pass_manager_config): """ import abc -from typing import List +from typing import List, Optional import stevedore @@ -174,12 +174,26 @@ class PassManagerStagePlugin(abc.ABC): stages in :func:`~.transpile`. A ``PassManagerStagePlugin`` object can be added to an external package and - + integrated into the :func:`~.transpile` function with an entrypoint. This + will enable users to use the output of :meth:`.pass_manager` to implement + a stage in the compilation process. """ @abc.abstractmethod - def pass_manager(self, pass_manager_config: PassManagerConfig) -> PassManager: - """This method is designed to return a :class:`~.PassManager` for the""" + def pass_manager( + self, pass_manager_config: PassManagerConfig, optimization_level: Optional[int] = None + ) -> PassManager: + """This method is designed to return a :class:`~.PassManager` for the stage this implements + + Args: + pass_manager_config: A configuration object that defines all the target device + specifications and any user specified options to :func:`~.transpile` or + :func:`~.generate_preset_pass_manager` + optimization_level: The optimization level of the transpilation, if set this + should be used to set values for any tunable parameters to trade off runtime + for potential optimization. Valid values should be ``0``, ``1``, ``2``, or ``3`` + and the higher the number the more optimization is expected. + """ pass @@ -208,21 +222,37 @@ def __init__(self): ) def get_passmanager_stage( - self, stage_name: str, plugin_name: str, pm_config: PassManagerConfig + self, + stage_name: str, + plugin_name: str, + pm_config: PassManagerConfig, + optimization_level=None, ) -> PassManager: """Get a stage""" if stage_name == "init": - return self._build_pm(self.init_plugins, stage_name, plugin_name, pm_config) + return self._build_pm( + self.init_plugins, stage_name, plugin_name, pm_config, optimization_level + ) elif stage_name == "layout": - return self._build_pm(self.layout_plugins, stage_name, plugin_name, pm_config) + return self._build_pm( + self.layout_plugins, stage_name, plugin_name, pm_config, optimization_level + ) elif stage_name == "routing": - return self._build_pm(self.routing_plugins, stage_name, plugin_name, pm_config) + return self._build_pm( + self.routing_plugins, stage_name, plugin_name, pm_config, optimization_level + ) elif stage_name == "translation": - return self._build_pm(self.translation_plugins, stage_name, plugin_name, pm_config) + return self._build_pm( + self.translation_plugins, stage_name, plugin_name, pm_config, optimization_level + ) elif stage_name == "optimization": - return self._build_pm(self.optimization_plugins, stage_name, plugin_name, pm_config) + return self._build_pm( + self.optimization_plugins, stage_name, plugin_name, pm_config, optimization_level + ) elif stage_name == "scheduling": - return self._build_pm(self.scheduling_plugins, stage_name, plugin_name, pm_config) + return self._build_pm( + self.scheduling_plugins, stage_name, plugin_name, pm_config, optimization_level + ) else: raise TranspilerError(f"Invalid stage name: {stage_name}") @@ -232,12 +262,12 @@ def _build_pm( stage_name: str, plugin_name: str, pm_config: PassManagerConfig, + optimization_level: Optional[int] = None, ): if plugin_name not in stage_obj: - raise TranspilerError( - f"Invalid plugin name {plugin_name} for stage {stage_name}" - ) - return plugin_obj.obj.pass_manager(stage_obj[plugin_name]) + raise TranspilerError(f"Invalid plugin name {plugin_name} for stage {stage_name}") + plugin_obj = stage_obj[plugin_name] + return plugin_obj.obj.pass_manager(pm_config, optimization_level) def list_stage_plugins(stage_name: str) -> List[str]: diff --git a/test/python/transpiler/test_stage_plugin.py b/test/python/transpiler/test_stage_plugin.py index 56a33758b1fa..807d6b2d5da0 100644 --- a/test/python/transpiler/test_stage_plugin.py +++ b/test/python/transpiler/test_stage_plugin.py @@ -48,9 +48,7 @@ def test_build_pm_invalid_plugin_name_valid_stage(self): """Test get pm from plugin with invalid plugin name and valid stage.""" plugin_manager = PassManagerStagePluginManager() with self.assertRaises(TranspilerError): - plugin_manager.get_passmanager_stage( - "init", "empty_plugin", PassManagerConfig() - ) + plugin_manager.get_passmanager_stage("init", "empty_plugin", PassManagerConfig()) def test_build_pm_invalid_stage(self): """Test get pm from plugin with invalid stage.""" @@ -63,6 +61,8 @@ def test_build_pm_invalid_stage(self): def test_build_pm(self): """Test get pm from plugin.""" plugin_manager = PassManagerStagePluginManager() - pm_config = PassManagerConfig(optimization_level=3) - pm = plugin_manager.get_passmanager_stage("routing", "sabre", pm_config) + pm_config = PassManagerConfig() + pm = plugin_manager.get_passmanager_stage( + "routing", "sabre", pm_config, optimization_level=3 + ) self.assertIsInstance(pm, PassManager)