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

Removal of deprecated Qiskit 2.0 related code #2318

Merged
merged 10 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from 7 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 docs/tutorials/2_device_noise_simulation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"source": [
"## Device Backend Noise Model\n",
"\n",
"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",
"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",
"\n",
"* The *gate_error* probability of each basis gate on each qubit.\n",
"* The *gate_length* of each basis gate on each qubit.\n",
Expand Down
3 changes: 1 addition & 2 deletions qiskit_aer/backends/aer_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from qiskit.circuit.classical.types import Bool, Uint
from qiskit.circuit.library import Initialize
from qiskit.providers.options import Options
from qiskit.pulse import Schedule, ScheduleBlock
from qiskit.circuit import Store
from qiskit.circuit.controlflow import (
WhileLoopOp,
Expand Down Expand Up @@ -85,7 +84,7 @@ def compile(self, circuits, optypes=None):
compiled circuit optypes for each circuit if
optypes kwarg is not None.
"""
if isinstance(circuits, (QuantumCircuit, Schedule, ScheduleBlock)):
if isinstance(circuits, QuantumCircuit):
circuits = [circuits]
if optypes is None:
compiled_optypes = len(circuits) * [None]
Expand Down
26 changes: 2 additions & 24 deletions qiskit_aer/backends/aer_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@

import copy
import logging
from warnings import warn
from qiskit.providers import convert_to_target
from qiskit.providers.options import Options
from qiskit.providers.backend import BackendV2, BackendV1
from qiskit.providers.backend import BackendV2

from ..version import __version__
from .aerbackend import AerBackend, AerError
Expand All @@ -34,7 +32,6 @@

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

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -858,28 +855,9 @@ def from_backend(cls, backend, **options):
)
properties = target_to_backend_properties(backend.target)
target = backend.target
elif isinstance(backend, BackendV1):
# BackendV1 will be removed in Qiskit 2.0, so we will remove this soon
warn(
" from_backend using V1 based backend is deprecated as of Aer 0.15"
" and will be removed no sooner than 3 months from that release"
" date. Please use backends based on V2.",
DeprecationWarning,
stacklevel=2,
)
# Get configuration and properties from backend
configuration = backend.configuration()
properties = copy.copy(backend.properties())

# Customize configuration name
name = configuration.backend_name
configuration.backend_name = f"aer_simulator_from({name})"

target = convert_to_target(configuration, properties, None, NAME_MAPPING)
else:
raise TypeError(
"The backend argument requires a BackendV2 or BackendV1 object, "
f"not a {type(backend)} object"
"The backend argument requires a BackendV2 object, " f"not a {type(backend)} object"
)
# Use automatic noise model if none is provided
if "noise_model" not in options:
Expand Down
24 changes: 3 additions & 21 deletions qiskit_aer/backends/aerbackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

from qiskit.circuit import QuantumCircuit, ParameterExpression, Delay
from qiskit.providers import BackendV2 as Backend
from qiskit.providers.models.backendstatus import BackendStatus
from qiskit.pulse import Schedule, ScheduleBlock
from qiskit.result import Result
from qiskit.transpiler import CouplingMap
from qiskit.transpiler.target import Target
Expand Down Expand Up @@ -181,7 +179,7 @@ def run(self, circuits, parameter_binds=None, **run_options):
Raises:
ValueError: if run is not implemented
"""
if isinstance(circuits, (QuantumCircuit, Schedule, ScheduleBlock)):
if isinstance(circuits, QuantumCircuit):
circuits = [circuits]

return self._run_circuits(circuits, parameter_binds, **run_options)
Expand Down Expand Up @@ -442,20 +440,6 @@ def clear_options(self):
self._options_configuration = {}
self._options_properties = {}

def status(self):
"""Return backend status.

Returns:
BackendStatus: the status of the backend.
"""
return BackendStatus(
backend_name=self.name,
backend_version=self.configuration().backend_version,
operational=True,
pending_jobs=0,
status_msg="",
)

def _execute_circuits_job(
self, circuits, parameter_binds, run_options, job_id="", format_result=True
):
Expand Down Expand Up @@ -536,7 +520,7 @@ def _format_results(output):

def _compile(self, circuits, **run_options):
"""Compile circuits and noise model"""
if isinstance(circuits, (QuantumCircuit, Schedule, ScheduleBlock)):
if isinstance(circuits, QuantumCircuit):
circuits = [circuits]
optypes = [circuit_optypes(circ) for circ in circuits]

Expand Down Expand Up @@ -582,9 +566,7 @@ def _assemble_noise_model(self, circuits, optypes, **run_options):

# Check if circuits contain quantum error instructions
for idx, circ in enumerate(run_circuits):
if QuantumChannelInstruction in optypes[idx] and not isinstance(
circ, (Schedule, ScheduleBlock)
):
if QuantumChannelInstruction in optypes[idx]:
updated_circ = False
new_data = []
for datum in circ.data:
Expand Down
25 changes: 2 additions & 23 deletions qiskit_aer/backends/qasm_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
import copy
import logging
from warnings import warn
from qiskit.providers import convert_to_target
from qiskit.providers.options import Options
from qiskit.providers.backend import BackendV2, BackendV1
from qiskit.providers.backend import BackendV2

from ..version import __version__
from ..aererror import AerError
Expand All @@ -35,7 +34,6 @@

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

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -552,28 +550,9 @@ def from_backend(cls, backend, **options):
)
properties = target_to_backend_properties(backend.target)
target = backend.target
elif isinstance(backend, BackendV1):
# BackendV1 will be removed in Qiskit 2.0, so we will remove this soon
warn(
" from_backend using V1 based backend is deprecated as of Aer 0.15"
" and will be removed no sooner than 3 months from that release"
" date. Please use backends based on V2.",
DeprecationWarning,
stacklevel=2,
)
# Get configuration and properties from backend
configuration = backend.configuration()
properties = copy.copy(backend.properties())

# Customize configuration name
name = configuration.backend_name
configuration.backend_name = f"aer_simulator_from({name})"

target = convert_to_target(configuration, properties, None, NAME_MAPPING)
else:
raise TypeError(
"The backend argument requires a BackendV2 or BackendV1 object, "
f"not a {type(backend)} object"
"The backend argument requires a BackendV2 object, " f"not a {type(backend)} object"
)
# Use automatic noise model if none is provided
if "noise_model" not in options:
Expand Down
2 changes: 2 additions & 0 deletions qiskit_aer/noise/device/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

"""
Functions to extract device error parameters from backend properties.

We assume the structure of the class `BackendProperties` in `qiskit-ibm-runtime`.
"""

from numpy import inf
Expand Down
34 changes: 6 additions & 28 deletions qiskit_aer/noise/noise_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@

from qiskit.circuit import QuantumCircuit, Instruction, Delay, Reset
from qiskit.circuit.library.generalized_gates import PauliGate, UnitaryGate
from qiskit.providers import QubitProperties
from qiskit.providers.exceptions import BackendPropertyError
from qiskit.providers.models.backendproperties import BackendProperties
from qiskit.transpiler import PassManager
from qiskit.utils import apply_prefix
from .device.models import _excited_population, _truncate_t2_value
Expand Down Expand Up @@ -381,27 +379,6 @@ def from_backend(
UserWarning,
)
dt = backend.dt
elif backend_interface_version <= 1:
# BackendV1 will be removed in Qiskit 2.0, so we will remove this soon
warn(
" from_backend using V1 based backend is deprecated as of Aer 0.15"
" and will be removed no sooner than 3 months from that release"
" date. Please use backends based on V2.",
DeprecationWarning,
stacklevel=2,
)
properties = backend.properties()
configuration = backend.configuration()
basis_gates = configuration.basis_gates
all_qubit_properties = [
QubitProperties(
t1=properties.t1(q), t2=properties.t2(q), frequency=properties.frequency(q)
)
for q in range(configuration.num_qubits)
]
dt = getattr(configuration, "dt", 0)
if not properties:
raise NoiseError(f"Qiskit backend {backend} does not have a BackendProperties")
else:
raise NoiseError(f"{backend} is not a Qiskit backend")

Expand Down Expand Up @@ -458,7 +435,7 @@ def from_backend(
@classmethod
def from_backend_properties(
cls,
backend_properties: BackendProperties,
backend_properties: "BackendProperties",
gate_error: bool = True,
readout_error: bool = True,
thermal_relaxation: bool = True,
Expand Down Expand Up @@ -506,10 +483,11 @@ def from_backend_properties(
Raises:
NoiseError: If the input backend properties are not valid.
"""
if not isinstance(backend_properties, BackendProperties):
raise NoiseError(
"{} is not a Qiskit backend or" " BackendProperties".format(backend_properties)
)
for required_field in ["gates", "qubits", "frequency", "t1", "t2"]:
if not hasattr(backend_properties, required_field):
raise NoiseError(
f"Backend properties are missing the required field '{required_field}'"
)
basis_gates = set()
for prop in backend_properties.gates:
basis_gates.add(prop.gate)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
deprecations:
- |
Remove the parts of the code that relied on deprecated `qiskit` components that are being removed in Qiskit 2.0::
* Everything that uses `convert_to_target` is removed
* Usage of `qiskit.pulse` is removed.
* Use of `BackendProperties` is removed.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Use of `BackendProperties` is removed.
* `BackendProperties` is not being imported from `qiskit.providers.models.backendproperties` anymore.
The method :meth:`NoiseModel.from_backend_properties` still assumes a `BackendProperties` object as in
`qiskit_ibm_runtime.models.backend_properties` passed through the `properties` argument.

* `BackendV1` related code is removed.
* Use of `BackendStatus` was removed, resulting in the removal of the :meth:`status` method for the Aer backend.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Use of `BackendStatus` was removed, resulting in the removal of the :meth:`status` method for the Aer backend.
* Use of `BackendStatus` was removed, resulting in the removal of the `status` method for the Aer backend.

20 changes: 0 additions & 20 deletions test/terra/noise/test_device_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import qiskit
from qiskit.circuit import library, Reset, Measure, Parameter
from qiskit.providers import convert_to_target
from qiskit.transpiler import CouplingMap, Target, QubitProperties, InstructionProperties

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

def test_basic_device_gate_errors_from_target_and_properties(self):
"""Test if the device same gate errors are produced both from target and properties"""
backend = Fake5QV1()
target = convert_to_target(
configuration=backend.configuration(),
properties=backend.properties(),
)
errors_from_properties = basic_device_gate_errors(properties=backend.properties())
errors_from_target = basic_device_gate_errors(target=target)
self.assertEqual(len(errors_from_properties), len(errors_from_target))
errors_from_properties_s = sorted(errors_from_properties)
errors_from_target_s = sorted(errors_from_target)
for err_properties, err_target in zip(errors_from_properties_s, errors_from_target_s):
name1, qargs1, err1 = err_properties
name2, qargs2, err2 = err_target
self.assertEqual(name1, name2)
self.assertEqual(tuple(qargs1), qargs2)
self.assertEqual(err1, err2)

def test_basic_device_gate_errors_from_target_with_no_t2_value(self):
"""Test if gate errors are successfully created from a target with qubits not reporting T2.
See https://github.com/Qiskit/qiskit-aer/issues/1896 for the details."""
Expand Down