1
1
import json
2
+ import randomname
2
3
3
- from typing import List , Optional , Dict
4
+ from typing import List , Optional , Dict , Union
4
5
5
6
from quantum_as_a_service_api_client .models import (
6
7
CreateJobBody ,
14
15
)
15
16
16
17
from quantum_as_a_service_api_client .api .sessions .create_session import (
17
- sync as create_session_sync ,
18
+ sync as _create_session_sync ,
19
+ )
20
+ from quantum_as_a_service_api_client .api .sessions .get_session import (
21
+ sync as _get_session_sync ,
18
22
)
19
23
from quantum_as_a_service_api_client .api .sessions .terminate_session import (
20
- sync as terminate_session_sync ,
24
+ sync as _terminate_session_sync ,
21
25
)
22
26
from quantum_as_a_service_api_client .api .sessions .delete_session import (
23
- sync_detailed as delete_session_sync ,
27
+ sync_detailed as _delete_session_sync ,
24
28
)
25
29
from quantum_as_a_service_api_client .api .platforms .list_platforms import (
26
- sync as list_platforms_sync ,
30
+ sync as _list_platforms_sync ,
27
31
)
28
32
from quantum_as_a_service_api_client .api .jobs .create_job import (
29
- sync as create_job_sync ,
33
+ sync as _create_job_sync ,
30
34
)
31
35
from quantum_as_a_service_api_client .api .jobs .get_job import (
32
- sync as get_job_sync ,
36
+ sync as _get_job_sync ,
33
37
)
34
38
from quantum_as_a_service_api_client .api .jobs .list_job_results import (
35
- sync as list_job_result_sync ,
39
+ sync as _list_job_result_sync ,
36
40
)
37
41
38
42
from quantum_as_a_service_api_client .client import Client
42
46
43
47
44
48
class QaaSClient :
45
- def __init__ (self , project_id : str , token : str , url : str = __DEFAULT_URL ):
46
- self .__token = token
49
+ def __init__ (self , project_id : str , secret_key : str , url : str = __DEFAULT_URL ):
47
50
self .__project_id = project_id
48
51
49
52
self .__client = Client (
50
- headers = {"X-Auth-Token" : self . __token },
51
- base_url = self . __url ,
53
+ headers = {"X-Auth-Token" : secret_key },
54
+ base_url = url ,
52
55
timeout = 10.0 ,
53
56
verify_ssl = "https" in url ,
54
57
)
55
58
56
59
def list_platforms (self , name : Optional [str ]) -> List [ScalewayQaasV1Alpha1Platform ]:
57
- response = list_platforms_sync (client = self .__client , name = name )
60
+ response = _list_platforms_sync (client = self .__client , name = name )
58
61
59
62
assert response
60
63
61
64
return response .platforms
62
65
63
66
def create_session (
64
67
self ,
65
- name : str ,
66
68
platform_id : str ,
67
- deduplication_id : str ,
68
69
max_duration : str ,
69
70
max_idle_duration : str ,
71
+ deduplication_id : Optional [str ] = None ,
72
+ name : Optional [str ] = None ,
70
73
) -> ScalewayQaasV1Alpha1Session :
71
- session = create_session_sync (
74
+ name = name if name else f"qs-{ randomname .get_name ()} "
75
+
76
+ session = _create_session_sync (
72
77
client = self .__client ,
73
78
body = CreateSessionBody (
74
79
project_id = self .__project_id ,
@@ -82,8 +87,13 @@ def create_session(
82
87
83
88
return session
84
89
90
+ def get_session (self , session_id : str ) -> ScalewayQaasV1Alpha1Session :
91
+ session = _get_session_sync (client = self .__client , session_id = session_id )
92
+
93
+ return session
94
+
85
95
def terminate_session (self , session_id : str ) -> ScalewayQaasV1Alpha1Session :
86
- session = terminate_session_sync (
96
+ session = _terminate_session_sync (
87
97
client = self .__client ,
88
98
body = TerminateSessionBody (
89
99
session_id = session_id ,
@@ -93,30 +103,34 @@ def terminate_session(self, session_id: str) -> ScalewayQaasV1Alpha1Session:
93
103
return session
94
104
95
105
def delete_session (self , session_id : str ):
96
- delete_session_sync (client = self .__client , session_id = session_id )
106
+ _delete_session_sync (client = self .__client , session_id = session_id )
97
107
98
108
def create_job (
99
- self , name : str , session_id : str , circuits : Dict
109
+ self ,
110
+ session_id : str ,
111
+ payload : Union [Dict , List , str ],
112
+ name : Optional [str ] = None ,
100
113
) -> ScalewayQaasV1Alpha1Job :
101
- circuits = circuits if isinstance (circuits , str ) else json .dumps (circuits )
114
+ payload = payload if isinstance (payload , str ) else json .dumps (payload )
115
+ name = name if name else f"qj-{ randomname .get_name ()} "
102
116
103
- job = create_job_sync (
117
+ job = _create_job_sync (
104
118
client = self .__client ,
105
119
body = CreateJobBody (
106
120
name = name ,
107
121
session_id = session_id ,
108
- circuit = CreateJobBodyCircuit (qiskit_circuit = circuits ),
122
+ circuit = CreateJobBodyCircuit (qiskit_circuit = payload ),
109
123
),
110
124
)
111
125
112
126
return job
113
127
114
128
def get_job (self , job_id : str ) -> ScalewayQaasV1Alpha1Job :
115
- job = get_job_sync (client = self .__client , job_id = job_id )
129
+ job = _get_job_sync (client = self .__client , job_id = job_id )
116
130
117
131
return job
118
132
119
133
def list_job_results (self , job_id : str ) -> List [ScalewayQaasV1Alpha1JobResult ]:
120
- response = list_job_result_sync (client = self .__client , job_id = job_id )
134
+ response = _list_job_result_sync (client = self .__client , job_id = job_id )
121
135
122
136
return response .job_results
0 commit comments