diff --git a/src/qibo/backends/__init__.py b/src/qibo/backends/__init__.py index b10357e805..3498c1c23d 100644 --- a/src/qibo/backends/__init__.py +++ b/src/qibo/backends/__init__.py @@ -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.""" @@ -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 @@ -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.",