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 BasicAer and introduce BasicProvider #11583

Merged
merged 35 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2245019
Add basic provider
ElePT Jan 16, 2024
7be459e
Restore changes from main that shouldn't be in 0.46.
ElePT Jan 16, 2024
8ba8f53
Fix style, docs
ElePT Jan 16, 2024
0a80294
Apply inline suggestions from Julien's code review
ElePT Jan 16, 2024
2135c54
Add suggestion from Julien's code review
ElePT Jan 16, 2024
b2858b8
Add release note
ElePT Jan 16, 2024
fc3cce6
Add deprecation warnings and address in tests
ElePT Jan 17, 2024
6d37ff9
Fix passmanager config test
ElePT Jan 17, 2024
bff156c
Fix passmanager test again
ElePT Jan 17, 2024
4b12ead
Fix tests
ElePT Jan 17, 2024
f97a676
Add opflow filter
ElePT Jan 17, 2024
eb7d3f8
Fix lint and docs
ElePT Jan 22, 2024
a8cf62a
Fix opflow and algorithms tests
ElePT Jan 22, 2024
8a04914
Remove execute log tests
ElePT Jan 22, 2024
bfeccc1
Remove unused imports
ElePT Jan 22, 2024
033df93
Fix lint
ElePT Jan 22, 2024
2dae10d
Raise deprecation warning on BasicAer global instance import
ElePT Jan 22, 2024
4ae566a
Fix tests
ElePT Jan 22, 2024
21e14d5
Fix lint
ElePT Jan 22, 2024
3910690
Fix lint again
ElePT Jan 22, 2024
a774920
Merge branch 'stable/0.46' into deprecate-basic-aer
ElePT Jan 22, 2024
119c47d
Apply suggestions from Matt's code review
ElePT Jan 24, 2024
2ac10d0
Remove BasicProvider global instance
ElePT Jan 25, 2024
8300a92
Apply remaining review comments
ElePT Jan 25, 2024
300e0b6
Remove uses of _deprecated_backend_names()
ElePT Jan 25, 2024
79a9ead
Fix forgotten examples
ElePT Jan 25, 2024
4a8c1b5
Update reno
ElePT Jan 25, 2024
33dfcf1
Fix examples
ElePT Jan 25, 2024
ff5a2df
Remove comment
ElePT Jan 26, 2024
e9f1cc1
Update random generator
ElePT Jan 26, 2024
c564cfe
Increase number of shots in failed tests
ElePT Jan 26, 2024
41e76ba
Update test_initializer.py
ElePT Jan 26, 2024
16f9bba
Fix conflict
ElePT Jan 27, 2024
6e92067
Merge branch 'deprecate-basic-aer' of https://github.com/ElePT/qiskit…
ElePT Jan 27, 2024
e7fba93
Fix black
ElePT Jan 29, 2024
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
3 changes: 2 additions & 1 deletion docs/apidoc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ API Reference
dagcircuit
extensions
passmanager
providers_basicaer
providers
providers_basicaer
providers_basic_provider
providers_fake_provider
providers_models
pulse
Expand Down
6 changes: 6 additions & 0 deletions docs/apidoc/providers_basic_provider.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _qiskit-providers-basicprovider:

.. automodule:: qiskit.providers.basic_provider
:no-members:
:no-inherited-members:
:no-special-members:
11 changes: 5 additions & 6 deletions examples/python/ghz.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2017.
# (C) Copyright IBM 2017, 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -14,9 +14,8 @@
GHZ state example. It also compares running on experiment and simulator.
"""

from qiskit import QuantumCircuit
from qiskit import BasicAer, transpile

from qiskit import QuantumCircuit, transpile
from qiskit.providers.basic_provider import BasicSimulator

###############################################################
# Make a quantum circuit for the GHZ state.
Expand All @@ -34,8 +33,8 @@
for i in range(num_qubits):
qc.measure(i, i)

sim_backend = BasicAer.get_backend("qasm_simulator")
sim_backend = BasicSimulator()
job = sim_backend.run(transpile(qc, sim_backend), shots=1024)
result = job.result()
print("Qasm simulator : ")
print("Basic simulator : ")
print(result.get_counts(qc))
7 changes: 4 additions & 3 deletions examples/python/initialize.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2017.
# (C) Copyright IBM 2017, 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -15,7 +15,8 @@
"""

import math
from qiskit import QuantumCircuit, transpile, BasicAer
from qiskit import QuantumCircuit, transpile
from qiskit.providers.basic_provider import BasicSimulator


###############################################################
Expand Down Expand Up @@ -58,7 +59,7 @@
print([format(abs(x * x), ".3f") for x in desired_vector])

