From e8d6ba9f5d1bc5676ccf5864821c1959671b9698 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Wed, 13 Nov 2024 18:52:43 +0100 Subject: [PATCH] remove deprecated Provider ABC https://github.com/Qiskit/qiskit/pull/12145 --- qiskit/providers/backend.py | 25 +++++++++++++++++-- .../basic_provider/basic_simulator.py | 4 +++ test/utils/base.py | 3 +-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/qiskit/providers/backend.py b/qiskit/providers/backend.py index 93b31308e21..327704fc1f0 100644 --- a/qiskit/providers/backend.py +++ b/qiskit/providers/backend.py @@ -86,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. @@ -158,6 +158,14 @@ def properties(self): """ return None + def provider(self): + """Return the backend provider. + + Returns: + provider: the provider responsible for the backend. + """ + return self._provider + def status(self): """Return the backend status. @@ -242,7 +250,7 @@ class QubitProperties: This class provides the optional properties that a backend can provide for a qubit. These represent the set of qubit properties that Qiskit can - currently work with if present. However, if your backend provides additional + currently work with if present. However if your backend provides additional properties of qubits you should subclass this to add additional custom attributes for those custom/additional properties provided by the backend. """ @@ -318,6 +326,7 @@ class BackendV2(Backend, ABC): def __init__( self, + provider=None, name: str = None, description: str = None, online_date: datetime.datetime = None, @@ -327,6 +336,8 @@ def __init__( """Initialize a BackendV2 based backend Args: + 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 @@ -345,6 +356,7 @@ def __init__( """ self._options = self._default_options() + self._provider = provider if fields: for field in fields: if field not in self._options.data: @@ -617,6 +629,15 @@ def options(self): """ return self._options + @property + def provider(self): + """Return the backend provider. + + Returns: + provider: the provider responsible for the backend. + """ + return self._provider + @abstractmethod def run(self, run_input, **options): """Run on the backend. diff --git a/qiskit/providers/basic_provider/basic_simulator.py b/qiskit/providers/basic_provider/basic_simulator.py index 71d0459c054..2101f921c84 100644 --- a/qiskit/providers/basic_provider/basic_simulator.py +++ b/qiskit/providers/basic_provider/basic_simulator.py @@ -73,11 +73,14 @@ class BasicSimulator(BackendV2): def __init__( self, + provider=None, target: Target | None = None, **fields, ) -> None: """ Args: + 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 options. @@ -88,6 +91,7 @@ def __init__( """ super().__init__( + provider=provider, name="basic_simulator", description="A python simulator for quantum experiments", backend_version="0.1", diff --git a/test/utils/base.py b/test/utils/base.py index 133666cfc7a..5872b896293 100644 --- a/test/utils/base.py +++ b/test/utils/base.py @@ -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."""