Skip to content

Commit cc15bf4

Browse files
1ucian0mergify[bot]
authored andcommitted
Deprecate BackendV1 and qiskit.providers.models (#12629)
* 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]> (cherry picked from commit a6ec8b9) # Conflicts: # qiskit/transpiler/target.py # test/python/pulse/test_builder.py
1 parent e28aec4 commit cc15bf4

35 files changed

+1982
-324
lines changed

qiskit/circuit/add_control.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def control(
7373
) -> ControlledGate:
7474
"""Return controlled version of gate using controlled rotations. This function
7575
first checks the name of the operation to see if it knows of a method from which
76-
to generate a controlled version. Currently these are `x`, `rx`, `ry`, and `rz`.
76+
to generate a controlled version. Currently, these are ``x``, ``rx``, ``ry``, and ``rz``.
7777
If a method is not directly known, it calls the unroller to convert to `u1`, `u3`,
7878
and `cx` gates.
7979

qiskit/compiler/transpiler.py

+22-4
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,28 @@ def callback_func(**kwargs):
315315
optimization_level = config.get("transpile_optimization_level", 1)
316316

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

323341
if (
324342
scheduling_method is not None

qiskit/providers/backend.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from qiskit.providers.provider import Provider
2424
from qiskit.providers.models.backendstatus import BackendStatus
2525
from qiskit.circuit.gate import Instruction
26+
from qiskit.utils import deprecate_func
2627

2728

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

7273
version = 1
7374

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

qiskit/providers/backend_compat.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,13 @@ def __init__(
390390
self._properties = None
391391
self._defaults = None
392392

393-
if hasattr(self._backend, "properties"):
394-
self._properties = self._backend.properties()
395-
if hasattr(self._backend, "defaults"):
396-
self._defaults = self._backend.defaults()
393+
with warnings.catch_warnings():
394+
# The class QobjExperimentHeader is deprecated
395+
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
396+
if hasattr(self._backend, "properties"):
397+
self._properties = self._backend.properties()
398+
if hasattr(self._backend, "defaults"):
399+
self._defaults = self._backend.defaults()
397400

398401
self._target = None
399402
self._name_mapping = name_mapping

qiskit/providers/basic_provider/basic_simulator.py

+26-18
Original file line numberDiff line numberDiff line change
@@ -236,24 +236,32 @@ def configuration(self) -> BackendConfiguration:
236236
for name in self.target.operation_names
237237
]
238238

239-
self._configuration = BackendConfiguration(
240-
backend_name=self.name,
241-
backend_version=self.backend_version,
242-
n_qubits=self.num_qubits,
243-
basis_gates=self.target.operation_names,
244-
gates=gates,
245-
local=True,
246-
simulator=True,
247-
conditional=True,
248-
open_pulse=False,
249-
memory=True,
250-
# This max_shots is used by the assembler, setting it to 0
251-
# to maintain the behavior from the previous implementation.
252-
# Not related to the actual shots set in the backend options
253-
max_shots=0,
254-
coupling_map=None,
255-
description="A python simulator for quantum experiments",
256-
)
239+
with warnings.catch_warnings():
240+
# TODO Provider models are deprecated
241+
# https://github.com/Qiskit/qiskit/issues/12843
242+
warnings.filterwarnings(
243+
"ignore",
244+
category=DeprecationWarning,
245+
message=r".+qiskit\.providers\.models\.backendconfiguration\..+",
246+
)
247+
self._configuration = BackendConfiguration(
248+
backend_name=self.name,
249+
backend_version=self.backend_version,
250+
n_qubits=self.num_qubits,
251+
basis_gates=self.target.operation_names,
252+
gates=gates,
253+
local=True,
254+
simulator=True,
255+
conditional=True,
256+
open_pulse=False,
257+
memory=True,
258+
# This max_shots is used by the assembler, setting it to 0
259+
# to maintain the behavior from the previous implementation.
260+
# Not related to the actual shots set in the backend options
261+
max_shots=0,
262+
coupling_map=None,
263+
description="A python simulator for quantum experiments",
264+
)
257265
return self._configuration
258266

259267
@classmethod

qiskit/providers/fake_provider/fake_qasm_backend.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import json
1818
import os
19+
import warnings
1920

2021
from qiskit.exceptions import QiskitError
2122
from qiskit.providers.models import BackendProperties, QasmBackendConfiguration
@@ -61,7 +62,10 @@ def _set_props_from_json(self):
6162
raise QiskitError("No properties file has been defined")
6263
props = self._load_json(self.props_filename)
6364
decode_backend_properties(props)
64-
self._properties = BackendProperties.from_dict(props)
65+
with warnings.catch_warnings():
66+
# This raises the BackendProperties deprecation warning internally
67+
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
68+
self._properties = BackendProperties.from_dict(props)
6569

6670
def _load_json(self, filename):
6771
with open(os.path.join(self.dirname, filename)) as f_json:

qiskit/providers/models/__init__.py

+11
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
GateProperties
3939
Nduv
4040
"""
41+
import warnings
4142

4243
from .backendconfiguration import (
4344
BackendConfiguration,
@@ -50,3 +51,13 @@
5051
from .backendstatus import BackendStatus
5152
from .jobstatus import JobStatus
5253
from .pulsedefaults import PulseDefaults, Command
54+
55+
56+
warnings.warn(
57+
"qiskit.providers.models is deprecated since Qiskit 1.2 and will be removed in Qiskit 2.0."
58+
"With the removal of Qobj, there is no need for these schema-conformant objects. If you still need"
59+
"to use them, it could be because you are using a BackendV1, which is also deprecated in favor"
60+
"of BackendV2",
61+
DeprecationWarning,
62+
2,
63+
)

qiskit/providers/models/backendconfiguration.py

+48-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
DriveChannel,
2727
MeasureChannel,
2828
)
29+
from qiskit.utils import deprecate_func
2930

