33
44from typing import List , Union
55
6- from qami import (
6+ from qio . core import (
77 QuantumProgram ,
88 QuantumProgramResult ,
99 QuantumComputationModel ,
@@ -54,50 +54,49 @@ def deallocate(self, **kwargs) -> None:
5454 return
5555
5656 self .__client .terminate_session (self .__session_id )
57+ self .__session_id = None
5758
5859 def run (
5960 self ,
6061 program : Union [QuantumProgram , List [QuantumProgram ]],
6162 shots : int ,
62- wait : bool ,
6363 ** kwargs ,
6464 ) -> List [QuantumProgramResult ]:
6565 if not isinstance (program , list ):
6666 program = [program ]
6767
68- computation_model = QuantumComputationModel (
68+ computation_model_dict = QuantumComputationModel (
6969 programs = program ,
7070 backend = None ,
7171 client = None ,
7272 ).to_dict ()
7373
74- computation_parameters = QuantumComputationParameters (
74+ computation_parameters_dict = QuantumComputationParameters (
7575 shots = shots ,
7676 ).to_dict ()
7777
78- model = self .__client .create_model (computation_model )
78+ model = self .__client .create_model (computation_model_dict )
7979
8080 if not model :
8181 raise RuntimeError ("Failed to push model data" )
8282
83- job = self .__client .create_job (self .__session_id , model_id = model .id )
83+ job = self .__client .create_job (
84+ self .__session_id , model_id = model .id , parameters = computation_parameters_dict
85+ )
8486
85- if wait :
86- while job .status in ["waiting" , "running" ]:
87- time .sleep (2 )
88- job = self .__client .get_job (job .id )
87+ while job .status in ["waiting" , "running" ]:
88+ time .sleep (2 )
89+ job = self .__client .get_job (job .id )
8990
9091 if job .status == "error" :
9192 raise RuntimeError (f"Job failed with error: { job .progress_message } " )
9293
93- raw_results = self .__client .list_job_results (job .id )
94+ job_results = self .__client .list_job_results (job .id )
9495
9596 program_results = list (
9697 map (
97- lambda r : QuantumProgramResult .from_json (
98- self ._extract_payload_from_response (r )
99- ),
100- raw_results ,
98+ lambda r : self ._extract_payload_from_response (r ),
99+ job_results ,
101100 )
102101 )
103102
@@ -106,7 +105,9 @@ def run(
106105
107106 return program_results
108107
109- def _extract_payload_from_response (self , job_result : QaaSJobResult ) -> str :
108+ def _extract_payload_from_response (
109+ self , job_result : QaaSJobResult
110+ ) -> QuantumProgramResult :
110111 result = job_result .result
111112
112113 if result is None or result == "" :
@@ -115,12 +116,11 @@ def _extract_payload_from_response(self, job_result: QaaSJobResult) -> str:
115116 if url is not None :
116117 resp = httpx .get (url )
117118 resp .raise_for_status ()
118-
119- return resp .text
119+ result = resp .text
120120 else :
121121 raise RuntimeError ("Got result with empty data and url fields" )
122- else :
123- return result
122+
123+ return QuantumProgramResult . from_json ( result )
124124
125125 @property
126126 def max_qubit_count (self ) -> int :
0 commit comments