MCPcopy Create free account
hub / github.com/dwavesystems/dwave-cloud-client / Future

Class Future

dwave/cloud/computation.py:53–992  ·  view source on GitHub ↗

Class for interacting with jobs submitted to SAPI. :class:`~dwave.cloud.solver.Solver` uses :class:`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 t

Source from the content-addressed store, hash-verified

51
52@functools.total_ordering
53class Future(object):
54 """Class for interacting with jobs submitted to SAPI.
55
56 :class:`~dwave.cloud.solver.Solver` uses :class:`Future` to construct
57 objects for pending SAPI calls that can wait for requests to complete and
58 parse returned messages.
59
60 Objects are blocked for the duration of any data accessed on the remote
61 resource.
62
63 Warning:
64 :class:`Future` objects are not intended to be directly
65 created. Problem submittal is initiated by one of the solvers in
66 :mod:`~dwave.cloud.solver` module and executed by one of the clients.
67
68 Args:
69 solver (:class:`~dwave.cloud.solver.Solver`):
70 Solver responsible for this :class:`Future` object.
71
72 id_ (str, optional, default=None):
73 Identification for a query submitted by a solver to SAPI. May be
74 None following submission until an identification number is set.
75
76 return_matrix (bool, optional, default=False):
77 Return values for this :class:`Future` object are NumPy matrices.
78
79 Examples:
80 This example creates a solver using the local system's default D-Wave
81 Cloud Client configuration file, submits a simple QUBO problem to a
82 remote D-Wave resource for 100 samples, and checks a couple of times
83 whether the sampling is completed.
84
85 >>> from dwave.cloud import Client
86 >>> client = Client.from_config() # doctest: +SKIP
87 >>> solver = client.get_solver() # doctest: +SKIP
88 >>> u, v = next(iter(solver.edges)) # doctest: +SKIP
89 >>> Q = {(u, u): -1, (u, v): 0, (v, u): 2, (v, v): -1} # doctest: +SKIP
90 >>> computation = solver.sample_qubo(Q, num_reads=100) # doctest: +SKIP
91 >>> computation.done() # doctest: +SKIP
92 False
93 >>> computation.id # doctest: +SKIP
94 '1cefeb6d-ebd5-4592-87c0-4cc43ec03e27'
95 >>> computation.done() # doctest: +SKIP
96 True
97 >>> client.close() # doctest: +SKIP
98 """
99
100 def __init__(self, solver, id_, return_matrix=False):
101 self.solver = solver
102
103 # Has the client tried to cancel this job
104 self._cancel_requested = False
105 self._cancel_sent = False
106 self._single_cancel_lock = threading.Lock() # Make sure we only call cancel once
107
108 # ID readiness notification
109 self._id_ready_event = threading.Event()
110

Callers 7

sample_problemMethod · 0.90
_sampleMethod · 0.90
retrieve_answerMethod · 0.90
test_cancel_with_idMethod · 0.90
test_id_getter_setterMethod · 0.90
test_sampleset_idMethod · 0.90
test_retrieve_failsMethod · 0.90

Calls

no outgoing calls

Tested by 4

test_cancel_with_idMethod · 0.72
test_id_getter_setterMethod · 0.72
test_sampleset_idMethod · 0.72
test_retrieve_failsMethod · 0.72