Skip to content

Commit

Permalink
refactor: made platforms a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoLiegiBastonLiegi committed Feb 27, 2024
1 parent 8b007aa commit f66bd12
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/qibojit/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
from qibojit.backends.cpu import NumbaBackend
from qibojit.backends.gpu import CupyBackend, CuQuantumBackend

QibojitBackend = NumbaBackend | CupyBackend | CuQuantumBackend


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

PLATFORMS = ("numba", "cupy", "cuquantum")

def load(self, platform: str) -> NumbaBackend | CupyBackend | CuQuantumBackend:
@staticmethod
def load(platform: str) -> QibojitBackend:
"""Loads the backend.
Args:
Expand All @@ -27,15 +30,15 @@ def load(self, platform: str) -> NumbaBackend | CupyBackend | CuQuantumBackend:
else:
raise_error(
ValueError,
f"Unsupported platform, please use one among {self.platforms}.",
f"Unsupported platform, please use one among {PLATFORMS}.",
)

def list_available(self) -> dict:
"""Lists all the available qibojit backends."""
available_backends = {}
for platform in self.platforms:
for platform in PLATFORMS:
try:
self.load(platform=platform)
MetaBackend.load(platform=platform)
available = True
except:
available = False
Expand Down

0 comments on commit f66bd12

Please sign in to comment.