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 Provider ABC (deprecated in 1.1) #13435

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
13 changes: 1 addition & 12 deletions qiskit/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,6 @@
Abstract Classes
================

Provider
--------

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

Provider
ProviderV1

Backend
-------

Expand Down Expand Up @@ -672,7 +663,7 @@ def status(self):
enable algorithms to get the best results with
mitigation applied directly from your backends. You can refer to the
documentation in :mod:`qiskit.primitives` on how to write custom
implementations. Also the built-in implementations: :class:`~.Sampler`,
implementations. Also, the built-in implementations: :class:`~.Sampler`,
:class:`~.Estimator`, :class:`~.BackendSampler`, and :class:`~.BackendEstimator`
can serve as references/models on how to implement these as well.

Expand Down Expand Up @@ -781,8 +772,6 @@ def status(self):
"""

# Providers interface
from qiskit.providers.provider import Provider
from qiskit.providers.provider import ProviderV1
from qiskit.providers.backend import Backend
from qiskit.providers.backend import BackendV1
from qiskit.providers.backend import BackendV2
Expand Down
18 changes: 8 additions & 10 deletions qiskit/providers/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import datetime
from typing import List, Union, Iterable, Tuple

from qiskit.providers.provider import Provider
from qiskit.providers.models.backendstatus import BackendStatus
from qiskit.circuit.gate import Instruction
from qiskit.utils import deprecate_func
Expand Down Expand Up @@ -87,7 +86,7 @@ def __init__(self, configuration, provider=None, **fields):
Args:
configuration (BackendConfiguration): A backend configuration
object for the backend object.
provider (qiskit.providers.Provider): Optionally, the provider
provider: Optionally, the provider
object that this Backend comes from.
fields: kwargs for the values to use to override the default
options.
Expand Down Expand Up @@ -160,10 +159,10 @@ def properties(self):
return None

def provider(self):
"""Return the backend Provider.
"""Return the backend provider.

Returns:
Provider: the Provider responsible for the backend.
provider: the provider responsible for the backend.
"""
return self._provider

Expand Down Expand Up @@ -327,7 +326,7 @@ class BackendV2(Backend, ABC):

