Skip to content

Commit

Permalink
Handle backend_props removal in PM plugins (#2134)
Browse files Browse the repository at this point in the history
* Remove backend_props from PM plugins

* Support qiskit 1 and 2
  • Loading branch information
kt474 authored Mar 6, 2025
1 parent 00b6c2f commit 3fbaa7e
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions qiskit_ibm_runtime/transpiler/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

"""Plugin for IBM provider backend transpiler stages."""

import re
from typing import Optional

from qiskit.transpiler.passmanager import PassManager
Expand All @@ -20,11 +21,17 @@
from qiskit.transpiler.preset_passmanagers import common
from qiskit.transpiler import passes

from qiskit.version import __version__ as _terra_version_string

from qiskit_ibm_runtime.transpiler.passes.basis import (
ConvertIdToDelay,
FoldRzzAngle,
)

_TERRA_VERSION = tuple(
int(x) for x in re.match(r"\d+\.\d+\.\d", _terra_version_string).group(0).split(".")[:3]
)


class IBMTranslationPlugin(PassManagerStagePlugin):
"""A translation stage plugin for targeting Qiskit circuits
Expand All @@ -37,16 +44,21 @@ def pass_manager(
) -> PassManager:
"""Build IBMTranslationPlugin PassManager."""

if _TERRA_VERSION[0] == 1:
legacy_options = {"backend_props": pass_manager_config.backend_properties}
else:
legacy_options = {}

translator_pm = common.generate_translation_passmanager(
target=pass_manager_config.target,
basis_gates=pass_manager_config.basis_gates,
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,
qubits_initially_zero=pass_manager_config.qubits_initially_zero,
**legacy_options,
)

plugin_passes = []
Expand All @@ -68,15 +80,20 @@ def pass_manager(
) -> PassManager:
"""Build IBMTranslationPlugin PassManager."""

if _TERRA_VERSION[0] == 1:
legacy_options = {"backend_props": pass_manager_config.backend_properties}
else:
legacy_options = {}

translator_pm = common.generate_translation_passmanager(
target=pass_manager_config.target,
basis_gates=pass_manager_config.basis_gates,
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,
**legacy_options,
)

instruction_durations = pass_manager_config.instruction_durations
Expand Down Expand Up @@ -111,15 +128,20 @@ def pass_manager(
) -> PassManager:
"""Build IBMTranslationPlugin PassManager."""

if _TERRA_VERSION[0] == 1:
legacy_options = {"backend_props": pass_manager_config.backend_properties}
else:
legacy_options = {}

translator_pm = common.generate_translation_passmanager(
target=pass_manager_config.target,
basis_gates=pass_manager_config.basis_gates,
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,
**legacy_options,
)

instruction_durations = pass_manager_config.instruction_durations
Expand Down

0 comments on commit 3fbaa7e

Please sign in to comment.