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 BackendV1 and qiskit.providers.models (backport #12629) #12864

Merged
merged 3 commits into from
Jul 31, 2024
Merged
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
2 changes: 1 addition & 1 deletion qiskit/circuit/add_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def control(
) -> ControlledGate:
"""Return controlled version of gate using controlled rotations. This function
first checks the name of the operation to see if it knows of a method from which
to generate a controlled version. Currently these are `x`, `rx`, `ry`, and `rz`.
to generate a controlled version. Currently, these are ``x``, ``rx``, ``ry``, and ``rz``.
If a method is not directly known, it calls the unroller to convert to `u1`, `u3`,
and `cx` gates.

Expand Down
26 changes: 22 additions & 4 deletions qiskit/compiler/transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,28 @@ def callback_func(**kwargs):
optimization_level = config.get("transpile_optimization_level", 1)

if backend is not None and getattr(backend, "version", 0) <= 1:
# This is a temporary conversion step to allow for a smoother transition
# to a fully target-based transpiler pipeline while maintaining the behavior
# of `transpile` with BackendV1 inputs.
backend = BackendV2Converter(backend)
warnings.warn(
"The `transpile` function will stop supporting inputs of "
f"type `BackendV1` ( {backend} ) in the `backend` parameter in a future "
"release no earlier than 2.0. `BackendV1` is deprecated and implementations "
"should move to `BackendV2`.",
category=DeprecationWarning,
stacklevel=2,
)
with warnings.catch_warnings():
# This is a temporary conversion step to allow for a smoother transition
# to a fully target-based transpiler pipeline while maintaining the behavior
# of `transpile` with BackendV1 inputs.
# TODO BackendV1 is deprecated and this path can be
# removed once it gets removed:
# https://github.com/Qiskit/qiskit/pull/12850
warnings.filterwarnings(
"ignore",
category=DeprecationWarning,
message=r".+qiskit\.providers\.backend_compat\.BackendV2Converter.+",
module="qiskit",
)
backend = BackendV2Converter(backend)

if (
scheduling_method is not None
Expand Down
11 changes: 10 additions & 1 deletion qiskit/providers/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from qiskit.providers.provider import Provider
from qiskit.providers.models.backendstatus import BackendStatus
from qiskit.circuit.gate import Instruction
from qiskit.utils import deprecate_func


class Backend:
Expand All @@ -43,7 +44,7 @@ class BackendV1(Backend, ABC):
This abstract class is to be used for Backend objects.
There are several classes of information contained in a Backend.
The first are the attributes of the class itself. These should be used to
defined the immutable characteristics of the backend. The ``options``
define the immutable characteristics of the backend. The ``options``
attribute of the backend is used to contain the dynamic user configurable
options of the backend. It should be used more for runtime options
that configure how the backend is used. For example, something like a
Expand Down Expand Up @@ -71,6 +72,14 @@ class BackendV1(Backend, ABC):

version = 1

@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="If the backend only encapsulates a hardware description, "
"consider constructing a Target directly. If it is part of a provider "
"that gives access to execution, consider using Primitives instead. "
"Alternatively, consider moving to BackendV2 (see https://qisk.it/backendV1-to-V2).",
)
def __init__(self, configuration, provider=None, **fields):
"""Initialize a backend class

Expand Down
11 changes: 7 additions & 4 deletions qiskit/providers/backend_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,13 @@ def __init__(
self._properties = None
self._defaults = None

if hasattr(self._backend, "properties"):
self._properties = self._backend.properties()
if hasattr(self._backend, "defaults"):
self._defaults = self._backend.defaults()
with warnings.catch_warnings():
# The class QobjExperimentHeader is deprecated
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
if hasattr(self._backend, "properties"):
self._properties = self._backend.properties()
if hasattr(self._backend, "defaults"):
self._defaults = self._backend.defaults()

self._target = None
self._name_mapping = name_mapping
Expand Down
44 changes: 26 additions & 18 deletions qiskit/providers/basic_provider/basic_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,24 +236,32 @@ def configuration(self) -> BackendConfiguration:
for name in self.target.operation_names
]

self._configuration = BackendConfiguration(
backend_name=self.name,
backend_version=self.backend_version,
n_qubits=self.num_qubits,
basis_gates=self.target.operation_names,
gates=gates,
local=True,
simulator=True,
conditional=True,
open_pulse=False,
memory=True,
# This max_shots is used by the assembler, setting it to 0
# to maintain the behavior from the previous implementation.
# Not related to the actual shots set in the backend options
max_shots=0,
coupling_map=None,
description="A python simulator for quantum experiments",
)
with warnings.catch_warnings():
# TODO Provider models are deprecated
# https://github.com/Qiskit/qiskit/issues/12843
warnings.filterwarnings(
"ignore",
category=DeprecationWarning,
message=r".+qiskit\.providers\.models\.backendconfiguration\..+",
)
self._configuration = BackendConfiguration(
backend_name=self.name,
backend_version=self.backend_version,
n_qubits=self.num_qubits,
basis_gates=self.target.operation_names,
gates=gates,
local=True,
simulator=True,
conditional=True,
open_pulse=False,
memory=True,
# This max_shots is used by the assembler, setting it to 0
# to maintain the behavior from the previous implementation.
# Not related to the actual shots set in the backend options
max_shots=0,
coupling_map=None,
description="A python simulator for quantum experiments",
)
return self._configuration

@classmethod
Expand Down
6 changes: 5 additions & 1 deletion qiskit/providers/fake_provider/fake_qasm_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import json
import os
import warnings

from qiskit.exceptions import QiskitError
from qiskit.providers.models import BackendProperties, QasmBackendConfiguration
Expand Down Expand Up @@ -61,7 +62,10 @@ def _set_props_from_json(self):
raise QiskitError("No properties file has been defined")
props = self._load_json(self.props_filename)
decode_backend_properties(props)
self._properties = BackendProperties.from_dict(props)
with warnings.catch_warnings():
# This raises the BackendProperties deprecation warning internally
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
self._properties = BackendProperties.from_dict(props)

def _load_json(self, filename):
with open(os.path.join(self.dirname, filename)) as f_json:
Expand Down
11 changes: 11 additions & 0 deletions qiskit/providers/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
GateProperties
Nduv
"""
import warnings

from .backendconfiguration import (
BackendConfiguration,
Expand All @@ -50,3 +51,13 @@
from .backendstatus import BackendStatus
from .jobstatus import JobStatus
from .pulsedefaults import PulseDefaults, Command


warnings.warn(
"qiskit.providers.models is deprecated since Qiskit 1.2 and will be removed in Qiskit 2.0."
"With the removal of Qobj, there is no need for these schema-conformant objects. If you still need"
"to use them, it could be because you are using a BackendV1, which is also deprecated in favor"
"of BackendV2",
DeprecationWarning,
2,
)
50 changes: 48 additions & 2 deletions qiskit/providers/models/backendconfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
DriveChannel,
MeasureChannel,
)
from qiskit.utils import deprecate_func


class GateConfig:
Expand All @@ -38,6 +39,15 @@ class GateConfig:
and CX.
"""

@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The models in ``qiskit.providers.models`` are part "
"of the deprecated `BackendV1` workflow and no longer necessary for `BackendV2`. If a user "
"workflow requires these representations it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
stacklevel=3,
)
def __init__(
self,
name,
Expand Down Expand Up @@ -141,6 +151,14 @@ class UchannelLO:
scale: Scale factor for qubit frequency.
"""

@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The models in ``qiskit.providers.models`` are part "
"of the deprecated `BackendV1` workflow and no longer necessary for `BackendV2`. If a user "
"workflow requires these representations it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
)
def __init__(self, q, scale):
"""Initialize a UchannelLOSchema object

Expand Down Expand Up @@ -211,6 +229,15 @@ class QasmBackendConfiguration:

_data = {}

@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The models in ``qiskit.providers.models`` are part "
"of the deprecated `BackendV1` workflow and no longer necessary for `BackendV2`. If a user "
"workflow requires these representations it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
stacklevel=3,
)
def __init__(
self,
backend_name,
Expand Down Expand Up @@ -491,16 +518,35 @@ def __contains__(self, item):


class BackendConfiguration(QasmBackendConfiguration):
"""Backwards compat shim representing an abstract backend configuration."""
"""Backwards compatibility shim representing an abstract backend configuration."""

pass
@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The models in ``qiskit.providers.models`` are part "
"of the deprecated `BackendV1` workflow and no longer necessary for `BackendV2`. If a user "
"workflow requires these representations it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
stacklevel=3,
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)


