From 52ece9dbfb1c2784adf222f45e4cbc15c446209d Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Tue, 22 Aug 2023 09:53:50 -0400 Subject: [PATCH] Simplify inner translation stage creation logic This commit changes the plugin construction logic slightly to adjust how the embedded translation stage is created. After #10621 merged we only need to use the plugin interface to get the translation stage pass manager. --- .../preset_passmanagers/builtin_plugins.py | 49 ++++++------------- .../transpiler/preset_passmanagers/level1.py | 2 - .../transpiler/preset_passmanagers/level2.py | 2 - .../transpiler/preset_passmanagers/level3.py | 3 -- 4 files changed, 16 insertions(+), 40 deletions(-) diff --git a/qiskit/transpiler/preset_passmanagers/builtin_plugins.py b/qiskit/transpiler/preset_passmanagers/builtin_plugins.py index 3bb950ff64f3..2ecd4653707b 100644 --- a/qiskit/transpiler/preset_passmanagers/builtin_plugins.py +++ b/qiskit/transpiler/preset_passmanagers/builtin_plugins.py @@ -416,31 +416,21 @@ def _opt_control(property_set): not property_set["size_fixed_point"] ) - 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( - pass_manager_config.target, - pass_manager_config.basis_gates, - translation_method, - pass_manager_config.approximation_degree, - pass_manager_config.coupling_map, - pass_manager_config.backend_properties, - pass_manager_config.unitary_synthesis_method, - pass_manager_config.unitary_synthesis_plugin_config, - pass_manager_config.hls_config, - ) - - if optimization_level == 2: + translation = plugin_manager.get_passmanager_stage( + "translation", + translation_method, + pass_manager_config, + optimization_level=optimization_level, + ) + if optimization_level == 1: + # Steps for optimization level 1 + _opt = [ + Optimize1qGatesDecomposition( + basis=pass_manager_config.basis_gates, target=pass_manager_config.target + ), + CXCancellation(), + ] + elif optimization_level == 2: # Steps for optimization level 2 _opt = [ Optimize1qGatesDecomposition( @@ -451,7 +441,6 @@ def _opt_control(property_set): target=pass_manager_config.target, ), ] - elif optimization_level == 3: # Steps for optimization level 3 _opt = [ @@ -480,13 +469,7 @@ def _opt_control(property_set): return not property_set["optimization_loop_minimum_point"] else: - # Steps for optimization level 1 - _opt = [ - Optimize1qGatesDecomposition( - basis=pass_manager_config.basis_gates, target=pass_manager_config.target - ), - CXCancellation(), - ] + raise TranspilerError(f"Invalid optimization_level: {optimization_level}") unroll = [pass_ for x in translation.passes() for pass_ in x["passes"]] # Build nested Flow controllers diff --git a/qiskit/transpiler/preset_passmanagers/level1.py b/qiskit/transpiler/preset_passmanagers/level1.py index 2204456fb65e..22be66c4370c 100644 --- a/qiskit/transpiler/preset_passmanagers/level1.py +++ b/qiskit/transpiler/preset_passmanagers/level1.py @@ -15,9 +15,7 @@ Level 1 pass manager: light optimization by simple adjacent gate collapsing. """ from __future__ import annotations -from qiskit.transpiler.basepasses import BasePass from qiskit.transpiler.passmanager_config import PassManagerConfig -from qiskit.transpiler.passmanager import PassManager from qiskit.transpiler.passmanager import StagedPassManager from qiskit.transpiler.preset_passmanagers import common from qiskit.transpiler.preset_passmanagers.plugin import ( diff --git a/qiskit/transpiler/preset_passmanagers/level2.py b/qiskit/transpiler/preset_passmanagers/level2.py index 8d2005ea4d78..8815a983ca61 100644 --- a/qiskit/transpiler/preset_passmanagers/level2.py +++ b/qiskit/transpiler/preset_passmanagers/level2.py @@ -16,9 +16,7 @@ gate cancellation using commutativity rules. """ from __future__ import annotations -from qiskit.transpiler.basepasses import BasePass from qiskit.transpiler.passmanager_config import PassManagerConfig -from qiskit.transpiler.passmanager import PassManager from qiskit.transpiler.passmanager import StagedPassManager from qiskit.transpiler.preset_passmanagers import common from qiskit.transpiler.preset_passmanagers.plugin import ( diff --git a/qiskit/transpiler/preset_passmanagers/level3.py b/qiskit/transpiler/preset_passmanagers/level3.py index e6c253be4781..1e4c7d589b35 100644 --- a/qiskit/transpiler/preset_passmanagers/level3.py +++ b/qiskit/transpiler/preset_passmanagers/level3.py @@ -16,9 +16,7 @@ gate cancellation using commutativity rules and unitary synthesis. """ from __future__ import annotations -from qiskit.transpiler.basepasses import BasePass from qiskit.transpiler.passmanager_config import PassManagerConfig -from qiskit.transpiler.passmanager import PassManager from qiskit.transpiler.passmanager import StagedPassManager from qiskit.transpiler.passes import RemoveResetInZeroState from qiskit.transpiler.passes import OptimizeSwapBeforeMeasure @@ -63,7 +61,6 @@ def level_3_pass_manager(pass_manager_config: PassManagerConfig) -> StagedPassMa scheduling_method = pass_manager_config.scheduling_method optimization_method = pass_manager_config.optimization_method or "default" scheduling_method = pass_manager_config.scheduling_method or "default" - backend_properties = pass_manager_config.backend_properties approximation_degree = pass_manager_config.approximation_degree unitary_synthesis_method = pass_manager_config.unitary_synthesis_method unitary_synthesis_plugin_config = pass_manager_config.unitary_synthesis_plugin_config