|
5 | 5 | Provider, |
6 | 6 | Backend, |
7 | 7 | BackendRunResult, |
| 8 | + BackendAvailability, |
8 | 9 | ComputationalModel, |
9 | 10 | ) |
10 | 11 |
|
11 | | -from scaleway_qaas_client.v1alpha1 import QaaSClient, QaaSPlatform |
| 12 | +from scaleway_qaas_client.v1alpha1 import ( |
| 13 | + QaaSClient, |
| 14 | + QaaSPlatform, |
| 15 | + QaaSPlatformAvailability, |
| 16 | + QaaS, |
| 17 | +) |
12 | 18 |
|
13 | 19 |
|
14 | 20 | class ScalewayBackend(Backend): |
15 | | - def __init__(self, platform: QaaSPlatform, provider: "ScalewayProvider"): |
16 | | - super().__init__(provider=provider) |
17 | | - |
18 | | - self.platform = platform |
19 | | - |
20 | | - def run(model: ComputationalModel) -> BackendRunResult: |
21 | | - pass |
| 21 | + def __init__( |
| 22 | + self, provider: "ScalewayProvider", platform: QaaSPlatform, client: QaaSClient |
| 23 | + ): |
| 24 | + super().__init__(provider=provider, name=platform.name) |
| 25 | + |
| 26 | + self.__platform: QaaSPlatform = platform |
| 27 | + self.__client: QaaSClient = client |
| 28 | + self.__session_id: str = None |
| 29 | + |
| 30 | + def allocate(self, **kwargs) -> None: |
| 31 | + deduplication_id = kwargs.get("deduplication_id", None) |
| 32 | + session = self.__client.create_session( |
| 33 | + self.__platform.id, deduplication_id=deduplication_id |
| 34 | + ) |
| 35 | + self.__session_id = session.id |
| 36 | + |
| 37 | + def deallocate(self, **kwargs) -> None: |
| 38 | + self.__client.terminate_session(self.__session_id) |
| 39 | + |
| 40 | + def run(self, model: ComputationalModel, **kwargs) -> BackendRunResult: |
| 41 | + model = self.__client.create_model(model) |
| 42 | + self.__client.create_job(self.__session_id, model_id=model.id) |
| 43 | + |
| 44 | + @property |
| 45 | + def max_qubit_count(self) -> int: |
| 46 | + return self.__platform.max_qubit_count |
| 47 | + |
| 48 | + @property |
| 49 | + def max_shots_per_run(self) -> int: |
| 50 | + return self.__platform.max_shot_count |
| 51 | + |
| 52 | + @property |
| 53 | + def availability(self) -> BackendAvailability: |
| 54 | + availability_map = { |
| 55 | + QaaSPlatformAvailability.AVAILABLE: BackendAvailability.AVAILABLE, |
| 56 | + QaaSPlatformAvailability.SHORTAGE: BackendAvailability.MAINTENANCE, |
| 57 | + QaaSPlatformAvailability.MAINTENANCE: BackendAvailability.MAINTENANCE, |
| 58 | + } |
| 59 | + return availability_map.get( |
| 60 | + self.__platform.availability, BackendAvailability.UNKOWN_AVAILABILITY |
| 61 | + ) |
22 | 62 |
|
23 | 63 |
|
24 | 64 | @provider("scaleway") |
|
0 commit comments