Skip to content

Commit a260d95

Browse files
authored
Removal of deprecated Qiskit 2.0 related code (#2318)
* Removal of deprecated Qiskit 2.0 related code * Linting * Linting * Fix windows CR issue * Small fixes * Small fixes * Return `from_backend_properties` method * Fixes according to review and version update * update cibuildwheel version
1 parent 37718fa commit a260d95

File tree

11 files changed

+35
-127
lines changed

11 files changed

+35
-127
lines changed

.github/workflows/deploy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
with:
5353
platforms: all
5454
- name: Build wheels
55-
uses: pypa/cibuildwheel@v2.19.2
55+
uses: pypa/cibuildwheel@v2.23.0
5656
env:
5757
CIBW_BEFORE_ALL_LINUX: "sed -i -e 's/^mirrorlist/#mirrorlist/' -e 's/^#baseurl/baseurl/' -e 's/mirror.centos.org/vault.centos.org/' /etc/yum.repos.d/*.repo && yum install -y https://dl.fedoraproject.org/pub/archive/epel/7/aarch64/Packages/e/epel-release-7-12.noarch.rpm && yum install -y openblas-devel"
5858
CIBW_ARCHS_LINUX: aarch64

docs/tutorials/2_device_noise_simulation.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"source": [
4141
"## Device Backend Noise Model\n",
4242
"\n",
43-
"The *Qiskit Aer* device noise model automatically generates a simplified noise model for a real device. This model is generated using the calibration information reported in the `BackendProperties` of a device and takes into account\n",
43+
"The *Qiskit Aer* device noise model automatically generates a simplified noise model for a real device. This model is generated using the calibration information reported in the properties of a device and takes into account\n",
4444
"\n",
4545
"* The *gate_error* probability of each basis gate on each qubit.\n",
4646
"* The *gate_length* of each basis gate on each qubit.\n",

qiskit_aer/VERSION.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.16.2
1+
0.16.3

qiskit_aer/backends/aer_compiler.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from qiskit.circuit.classical.types import Bool, Uint
2828
from qiskit.circuit.library import Initialize
2929
from qiskit.providers.options import Options
30-
from qiskit.pulse import Schedule, ScheduleBlock
3130
from qiskit.circuit import Store
3231
from qiskit.circuit.controlflow import (
3332
WhileLoopOp,
@@ -85,7 +84,7 @@ def compile(self, circuits, optypes=None):
8584
compiled circuit optypes for each circuit if
8685
optypes kwarg is not None.
8786
"""
88-
if isinstance(circuits, (QuantumCircuit, Schedule, ScheduleBlock)):
87+
if isinstance(circuits, QuantumCircuit):
8988
circuits = [circuits]
9089
if optypes is None:
9190
compiled_optypes = len(circuits) * [None]

qiskit_aer/backends/aer_simulator.py

+2-24
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515

1616
import copy
1717
import logging
18-
from warnings import warn
19-
from qiskit.providers import convert_to_target
2018
from qiskit.providers.options import Options
21-
from qiskit.providers.backend import BackendV2, BackendV1
19+
from qiskit.providers.backend import BackendV2
2220

2321
from ..version import __version__
2422
from .aerbackend import AerBackend, AerError
@@ -34,7 +32,6 @@
3432

3533
# pylint: disable=import-error, no-name-in-module, abstract-method
3634
from .controller_wrappers import aer_controller_execute
37-
from .name_mapping import NAME_MAPPING
3835

3936
logger = logging.getLogger(__name__)
4037

@@ -858,28 +855,9 @@ def from_backend(cls, backend, **options):
858855
)
859856
properties = target_to_backend_properties(backend.target)
860857
target = backend.target
861-
elif isinstance(backend, BackendV1):
862-
# BackendV1 will be removed in Qiskit 2.0, so we will remove this soon
863-
warn(
864-
" from_backend using V1 based backend is deprecated as of Aer 0.15"
865-
" and will be removed no sooner than 3 months from that release"
866-
" date. Please use backends based on V2.",
867-
DeprecationWarning,
868-
stacklevel=2,
869-
)
870-
# Get configuration and properties from backend
871-
configuration = backend.configuration()
872-
properties = copy.copy(backend.properties())
873-
874-
# Customize configuration name
875-
name = configuration.backend_name
876-
configuration.backend_name = f"aer_simulator_from({name})"
877-
878-
target = convert_to_target(configuration, properties, None, NAME_MAPPING)
879858
else:
880859
raise TypeError(
881-
"The backend argument requires a BackendV2 or BackendV1 object, "
882-
f"not a {type(backend)} object"
860+
"The backend argument requires a BackendV2 object, " f"not a {type(backend)} object"
883861
)
884862
# Use automatic noise model if none is provided
885863
if "noise_model" not in options:

qiskit_aer/backends/aerbackend.py

+3-27
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323

2424
from qiskit.circuit import QuantumCircuit, ParameterExpression, Delay
2525
from qiskit.providers import BackendV2 as Backend
26-
from qiskit.providers.models.backendstatus import BackendStatus
27-
from qiskit.pulse import Schedule, ScheduleBlock
2826
from qiskit.result import Result
2927
from qiskit.transpiler import CouplingMap
3028
from qiskit.transpiler.target import Target
@@ -181,7 +179,7 @@ def run(self, circuits, parameter_binds=None, **run_options):
181179
Raises:
182180
ValueError: if run is not implemented
183181
"""
184-
if isinstance(circuits, (QuantumCircuit, Schedule, ScheduleBlock)):
182+
if isinstance(circuits, QuantumCircuit):
185183
circuits = [circuits]
186184

187185
return self._run_circuits(circuits, parameter_binds, **run_options)
@@ -442,26 +440,6 @@ def clear_options(self):
442440
self._options_configuration = {}
443441
self._options_properties = {}
444442

445-
def status(self):
446-
"""Return backend status.
447-
448-
Returns:
449-
BackendStatus: the status of the backend.
450-
"""
451-
warnings.warn(
452-
"AerBackend.status has been deprecated as of Aer 0.16.2, "
453-
"please access the non-trivial data (name and version) directly",
454-
DeprecationWarning,
455-
stacklevel=3,
456-
)
457-
return BackendStatus(
458-
backend_name=self.name,
459-
backend_version=self.configuration().backend_version,
460-
operational=True,
461-
pending_jobs=0,
462-
status_msg="",
463-
)
464-
465443
def _execute_circuits_job(
466444
self, circuits, parameter_binds, run_options, job_id="", format_result=True
467445
):
@@ -542,7 +520,7 @@ def _format_results(output):
542520

543521
def _compile(self, circuits, **run_options):
544522
"""Compile circuits and noise model"""
545-
if isinstance(circuits, (QuantumCircuit, Schedule, ScheduleBlock)):
523+
if isinstance(circuits, QuantumCircuit):
546524
circuits = [circuits]
547525
optypes = [circuit_optypes(circ) for circ in circuits]
548526

@@ -588,9 +566,7 @@ def _assemble_noise_model(self, circuits, optypes, **run_options):
588566

589567
# Check if circuits contain quantum error instructions
590568
for idx, circ in enumerate(run_circuits):
591-
if QuantumChannelInstruction in optypes[idx] and not isinstance(
592-
circ, (Schedule, ScheduleBlock)
593-
):
569+
if QuantumChannelInstruction in optypes[idx]:
594570
updated_circ = False
595571
new_data = []
596572
for datum in circ.data:

qiskit_aer/backends/qasm_simulator.py

+2-23
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
import copy
1717
import logging
1818
from warnings import warn
19-
from qiskit.providers import convert_to_target
2019
from qiskit.providers.options import Options
21-
from qiskit.providers.backend import BackendV2, BackendV1
20+
from qiskit.providers.backend import BackendV2
2221

2322
from ..version import __version__
2423
from ..aererror import AerError
@@ -35,7 +34,6 @@
3534

3635
# pylint: disable=import-error, no-name-in-module, abstract-method
3736
from .controller_wrappers import aer_controller_execute
38-
from .name_mapping import NAME_MAPPING
3937

4038
logger = logging.getLogger(__name__)
4139

@@ -552,28 +550,9 @@ def from_backend(cls, backend, **options):
552550
)
553551
properties = target_to_backend_properties(backend.target)
554552
target = backend.target
555-
elif isinstance(backend, BackendV1):
556-
# BackendV1 will be removed in Qiskit 2.0, so we will remove this soon
557-
warn(
558-
" from_backend using V1 based backend is deprecated as of Aer 0.15"
559-
" and will be removed no sooner than 3 months from that release"
560-
" date. Please use backends based on V2.",
561-
DeprecationWarning,
562-
stacklevel=2,
563-
)
564-
# Get configuration and properties from backend
565-
configuration = backend.configuration()
566-
properties = copy.copy(backend.properties())
567-
568-
# Customize configuration name
569-
name = configuration.backend_name
570-
configuration.backend_name = f"aer_simulator_from({name})"
571-
572-
target = convert_to_target(configuration, properties, None, NAME_MAPPING)
573553
else:
574554
raise TypeError(
575-
"The backend argument requires a BackendV2 or BackendV1 object, "
576-
f"not a {type(backend)} object"
555+
"The backend argument requires a BackendV2 object, " f"not a {type(backend)} object"
577556
)
578557
# Use automatic noise model if none is provided
579558
if "noise_model" not in options:

qiskit_aer/noise/device/parameters.py

+7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
"""
1414
Functions to extract device error parameters from backend properties.
15+
16+
We assume the structure of the class `BackendProperties` in `qiskit-ibm-runtime`.
1517
"""
1618

1719
from numpy import inf
@@ -27,6 +29,7 @@ def gate_param_values(properties):
2729
2830
Args:
2931
properties (BackendProperties): device backend properties
32+
We assume the structure of the class `BackendProperties` in `qiskit-ibm-runtime`
3033
3134
Returns:
3235
list: A list of tuples ``(name, qubits, time, error)``. If gate
@@ -61,6 +64,7 @@ def gate_error_values(properties):
6164
6265
Args:
6366
properties (BackendProperties): device backend properties
67+
We assume the structure of the class `BackendProperties` in `qiskit-ibm-runtime`
6468
6569
Returns:
6670
list: A list of tuples ``(name, qubits, value)``. If gate
@@ -85,6 +89,7 @@ def gate_length_values(properties):
8589
8690
Args:
8791
properties (BackendProperties): device backend properties
92+
We assume the structure of the class `BackendProperties` in `qiskit-ibm-runtime`
8893
8994
Returns:
9095
list: A list of tuples ``(name, qubits, value)``. If gate length
@@ -114,6 +119,7 @@ def readout_error_values(properties):
114119
115120
Args:
116121
properties (BackendProperties): device backend properties
122+
We assume the structure of the class `BackendProperties` in `qiskit-ibm-runtime`
117123
118124
Returns:
119125
list: A list of readout error values for qubits. If readout
@@ -142,6 +148,7 @@ def thermal_relaxation_values(properties):
142148
143149
Args:
144150
properties (BackendProperties): device backend properties
151+
We assume the structure of the class `BackendProperties` in `qiskit-ibm-runtime`
145152
146153
Returns:
147154
list: A list of tuples ``(T1, T2, freq)`` for each qubit in the device.

qiskit_aer/noise/noise_model.py

+8-28
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222

2323
from qiskit.circuit import QuantumCircuit, Instruction, Delay, Reset
2424
from qiskit.circuit.library.generalized_gates import PauliGate, UnitaryGate
25-
from qiskit.providers import QubitProperties
2625
from qiskit.providers.exceptions import BackendPropertyError
27-
from qiskit.providers.models.backendproperties import BackendProperties
2826
from qiskit.transpiler import PassManager
2927
from qiskit.utils import apply_prefix
3028
from .device.models import _excited_population, _truncate_t2_value
@@ -381,27 +379,6 @@ def from_backend(
381379
UserWarning,
382380
)
383381
dt = backend.dt
384-
elif backend_interface_version <= 1:
385-
# BackendV1 will be removed in Qiskit 2.0, so we will remove this soon
386-
warn(
387-
" from_backend using V1 based backend is deprecated as of Aer 0.15"
388-
" and will be removed no sooner than 3 months from that release"
389-
" date. Please use backends based on V2.",
390-
DeprecationWarning,
391-
stacklevel=2,
392-
)
393-
properties = backend.properties()
394-
configuration = backend.configuration()
395-
basis_gates = configuration.basis_gates
396-
all_qubit_properties = [
397-
QubitProperties(
398-
t1=properties.t1(q), t2=properties.t2(q), frequency=properties.frequency(q)
399-
)
400-
for q in range(configuration.num_qubits)
401-
]
402-
dt = getattr(configuration, "dt", 0)
403-
if not properties:
404-
raise NoiseError(f"Qiskit backend {backend} does not have a BackendProperties")
405382
else:
406383
raise NoiseError(f"{backend} is not a Qiskit backend")
407384

@@ -458,7 +435,7 @@ def from_backend(
458435
@classmethod
459436
def from_backend_properties(
460437
cls,
461-
backend_properties: BackendProperties,
438+
backend_properties: "BackendProperties",
462439
gate_error: bool = True,
463440
readout_error: bool = True,
464441
thermal_relaxation: bool = True,
@@ -468,6 +445,7 @@ def from_backend_properties(
468445
dt: Optional[float] = None,
469446
):
470447
"""Return a noise model derived from a backend properties.
448+
We assume the structure of the class `BackendProperties` in `qiskit-ibm-runtime`
471449
472450
This method basically generates a noise model in the same way as
473451
:meth:`~.NoiseModel.from_backend`. One small difference is that the ``dt`` option is
@@ -479,6 +457,7 @@ def from_backend_properties(
479457
480458
Args:
481459
backend_properties (BackendProperties): The property of backend.
460+
We assume the structure of the class `BackendProperties` in `qiskit-ibm-runtime`
482461
gate_error (Bool): Include depolarizing gate errors (Default: True).
483462
readout_error (Bool): Include readout errors in model (Default: True).
484463
thermal_relaxation (Bool): Include thermal relaxation errors (Default: True).
@@ -506,10 +485,11 @@ def from_backend_properties(
506485
Raises:
507486
NoiseError: If the input backend properties are not valid.
508487
"""
509-
if not isinstance(backend_properties, BackendProperties):
510-
raise NoiseError(
511-
"{} is not a Qiskit backend or" " BackendProperties".format(backend_properties)
512-
)
488+
for required_field in ["gates", "qubits", "frequency", "t1", "t2"]:
489+
if not hasattr(backend_properties, required_field):
490+
raise NoiseError(
491+
f"Backend properties are missing the required field '{required_field}'"
492+
)
513493
basis_gates = set()
514494
for prop in backend_properties.gates:
515495
basis_gates.add(prop.gate)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
deprecations:
3+
- |
4+
Remove the parts of the code that relied on deprecated `qiskit` components that are being removed in Qiskit 2.0::
5+
* Everything that uses `convert_to_target` is removed
6+
* Usage of `qiskit.pulse` is removed.
7+
* `BackendProperties` is not being imported from `qiskit.providers.models.backendproperties` anymore.
8+
* `BackendV1` related code is removed.
9+
* Use of `BackendStatus` was removed, resulting in the removal of the `status` method for the Aer backend.

test/terra/noise/test_device_models.py

-20
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import qiskit
2020
from qiskit.circuit import library, Reset, Measure, Parameter
21-
from qiskit.providers import convert_to_target
2221
from qiskit.transpiler import CouplingMap, Target, QubitProperties, InstructionProperties
2322

2423
if qiskit.__version__.startswith("0."):
@@ -101,25 +100,6 @@ def test_basic_device_gate_errors_from_target_with_non_operational_qubits(self):
101100
# check if no error is added on cx gate on a qubit pair without T1 and T2 definitions
102101
self.assertTrue(errors_on_cx[faulty_qubits].ideal())
103102

104-
def test_basic_device_gate_errors_from_target_and_properties(self):
105-
"""Test if the device same gate errors are produced both from target and properties"""
106-
backend = Fake5QV1()
107-
target = convert_to_target(
108-
configuration=backend.configuration(),
109-
properties=backend.properties(),
110-
)
111-
errors_from_properties = basic_device_gate_errors(properties=backend.properties())
112-
errors_from_target = basic_device_gate_errors(target=target)
113-
self.assertEqual(len(errors_from_properties), len(errors_from_target))
114-
errors_from_properties_s = sorted(errors_from_properties)
115-
errors_from_target_s = sorted(errors_from_target)
116-
for err_properties, err_target in zip(errors_from_properties_s, errors_from_target_s):
117-
name1, qargs1, err1 = err_properties
118-
name2, qargs2, err2 = err_target
119-
self.assertEqual(name1, name2)
120-
self.assertEqual(tuple(qargs1), qargs2)
121-
self.assertEqual(err1, err2)
122-
123103
def test_basic_device_gate_errors_from_target_with_no_t2_value(self):
124104
"""Test if gate errors are successfully created from a target with qubits not reporting T2.
125105
See https://github.com/Qiskit/qiskit-aer/issues/1896 for the details."""

0 commit comments

Comments
 (0)