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

Address BackendV1 deprecation warning oversights #13868

Merged
merged 20 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
17 changes: 17 additions & 0 deletions qiskit/primitives/backend_estimator_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from __future__ import annotations

import math
import warnings
from collections import defaultdict
from collections.abc import Iterable
from dataclasses import dataclass
Expand Down Expand Up @@ -131,12 +132,28 @@ def __init__(
options: dict | None = None,
):
"""
.. deprecated:: 1.4
The method ``BackendEstimatorV2.__init__`` will stop supporting inputs of type
:class:`.BackendV1` in the `backend` parameter in a future release no
earlier than 2.0. :class:`.BackendV1` is deprecated and implementations should
move to :class:`.BackendV2`.

Args:
backend: The backend to run the primitive on.
options: The options to control the default precision (``default_precision``),
the operator grouping (``abelian_grouping``), and
the random seed for the simulator (``seed_simulator``).
"""

if not isinstance(backend, BackendV2):
warnings.warn(
"The method `BackendEstimatorV2.__init__` 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,
)
self._backend = backend
self._options = Options(**options) if options else Options()

Expand Down
15 changes: 15 additions & 0 deletions qiskit/primitives/backend_sampler_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,26 @@ def __init__(
options: dict | None = None,
):
"""
.. deprecated:: 1.4
The method ``BackendSamplerV2.__init__`` will stop supporting inputs of type
:class:`.BackendV1` in the `backend` parameter in a future release no
earlier than 2.0. :class:`.BackendV1` is deprecated and implementations should
move to :class:`.BackendV2`.

Args:
backend: The backend to run the primitive on.
options: The options to control the default shots (``default_shots``) and
the random seed for the simulator (``seed_simulator``).
"""
if not isinstance(backend, BackendV2):
warnings.warn(
"The method `BackendSamplerV2.__init__` 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,
)
self._backend = backend
self._options = Options(**options) if options else Options()

Expand Down
34 changes: 23 additions & 11 deletions qiskit/providers/backend_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@
logger = logging.getLogger(__name__)


@deprecate_func(
since="1.4",
removal_timeline="in the 2.0 release",
additional_msg="With the deprecation of `qiskit.providers.models` this utility function "
"is not needed.",
)
@deprecate_pulse_arg("defaults")
def convert_to_target(
configuration: BackendConfiguration,
Expand Down Expand Up @@ -66,9 +60,19 @@ def convert_to_target(
Returns:
A ``Target`` instance.
"""
return _convert_to_target(
configuration, properties, defaults, custom_name_mapping, add_delay, filter_faulty
)
# If a deprecated error is raised during the conversion, we should not return the
# deprecation warning to the user,as it is not actionable for them.
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore",
category=DeprecationWarning,
message=".*``qiskit.providers.exceptions.BackendPropertyError``",
module="qiskit",
)
target = _convert_to_target(
configuration, properties, defaults, custom_name_mapping, add_delay, filter_faulty
)
return target


def _convert_to_target(
Expand Down Expand Up @@ -323,7 +327,6 @@ 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 @@ -440,7 +443,16 @@ def target(self):
:rtype: Target
"""
if self._target is None:
# If a deprecated error is raised during the conversion,
# we should not return the deprecation warning to the user,
# as it is not actionable for them.
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore",
category=DeprecationWarning,
message=".*``qiskit.providers.exceptions.BackendPropertyError``",
module="qiskit",
)
# convert_to_target is deprecated along BackendV2Converter
# They both need to be removed at the same time
warnings.filterwarnings(
Expand All @@ -449,7 +461,7 @@ def target(self):
message=r".+qiskit\.providers\.backend_compat\.convert_to_target.+",
module="qiskit",
)
self._target = convert_to_target(
self._target = _convert_to_target(
configuration=self._config,
properties=self._properties,
defaults=self._defaults,
Expand Down
1 change: 0 additions & 1 deletion qiskit/providers/basic_provider/basic_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,6 @@ def _run_job(self, job_id: str, qobj: QasmQobj) -> Result:
"time_taken": (end - start),
"header": qobj.header.to_dict(),
}

return Result.from_dict(result)

@deprecate_func(
Expand Down
25 changes: 23 additions & 2 deletions qiskit/providers/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""Exceptions for errors raised while handling Backends and Jobs."""

from qiskit.exceptions import QiskitError
from qiskit.utils import deprecate_func


class JobError(QiskitError):
Expand All @@ -36,10 +37,30 @@ class QiskitBackendNotFoundError(QiskitError):
class BackendPropertyError(QiskitError):
"""Base class for errors raised while looking for a backend property."""

pass
@deprecate_func(
since="1.4",
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=2,
)
def __init__(self, *message):
super().__init__(*message)


class BackendConfigurationError(QiskitError):
"""Base class for errors raised by the BackendConfiguration."""

pass
@deprecate_func(
since="1.4",
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=2,
)
def __init__(self, *message):
super().__init__(*message)
20 changes: 19 additions & 1 deletion qiskit/providers/models/backendproperties.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ class Nduv:
value: value.
"""

@deprecate_func(
since="1.4",
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=2,
)
def __init__(self, date, name, unit, value):
"""Initialize a new name-date-unit-value object

Expand Down Expand Up @@ -97,6 +106,15 @@ class GateProperties:

_data = {}

@deprecate_func(
since="1.4",
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=2,
)
def __init__(self, qubits, gate, parameters, **kwargs):
"""Initialize a new :class:`GateProperties` object

Expand Down Expand Up @@ -180,7 +198,7 @@ class BackendProperties:
"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,
stacklevel=2,
)
def __init__(
self, backend_name, backend_version, last_update_date, qubits, gates, general, **kwargs
Expand Down
10 changes: 10 additions & 0 deletions qiskit/providers/models/backendstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@

import html
from qiskit.exceptions import QiskitError
from qiskit.utils import deprecate_func


class BackendStatus:
"""Class representing Backend Status."""

@deprecate_func(
since="1.4",
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=2,
)
def __init__(
self,
backend_name: str,
Expand Down
11 changes: 11 additions & 0 deletions qiskit/providers/models/jobstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

"""Class for job status."""

from qiskit.utils import deprecate_func


class JobStatus:
"""Model for JobStatus.
Expand All @@ -24,6 +26,15 @@ class JobStatus:

_data = {}

@deprecate_func(
since="1.4",
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=2,
)
def __init__(self, job_id, status, status_msg, **kwargs):
self._data = {}
self.job_id = job_id
Expand Down
Loading