From 32c922436601d6bf0af9bd59396e434d94cd736d Mon Sep 17 00:00:00 2001 From: Renato Mello Date: Wed, 16 Oct 2024 14:01:16 +0400 Subject: [PATCH] lint improvements --- src/qibo/backends/__init__.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/qibo/backends/__init__.py b/src/qibo/backends/__init__.py index 1cc48193ca..74f74e1187 100644 --- a/src/qibo/backends/__init__.py +++ b/src/qibo/backends/__init__.py @@ -26,28 +26,36 @@ def load(backend: str, **kwargs) -> Backend: Args: backend (str): Name of the backend to load. - kwargs (dict): Additional arguments for the qibo backend. + kwargs (dict): Additional arguments for the ``qibo`` backend. + Returns: - qibo.backends.abstract.Backend: The loaded backend. + :class:`qibo.backends.abstract.Backend`: Loaded backend. """ - if backend == "numpy": - return NumpyBackend() - elif backend == "pytorch": + possible_backends = ["numpy", "pytorch", "clifford", "qulacs"] + + if backend not in possible_backends: + raise_error( + ValueError, + f"Backend {backend} is not available. " + + f"The native qibo backends are {QIBO_NATIVE_BACKENDS}.", + ) + + if backend == "pytorch": return PyTorchBackend() - elif backend == "clifford": + + if backend == "clifford": engine = kwargs.pop("platform", None) kwargs["engine"] = engine + return CliffordBackend(**kwargs) - elif backend == "qulacs": - from qibo.backends.qulacs import QulacsBackend + + if backend == "qulacs": + from qibo.backends.qulacs import QulacsBackend # pylint: disable=C0415 return QulacsBackend() - else: - raise_error( - ValueError, - f"Backend {backend} is not available. The native qibo backends are {QIBO_NATIVE_BACKENDS}.", - ) + + return NumpyBackend() def list_available(self) -> dict: """Lists all the available native qibo backends."""