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

backend -> platform in MetaBackend #27

Merged
merged 1 commit into from
Jun 20, 2024
Merged
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
23 changes: 11 additions & 12 deletions src/qiboml/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,43 @@
from qiboml.backends.pytorch import PyTorchBackend
from qiboml.backends.tensorflow import TensorflowBackend

QIBOML_BACKENDS = ["tensorflow", "pytorch", "jax"]
PLATFORMS = ["tensorflow", "pytorch", "jax"]
QibomlBackend = Union[TensorflowBackend, PyTorchBackend, JaxBackend]


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

@staticmethod
def load(backend: str, **kwargs) -> QibomlBackend:
def load(platform: str, **kwargs) -> QibomlBackend:
"""Load the qiboml backend.

Args:
backend (str): Name of the backend to load.
kwargs (dict): Additional arguments for the qibo backend.
platform (str): Name of the backend to load.
Returns:
qibo.backends.abstract.Backend: The loaded backend.
"""

if backend == "tensorflow":
if platform == "tensorflow":
return TensorflowBackend()
elif backend == "pytorch":
elif platform == "pytorch":
return PyTorchBackend()
elif backend == "jax":
elif platform == "jax":
return JaxBackend()
else:
raise_error(
ValueError,
f"Backend {backend} is not available. The qiboml backends are {QIBOML_BACKENDS}.",
f"Backend {platform} is not available. The qiboml backends are {PLATFORMS}.",
)

def list_available(self) -> dict:
"""List all the available native qibo backends."""
"""List all the available qiboml backends."""
available_backends = {}
for backend in QIBOML_BACKENDS:
for platform in PLATFORMS:
try:
MetaBackend.load(backend)
MetaBackend.load(platform)
available = True
except: # pragma: no cover
available = False
available_backends[backend] = available
available_backends[platform] = available
return available_backends
Loading