author | description | ms.author | ms.date | ms.service | ms.subservice | ms.topic | title | uid |
---|---|---|---|---|---|---|---|---|
KittyYeungQ |
This document provides a basic guide to solving long-running problems in Azure Quantum using Python. |
kitty |
02/01/2021 |
azure-quantum |
optimization |
how-to |
Solve long-running problems |
microsoft.quantum.optimization.solve-long-running-problems |
In the example in Apply solvers to solve optimization problems, a problem was submitted to Azure Quantum and solved synchronously. This is convenient for certain environments, but unsuitable for others where there is a need to either submit a problem and check on it later, or submit many problems and compare the results.
To submit a problem asynchronously, use the submit
method on the solver
. This submits a Job
which is returned by the method:
solver = ParallelTempering(workspace, timeout=100, seed=11)
job = solver.submit(problem)
print(job.id)
> ea81bb40-682f-11ea-8271-c49dede60d7c
After submitting the job, you can check on the status of the job by calling the
refresh
method. Each time refresh
is called, the job metadata gets refreshed.
job.refresh()
print(job.details.status)
> Succeeded
Once the job is in a final state, such as Succeeded
, you may download the job output using get_results
:
jobId = "ea81bb40-682f-11ea-8271-c49dede60d7c"
job = workspace.get_job(jobId)
result = job.get_results()
print(result)
> {'solutions': [{'configuration': {'0': 1, '1': 1, '2': -1, '3': 1}, 'cost': -32.0}]}