DWaveSampler returns done() prematurely

Open
#297 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
api, backend

Research direction

Reproduce the asynchronous example using DWaveSampler.sample, dimod.SampleSet.from_future, and the contrasting EmbeddingComposite case. Trace how done() and info are resolved, then add a regression test showing that done() does not precede job completion; the reported behavior should be corrected without changing the documented workflow.

Written by the indexing model from the issue text.

Description

bug/fix

Description
Jobs submitted asynchronously to a DWaveSampler à la the example in the from_future documentation may return done() == True before they're actually done.

To Reproduce
Consider the following code:

#! /usr/bin/env python

import dimod
from concurrent.futures import ThreadPoolExecutor
from dwave.system import DWaveSampler, EmbeddingComposite
import time

# Ensure some jobs.
njobs = 5
#sampler = EmbeddingComposite(DWaveSampler())
sampler = DWaveSampler()
bqm = dimod.BinaryQuadraticModel.from_ising({}, {(0, 4): -1})
executor = ThreadPoolExecutor()
futures = []
samplesets = []
for i in range(njobs):
    futures.append(executor.submit(sampler.sample, bqm, num_reads=1000, annealing_time=2000))
    samplesets.append(dimod.SampleSet.from_future(futures[i]))
executor.shutdown(wait=False)

# Report when they're finished.
print("Enqueued %d job(s)" % njobs)
start_time = time.time()
while not all([ss.done() for ss in samplesets]):
    pass
print("Done is claimed after %d second(s)" % (time.time() - start_time))
start_time = time.time()
info = []
for i in range(njobs):
    info.append(samplesets[i].info)
print("Have info after %d more second(s)" % (time.time() - start_time))

Run it with sampler = DWaveSampler() as written. Then comment out that line, uncomment the sampler = EmbeddingComposite(DWaveSampler()) line, and run it again.

Expected behavior
With sampler = EmbeddingComposite(DWaveSampler()), most of the time is attributed to waiting for all the jobs to finish, as expected:

./premature.py
Enqueued 5 job(s)
Done is claimed after 14 second(s)
Have info after 0 more second(s)

However, with sampler = DWaveSampler(), most of the time is attributed to accessing info, which implies to me that the future is returning done() == True before the job is actually done, and tickling info is forcing the wait for completion:

./premature.py
Enqueued 5 job(s)
Done is claimed after 0 second(s)
Have info after 13 more second(s)

Environment:

  • OS: Ubuntu 19.10
  • Python version: 3.8.2
Dominant language
Python
Stars
100
Forks
70
Avg merge
9h 33m
Merged PRs (30d)
4

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dwavesystems/dwave-system

All issues in dwavesystems/dwave-system

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.