class PulseBackendConfiguration(QasmBackendConfiguration):
"""Static configuration state for an OpenPulse enabled backend. This contains information
about the set up of the device which can be useful for building Pulse programs.
"""

@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The models in ``qiskit.providers.models`` are part "
"of the deprecated `BackendV1` workflow and no longer necessary for `BackendV2`. If a user "
"workflow requires these representations it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
stacklevel=3,
)
def __init__(
self,
backend_name: str,
Expand Down
11 changes: 11 additions & 0 deletions qiskit/providers/models/backendproperties.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import dateutil.parser

from qiskit.providers.exceptions import BackendPropertyError
from qiskit.utils import deprecate_func
from qiskit.utils.units import apply_prefix

PropertyT = Tuple[Any, datetime.datetime]
Expand Down Expand Up @@ -172,6 +173,15 @@ class BackendProperties:

_data = {}

@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The models in ``qiskit.providers.models`` and related objects are part "
"of the deprecated `BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
"workflow requires these representations it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
stacklevel=3,
)
def __init__(
self, backend_name, backend_version, last_update_date, qubits, gates, general, **kwargs
):
Expand Down Expand Up @@ -248,6 +258,7 @@ def from_dict(cls, data):
qubits.append(nduvs)
gates = [GateProperties.from_dict(x) for x in in_data.pop("gates")]
general = [Nduv.from_dict(x) for x in in_data.pop("general")]

