Skip to content

Commit

Permalink
Merge pull request #1430 from qiboteam/only-fix-1424
Browse files Browse the repository at this point in the history
Fix default backend loading
  • Loading branch information
scarrazza authored Aug 28, 2024
2 parents ecbd16d + 8b080b0 commit 21732ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/qibo/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
QIBO_NATIVE_BACKENDS = ("numpy", "tensorflow", "pytorch", "qulacs")


class MissingBackend(ValueError):
"""Impossible to locate backend provider package."""


class MetaBackend:
"""Meta-backend class which takes care of loading the qibo backends."""

Expand Down Expand Up @@ -89,7 +93,7 @@ def __new__(cls):
try:
cls._instance = construct_backend(**kwargs)
break
except (ModuleNotFoundError, ImportError):
except (ImportError, MissingBackend):
pass

if cls._instance is None: # pragma: no cover
Expand Down Expand Up @@ -228,7 +232,7 @@ def construct_backend(backend, **kwargs) -> Backend:
if provider not in e.msg:
raise e
raise_error(
ValueError,
MissingBackend,
f"The '{backend}' backends' provider is not available. Check that a Python "
f"package named '{provider}' is installed, and it is exposing valid Qibo "
"backends.",
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ def get_backend(backend_name):
AVAILABLE_BACKENDS.append(backend_name)
if _backend.supports_multigpu: # pragma: no cover
MULTIGPU_BACKENDS.append(backend_name)
except (ModuleNotFoundError, ImportError):
except ImportError:
pass

try:
get_backend("qulacs")
QULACS_INSTALLED = True
except ModuleNotFoundError:
except ImportError:
QULACS_INSTALLED = False


Expand Down

0 comments on commit 21732ad

Please sign in to comment.