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

Remove Aer and imports from qiskit.providers.aer #11442

Merged
merged 5 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
55 changes: 0 additions & 55 deletions qiskit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@
"qiskit._accelerate.convert_2q_block_matrix"
] = qiskit._accelerate.convert_2q_block_matrix


# Extend namespace for backwards compat
from qiskit import namespace

# Add hook to redirect imports from qiskit.providers.aer* to qiskit_aer*
# this is necessary for backwards compatibility for users when qiskit-aer
# and qiskit-terra shared the qiskit namespace
new_meta_path_finder = namespace.QiskitElementImport("qiskit.providers.aer", "qiskit_aer")
sys.meta_path = [new_meta_path_finder] + sys.meta_path

# qiskit errors operator
from qiskit.exceptions import QiskitError, MissingOptionalLibraryError

Expand Down Expand Up @@ -82,49 +72,6 @@
from .version import __version__


class AerWrapper:
"""Lazy loading wrapper for Aer provider."""

def __init__(self):
self.aer = None

def __bool__(self):
if self.aer is None:
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,
)
except ImportError:
return False
return True

def __getattr__(self, attr):
if not self.aer:
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,
)
except ImportError as ex:
raise MissingOptionalLibraryError(
"qiskit-aer", "Aer provider", "pip install qiskit-aer"
) from ex
return getattr(self.aer, attr)


class IBMQWrapper:
"""Lazy loading wrapper for IBMQ provider."""

Expand Down Expand Up @@ -174,11 +121,9 @@ def __getattr__(self, attr):
return getattr(self.ibmq, attr)


Aer = AerWrapper()
IBMQ = IBMQWrapper()

__all__ = [
"Aer",
"AncillaRegister",
"BasicAer",
"ClassicalRegister",
Expand Down
76 changes: 0 additions & 76 deletions qiskit/namespace.py

This file was deleted.

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
32 changes: 16 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
from qiskit_aer import AerSimulator

self.sim = aer.AerSimulator()
self.sim = 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 @@ -199,9 +199,9 @@ def _default_options(cls):
default values set
"""
if _optionals.HAS_AER:
from qiskit.providers import aer
from qiskit_aer import AerSimulator

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

Expand Down Expand Up @@ -375,13 +375,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 @@ -402,7 +402,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 @@ -458,10 +458,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
from qiskit_aer import AerSimulator
from qiskit_aer.noise import NoiseModel

self.sim = aer.AerSimulator()
self.sim = AerSimulator()
if self.properties():
noise_model = NoiseModel.from_backend(self)
self.sim.set_options(noise_model=noise_model)
Expand Down Expand Up @@ -526,9 +526,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,11 +553,11 @@ def run(self, run_input, **kwargs):
)
if pulse_job:
if _optionals.HAS_AER:
from qiskit.providers import aer
from qiskit.providers.aer.pulse import PulseSystemModel
from qiskit_aer import 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 = 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
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
6 changes: 3 additions & 3 deletions qiskit/utils/optionals.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
: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
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
8 changes: 8 additions & 0 deletions releasenotes/notes/remove-aer-hooks-1144714bbbdd0fe8.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
upgrade:
- |
The object ``qiskit.Aer`` has been removed following its deprecation in Qiskit 0.46. You can
instead use ``qiskit_aer.Aer``, which is a drop-in replacement.
- |
Importing from ``qiskit.providers.aer`` will no longer work, following its deprecation in Qiskit
0.46. You should instead import from ``qiskit_aer``, which is a drop-in replacement.
2 changes: 1 addition & 1 deletion test/python/transpiler/test_sabre_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def test_no_infinite_loop(self, method):
if not optionals.HAS_AER:
return

from qiskit import Aer
from qiskit_aer import Aer

sim = Aer.get_backend("aer_simulator")
in_results = sim.run(qc, shots=4096).result().get_counts()
Expand Down
5 changes: 3 additions & 2 deletions test/randomized/test_transpiler_equivalence.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

import hypothesis.strategies as st

from qiskit import transpile, Aer, qasm2
from qiskit import transpile, qasm2
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit.circuit import Measure, Reset, Gate, Barrier
from qiskit.providers.fake_provider import (
Expand Down Expand Up @@ -91,10 +91,11 @@
)
from qiskit.test.base import dicts_almost_equal


# pylint: disable=wildcard-import,unused-wildcard-import
from qiskit.circuit.library.standard_gates import *

from qiskit_aer import Aer # pylint: disable=wrong-import-order

default_profile = "transpiler_equivalence"
settings.register_profile(
default_profile,
Expand Down
2 changes: 1 addition & 1 deletion tools/find_optional_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _main():
"ipywidgets",
"scipy.stats",
"matplotlib",
"qiskit.providers.aer",
"qiskit_aer",
"qiskit.providers.ibmq",
"qiskit.ignis",
"qiskit.aqua",
Expand Down