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

Defer gathering backends until they are needed #1760

Merged
merged 4 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 8 additions & 2 deletions qiskit_aer/aerprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class AerProvider(Provider):

_BACKENDS = None

def __init__(self):
@staticmethod
def _get_backends():
if AerProvider._BACKENDS is None:
# Populate the list of Aer simulator backends.
methods = AerSimulator().available_methods()
Expand Down Expand Up @@ -60,6 +61,8 @@ def __init__(self):
]
AerProvider._BACKENDS = backends

return AerProvider._BACKENDS

def get_backend(self, name=None, **kwargs):
if name == "pulse_simulator":
warnings.warn(
Expand All @@ -76,7 +79,10 @@ def backends(self, name=None, filters=None, **kwargs):
# Instantiate a new backend instance so if config options
# are set they will only last as long as that backend object exists
backends = []
for backend_name, backend_cls, method, device in self._BACKENDS:

# pylint: disable=not-an-iterable
# pylint infers _get_backends to always return None
for backend_name, backend_cls, method, device in self._get_backends():
opts = {"provider": self}
if method is not None:
opts["method"] = method
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
Available devices and methods are no longer queried when importing Aer.