Skip to content

Commit

Permalink
Deprecate BackendV1 and qiskit.providers.models (#12629)
Browse files Browse the repository at this point in the history
* initial commit

* reno

* Apply suggestions from code review

* deprecate qobj and assemble

* reno

* first attempt on Fake1QV2

* deprecate Fake1Q

* Fake1QV2 should not have two-qubit gates

Co-authored-by: Elena Peña Tapia <[email protected]>

* test.python.circuit.test_parameters.TestParameters

* test.python.providers.fake_provider.test_fake_backends.FakeBackendsTest

* test.python.providers.test_fake_backends.TestFakeBackends

* test.python.result.test_mitigators

* test.python.transpiler.test_preset_passmanagers

* test.python.transpiler.test_target

* test.python.transpiler.test_unitary_synthesis

* test.python.transpiler.test_vf2_layout

* test.python.transpiler.test_vf2_post_layout

* test/python/visualization/test_circuit_latex

* test.python.transpiler.test_sabre_layout

* test.python.transpiler.test_sabre_layout

* test.python.transpiler.test_pulse_gate_pass

* test.python.scheduler.test_basic_scheduler.TestBasicSchedule

* test.python.pulse.test_transforms

* test.python.pulse.test_schedule

* test.python.pulse.test_macros

* test.python.pulse.test_instruction_schedule_map

* test.python.pulse.test_block

* test.python.circuit.test_scheduled_circuit

* test.python.transpiler.test_calibrationbuilder

* test.python.providers.test_backendconfiguration

* test.python.compiler.test_transpiler

* test.python.transpiler.test_passmanager_run

* test.python.transpiler.test_passmanager_config.TestPassManagerConfig.test_from_backend_and_user

* test.python.transpiler.test_passmanager_config

* test.python.primitives.test_backend_estimator.TestBackendEstimator

* test.python.circuit.test_scheduled_circuit.TestScheduledCircuit.test_schedule_circuit_when_backend_tells_dt

* test.python.circuit.test_scheduled_circuit

* test.python.transpiler.test_vf2_layout

* shallow deprecation of assemble

* test.python.compiler.test_disassembler

* fakebackend pulse

* test.python.circuit.test_parameters

* PulseQobjInstruction  is used by GenericBackendV2

* test.python.scheduler.test_basic_scheduler

* test.python.result.test_result

* test.python.pulse.test_calibration_entries

* test.python.compiler.test_assembler

* test.python.transpiler.test_star_prerouting

* test.python.pulse.test_instruction_schedule_map

* test.python.providers.basic_provider.test_basic_simulator

* test.python.primitives.test_backend_sampler_v2

* test.python.compiler.test_disassembler

* test.python.compiler.test_compiler

* test.python.circuit.test_scheduled_circuit

* test.python.providers.test_fake_backends

* test.python.circuit.test_unitary

* test.python.transpiler.test_sabre_swap

* test.python.providers.fake_provider.test_fake_backends

* Aer using Provider ABC

* aer warnings

* reno

* another pass on reno

* test.python.pulse

* test.python.compiler.test_compiler

* add module to fiterwarning

* test.python.compiler.test_transpiler

* fixing obscure expcetion handleing for comparison

* test.python.transpiler.test_stochastic_swap test.python.transpiler.test_sabre_swap

* test.python.transpiler.test_echo_rzx_weyl_decomposition

* test.python.transpiler.test_instruction_durations

* test.python.providers.test_backendproperties

* test.python.qpy.test_circuit_load_from_qpy

* test.python.providers.test_pulse_defaults

* test.python.primitives.test_backend_sampler_v2

* test.python.primitives.test_backend_sampler

* test.python.compiler.test_scheduler

* test/python/compiler/test_scheduler.py

* test.python.compiler.test_disassembler

* test.python.compiler.test_assembler

* test.python.compiler.test_sequencer

* test.python.compiler.test_transpiler

* test.python.primitives.test_primitive

* better depreaction handleling from Aer

* test.python.primitives.test_backend_estimator_v2

* test.python.compiler.test_compiler

* ignore warnings, because the output is otherwise very verbose

* ignore to avoid fludding the CI log

* seeding all GenericBackendV2

* test.python.visualization.test_gate_map

* deprecation warnings: once

* default

* default

* BackendConfiguration

* PulseBackendConfiguration

* QasmBackendConfiguration

* QasmBackendConfiguration and adjust stacklevel

* UchannelLO

* GateConfig

* test.python.providers.test_fake_backends.TestFakeBackends

* test.python.providers.test_fake_backends

* test.python.compiler.test_transpiler

* remove catch

* Apply suggestions from code review

Co-authored-by: Elena Peña Tapia <[email protected]>

* remove catch

* new deprecate warning message

* lint qiskit/assembler/assemble_circuits.py

* concurrency warnings

* ignore aer warnings

* Update test/python/providers/fake_provider/test_fake_backends.py

Co-authored-by: Elena Peña Tapia <[email protected]>

* Update test/python/circuit/test_parameters.py

Co-authored-by: Elena Peña Tapia <[email protected]>

* Update qiskit/providers/models/pulsedefaults.py

Co-authored-by: Elena Peña Tapia <[email protected]>

* Update test/python/providers/fake_provider/test_fake_backends.py

Co-authored-by: Elena Peña Tapia <[email protected]>

* Update test/python/providers/fake_provider/test_generic_backend_v2.py

Co-authored-by: Elena Peña Tapia <[email protected]>

* lint

* #12649 (comment)

* #12649 (comment)

* Update test/python/transpiler/test_sabre_swap.py

Co-authored-by: Elena Peña Tapia <[email protected]>

* Update qiskit/providers/models/pulsedefaults.py

Co-authored-by: Elena Peña Tapia <[email protected]>

* ignore Treating CircuitInstruction...

* another unnecessary catch from aer

* another unnecessary catch from aer, again

* removing more unnecesary catches

* less lines

* seeding

* remove those comments

* test.python.compiler.test_transpiler.TestTranspile.test_scheduling_timing_constraints

* tokyo cmap

* test.python.circuit.test_scheduled_circuit.TestScheduledCircuit.test_schedule_circuit_when_backend_tells_dt

* comment in test_sequencer.py

* test.python.compiler.test_transpiler.TestPostTranspileIntegration.test_qasm3_output

* Update test/python/primitives/test_primitive.py

Co-authored-by: Elena Peña Tapia <[email protected]>

* test/python/providers/test_backendconfiguration.py:30

* test.python.primitives.test_backend_sampler

* restore the assertWarns, waiting for #12818

* use legacy_cmaps instead of explict coupling maps

* use more legacy_map

* KYOTO_CMAP

* more legacy_cmap

* #12832

* test.python.transpiler.test_vf2_post_layout

* comma

* #12660 (comment)

* do not deprecate BackendV2Converter yet

* test.python.providers.test_faulty_backend

* test.python.compiler.test_transpiler.TestTranspile

* cleaning up warnings

* no deprecation in test/python/compiler/test_transpiler.py

* Apply suggestions from code review

Co-authored-by: Elena Peña Tapia <[email protected]>

* reno lint

* adding models in reno

* black

* test.python.transpiler.test_preset_passmanagers

* seeding GenericBackendV2

* less Fake5QV1

* test.python.transpiler.test_sabre_layout

* test.python.transpiler.test_pulse_gate_pass

* test.python.pulse.test_builder

* test.python.primitives.test_backend_sampler_v2

* test.python.primitives.test_backend_sampler_v2

* test.python.primitives.test_backend_estimator_v2

* test.python.compiler.test_transpiler

* Apply suggestions from code review

Co-authored-by: Elena Peña Tapia <[email protected]>

* Apply suggestions from code review

Co-authored-by: Elena Peña Tapia <[email protected]>

* test.python.primitives.test_backend_estimator_v2.TestBackendEstimatorV2

* test.python.primitives.test_backend_estimator_v2

* Fix expected_regex in transpile tests

* Fix missing assertions in:

* test.python.circuit.test_scheduled_circuit

* test.python.compiler.test_sequencer

* test.python.circuit.test_parameters

* test.python.primitives.test_backend_sampler_v2

* test.python.primitives.test_backend_sampler

* Fix line-too-long lint complaints

---------

Co-authored-by: Elena Peña Tapia <[email protected]>
Co-authored-by: Elena Peña Tapia <[email protected]>
  • Loading branch information
3 people authored Jul 31, 2024
1 parent f9fcd1d commit a6ec8b9
Show file tree
Hide file tree
Showing 35 changed files with 1,967 additions and 329 deletions.
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", 2)

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 @@ -254,6 +255,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 @@ -331,7 +340,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

0 comments on commit a6ec8b9

Please sign in to comment.