# Initialize on local simulator
sim_backend = BasicAer.get_backend("qasm_simulator")
sim_backend = BasicSimulator()
job = sim_backend.run(transpile(circuit, sim_backend), shots=shots)
result = job.result()

Expand Down
7 changes: 3 additions & 4 deletions examples/python/load_qasm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2017, 2018.
# (C) Copyright IBM 2017, 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -13,14 +13,13 @@
"""Example on how to load a file into a QuantumCircuit."""

from qiskit import QuantumCircuit
from qiskit import BasicAer
from qiskit.providers.basic_provider import BasicSimulator

circ = QuantumCircuit.from_qasm_file("examples/qasm/entangled_registers.qasm")
print(circ)

# See the backend
sim_backend = BasicAer.get_backend("qasm_simulator")

sim_backend = BasicSimulator()

# Compile and run the Quantum circuit on a local simulator backend
job_sim = sim_backend.run(circ)
Expand Down
7 changes: 4 additions & 3 deletions examples/python/qft.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

import math
from qiskit import QuantumCircuit
from qiskit import transpile, BasicAer
from qiskit import transpile
from qiskit.providers.basic_provider import BasicSimulator


###############################################################
Expand Down Expand Up @@ -66,8 +67,8 @@ def qft(circ, n):
print(qft4)
print(qft5)

print("Qasm simulator")
sim_backend = BasicAer.get_backend("qasm_simulator")
print("Basic simulator")
sim_backend = BasicSimulator()
job = sim_backend.run(transpile([qft3, qft4, qft5], sim_backend), shots=1024)
result = job.result()
print(result.get_counts(qft3))
Expand Down
6 changes: 3 additions & 3 deletions examples/python/rippleadd.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2017.
# (C) Copyright IBM 2017, 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -16,13 +16,13 @@
"""

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit import BasicAer
from qiskit import transpile
from qiskit.providers.basic_provider import BasicSimulator

###############################################################
# Set the backend name and coupling map.
###############################################################
backend = BasicAer.get_backend("qasm_simulator")
backend = BasicSimulator()
coupling_map = [
[0, 1],
[0, 8],
Expand Down
6 changes: 3 additions & 3 deletions examples/python/teleport.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2017.
# (C) Copyright IBM 2017, 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -18,14 +18,14 @@
"""

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit import BasicAer
from qiskit import transpile
from qiskit.providers.basic_provider import BasicSimulator

###############################################################
# Set the backend name and coupling map.
###############################################################
coupling_map = [[0, 1], [0, 2], [1, 2], [3, 2], [3, 4], [4, 2]]
backend = BasicAer.get_backend("qasm_simulator")
backend = BasicSimulator()

###############################################################
# Make a quantum program for quantum teleportation.
Expand Down
21 changes: 7 additions & 14 deletions examples/python/using_qiskit_terra_level_0.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2017, 2018.
# (C) Copyright IBM 2017, 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -11,19 +11,16 @@
# that they have been altered from the originals.

"""
Example showing how to use Qiskit at level 0 (no optimization).

This example shows the most basic way to user Terra. It builds some circuits
and runs them on both the BasicAer (local Qiskit provider) or IBM Quantum (remote IBM Quantum provider).

To control the compile parameters we have provided a transpile function which can be used
as a level 1 user.
Example showing how to use Qiskit-Terra at level 0 (novice).

This example shows the most basic way to use Qiskit. It builds some circuits
and runs them on the BasicProvider (local Qiskit provider).
"""

# Import the Qiskit modules
from qiskit import QuantumCircuit
from qiskit import transpile, BasicAer
from qiskit import transpile
from qiskit.providers.basic_provider import BasicSimulator

# making first circuit: bell state
qc1 = QuantumCircuit(2, 2)
Expand All @@ -36,12 +33,8 @@
qc2.h([0, 1])
qc2.measure([0, 1], [0, 1])

# setting up the backend
print("(BasicAER Backends)")
print(BasicAer.backends())

# running the job
sim_backend = BasicAer.get_backend("qasm_simulator")
sim_backend = BasicSimulator()
job_sim = sim_backend.run(transpile([qc1, qc2], sim_backend))
sim_result = job_sim.result()

Expand Down
27 changes: 23 additions & 4 deletions qiskit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@
# Remove this after 0.46.0 release
__path__ = pkgutil.extend_path(__path__, __name__)

# Please note these are global instances, not modules.
from qiskit.providers.basicaer import BasicAer

_config = _user_config.get_config()

