Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend handling of job output to consider empty responses #3776

Merged
merged 2 commits into from
Aug 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/quantum/azext_quantum/operations/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,25 @@ 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:
if job.target.startswith("microsoft.simulator"):
lines = [line.strip() for line in json_file.readlines()]

# Receiving an empty response is valid.
if len(lines) == 0:
return

lines = [line.strip() for line in json_file.readlines()]
if job.target.startswith("microsoft.simulator"):
result_start_line = len(lines) - 1
if lines[-1].endswith('"'):
while not lines[result_start_line].startswith('"'):
while result_start_line >= 0 and not lines[result_start_line].startswith('"'):
result_start_line -= 1
if result_start_line < 0:
raise CLIError("Job output is malformed, mismatched quote characters.")

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")
print('_' * len(result) + '\n')

json_string = "{ \"histogram\" : { \"" + result + "\" : 1 } }"
json_string = '{ "histogram" : { "' + result + '" : 1 } }'
data = json.loads(json_string)
else:
data = json.load(json_file)
Expand Down