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

Deprecate qiskit.Aer and qiskit.providers.aer #11439

Merged
merged 5 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
79 changes: 39 additions & 40 deletions qiskit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,34 +102,34 @@ def __init__(self):

def __bool__(self):
if self.aer is None:
warnings.warn(
"The qiskit.Aer entry point will be deprecated in a future release and "
"subsequently removed. Instead you should use this "
"directly from the root of the qiskit-aer package.",
DeprecationWarning,
stacklevel=2,
)
try:
from qiskit.providers import aer

self.aer = aer.Aer
warnings.warn(
"The qiskit.Aer entry point will be deprecated in a future release and "
"subsequently removed. Instead you should use this "
"directly from the root of the qiskit-aer package.",
PendingDeprecationWarning,
stacklevel=2,
)
import qiskit_aer

self.aer = qiskit_aer.Aer
except ImportError:
return False
return True

def __getattr__(self, attr):
if not self.aer:
warnings.warn(
"The qiskit.Aer entry point will be deprecated in a future release and "
"subsequently removed. Instead you should use this "
"directly from the root of the qiskit-aer package.",
DeprecationWarning,
stacklevel=2,
)
try:
from qiskit.providers import aer

self.aer = aer.Aer
warnings.warn(
"The qiskit.Aer entry point will be deprecated in a future release and "
"subsequently removed. Instead you should use this "
"directly from the root of the qiskit-aer package.",
PendingDeprecationWarning,
stacklevel=2,
)
import qiskit_aer

