Skip to content

Commit ea3baf2

Browse files
committed
feat(client): update client side
1 parent 65781ef commit ea3baf2

File tree

7 files changed

+64
-329
lines changed

7 files changed

+64
-329
lines changed

cirq_scaleway/scaleway_client.py

Lines changed: 0 additions & 173 deletions
This file was deleted.

cirq_scaleway/scaleway_device.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,20 @@
1515

1616
from typing import Union, Optional
1717

18+
from scaleway_qaas_client import QaaSClient, QaaSPlatform
19+
1820
from .scaleway_session import ScalewaySession
19-
from .scaleway_client import QaaSClient
2021

2122

2223
class ScalewayDevice(cirq.devices.Device):
2324
def __init__(
2425
self,
2526
client: QaaSClient,
26-
id: str,
27-
name: str,
28-
version: str,
29-
num_qubits: int,
30-
metadata: Optional[str],
27+
platform: QaaSPlatform,
3128
) -> None:
3229
self.__id = id
3330
self.__client = client
34-
self.__version = version
35-
self.__num_qubits = num_qubits
36-
self.__name = name
37-
self.__metadata = metadata
31+
self.__platform = platform
3832

3933
def __repr__(self) -> str:
4034
return f"<ScalewayDevice(name={self.__name},num_qubits={self.__num_qubits},platform_id={self.id})>"
@@ -46,7 +40,7 @@ def id(self) -> str:
4640
Returns:
4741
str: The UUID of the platform.
4842
"""
49-
return self.__id
43+
return self.__platform.id
5044

5145
@property
5246
def availability(self) -> str:
@@ -55,9 +49,9 @@ def availability(self) -> str:
5549
Returns:
5650
str: the current availability statys of the session. Can be either: available, shortage or scarce
5751
"""
58-
resp = self.__client.get_platform(self.__id)
52+
platform = self.__client.get_platform(self.__platform.id)
5953

60-
return resp.get("availability")
54+
return platform.availability
6155

6256
@property
6357
def name(self) -> str:
@@ -66,7 +60,7 @@ def name(self) -> str:
6660
Returns:
6761
str: the name of the platform.
6862
"""
69-
return self.__name
63+
return self.__platform.name
7064

7165
@property
7266
def num_qubits(self) -> int:
@@ -76,7 +70,7 @@ def num_qubits(self) -> int:
7670
Returns:
7771
int: the estimated amount of maximum number of runnable qubits.
7872
"""
79-
return self.__num_qubits
73+
return self.__platform.max_qubit_count
8074

8175
@property
8276
def version(self):
@@ -85,13 +79,13 @@ def version(self):
8579
Returns:
8680
str: the platform's version.
8781
"""
88-
return self.__version
82+
return self.__platform.version
8983

9084
def create_session(
9185
self,
9286
name: Optional[str] = "qsim-session-from-cirq",
9387
deduplication_id: Optional[str] = "qsim-session-from-cirq",
94-
max_duration: Union[int, str] = "1h",
88+
max_duration: Union[int, str] = "59m",
9589
max_idle_duration: Union[int, str] = "20m",
9690
) -> ScalewaySession:
9791
"""Create a new device session to run job against.

cirq_scaleway/scaleway_models.py

Lines changed: 0 additions & 63 deletions
This file was deleted.

cirq_scaleway/scaleway_service.py

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@
1414
import os
1515

1616
from typing import Optional, List, Dict
17-
from dotenv import dotenv_values
18-
19-
from .scaleway_device import ScalewayDevice
20-
from .scaleway_client import QaaSClient
2117

18+
from scaleway_qaas_client import QaaSClient
2219

23-
_ENDPOINT_URL = "https://api.scaleway.com/qaas/v1alpha1"
20+
from .scaleway_device import ScalewayDevice
2421

2522

2623
class ScalewayQuantumService:
@@ -39,27 +36,19 @@ def __init__(
3936
Returns:
4037
ScalewayDevice: The device that match the given name. None if no match.
4138
"""
42-
env_token = dotenv_values().get("CIRQ_SCALEWAY_API_TOKEN") or os.getenv(
43-
"CIRQ_SCALEWAY_API_TOKEN"
44-
)
45-
env_project_id = dotenv_values().get("CIRQ_SCALEWAY_PROJECT_ID") or os.getenv(
46-
"CIRQ_SCALEWAY_PROJECT_ID"
47-
)
48-
env_api_url = dotenv_values().get("CIRQ_SCALEWAY_API_URL") or os.getenv(
49-
"CIRQ_SCALEWAY_API_URL"
50-
)
39+
secret_key = secret_key or os.getenv("CIRQ_SCALEWAY_SECRET_KEY")
40+
project_id = project_id or os.getenv("CIRQ_SCALEWAY_PROJECT_ID")
41+
url = url or os.getenv("CIRQ_SCALEWAY_API_URL")
5142

52-
token = secret_key or env_token
53-
if token is None:
43+
if secret_key is None:
5444
raise Exception("secret_key is missing")
5545

56-
project_id = project_id or env_project_id
5746
if project_id is None:
5847
raise Exception("project_id is missing")
5948

60-
api_url = url or env_api_url or _ENDPOINT_URL
61-
62-
self.__client = QaaSClient(url=api_url, token=token, project_id=project_id)
49+
self.__client = QaaSClient(
50+
url=url, secret_key=secret_key, project_id=project_id
51+
)
6352

6453
def device(self, name: str) -> ScalewayDevice:
6554
"""Returns a device matching the specified name.
@@ -97,20 +86,16 @@ def devices(self, name: Optional[str] = None, **kwargs) -> List[ScalewayDevice]:
9786
if kwargs.get("min_num_qubits") is not None:
9887
filters["min_num_qubits"] = kwargs.pop("min_num_qubits", None)
9988

100-
json_resp = self.__client.list_platforms(name)
89+
platforms = self.__client.list_platforms(name)
10190

102-
for platform_dict in json_resp["platforms"]:
103-
backend_name = platform_dict.get("backend_name")
91+
for platform in platforms:
92+
backend_name = platform.backend_name
10493

10594
if backend_name == "qsim":
10695
scaleway_platforms.append(
10796
ScalewayDevice(
10897
client=self.__client,
109-
id=platform_dict.get("id"),
110-
name=platform_dict.get("name"),
111-
version=platform_dict.get("version"),
112-
num_qubits=platform_dict.get("max_qubit_count"),
113-
metadata=platform_dict.get("metadata", None),
98+
platform=platform,
11499
)
115100
)
116101

0 commit comments

Comments
 (0)