dwave.cloud.computation.Future.as_completed

static Future.as_completed(fs, timeout=None)[source]

Yield Futures objects as they complete.

Returns an iterator over the specified list of Future objects that yields those objects as they complete. Completion occurs when the submitted job is finished or cancelled.

Emulates the behavior of the concurrent.futures.as_completed() function.

Parameters:
  • fs (list) – List of Future objects to iterate over.
  • timeout (float, optional, default=None) – Maximum number of seconds to await completion. If None, awaits indefinitely.
Returns:

Listed Future objects as they complete.

Return type:

Generator (Future objects)

Raises:
  • concurrent.futures.TimeoutError is raised if per-future timeout is
  • exceeded.

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 yields timing information for each job as it completes.

>>> 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
>>> for tasks in dc.computation.Future.as_completed(computation, timeout=10)
...     print(tasks.timing)   # doctest: +SKIP
...
{'total_real_time': 17318, ... 'qpu_readout_time_per_sample': 123}
{'total_real_time': 10816, ... 'qpu_readout_time_per_sample': 123}
{'total_real_time': 26285, ... 'qpu_readout_time_per_sample': 123}
...
>>> client.close()