Skip to content

Commit

Permalink
Handle deprecation of FakeBackendV2 in Qiskit 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wshanks committed Feb 3, 2024
1 parent 08ea54c commit 632f793
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions qiskit_experiments/framework/backend_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,36 @@ 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:
Expand Down Expand Up @@ -255,7 +284,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
Expand Down

0 comments on commit 632f793

Please sign in to comment.