3031

3132
class GateConfig:
@@ -38,6 +39,15 @@ class GateConfig:
3839
and CX.
3940
"""
4041

42+
@deprecate_func(
43+
since="1.2",
44+
removal_timeline="in the 2.0 release",
45+
additional_msg="The models in ``qiskit.providers.models`` are part "
46+
"of the deprecated `BackendV1` workflow and no longer necessary for `BackendV2`. If a user "
47+
"workflow requires these representations it likely relies on deprecated functionality and "
48+
"should be updated to use `BackendV2`.",
49+
stacklevel=3,
50+
)
4151
def __init__(
4252
self,
4353
name,
@@ -141,6 +151,14 @@ class UchannelLO:
141151
scale: Scale factor for qubit frequency.
142152
"""
143153

154+
@deprecate_func(
155+
since="1.2",
156+
removal_timeline="in the 2.0 release",
157+
additional_msg="The models in ``qiskit.providers.models`` are part "
158+
"of the deprecated `BackendV1` workflow and no longer necessary for `BackendV2`. If a user "
159+
"workflow requires these representations it likely relies on deprecated functionality and "
160+
"should be updated to use `BackendV2`.",
161+
)
144162
def __init__(self, q, scale):
145163
"""Initialize a UchannelLOSchema object
146164
@@ -211,6 +229,15 @@ class QasmBackendConfiguration:
211229

212230
_data = {}
213231

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

492519

493520
class BackendConfiguration(QasmBackendConfiguration):
494-
"""Backwards compat shim representing an abstract backend configuration."""
521+
"""Backwards compatibility shim representing an abstract backend configuration."""
495522

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

498535

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

541+
@deprecate_func(
542+
since="1.2",
543+
removal_timeline="in the 2.0 release",
544+
additional_msg="The models in ``qiskit.providers.models`` are part "
545+
"of the deprecated `BackendV1` workflow and no longer necessary for `BackendV2`. If a user "
546+
"workflow requires these representations it likely relies on deprecated functionality and "
547+
"should be updated to use `BackendV2`.",
548+
stacklevel=3,
549+
)
504550
def __init__(
505551
self,
506552
backend_name: str,

qiskit/providers/models/backendproperties.py

+11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import dateutil.parser
1919

2020
from qiskit.providers.exceptions import BackendPropertyError
21+
from qiskit.utils import deprecate_func
2122
from qiskit.utils.units import apply_prefix
2223

2324
PropertyT = Tuple[Any, datetime.datetime]
@@ -172,6 +173,15 @@ class BackendProperties:
172173

173174
_data = {}
174175

176+
@deprecate_func(
177+
since="1.2",
178+
removal_timeline="in the 2.0 release",
179+
additional_msg="The models in ``qiskit.providers.models`` and related objects are part "
180+
"of the deprecated `BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
181+
"workflow requires these representations it likely relies on deprecated functionality and "
182+
"should be updated to use `BackendV2`.",
183+
stacklevel=3,
184+
)
175185
def __init__(
176186
self, backend_name, backend_version, last_update_date, qubits, gates, general, **kwargs
177187
):
@@ -248,6 +258,7 @@ def from_dict(cls, data):
248258
qubits.append(nduvs)
249259
gates = [GateProperties.from_dict(x) for x in in_data.pop("gates")]
250260
general = [Nduv.from_dict(x) for x in in_data.pop("general")]
261+
251262
return cls(
252263
backend_name, backend_version, last_update_date, qubits, gates, general, **in_data
253264
)

qiskit/transpiler/preset_passmanagers/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@
5757
.. autofunction:: generate_scheduling
5858
.. currentmodule:: qiskit.transpiler.preset_passmanagers
5959
"""
60-
60+
from .generate_preset_pass_manager import generate_preset_pass_manager
6161
from .level0 import level_0_pass_manager
6262
from .level1 import level_1_pass_manager
6363
from .level2 import level_2_pass_manager
6464
from .level3 import level_3_pass_manager
65-
from .generate_preset_pass_manager import generate_preset_pass_manager
65+
6666

6767
__all__ = [
6868
"level_0_pass_manager",

qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""
1616

1717
import copy
18+
import warnings
1819

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

247256
# Check if a custom inst_map was specified before overwriting inst_map
@@ -319,7 +328,17 @@ def generate_preset_pass_manager(
319328
if timing_constraints is None:
320329
timing_constraints = target.timing_constraints()
321330
if backend_properties is None:
322-
backend_properties = target_to_backend_properties(target)
331+
with warnings.catch_warnings():
332+
# TODO this approach (target-to-properties) is going to be removed soon (1.3) in favor
333+
# of backend-to-target approach
334+
# https://github.com/Qiskit/qiskit/pull/12850
335+
warnings.filterwarnings(
336+
"ignore",
337+
category=DeprecationWarning,
338+
message=r".+qiskit\.transpiler\.target\.target_to_backend_properties.+",
339+
module="qiskit",
340+
)
341+
backend_properties = target_to_backend_properties(target)
323342

324343
# Parse non-target dependent pm options
325344
initial_layout = _parse_initial_layout(initial_layout)

0 commit comments

Comments
 (0)