From 1c110e7997b47137515fb0a8eb925793a141858b Mon Sep 17 00:00:00 2001 From: Will Shanks Date: Sat, 3 Feb 2024 00:05:45 -0500 Subject: [PATCH] Handle deprecation of FakeBackendV2 in Qiskit 1.0 --- qiskit_experiments/framework/backend_data.py | 37 ++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/qiskit_experiments/framework/backend_data.py b/qiskit_experiments/framework/backend_data.py index 93ed671d6d..90e8910100 100644 --- a/qiskit_experiments/framework/backend_data.py +++ b/qiskit_experiments/framework/backend_data.py @@ -17,7 +17,38 @@ class unifies data access for various data fields. """ from qiskit.providers.models import PulseBackendConfiguration from qiskit.providers import BackendV1, BackendV2 -from qiskit.providers.fake_provider import fake_backend, FakeBackendV2, FakeBackend +from qiskit.providers.fake_provider import FakeBackendV2, FakeBackend + +# One of the FakeBackendV2's was moved from qiskit to qiskit-ibm-runtime. Check +# both packages until dropping support for qiskit<1 +try: + from qiskit.providers.fake_provider.fake_backend import FakeBackendV2 as QiskitFakeBackendV2 +except ImportError: + + class QiskitFakeBackendV2: + """Dummy class for when FakeBackendV2 import fails + + This class is only used in isinstance checks. If the import fails, then + there won't be an instance of the class either so any dummy class is + fine. + """ + + pass + + +try: + from qiskit_ibm_runtime.fake_provider.fake_backend import FakeBackendV2 as RuntimeFakeBackendV2 +except ImportError: + + class RuntimeFakeBackendV2: + """Dummy class for when FakeBackendV2 import fails + + This class is only used in isinstance checks. If the import fails, then + there won't be an instance of the class either so any dummy class is + fine. + """ + + pass class BackendData: @@ -255,7 +286,9 @@ def is_simulator(self): if self._backend.configuration().simulator or isinstance(self._backend, FakeBackend): return True if self._v2: - if isinstance(self._backend, (FakeBackendV2, fake_backend.FakeBackendV2)): + if isinstance( + self._backend, (FakeBackendV2, QiskitFakeBackendV2, RuntimeFakeBackendV2) + ): return True return False