author | description | ms.author | ms.date | ms.service | ms.subservice | ms.topic | title | uid |
---|---|---|---|---|---|---|---|---|
bradben |
This document provides a basic guide to interpreting results of optimization problems solved in Azure Quantum using Python. |
brbenefield |
10/25/2021 |
azure-quantum |
optimization |
reference |
Understand solver results |
microsoft.quantum.optimization.understand-solver-results |
The result of a solver job is a JobOutput
object which can be examined to obtain useful information.
Some of the useful properties in a JobOutput
object are:
configuration
: A dictionary that describes the assignment of variables, where, for each key-value pair in the dictionary, the key is the index of a variable and value is the value assigned to that variable by the solver.cost
: The optimized solution to the problem when theconfiguration
is applied to the variables.parameters
: This field is present when a parameter-free solver is used. It contains the optimal parameters found by the solver for the specific problem submitted. Different solvers take different parameters to solve the problem. The examples that follow show:all_betas
: An array of the starting temperatures for the parallel tempering solver.replicas
: The number of runs of the solver before evaluating the best configuration from all the runs.sweeps
: The number of Monte Carlo steps performed in each iteration of the solver.
solutions
: Contains all the solutions that the solver returns. This includes the best solution found, which is also contained inconfiguration
.
The following example shows how to print the result if a solver job was submitted synchronously.
result = solver.optimize(problem)
print(result)
The next example shows the asynchronous version.
job = solver.submit(problem)
result = job.get_results()
print(result)
In both cases, the result should look like the following:
> {'version': '1.0', 'configuration': {'0': 1, '1': 1, '2': -1, '3': 1}, 'cost': -32.0, 'parameters': {'all_betas': [0.1,0.5,1,2,4], 'replicas': 70, 'sweeps': 600}, 'solutions':[{'configuration': {'0': 1, '1': 1, '2': -1, '3': 1}, 'cost': -32.0}]}
Important
Currently, the solution appears in both the root of the payload ('configuration' and 'cost') as well as in the 'solutions' field. However, it is recommended to consume solutions from the 'solutions' field, as the root 'configuration' and 'cost' fields will be deprecated in the future.
The best solution found by the solver will always appear in index 0 of the 'solutions' list (if multiple solutions are specified). You can specify the amount of solutions that you would like to receive when configuring your solver.
Here is an example of a small problem where two solutions are returned.
> {'version': '1.0', 'configuration': {'0': 1, '1': -1, '2': 1, '3': 1}, 'cost': -32.0, 'parameters': {'all_betas': [0.1,0.5,1,2,4], 'replicas': 70, 'sweeps': 600}, 'solutions':[{'configuration': {'0': 1, '1': -1, '2': 1, '3': 1}, 'cost': -32.0}, {'configuration': {'0': -1, '1': 1, '2': -1, '3': -1}, 'cost': -32.0}]}
- Re-use problem definitions
- Solve long-running problems
- Solver overview
- Expressing problems & supplying terms
- Understand solver results