# Moved to after IBMQ and Aer imports due to import issues
Expand Down Expand Up @@ -189,7 +186,6 @@ def __getattr__(self, attr):
__all__ = [
"Aer",
"AncillaRegister",
"BasicAer",
"ClassicalRegister",
"IBMQ",
"MissingOptionalLibraryError",
Expand All @@ -202,3 +198,26 @@ def __getattr__(self, attr):
"sequence",
"transpile",
]

# lazily deprecate BasicAer import (global instance)
_DEPRECATED_NAMES = {
"BasicAer": "qiskit.providers.basicaer",
}


def __getattr__(name):
if name in _DEPRECATED_NAMES:
import importlib

module_name = _DEPRECATED_NAMES[name]
warnings.warn(
f"{name} is deprecated since Qiskit 0.46 and will be removed in Qiskit 1.0. "
f"The BasicAer (qiskit.providers.basicaer) module has been superseded by "
f"qiskit.providers.basic_provider, and all its classes have been renamed "
f"to follow a new naming convention. More information and migration guidelines "
f"can be found in the 0.46 API docs for BasicAer.",
DeprecationWarning,
stacklevel=2,
)
return getattr(importlib.import_module(module_name), name)
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
11 changes: 6 additions & 5 deletions qiskit/circuit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@
.. plot::
:include-source:

from qiskit import BasicAer, transpile, QuantumRegister, ClassicalRegister, QuantumCircuit

from qiskit import transpile, QuantumRegister, ClassicalRegister, QuantumCircuit
qr = QuantumRegister(1)
cr = ClassicalRegister(1)
qc = QuantumCircuit(qr, cr)
Expand All @@ -82,7 +81,8 @@

.. code-block::

backend = BasicAer.get_backend('qasm_simulator')
from qiskit.providers.basic_provider import BasicSimulator
backend = BasicSimulator()
tqc = transpile(qc, backend)
counts = backend.run(tqc).result().get_counts()

Expand All @@ -100,7 +100,7 @@
.. plot::
:include-source:

from qiskit import BasicAer, transpile, QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit import transpile, QuantumRegister, ClassicalRegister, QuantumCircuit

qr = QuantumRegister(1)
cr = ClassicalRegister(1)
Expand All @@ -115,7 +115,8 @@

.. code-block::

backend = BasicAer.get_backend('qasm_simulator')
from qiskit.providers.basic_provider import BasicSimulator
backend = BasicSimulator()
tqc = transpile(qc, backend)
counts = backend.run(tqc).result().get_counts()

Expand Down
2 changes: 1 addition & 1 deletion qiskit/opflow/expectations/expectation_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import logging
from typing import Optional, Union

from qiskit import BasicAer
from qiskit.providers.basicaer import BasicAer # pylint: disable=no-name-in-module
from qiskit.opflow.expectations.aer_pauli_expectation import AerPauliExpectation
from qiskit.opflow.expectations.expectation_base import ExpectationBase
from qiskit.opflow.expectations.matrix_expectation import MatrixExpectation
Expand Down
8 changes: 7 additions & 1 deletion qiskit/opflow/state_fns/circuit_state_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@

import numpy as np

from qiskit import BasicAer, ClassicalRegister, QuantumCircuit, transpile
from qiskit import ( # pylint: disable=no-name-in-module
BasicAer,
ClassicalRegister,
QuantumCircuit,
transpile,
)

from qiskit.circuit import Instruction, ParameterExpression
from qiskit.circuit.exceptions import CircuitError
from qiskit.circuit.library import IGate, StatePreparation
Expand Down
66 changes: 66 additions & 0 deletions qiskit/providers/basic_provider/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2017, 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""
===============================================================================
BasicProvider: Python-based Simulators (:mod:`qiskit.providers.basic_provider`)
===============================================================================

.. currentmodule:: qiskit.providers.basic_provider

A module of Python-based quantum simulators. Simulators can be accessed
via the `BasicProvider` provider, e.g.:

.. code-block::

from qiskit.providers.basic_provider import BasicProvider

backend = BasicProvider().get_backend('basic_simulator')


Simulators
==========

.. autosummary::
:toctree: ../stubs/

BasicSimulator

Provider
========

.. autosummary::
:toctree: ../stubs/

BasicProvider

Job Class
=========

.. autosummary::
:toctree: ../stubs/

BasicProviderJob

Exceptions
==========

.. autosummary::
:toctree: ../stubs/

BasicProviderError
"""

from .basic_provider import BasicProvider
from .basic_provider_job import BasicProviderJob
from .basic_simulator import BasicSimulator
from .exceptions import BasicProviderError
Loading
Loading