return cls(
backend_name, backend_version, last_update_date, qubits, gates, general, **in_data
)
Expand Down
4 changes: 2 additions & 2 deletions qiskit/transpiler/preset_passmanagers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@
.. autofunction:: generate_scheduling
.. currentmodule:: qiskit.transpiler.preset_passmanagers
"""

from .generate_preset_pass_manager import generate_preset_pass_manager
from .level0 import level_0_pass_manager
from .level1 import level_1_pass_manager
from .level2 import level_2_pass_manager
from .level3 import level_3_pass_manager
from .generate_preset_pass_manager import generate_preset_pass_manager


__all__ = [
"level_0_pass_manager",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""

import copy
import warnings

from qiskit.circuit.controlflow import CONTROL_FLOW_OP_NAMES
from qiskit.circuit.library.standard_gates import get_standard_gate_name_mapping
Expand Down Expand Up @@ -242,6 +243,14 @@ def generate_preset_pass_manager(
# This is a temporary conversion step to allow for a smoother transition
# to a fully target-based transpiler pipeline while maintaining the behavior
# of `transpile` with BackendV1 inputs.
warnings.warn(
"The `generate_preset_pass_manager` function will stop supporting inputs of "
f"type `BackendV1` ( {backend} ) in the `backend` parameter in a future "
"release no earlier than 2.0. `BackendV1` is deprecated and implementations "
"should move to `BackendV2`.",
category=DeprecationWarning,
stacklevel=2,
)
backend = BackendV2Converter(backend)

# Check if a custom inst_map was specified before overwriting inst_map
Expand Down Expand Up @@ -319,7 +328,17 @@ def generate_preset_pass_manager(
if timing_constraints is None:
timing_constraints = target.timing_constraints()
if backend_properties is None:
backend_properties = target_to_backend_properties(target)
with warnings.catch_warnings():
# TODO this approach (target-to-properties) is going to be removed soon (1.3) in favor
# of backend-to-target approach
# https://github.com/Qiskit/qiskit/pull/12850
warnings.filterwarnings(
"ignore",
category=DeprecationWarning,
message=r".+qiskit\.transpiler\.target\.target_to_backend_properties.+",
module="qiskit",
)
backend_properties = target_to_backend_properties(target)

# Parse non-target dependent pm options
initial_layout = _parse_initial_layout(initial_layout)
Expand Down
Loading
Loading