Computation#

Computation manages the interactions between your code and a solver, which manages interactions between the remote resource and your submitted problems.

Your solver instantiates a Future object for its calls, via D-Wave Sampler API (SAPI) servers, to the remote resource.

You can interact through the Future object with pending (running) or completed computation—sampling on a QPU or software solver—executed remotely, monitoring problem status, waiting for and retrieving results, cancelling enqueued jobs, etc.

Some Future methods are blocking.

Class#

class Future(solver, id_, return_matrix=False)[source]#

Class for interacting with jobs submitted to SAPI.

Solver uses Future to construct objects for pending SAPI calls that can wait for requests to complete and parse returned messages.

Objects are blocked for the duration of any data accessed on the remote resource.

Warning

Future objects are not intended to be directly created. Problem submittal is initiated by one of the solvers in solver module and executed by one of the clients.

Parameters:
  • solver (Solver) – Solver responsible for this Future object.

  • id (str, optional, default=None) – Identification for a query submitted by a solver to SAPI. May be None following submission until an identification number is set.

  • return_matrix (bool, optional, default=False) – Return values for this Future object are NumPy matrices.

Examples

This example creates a solver using the local system’s default D-Wave Cloud Client configuration file, submits a simple QUBO problem to a remote D-Wave resource for 100 samples, and checks a couple of times whether the sampling is completed.

>>> from dwave.cloud import Client
>>> client = Client.from_config()       
>>> solver = client.get_solver()        
>>> u, v = next(iter(solver.edges))     
>>> Q = {(u, u): -1, (u, v): 0, (v, u): 2, (v, v): -1}   
>>> computation = solver.sample_qubo(Q, num_reads=100)   
>>> computation.done()  
False
>>> computation.id   
'1cefeb6d-ebd5-4592-87c0-4cc43ec03e27'
>>> computation.done()   
True
>>> client.close()       

Methods#

Future.result()

Results for a submitted job.

Future.exception()

Future.as_completed(fs[, timeout])

Yield Futures objects as they complete.

Future.wait([timeout])

Wait for the solver to receive a response for a submitted problem.

Future.wait_id([timeout])

Blocking id getter.

Future.wait_sampleset()

Blocking sampleset getter.

Future.wait_multiple(futures[, min_done, ...])

Wait for multiple Future objects to complete.

Future.done()

Check whether the solver received a response for a submitted problem.

Future.cancel()

Try to cancel the problem corresponding to this result.

Properties#

Future.samples

State buffer for the submitted job.

Future.variables

List of active variables in response/answer.

Future.energies

Energy buffer for the submitted job.

Future.num_occurrences

Number of sample occurrences buffer for the submitted job.

Future.sampleset

Return SampleSet representation of the results.

Future.id

The id the server will use to identify this problem, None until the id is actually known

Future.problem_type

Submitted problem type for this computation, as returned by the solver API.

Future.timing

Timing information about a solver operation.