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

Method as_completed

dwave/cloud/computation.py:351–407  ·  view source on GitHub ↗

Yield Futures objects as they complete. Returns an iterator over the specified list of :class:`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.fut

(fs, timeout=None)

Source from the content-addressed store, hash-verified

349
350 @staticmethod
351 def as_completed(fs, timeout=None):
352 """Yield Futures objects as they complete.
353
354 Returns an iterator over the specified list of :class:`Future` objects
355 that yields those objects as they complete. Completion occurs when the
356 submitted job is finished or cancelled.
357
358 Emulates the behavior of the `concurrent.futures.as_completed()`
359 function.
360
361 Args:
362 fs (list):
363 List of :class:`Future` objects to iterate over.
364
365 timeout (float, optional, default=None):
366 Maximum number of seconds to await completion. If None, awaits
367 indefinitely.
368
369 Returns:
370 Generator (:class:`Future` objects):
371 Listed :class:`Future` objects as they complete.
372
373 Raises:
374 `concurrent.futures.TimeoutError` is raised if per-future timeout is
375 exceeded.
376
377 Examples:
378 This example creates a solver using the local system's default D-Wave
379 Cloud Client configuration file, submits a simple QUBO problem to a
380 remote D-Wave resource 3 times for differing numbers of samples, and
381 yields timing information for each job as it completes.
382
383 >>> import dwave.cloud as dc
384 >>> client = dc.Client.from_config() # doctest: +SKIP
385 >>> solver = client.get_solver() # doctest: +SKIP
386 >>> u, v = next(iter(solver.edges)) # doctest: +SKIP
387 >>> Q = {(u, u): -1, (u, v): 0, (v, u): 2, (v, v): -1} # doctest: +SKIP
388 >>> computation = [solver.sample_qubo(Q, num_reads=1000),
389 ... solver.sample_qubo(Q, num_reads=50),
390 ... solver.sample_qubo(Q, num_reads=10)] # doctest: +SKIP
391 >>> for tasks in dc.computation.Future.as_completed(computation, timeout=10)
392 ... print(tasks.timing) # doctest: +SKIP
393 ...
394 {'total_real_time': 17318, ... 'qpu_readout_time_per_sample': 123}
395 {'total_real_time': 10816, ... 'qpu_readout_time_per_sample': 123}
396 {'total_real_time': 26285, ... 'qpu_readout_time_per_sample': 123}
397 ...
398 >>> client.close() # doctest: +SKIP
399
400 """
401 not_done = fs
402 while not_done:
403 done, not_done = Future.wait_multiple(not_done, min_done=1, timeout=timeout)
404 if not done:
405 raise TimeoutError
406 for f in done:
407 yield f
408

Callers 2

multiple.pyFile · 0.80
test_as_completedMethod · 0.80

Calls 1

wait_multipleMethod · 0.80

Tested by 1

test_as_completedMethod · 0.64