Skip to content

Commit

Permalink
fix: Make error type more specific
Browse files Browse the repository at this point in the history
  • Loading branch information
alecandido committed Aug 22, 2024
1 parent bd39482 commit 0796910
Showing 1 changed file with 6 additions and 2 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 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(
ImportError,
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

0 comments on commit 0796910

Please sign in to comment.