Get Started

Results

Results

When you solve an optimization problem by submitting and running a job using qci-client, you will get back a response object. We'll show how to extract information from the response object using some Python code examples.
This is an example of a call to run a job using qci-client:
1
response = qc.process_job(job_type=job_type, job_body=job_body, wait=True)

Checking for errors

Before attempting to decode the response, It is good practice to check the response object for the status (success or failure) of the request. The following code will check for an error response. If there is an error, we print details of the error:
123
if response['job_info']['details']['status'] == "ERROR":
    print(response['job_info']['details']['status'])
    print(response['job_info']['results']['error'])

Inspecting results

The code below shows a more complete example which first checks for an error response. If the request was successful (no error), we print out some useful data elements in the response:
1234567891011
if response['job_info']['details']['status'] == "ERROR":
    print(response['job_info']['details']['status'])
    print(response['job_info']['results']['error'])
else:
    results = response["results"]

    print("Results:")
    print(f"is_feasible: {results['is_feasible']}")
    print(f"energies: {results['energies']}")
    print(f"counts: {results['counts']}")
    print(f"samples: {results['samples']}")
Sample output:
12345
Results:
is_feasible: [False]
energies: [4]
counts: [1]
samples: [[1, 0]]
response["results"] contains the results of running an optimization problem on a quantum computer.
The code above prints some of most common values from response["results"] that most users will want to review to understand the result ("the answer") of running their optimization problem.
To see all the fields and values which are returned in response["results"], use:
1234
results = response["results"]
print(results)
for item in results:
    print(f"{item}: {results[item]}")
Graph Partitioning results
For a 3 nodes graph problem
1
nx.random_geometric_graph(n=3, radius=0.4, dim=2)
a sample output of response["results"] will output
123456789101112131415
{'balance': [0.75, 0.75, 0.75, 0.75, 0.75, 0.75, 0.5, 0.5],
 'counts': [1, 1, 1, 1, 1, 1, 1, 1],
 'cut_size': [-1.5, -1.5, -1, -1, 0.5, 0.5, 0, 0],
 'energies': [-12, -12, -10, -10, -4, -4, 0, 0],
 'is_feasible': [True, True, True, True, True, True, True, True],
 'samples': [[{'class': 0, 'id': 0},
   {'class': 0, 'id': 2},
   {'class': 1, 'id': 1}],
  [{'class': 0, 'id': 1}, {'class': 1, 'id': 0}, {'class': 1, 'id': 2}],
  [{'class': 0, 'id': 1}, {'class': 0, 'id': 2}, {'class': 1, 'id': 0}],
  [{'class': 0, 'id': 0}, {'class': 1, 'id': 1}, {'class': 1, 'id': 2}],
  [{'class': 0, 'id': 2}, {'class': 1, 'id': 0}, {'class': 1, 'id': 1}],
  [{'class': 0, 'id': 0}, {'class': 0, 'id': 1}, {'class': 1, 'id': 2}],
  [{'class': 1, 'id': 0}, {'class': 1, 'id': 1}, {'class': 1, 'id': 2}],
  [{'class': 0, 'id': 0}, {'class': 0, 'id': 1}, {'class': 0, 'id': 2}]]}
Additional elements, on top of counts, energies, samples, and is_feasible in the response body, include:
  • balance - the partition balance
  • cut_size - weighted cut size
Further, in samples, each sample is a list of dicts, where each dict element is structured as
1
{'class': x, 'id': xx}
  • 'id' - node number
  • 'class' - partition index
Community Detection results
For a 3 nodes graph
1
nx.random_geometric_graph(n=3, radius=0.4, dim=2)
a sample output of response["results"] will output
123456789101112
{'counts': [1, 1, 1, 1, 1, 1, 1, 1],
 'energies': [-4.5, -4.5, -2, -2, -0.5, -0.5, 0, 0],
 'is_feasible': [True, True, True, True, True, True, True, True],
 'modularity': [-1.125, -1.125, -0.5, -0.5, -0.125, -0.125, 0, 0],
 'samples': [[{'class': 0, 'id': 1}, {'class': 1, 'id': 0}, {'class': 1, 'id': 2}],
  [{'class': 0, 'id': 0}, {'class': 0, 'id': 2}, {'class': 1, 'id': 1}],
  [{'class': 0, 'id': 0}, {'class': 1, 'id': 1}, {'class': 1, 'id': 2}],
  [{'class': 0, 'id': 1}, {'class': 0, 'id': 2}, {'class': 1, 'id': 0}],
  [{'class': 0, 'id': 2}, {'class': 1, 'id': 0}, {'class': 1, 'id': 1}],
  [{'class': 0, 'id': 0}, {'class': 0, 'id': 1}, {'class': 1, 'id': 2}],
  [{'class': 0, 'id': 0}, {'class': 0, 'id': 1}, {'class': 0, 'id': 2}],
  [{'class': 1, 'id': 0}, {'class': 1, 'id': 1}, {'class': 1, 'id': 2}]]}
Additional elements, on top of counts, energies, samples, and is_feasible in the response body, include:
  • modularity - community detection measure of network modularity
Further, in samples, each sample is a list of dicts, where each dict element is structured as
1
{'class': x, 'id': xx}
  • 'id' - node number
  • 'class' - partition index.

Viewing additional job information

In addition to response["results"], there is additional information available in response["job_info"]. The information returned in response["job_info"] is not normally needed in order to understand the result or the "answer" to the problem The information returned in response["job_info"] includes the status of the job (as seen above), copies of parameters that were used to run the job, and job timing information.
The following code will print the information returned in response["job_info"]:
123
job_info = response["job_info"]
for item in job_info:
    print(f"{item}: {job_info[item]}")
Sample output:
12345
details: {'status': 'COMPLETED', 'type': 'sample_constraint', 'organization_id': '54321', 'username': 'sample_user'}
results: {'file_id': '65432'}
submission: {'job_name': 'constraint_job_0', ... 'params': {'nsamples': 5, 'sampler_type': 'eqc1'}}
metrics: {'time_ns': {'wall': {'start': 1685649144515407214, 'end': 1685649162169957345, 'total': 17654550131, ... }}}
job_info['details'] contains information about the status (success or failure) if the job
job_info['submission'] contains references to files containing the data for the problem that was run, and parameters that were specified when running the problem.
job_info['metrics'] contains timing metrics showing how long it took to solve the problem on the quantum computer, how long the problem waited in a queue before being run, etc... More details on the timing metrics can be found on the Timing Information page.

Contents