def __init__(
self,
provider: Provider = None,
provider=None,
name: str = None,
description: str = None,
online_date: datetime.datetime = None,
Expand All @@ -337,9 +336,8 @@ def __init__(
"""Initialize a BackendV2 based backend

Args:
provider: An optional backwards reference to the
:class:`~qiskit.providers.Provider` object that the backend
is from
provider: An optional backwards reference to the provider
object that the backend is from
name: An optional name for the backend
description: An optional description of the backend
online_date: An optional datetime the backend was brought online
Expand Down Expand Up @@ -633,10 +631,10 @@ def options(self):

@property
def provider(self):
"""Return the backend Provider.
"""Return the backend provider.

Returns:
Provider: the Provider responsible for the backend.
provider: the provider responsible for the backend.
"""
return self._provider

Expand Down
38 changes: 29 additions & 9 deletions qiskit/providers/basic_provider/basic_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

from qiskit.exceptions import QiskitError
from qiskit.providers.backend import Backend
from qiskit.providers.provider import ProviderV1
from qiskit.providers.exceptions import QiskitBackendNotFoundError
from qiskit.providers.providerutils import filter_backends

Expand All @@ -35,7 +34,7 @@
SIMULATORS = [BasicSimulator]


class BasicProvider(ProviderV1):
class BasicProvider:
"""Provider for test simulators."""

def __init__(self) -> None:
Expand All @@ -44,12 +43,33 @@ def __init__(self) -> None:
# Populate the list of test backends (simulators)
self._backends = self._verify_backends()

def get_backend(self, name: str | None = None, **kwargs) -> Backend:
return super().get_backend(name=name, **kwargs)

def backends(
self, name: str | None = None, filters: Callable | None = None, **kwargs
) -> list[Backend]:
def get_backend(self, name=None, **kwargs):
"""Return a single backend matching the specified filtering.
Args:
name (str): name of the backend.
**kwargs: dict used for filtering.
Returns:
Backend: a backend matching the filtering.
Raises:
QiskitBackendNotFoundError: if no backend could be found or
more than one backend matches the filtering criteria.
"""
backends = self.backends(name, **kwargs)
if len(backends) > 1:
raise QiskitBackendNotFoundError("More than one backend matches the criteria")
if not backends:
raise QiskitBackendNotFoundError("No backend matches the criteria")
return backends[0]

def backends(self, name: str | None = None, filters: Callable | None = None) -> list[Backend]:
"""Return a list of backends matching the specified filtering.
Args:
name: name of the backend.
filters: callable for filtering.
Returns:
list[Backend]: a list of Backends that match the filtering
criteria.
"""
backends = self._backends.values()
if name:
available = [
Expand All @@ -59,7 +79,7 @@ def backends(
raise QiskitBackendNotFoundError(
f"The '{name}' backend is not installed in your system."
)
return filter_backends(backends, filters=filters, **kwargs)
return filter_backends(backends, filters=filters)

def _verify_backends(self) -> OrderedDict[str, Backend]:
"""
Expand Down
6 changes: 2 additions & 4 deletions qiskit/providers/basic_provider/basic_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
from qiskit.circuit import QuantumCircuit
from qiskit.circuit.library import UnitaryGate
from qiskit.circuit.library.standard_gates import get_standard_gate_name_mapping, GlobalPhaseGate
from qiskit.providers import Provider
from qiskit.providers.backend import BackendV2
from qiskit.providers.models.backendconfiguration import BackendConfiguration
from qiskit.providers.options import Options
Expand Down Expand Up @@ -76,14 +75,13 @@ class BasicSimulator(BackendV2):

def __init__(
self,
provider: Provider | None = None,
provider=None,
target: Target | None = None,
**fields,
) -> None:
"""
Args:
provider: An optional backwards reference to the
:class:`~qiskit.providers.Provider` object that the backend
provider: An optional backwards reference to the provider object that the backend
is from.
target: An optional target to configure the simulator.
fields: kwargs for the values to use to override the default
Expand Down
95 changes: 0 additions & 95 deletions qiskit/providers/provider.py

This file was deleted.

17 changes: 17 additions & 0 deletions releasenotes/notes/remove_provider_abc-87b611c223311a40.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
upgrade_providers:
- |
The abstract base classes ``Provider`` and ``ProviderV1`` have been deprecated since Qiskit 1.1 and they are now removed.
The abstraction provided by these interface definitions were not providing a huge value, solely just the attributes
``name``, ``backends``, and a ``get_backend()``. A _provider_, as a concept, will continue existing as a collection
of backends. If you're implementing a provider currently you can adjust your
code by simply removing ``ProviderV1`` as the parent class of your
implementation. As part of this you probably would want to add an
implementation of ``get_backend`` for backwards compatibility. For example::
def get_backend(self, name=None, **kwargs):
backend = self.backends(name, **kwargs)
if len(backends) > 1:
raise QiskitBackendNotFoundError("More than one backend matches the criteria")
if not backends:
raise QiskitBackendNotFoundError("No backend matches the criteria")
return backends[0]
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class TestBasicProviderBackends(QiskitTestCase):

def setUp(self):
super().setUp()
with self.assertWarns(DeprecationWarning):
self.provider = BasicProvider()
self.provider = BasicProvider()
self.backend_name = "basic_simulator"

def test_backends(self):
Expand All @@ -33,11 +32,9 @@ def test_backends(self):

def test_get_backend(self):
"""Test getting a backend from the provider."""
with self.assertWarns(DeprecationWarning):
backend = self.provider.get_backend(name=self.backend_name)
backend = self.provider.get_backend(name=self.backend_name)
self.assertEqual(backend.name, self.backend_name)

def test_aliases_fail(self):
"""Test a failing backend lookup."""
with self.assertWarns(DeprecationWarning):
self.assertRaises(QiskitBackendNotFoundError, BasicProvider().get_backend, "bad_name")
self.assertRaises(QiskitBackendNotFoundError, BasicProvider().get_backend, "bad_name")
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ def test_circuit_multi(self):

qc = circ.compose(meas)

with self.assertWarns(DeprecationWarning):
backend_sim = BasicProvider().get_backend("basic_simulator")
backend_sim = BasicProvider().get_backend("basic_simulator")

result = backend_sim.run(qc).result()
counts = result.get_counts(qc)
Expand Down
3 changes: 1 addition & 2 deletions test/utils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ def tearDown(self):
# due to importing the instances from the top-level qiskit namespace.
from qiskit.providers.basic_provider import BasicProvider

with self.assertWarns(DeprecationWarning):
BasicProvider()._backends = BasicProvider()._verify_backends()
BasicProvider()._backends = BasicProvider()._verify_backends()

def assertQuantumCircuitEqual(self, qc1, qc2, msg=None):
"""Extra assertion method to give a better error message when two circuits are unequal."""
Expand Down
Loading