diff --git a/pyproject.toml b/pyproject.toml index a89f191fe848..3c399ce1bca5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -122,6 +122,7 @@ sk = "qiskit.transpiler.passes.synthesis.solovay_kitaev_synthesis:SolovayKitaevS default = "qiskit.transpiler.preset_passmanagers.builtin_plugins:DefaultInitPassManager" [project.entry-points."qiskit.transpiler.translation"] +default = "qiskit.transpiler.preset_passmanagers.builtin_plugins:DefaultTranslationPassManager" synthesis = "qiskit.transpiler.preset_passmanagers.builtin_plugins:UnitarySynthesisPassManager" translator = "qiskit.transpiler.preset_passmanagers.builtin_plugins:BasisTranslatorPassManager" diff --git a/qiskit/compiler/transpiler.py b/qiskit/compiler/transpiler.py index 5e361503091f..4d705481ce71 100644 --- a/qiskit/compiler/transpiler.py +++ b/qiskit/compiler/transpiler.py @@ -191,10 +191,10 @@ def transpile( # pylint: disable=too-many-return-statements This can also be the external plugin name to use for the ``routing`` stage. You can see a list of installed plugins by using :func:`~.list_stage_plugins` with ``"routing"`` for the ``stage_name`` argument. - translation_method: Name of translation pass (``"translator"`` or ``"synthesis"``) - This can also be the external plugin name to use for the ``translation`` stage. - You can see a list of installed plugins by using :func:`~.list_stage_plugins` with - ``"translation"`` for the ``stage_name`` argument. + translation_method: Name of translation pass (``"default"``, ``"translator"`` or + ``"synthesis"``). This can also be the external plugin name to use for the + ``translation`` stage. You can see a list of installed plugins by using + :func:`~.list_stage_plugins` with ``"translation"`` for the ``stage_name`` argument. scheduling_method: Name of scheduling pass. * ``'as_soon_as_possible'``: Schedule instructions greedily, as early as possible on a qubit resource. (alias: ``'asap'``) diff --git a/qiskit/transpiler/__init__.py b/qiskit/transpiler/__init__.py index 696df5151cc3..136dfb70d766 100644 --- a/qiskit/transpiler/__init__.py +++ b/qiskit/transpiler/__init__.py @@ -643,6 +643,9 @@ * - Method - Summary + * - :ref:`default ` + - Use a Qiskit-chosen default translation method. + * - :ref:`translator ` - Symbolic translation of gates to the target basis using known equivalences. @@ -650,6 +653,15 @@ - Collect each run of one- and two-qubit gates into a matrix representation, and resynthesize from there. +.. _transpiler-preset-stage-translation-default: + +Built-in ``default`` plugin +........................... + +Use a Qiskit-chosen default method for translation. As of Qiskit 2.0, this is the same as +:ref:`transpiler-preset-stage-translation-translator`, but the chosen algorithm might change during +the 2.x series, either for all targets, or only for certain classes of target. + .. _transpiler-preset-stage-translation-synthesis: Built-in ``synthesis`` plugin diff --git a/qiskit/transpiler/preset_passmanagers/builtin_plugins.py b/qiskit/transpiler/preset_passmanagers/builtin_plugins.py index 1e5ca4519864..4742de6fda49 100644 --- a/qiskit/transpiler/preset_passmanagers/builtin_plugins.py +++ b/qiskit/transpiler/preset_passmanagers/builtin_plugins.py @@ -197,6 +197,17 @@ def pass_manager(self, pass_manager_config, optimization_level=None) -> PassMana return init +class DefaultTranslationPassManager(PassManagerStagePlugin): + """Plugin class for the default-method translation stage.""" + + def pass_manager(self, pass_manager_config, optimization_level=None) -> PassManager: + # For now, this is just a wrapper around the `BasisTranslator`. It might expand in the + # future if we want to change the default method to do more context-aware switching, or to + # start transitioning the default method without breaking the semantics of the default + # string referring to the `BasisTranslator`. + return BasisTranslatorPassManager().pass_manager(pass_manager_config, optimization_level) + + class BasisTranslatorPassManager(PassManagerStagePlugin): """Plugin class for translation stage with :class:`~.BasisTranslator`""" @@ -535,7 +546,7 @@ class OptimizationPassManager(PassManagerStagePlugin): def pass_manager(self, pass_manager_config, optimization_level=None) -> PassManager: """Build pass manager for optimization stage.""" # Obtain the translation method required for this pass to work - translation_method = pass_manager_config.translation_method or "translator" + translation_method = pass_manager_config.translation_method or "default" optimization = PassManager() if optimization_level != 0: plugin_manager = PassManagerStagePluginManager() diff --git a/qiskit/transpiler/preset_passmanagers/common.py b/qiskit/transpiler/preset_passmanagers/common.py index 431089f657dd..4f360cd1998f 100644 --- a/qiskit/transpiler/preset_passmanagers/common.py +++ b/qiskit/transpiler/preset_passmanagers/common.py @@ -60,15 +60,17 @@ # Any method neither known good nor known bad (i.e. not a Terra-internal pass) is passed through # without error, since it is being supplied by a plugin and we don't have any knowledge of these. _CONTROL_FLOW_STATES = { - "layout_method": _ControlFlowState(working={"trivial", "dense", "sabre"}, not_working=set()), + "layout_method": _ControlFlowState( + working={"default", "trivial", "dense", "sabre"}, not_working=set() + ), "routing_method": _ControlFlowState( working={"none", "stochastic", "sabre"}, not_working={"lookahead", "basic"} ), "translation_method": _ControlFlowState( - working={"translator", "synthesis"}, + working={"default", "translator", "synthesis"}, not_working=set(), ), - "optimization_method": _ControlFlowState(working=set(), not_working=set()), + "optimization_method": _ControlFlowState(working={"default"}, not_working=set()), "scheduling_method": _ControlFlowState(working=set(), not_working={"alap", "asap"}), } diff --git a/qiskit/transpiler/preset_passmanagers/level0.py b/qiskit/transpiler/preset_passmanagers/level0.py index 58381b3db7a8..865cc13f2407 100644 --- a/qiskit/transpiler/preset_passmanagers/level0.py +++ b/qiskit/transpiler/preset_passmanagers/level0.py @@ -49,7 +49,7 @@ def level_0_pass_manager(pass_manager_config: PassManagerConfig) -> StagedPassMa init_method = pass_manager_config.init_method or "default" layout_method = pass_manager_config.layout_method or "default" routing_method = pass_manager_config.routing_method or "sabre" - translation_method = pass_manager_config.translation_method or "translator" + translation_method = pass_manager_config.translation_method or "default" optimization_method = pass_manager_config.optimization_method or "default" scheduling_method = pass_manager_config.scheduling_method or "default" target = pass_manager_config.target diff --git a/qiskit/transpiler/preset_passmanagers/level1.py b/qiskit/transpiler/preset_passmanagers/level1.py index 0a0b1c2a8e43..e665b9f31186 100644 --- a/qiskit/transpiler/preset_passmanagers/level1.py +++ b/qiskit/transpiler/preset_passmanagers/level1.py @@ -53,7 +53,7 @@ def level_1_pass_manager(pass_manager_config: PassManagerConfig) -> StagedPassMa # based on whether the input circuit has control flow. layout_method = pass_manager_config.layout_method or "default" routing_method = pass_manager_config.routing_method or "sabre" - translation_method = pass_manager_config.translation_method or "translator" + translation_method = pass_manager_config.translation_method or "default" optimization_method = pass_manager_config.optimization_method or "default" scheduling_method = pass_manager_config.scheduling_method or "default" target = pass_manager_config.target diff --git a/qiskit/transpiler/preset_passmanagers/level2.py b/qiskit/transpiler/preset_passmanagers/level2.py index b22743883fbe..4a438fe32037 100644 --- a/qiskit/transpiler/preset_passmanagers/level2.py +++ b/qiskit/transpiler/preset_passmanagers/level2.py @@ -54,7 +54,7 @@ def level_2_pass_manager(pass_manager_config: PassManagerConfig) -> StagedPassMa init_method = pass_manager_config.init_method or "default" layout_method = pass_manager_config.layout_method or "default" routing_method = pass_manager_config.routing_method or "sabre" - translation_method = pass_manager_config.translation_method or "translator" + translation_method = pass_manager_config.translation_method or "default" optimization_method = pass_manager_config.optimization_method or "default" scheduling_method = pass_manager_config.scheduling_method or "default" target = pass_manager_config.target diff --git a/qiskit/transpiler/preset_passmanagers/level3.py b/qiskit/transpiler/preset_passmanagers/level3.py index c1393a0b7c6e..a67737ed24f9 100644 --- a/qiskit/transpiler/preset_passmanagers/level3.py +++ b/qiskit/transpiler/preset_passmanagers/level3.py @@ -54,7 +54,7 @@ def level_3_pass_manager(pass_manager_config: PassManagerConfig) -> StagedPassMa init_method = pass_manager_config.init_method or "default" layout_method = pass_manager_config.layout_method or "default" routing_method = pass_manager_config.routing_method or "sabre" - translation_method = pass_manager_config.translation_method or "translator" + translation_method = pass_manager_config.translation_method or "default" 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" diff --git a/qiskit/transpiler/preset_passmanagers/plugin.py b/qiskit/transpiler/preset_passmanagers/plugin.py index 3ac1c4545fd5..26732c2343c6 100644 --- a/qiskit/transpiler/preset_passmanagers/plugin.py +++ b/qiskit/transpiler/preset_passmanagers/plugin.py @@ -71,7 +71,7 @@ * - :ref:`translation ` - ``qiskit.transpiler.translation`` - - ``translator``, ``synthesis`` + - ``default``, ``translator``, ``synthesis`` - Rewrite all gates outside the target ISA to use only gates within the ISA. * - :ref:`optimization ` diff --git a/releasenotes/notes/default-translation-stage-9d0335e354751af0.yaml b/releasenotes/notes/default-translation-stage-9d0335e354751af0.yaml new file mode 100644 index 000000000000..bc5d6202a249 --- /dev/null +++ b/releasenotes/notes/default-translation-stage-9d0335e354751af0.yaml @@ -0,0 +1,18 @@ +--- +features_transpiler: + - | + A new :ref:`translation plugin stage ` is added, called + ``"default"``. In Qiskit 2.0, this is simply an alias for the previous default ``"translator"``. + The underlying default algorithm may change over the course of the Qiskit 2.x series for some or + all targets, but you can always set ``translation_method=="translator"`` explicitly to maintain + the current behavior. +upgrade_transpiler: + - | + The :ref:`translation plugin stage ` name ``default`` is + now reserved for the Qiskit built-in plugin of the same name. + - | + The default :ref:`translation plugin stage ` is now + ``"default"``. In Qiskit 2.0, this is simply an alias for the previous default ``"translator"``. + The underlying default algorithm may change over the course of the Qiskit 2.x series for some or + all targets, but you can always set ``translation_method=="translator"`` explicitly to maintain + the current behavior.