11import json
2+ import randomname
23
3- from typing import List , Optional , Dict
4+ from typing import List , Optional , Dict , Union
45
56from quantum_as_a_service_api_client .models import (
67 CreateJobBody ,
1415)
1516
1617from 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 ,
1822)
1923from quantum_as_a_service_api_client .api .sessions .terminate_session import (
20- sync as terminate_session_sync ,
24+ sync as _terminate_session_sync ,
2125)
2226from 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 ,
2428)
2529from quantum_as_a_service_api_client .api .platforms .list_platforms import (
26- sync as list_platforms_sync ,
30+ sync as _list_platforms_sync ,
2731)
2832from quantum_as_a_service_api_client .api .jobs .create_job import (
29- sync as create_job_sync ,
33+ sync as _create_job_sync ,
3034)
3135from quantum_as_a_service_api_client .api .jobs .get_job import (
32- sync as get_job_sync ,
36+ sync as _get_job_sync ,
3337)
3438from 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 ,
3640)
3741
3842from quantum_as_a_service_api_client .client import Client
4246
4347
4448class 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 ):
4750 self .__project_id = project_id
4851
4952 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 ,
5255 timeout = 10.0 ,
5356 verify_ssl = "https" in url ,
5457 )
5558
5659 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 )
5861
5962 assert response
6063
6164 return response .platforms
6265
6366 def create_session (
6467 self ,
65- name : str ,
6668 platform_id : str ,
67- deduplication_id : str ,
6869 max_duration : str ,
6970 max_idle_duration : str ,
71+ deduplication_id : Optional [str ] = None ,
72+ name : Optional [str ] = None ,
7073 ) -> ScalewayQaasV1Alpha1Session :
71- session = create_session_sync (
74+ name = name if name else f"qs-{ randomname .get_name ()} "
75+
76+ session = _create_session_sync (
7277 client = self .__client ,
7378 body = CreateSessionBody (
7479 project_id = self .__project_id ,
@@ -82,8 +87,13 @@ def create_session(
8287
8388 return session
8489
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+
8595 def terminate_session (self , session_id : str ) -> ScalewayQaasV1Alpha1Session :
86- session = terminate_session_sync (
96+ session = _terminate_session_sync (
8797 client = self .__client ,
8898 body = TerminateSessionBody (
8999 session_id = session_id ,
@@ -93,30 +103,34 @@ def terminate_session(self, session_id: str) -> ScalewayQaasV1Alpha1Session:
93103 return session
94104
95105 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 )
97107
98108 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 ,
100113 ) -> 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 ()} "
102116
103- job = create_job_sync (
117+ job = _create_job_sync (
104118 client = self .__client ,
105119 body = CreateJobBody (
106120 name = name ,
107121 session_id = session_id ,
108- circuit = CreateJobBodyCircuit (qiskit_circuit = circuits ),
122+ circuit = CreateJobBodyCircuit (qiskit_circuit = payload ),
109123 ),
110124 )
111125
112126 return job
113127
114128 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 )
116130
117131 return job
118132
119133 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 )
121135
122136 return response .job_results
0 commit comments