self.aer = qiskit_aer.Aer
except ImportError as ex:
raise MissingOptionalLibraryError(
"qiskit-aer", "Aer provider", "pip install qiskit-aer"
Expand All @@ -145,40 +145,39 @@ def __init__(self):

def __bool__(self):
if self.ibmq is None:
warnings.warn(
"The qiskit.IBMQ entrypoint and the qiskit-ibmq-provider package ("
"accessible from 'qiskit.providers.ibmq`) are deprecated and will be removed "
"in a future release. Instead you should use the qiskit-ibm-provider package "
jakelishman marked this conversation as resolved.
Show resolved Hide resolved
"which is accessible from 'qiskit_ibm_provider'. You can install it with "
"'pip install qiskit_ibm_provider'",
DeprecationWarning,
stacklevel=2,
)
try:
from qiskit.providers import ibmq

self.ibmq = ibmq.IBMQ
warnings.warn(
"The qiskit.IBMQ entrypoint and the qiskit-ibmq-provider package ("
"accessible from 'qiskit.providers.ibmq`) are deprecated and will be removed "
"in a future release. Instead you should use the qiskit-ibm-provider package "
"which is accessible from 'qiskit_ibm_provider'. You can install it with "
"'pip install qiskit_ibm_provider'",
DeprecationWarning,
stacklevel=2,
)

except ImportError:
return False
return True

def __getattr__(self, attr):
if not self.ibmq:
warnings.warn(
"The qiskit.IBMQ entrypoint and the qiskit-ibmq-provider package ("
"accessible from 'qiskit.providers.ibmq`) are deprecated and will be removed "
"in a future release. Instead you should use the qiskit-ibm-provider package "
"which is accessible from 'qiskit_ibm_provider'. You can install it with "
"'pip install qiskit_ibm_provider'. Just replace 'qiskit.IBMQ' with "
"'qiskit_ibm_provider.IBMProvider'",
DeprecationWarning,
stacklevel=2,
)
try:
from qiskit.providers import ibmq

self.ibmq = ibmq.IBMQ
warnings.warn(
"The qiskit.IBMQ entrypoint and the qiskit-ibmq-provider package ("
"accessible from 'qiskit.providers.ibmq`) are deprecated and will be removed "
"in a future release. Instead you should use the qiskit-ibm-provider package "
"which is accessible from 'qiskit_ibm_provider'. You can install it with "
"'pip install qiskit_ibm_provider'. Just replace 'qiskit.IBMQ' with "
"'qiskit_ibm_provider.IBMProvider'",
DeprecationWarning,
stacklevel=2,
)
except ImportError as ex:
raise MissingOptionalLibraryError(
"qiskit-ibmq-provider", "IBMQ provider", "pip install qiskit-ibmq-provider"
Expand Down
2 changes: 1 addition & 1 deletion qiskit/algorithms/optimizers/umda.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class UMDA(Optimizer):
.. code-block:: python

from qiskit.opflow import X, Z, I
from qiskit import Aer
from qiskit_aer import Aer
from qiskit.algorithms.optimizers import UMDA
from qiskit.algorithms import QAOA
from qiskit.utils import QuantumInstance
Expand Down
7 changes: 7 additions & 0 deletions qiskit/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import sys
from importlib.abc import MetaPathFinder, Loader
import importlib
import warnings


def _new_namespace(fullname, old_namespace, new_package):
Expand All @@ -34,6 +35,12 @@ def __init__(self, new_package, old_namespace):
super().__init__()
self.new_package = new_package
self.old_namespace = old_namespace
warnings.warn(
f"Importing from '{self.old_namespace}' is deprecated."
f" Import from '{self.new_package}' instead, which should work identically.",
category=DeprecationWarning,
stacklevel=3,
)

def module_repr(self, module):
return repr(module)
Expand Down
2 changes: 1 addition & 1 deletion qiskit/opflow/expectations/aer_pauli_expectation.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def convert(self, operator: OperatorBase) -> OperatorBase:
@classmethod
def _replace_pauli_sums(cls, operator):
try:
from qiskit.providers.aer.library import SaveExpectationValue
from qiskit_aer.library import SaveExpectationValue
except ImportError as ex:
raise MissingOptionalLibraryError(
libname="qiskit-aer",
Expand Down
2 changes: 1 addition & 1 deletion qiskit/providers/fake_provider/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
.. code-block:: python

from qiskit.providers.ibmq import IBMQ
from qiskit.providers.aer import AerSimulator
from qiskit_aer import AerSimulator

# get a real backend from a real provider
provider = IBMQ.load_account()
Expand Down
40 changes: 24 additions & 16 deletions qiskit/providers/fake_provider/fake_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ def _parse_channels(self, channels):

def _setup_sim(self):
if _optionals.HAS_AER:
from qiskit.providers import aer
import qiskit_aer

self.sim = aer.AerSimulator()
self.sim = qiskit_aer.AerSimulator()
if self.target and self._props_dict:
noise_model = self._get_noise_model_from_backend_v2()
self.sim.set_options(noise_model=noise_model)
Expand Down Expand Up @@ -200,9 +200,9 @@ def _default_options(cls):
default values set
"""
if _optionals.HAS_AER:
from qiskit.providers import aer
import qiskit_aer

return aer.AerSimulator._default_options()
return qiskit_aer.AerSimulator._default_options()
else:
return basicaer.QasmSimulatorPy._default_options()

Expand Down Expand Up @@ -376,13 +376,13 @@ def _get_noise_model_from_backend_v2(

from qiskit.circuit import Delay
from qiskit.providers.exceptions import BackendPropertyError
from qiskit.providers.aer.noise import NoiseModel
from qiskit.providers.aer.noise.device.models import (
from qiskit_aer.noise import NoiseModel
from qiskit_aer.noise.device.models import (
_excited_population,
basic_device_gate_errors,
basic_device_readout_errors,
)
from qiskit.providers.aer.noise.passes import RelaxationNoisePass
from qiskit_aer.noise.passes import RelaxationNoisePass

if self._props_dict is None:
self._set_props_dict_from_json()
Expand All @@ -403,7 +403,7 @@ def _get_noise_model_from_backend_v2(
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore",
module="qiskit.providers.aer.noise.device.models",
module="qiskit_aer.noise.device.models",
)
gate_errors = basic_device_gate_errors(
properties,
Expand Down Expand Up @@ -459,10 +459,10 @@ def __init__(self, configuration, time_alive=10):

def _setup_sim(self):
if _optionals.HAS_AER:
from qiskit.providers import aer
from qiskit.providers.aer.noise import NoiseModel
import qiskit_aer
from qiskit_aer.noise import NoiseModel

self.sim = aer.AerSimulator()
self.sim = qiskit_aer.AerSimulator()
if self.properties():
noise_model = NoiseModel.from_backend(self)
self.sim.set_options(noise_model=noise_model)
Expand Down Expand Up @@ -527,9 +527,9 @@ def properties(self):
@classmethod
def _default_options(cls):
if _optionals.HAS_AER:
from qiskit.providers import aer
from qiskit_aer import QasmSimulator

return aer.QasmSimulator._default_options()
return QasmSimulator._default_options()
else:
return basicaer.QasmSimulatorPy._default_options()

Expand All @@ -553,12 +553,20 @@ def run(self, run_input, **kwargs):
"QuantumCircuit, Schedule, or a list of either" % circuits
)
if pulse_job:
warnings.warn(
"Simulating pulse jobs on fake backends is deprecated as of Qiskit 0.46,"
" and the functionality will be removed in Qiskit 1.0, due to Qiskit Aer removing"
" its pulse-simulation capabilities in its most recent versions."
" You can try using Qiskit Dynamics instead.",
DeprecationWarning,
stacklevel=2,
)
if _optionals.HAS_AER:
from qiskit.providers import aer
from qiskit.providers.aer.pulse import PulseSystemModel
import qiskit_aer
from qiskit_aer.pulse import PulseSystemModel
jakelishman marked this conversation as resolved.
Show resolved Hide resolved

system_model = PulseSystemModel.from_backend(self)
sim = aer.Aer.get_backend("pulse_simulator")
sim = qiskit_aer.Aer.get_backend("pulse_simulator")
job = sim.run(circuits, system_model=system_model, **kwargs)
else:
raise QiskitError("Unable to run pulse schedules without qiskit-aer installed")
Expand Down
12 changes: 2 additions & 10 deletions qiskit/test/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
import functools
import os
import socket
import sys
from typing import Union, Callable, Type, Iterable
import unittest

from qiskit.utils import wrap_method
from qiskit.utils import wrap_method, optionals
from .testing_options import get_test_options

HAS_NET_CONNECTION = None
Expand Down Expand Up @@ -55,14 +54,7 @@ def is_aer_provider_available():
Returns:
bool: True if simulator executable is available
"""
# TODO: HACK FROM THE DEPTHS OF DESPAIR AS AER DOES NOT WORK ON MAC
Copy link
Member

Choose a reason for hiding this comment

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

How long as this been here? Aer has worked on mac for a really long time now...

Copy link
Member Author

Choose a reason for hiding this comment

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

commit b2bbb3f05968f3cadc2993ed66123077d80026ef
Author: Jay M. Gambetta <[email protected]>
Date:   Fri Dec 28 17:32:27 2018 -0500

    Remove legacy simulators  (#1615)

so not too long, you know

if sys.platform == "darwin":
return False
try:
import qiskit.providers.aer # pylint: disable=unused-import
except ImportError:
return False
return True
return bool(optionals.HAS_AER)


def requires_aer_provider(test_item):
Expand Down
20 changes: 5 additions & 15 deletions qiskit/utils/backend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import logging
from qiskit.utils.deprecation import deprecate_func
from qiskit.utils import optionals

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -79,18 +80,7 @@ def has_ibmq():
)
def has_aer():
"""Check if Aer is installed."""
if not _PROVIDER_CHECK.checked_aer:
try:
from qiskit.providers.aer import AerProvider

_PROVIDER_CHECK.has_aer = True
except Exception as ex: # pylint: disable=broad-except
_PROVIDER_CHECK.has_aer = False
logger.debug("AerProvider not loaded: '%s'", str(ex))

_PROVIDER_CHECK.checked_aer = True

return _PROVIDER_CHECK.has_aer
return bool(optionals.HAS_AER)


@deprecate_func(
Expand All @@ -107,11 +97,11 @@ def is_aer_provider(backend):
bool: True is AerProvider
"""
if has_aer():
from qiskit.providers.aer import AerProvider
from qiskit_aer import AerProvider

if isinstance(_get_backend_provider(backend), AerProvider):
return True
from qiskit.providers.aer.backends.aerbackend import AerBackend
from qiskit_aer.backends.aerbackend import AerBackend

return isinstance(backend, AerBackend)

Expand Down Expand Up @@ -192,7 +182,7 @@ def is_statevector_backend(backend):
return False
backend_interface_version = _get_backend_interface_version(backend)
if has_aer():
from qiskit.providers.aer.backends import AerSimulator, StatevectorSimulator
from qiskit_aer.backends import AerSimulator, StatevectorSimulator

if isinstance(backend, StatevectorSimulator):
return True
Expand Down
14 changes: 7 additions & 7 deletions qiskit/utils/optionals.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@
:widths: 25 75

* - .. py:data:: HAS_AER
- :mod:`Qiskit Aer <qiskit.providers.aer>` provides high-performance simulators for the
quantum circuits constructed within Qiskit.
- `Qiskit Aer <https://qiskit.org/ecosystem/aer/>`__ provides high-performance simulators for
the quantum circuits constructed within Qiskit.

* - .. py:data:: HAS_IBMQ
- The :mod:`Qiskit IBMQ Provider <qiskit.providers.ibmq>` is used for accessing IBM Quantum
hardware in the IBM cloud.
- The Qiskit IBMQ Provider was historically used for accessing IBM Quantum hardware in the IBM
cloud, but is now deprecated.

* - .. py:data:: HAS_IGNIS
- :mod:`Qiskit Ignis <qiskit.ignis>` provides tools for quantum hardware verification, noise
characterization, and error correction.
- Qiskit Ignis provided tools for quantum hardware verification, noise characterization, and
error correction, but is now deprecated.

* - .. py:data:: HAS_TOQM
- `Qiskit TOQM <https://github.com/qiskit-toqm/qiskit-toqm>`__ provides transpiler passes
Expand Down Expand Up @@ -224,7 +224,7 @@
_logger = _logging.getLogger(__name__)

HAS_AER = _LazyImportTester(
"qiskit.providers.aer",
"qiskit_aer",
name="Qiskit Aer",
install="pip install qiskit-aer",
)
Expand Down
2 changes: 1 addition & 1 deletion qiskit/utils/quantum_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def execute(self, circuits, had_transpiled: bool = False):

if self.is_statevector and "aer_simulator_statevector" in self.backend_name:
try:
from qiskit.providers.aer.library import SaveStatevector
from qiskit_aer.library import SaveStatevector

def _find_save_state(data):
for instruction in reversed(data):
Expand Down
6 changes: 2 additions & 4 deletions qiskit/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,9 @@ def _load_versions(self):
stacklevel=3,
)
try:
# TODO: Update to use qiskit_aer instead when we remove the
# namespace redirect
from qiskit.providers import aer
import qiskit_aer

self._version_dict["qiskit-aer"] = aer.__version__
self._version_dict["qiskit-aer"] = qiskit_aer.__version__
except Exception:
self._version_dict["qiskit-aer"] = None
try:
Expand Down
Loading