Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate more utils and parameters that depend on qiskit.providers.models #12915

Draft
wants to merge 8 commits into
base: stable/1.4
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions qiskit/compiler/assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,22 @@ def _assemble(

# assemble either circuits or schedules
if all(isinstance(exp, QuantumCircuit) for exp in experiments):
run_config = _parse_circuit_args(
parameter_binds,
backend,
meas_level,
meas_return,
parametric_pulses,
**run_config_common_dict,
)
with warnings.catch_warnings():
# Internally calls deprecated BasicSimulator.configuration()`
warnings.filterwarnings(
"ignore",
category=DeprecationWarning,
message=r".+\.basic_provider\.basic_simulator\.BasicSimulator\.configuration.+",
module="qiskit",
)
run_config = _parse_circuit_args(
parameter_binds,
backend,
meas_level,
meas_return,
parametric_pulses,
**run_config_common_dict,
)

# If circuits are parameterized, bind parameters and remove from run_config
bound_experiments, run_config = _expand_parameters(
Expand Down
8 changes: 8 additions & 0 deletions qiskit/compiler/transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,20 @@
from qiskit.transpiler.passes.synthesis.high_level_synthesis import HLSConfig
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit.transpiler.target import Target
from qiskit.utils import deprecate_arg

logger = logging.getLogger(__name__)

_CircuitT = TypeVar("_CircuitT", bound=Union[QuantumCircuit, List[QuantumCircuit]])


@deprecate_arg(
"backend_properties",
since="1.3",
removal_timeline="in the 2.0 release",
additional_msg="Because `qiskit.providers.models.BackendProperties` is deprecated, it wont be"
"accepted anymore as a parameter.",
)
def transpile( # pylint: disable=too-many-return-statements
circuits: _CircuitT,
backend: Optional[Backend] = None,
Expand Down
33 changes: 25 additions & 8 deletions qiskit/providers/backend_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@
from qiskit.providers.models.pulsedefaults import PulseDefaults
from qiskit.providers.options import Options
from qiskit.providers.exceptions import BackendPropertyError
from qiskit.utils import deprecate_func

logger = logging.getLogger(__name__)


@deprecate_func(
since="1.3",
removal_timeline="in the 2.0 release",
additional_msg="With the deprecation of `qiskit.providers.models` this utility function "
"is not needed.",
)
def convert_to_target(
configuration: BackendConfiguration,
properties: BackendProperties = None,
Expand Down Expand Up @@ -300,6 +307,7 @@ def _get_value(prop_dict, prop_name):
def qubit_props_list_from_props(
properties: BackendProperties,
) -> List[QubitProperties]:
# TODO Remove this function with BackendProperties
"""Uses BackendProperties to construct
and return a list of QubitProperties.
"""
Expand Down Expand Up @@ -410,14 +418,23 @@ def target(self):
:rtype: Target
"""
if self._target is None:
self._target = convert_to_target(
configuration=self._config,
properties=self._properties,
defaults=self._defaults,
custom_name_mapping=self._name_mapping,
add_delay=self._add_delay,
filter_faulty=self._filter_faulty,
)
with warnings.catch_warnings():
# convert_to_target is deprecated along BackendV2Converter
# They both need to be removed at the same time
warnings.filterwarnings(
"ignore",
category=DeprecationWarning,
message=r".+qiskit\.providers\.backend_compat\.convert_to_target.+",
module="qiskit",
)
self._target = convert_to_target(
configuration=self._config,
properties=self._properties,
defaults=self._defaults,
custom_name_mapping=self._name_mapping,
add_delay=self._add_delay,
filter_faulty=self._filter_faulty,
)
return self._target

@property
Expand Down
7 changes: 7 additions & 0 deletions qiskit/providers/basic_provider/basic_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
)
from .basic_provider_tools import einsum_vecmul_index
from .exceptions import BasicProviderError
from ...utils import deprecate_func

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -212,6 +213,12 @@ def _build_basic_target(self) -> Target:
)
return target

@deprecate_func(
since="1.3",
removal_timeline="in the 2.0 release",
additional_msg="Because `qiskit.providers.models.BackendConfiguration` is deprecated, this "
"method wont be accepted anymore as a parameter.",
)
def configuration(self) -> BackendConfiguration:
"""Return the simulator backend configuration.

Expand Down
10 changes: 9 additions & 1 deletion qiskit/transpiler/passes/synthesis/unitary_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
)
from qiskit.transpiler.passes.synthesis import plugin
from qiskit.transpiler.target import Target

from qiskit.utils import deprecate_arg

GATE_NAME_MAP = {
"cx": CXGate._standard_gate,
Expand Down Expand Up @@ -314,6 +314,14 @@ def _preferred_direction(
class UnitarySynthesis(TransformationPass):
"""Synthesize gates according to their basis gates."""

@deprecate_arg(
"backend_props",
since="1.3",
removal_timeline="in the 2.0 release",
additional_msg="Because `qiskit.providers.models.BackendProperties` is deprecated, it wont be"
"accepted anymore as a parameter.",
predicate=lambda x: x is not None,
)
def __init__(
self,
basis_gates: list[str] = None,
Expand Down
15 changes: 12 additions & 3 deletions qiskit/transpiler/passmanager_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@

from qiskit.transpiler.coupling import CouplingMap
from qiskit.transpiler.instruction_durations import InstructionDurations
from qiskit.utils import deprecate_arg


class PassManagerConfig:
"""Pass Manager Configuration."""

@deprecate_arg(
"backend_properties",
since="1.3",
removal_timeline="in the 2.0 release",
additional_msg="Because `qiskit.providers.models.BackendProperties` is deprecated, it wont be"
"accepted anymore as a parameter.",
predicate=lambda x: x is not None,
)
def __init__(
self,
initial_layout=None,
Expand Down Expand Up @@ -113,11 +122,11 @@ def __init__(
def from_backend(cls, backend, _skip_target=False, **pass_manager_options):
"""Construct a configuration based on a backend and user input.

This method automatically gererates a PassManagerConfig object based on the backend's
This method automatically generates a PassManagerConfig object based on the backend's
features. User options can be used to overwrite the configuration.

Args:
backend (BackendV1): The backend that provides the configuration.
backend (BackendV1 or BackendV2): The backend that provides the configuration.
pass_manager_options: User-defined option-value pairs.

Returns:
Expand All @@ -126,12 +135,12 @@ def from_backend(cls, backend, _skip_target=False, **pass_manager_options):
Raises:
AttributeError: If the backend does not support a `configuration()` method.
"""
res = cls(**pass_manager_options)
backend_version = getattr(backend, "version", 0)
if not isinstance(backend_version, int):
backend_version = 0
if backend_version < 2:
config = backend.configuration()
res = cls(**pass_manager_options)
if res.basis_gates is None:
if backend_version < 2:
res.basis_gates = getattr(config, "basis_gates", None)
Expand Down
10 changes: 9 additions & 1 deletion qiskit/transpiler/preset_passmanagers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
from qiskit.transpiler.passes.layout.vf2_post_layout import VF2PostLayoutStopReason
from qiskit.transpiler.exceptions import TranspilerError
from qiskit.transpiler.layout import Layout

from qiskit.utils import deprecate_arg

_ControlFlowState = collections.namedtuple("_ControlFlowState", ("working", "not_working"))

Expand Down Expand Up @@ -408,6 +408,14 @@ def _direction_condition(property_set):
return pre_opt


@deprecate_arg(
"backend_props",
since="1.3",
removal_timeline="in the 2.0 release",
additional_msg="Because `qiskit.providers.models.BackendProperties` is deprecated, it wont be"
"accepted anymore as a parameter.",
predicate=lambda x: x is not None,
)
def generate_translation_passmanager(
target,
basis_gates=None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,12 @@ def generate_preset_pass_manager(
initial_layout = _parse_initial_layout(initial_layout)
approximation_degree = _parse_approximation_degree(approximation_degree)
seed_transpiler = _parse_seed_transpiler(seed_transpiler)

pm_options = {
"target": target,
"basis_gates": basis_gates,
"inst_map": inst_map,
"coupling_map": coupling_map,
"instruction_durations": instruction_durations,
"backend_properties": backend_properties,
"timing_constraints": timing_constraints,
"layout_method": layout_method,
"routing_method": routing_method,
Expand Down
9 changes: 8 additions & 1 deletion qiskit/transpiler/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
# full target
from qiskit.providers.backend import QubitProperties # pylint: disable=unused-import
from qiskit.providers.models.backendproperties import BackendProperties
from qiskit.utils import deprecate_func
from qiskit.utils import deprecate_func, deprecate_arg

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -927,6 +927,13 @@ def __setstate__(self, state: tuple):
super().__setstate__(state["base"])

@classmethod
@deprecate_arg(
"backend_properties",
since="1.3",
removal_timeline="in the 2.0 release",
additional_msg="Because `qiskit.providers.models.BackendProperties` is deprecated, it wont be"
"accepted anymore as a parameter.",
)
def from_configuration(
cls,
basis_gates: list[str],
Expand Down
20 changes: 20 additions & 0 deletions releasenotes/notes/followup_12906-dc23a5f580dfd0da.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
deprecations_providers:
- |
With the deprecation of the classes in ``qiskit.providers.models`` from 1.2 on, several methods taking or returning
instances of these classes need to be deprecated too. The following methods, functions and parameters
are deprecated:

- :meth:`.BasicSimulator.configuration`: returns deprecated :class:`.BackendConfiguration`.
- The function :func:`.convert_to_target` since it takes deprecated classes such as
:class:`.BackendConfiguration` and :class:`.BackendProperties`.
- The parameter ``backend_properties`` (of the deprecated type :class:`BackendProperties`) in function
:func:`.transpile`.
- The parameter ``backend_props`` (of the deprecated type :class:`BackendProperties`) in the
:class:`.UnitarySynthesis` constructor.
- The parameter ``backend_properties`` (of the deprecated type :class:`BackendProperties`) in the method
:meth:`.Target.from_configuration`.
- The parameter ``backend_props`` (of the deprecated type :class:`BackendProperties`) in the function
:func:`.generate_translation_passmanager`.
- The parameter ``backend_properties`` (of the deprecated type :class:`BackendProperties`) in the
:class:`.PassManagerConfig` constructor.
Loading