Skip to content

Commit

Permalink
Merge pull request #27 from qiboteam/metab
Browse files Browse the repository at this point in the history
`backend` -> `platform` in `MetaBackend`
  • Loading branch information
MatteoRobbiati authored Jun 20, 2024
2 parents d91dd13 + fc69886 commit 8c18289
Showing 1 changed file with 11 additions and 12 deletions.
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

0 comments on commit 8c18289

Please sign in to comment.