Skip to content

Commit 459cef4

Browse files
committed
feat(ys): wip scw prov
1 parent 1956ae4 commit 459cef4

File tree

1 file changed

+48
-8
lines changed

1 file changed

+48
-8
lines changed

yardstiq_scaleway/scaleway_provider.py

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,60 @@
55
Provider,
66
Backend,
77
BackendRunResult,
8+
BackendAvailability,
89
ComputationalModel,
910
)
1011

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+
)
1218

1319

1420
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+
)
2262

2363

2464
@provider("scaleway")

0 commit comments

Comments
 (0)