diff --git a/src/quantum/azext_quantum/commands.py b/src/quantum/azext_quantum/commands.py index 8dba4d30994..b99e711e29c 100644 --- a/src/quantum/azext_quantum/commands.py +++ b/src/quantum/azext_quantum/commands.py @@ -64,7 +64,7 @@ def one(key, value): return OrderedDict([ ('Result', key), ('Frequency', f"{value:10.8f}"), - ('', f"\u2590{barra:<22} |"), + ('', f"\u007C{barra:^20}\u007C") ]) if 'Histogram' in results: diff --git a/src/quantum/azext_quantum/operations/job.py b/src/quantum/azext_quantum/operations/job.py index 97cedc129a1..776f7c51bf0 100644 --- a/src/quantum/azext_quantum/operations/job.py +++ b/src/quantum/azext_quantum/operations/job.py @@ -186,16 +186,15 @@ def output(cmd, job_id, resource_group_name=None, workspace_name=None, location= from azure.cli.command_modules.storage._client_factory import blob_data_service_factory path = os.path.join(tempfile.gettempdir(), job_id) + info = WorkspaceInfo(cmd, resource_group_name, workspace_name, location) + client = cf_jobs(cmd.cli_ctx, info.subscription, info.resource_group, info.name, info.location) + job = client.get(job_id) if os.path.exists(path): logger.debug("Using existing blob from %s", path) else: logger.debug("Downloading job results blob into %s", path) - info = WorkspaceInfo(cmd, resource_group_name, workspace_name, location) - client = cf_jobs(cmd.cli_ctx, info.subscription, info.resource_group, info.name, info.location) - job = client.get(job_id) - if job.status != "Succeeded": return f"Job status: {job.status}. Output only available if Succeeded." @@ -204,7 +203,22 @@ def output(cmd, job_id, resource_group_name=None, workspace_name=None, location= blob_service.get_blob_to_path(args['container'], args['blob'], path) with open(path) as json_file: - data = json.load(json_file) + if job.target.startswith("microsoft.simulator"): + + lines = [line.strip() for line in json_file.readlines()] + result_start_line = len(lines) - 1 + if lines[-1].endswith('"'): + while not lines[result_start_line].startswith('"'): + result_start_line -= 1 + + print('\n'.join(lines[:result_start_line])) + result = ' '.join(lines[result_start_line:])[1:-1] # seems the cleanest version to display + print("_" * len(result) + "\n") + + json_string = "{ \"histogram\" : { \"" + result + "\" : 1 } }" + data = json.loads(json_string) + else: + data = json.load(json_file) return data