dwave.cloud.computation.Future.wait_multiple

static Future.wait_multiple(futures, min_done=None, timeout=None)[source]

Wait for multiple Future objects to complete.

Blocking call that uses an event object to emulate multi-wait for Python.

Parameters:
  • futures (list of Futures) – List of Future objects to await.
  • min_done (int, optional, default=None) – Minimum required completions to end the waiting. The wait is terminated when this number of results are ready. If None, waits for all the Future objects to complete.
  • timeout (float, optional, default=None) – Maximum number of seconds to await completion. If None, waits indefinitely.
Returns:

completed and not completed submitted tasks. Similar to concurrent.futures.wait() method’s returned two-tuple of done and not_done sets.

Return type:

Two-tuple of Future objects

See also

as_completed() for a blocking iterable of resolved futures similar to concurrent.futures.as_completed() method.

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 3 times for differing numers of samples, and waits for sampling to complete on any two of the submissions. The wait ends with the completion of two submissions while the third is still in progress. (A more typical approach would use something like first = next(Future.as_completed(computation)) instead.)

>>> import dwave.cloud as dc
>>> client = dc.Client.from_config()
>>> solver = client.get_solver()      # doctest: +SKIP
>>> u, v = next(iter(solver.edges))   # doctest: +SKIP
>>> Q = {(u, u): -1, (u, v): 0, (v, u): 2, (v, v): -1}    # doctest: +SKIP
>>> computation = [solver.sample_qubo(Q, num_reads=1000),
...                solver.sample_qubo(Q, num_reads=50),
...                solver.sample_qubo(Q, num_reads=10)]   # doctest: +SKIP
>>> dc.computation.Future.wait_multiple(computation, min_done=1)    # doctest: +SKIP
([<dwave.cloud.computation.Future at 0x17dde518>,
  <dwave.cloud.computation.Future at 0x17ddee80>],
 [<dwave.cloud.computation.Future at 0x15078080>])
>>> print(computation[0].done())   # doctest: +SKIP
False
>>> print(computation[1].done())  # doctest: +SKIP
True
>>> print(computation[2].done())   # doctest: +SKIP
True
>>> client.close()