Skip to content

Commit b4e0709

Browse files
authored
Updating the quantum extension to add simulator support (Azure#3575)
This PR edits the output function to allow for jobs that run on the simulator to have output logged during execution that is not in json format. For simulator jobs, we expect the job result to be printed as the last item on its own line, and string output to be enclosed with `"`.
1 parent e44bb62 commit b4e0709

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/quantum/azext_quantum/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def one(key, value):
6464
return OrderedDict([
6565
('Result', key),
6666
('Frequency', f"{value:10.8f}"),
67-
('', f"\u2590{barra:<22} |"),
67+
('', f"\u007C{barra:^20}\u007C")
6868
])
6969

7070
if 'Histogram' in results:

src/quantum/azext_quantum/operations/job.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,15 @@ def output(cmd, job_id, resource_group_name=None, workspace_name=None, location=
186186
from azure.cli.command_modules.storage._client_factory import blob_data_service_factory
187187

188188
path = os.path.join(tempfile.gettempdir(), job_id)
189+
info = WorkspaceInfo(cmd, resource_group_name, workspace_name, location)
190+
client = cf_jobs(cmd.cli_ctx, info.subscription, info.resource_group, info.name, info.location)
191+
job = client.get(job_id)
189192

190193
if os.path.exists(path):
191194
logger.debug("Using existing blob from %s", path)
192195
else:
193196
logger.debug("Downloading job results blob into %s", path)
194197

195-
info = WorkspaceInfo(cmd, resource_group_name, workspace_name, location)
196-
client = cf_jobs(cmd.cli_ctx, info.subscription, info.resource_group, info.name, info.location)
197-
job = client.get(job_id)
198-
199198
if job.status != "Succeeded":
200199
return f"Job status: {job.status}. Output only available if Succeeded."
201200

@@ -204,7 +203,22 @@ def output(cmd, job_id, resource_group_name=None, workspace_name=None, location=
204203
blob_service.get_blob_to_path(args['container'], args['blob'], path)
205204

206205
with open(path) as json_file:
207-
data = json.load(json_file)
206+
if job.target.startswith("microsoft.simulator"):
207+
208+
lines = [line.strip() for line in json_file.readlines()]
209+
result_start_line = len(lines) - 1
210+
if lines[-1].endswith('"'):
211+
while not lines[result_start_line].startswith('"'):
212+
result_start_line -= 1
213+
214+
print('\n'.join(lines[:result_start_line]))
215+
result = ' '.join(lines[result_start_line:])[1:-1] # seems the cleanest version to display
216+
print("_" * len(result) + "\n")
217+
218+
json_string = "{ \"histogram\" : { \"" + result + "\" : 1 } }"
219+
data = json.loads(json_string)
220+
else:
221+
data = json.load(json_file)
208222
return data
209223

210224

0 commit comments

Comments
 (0)