dwavesystems / dwavesystems/dwave-system

DWaveSampler returns done() prematurely

Open
#297 5 comments 0 reactions 0 assignees View on GitHub
bug/fix
Dominant language
Python
Stars
98
Forks
67
Avg merge
7m
Merged PRs (30d)
1

Description

**Description**
Jobs submitted asynchronously to a `DWaveSampler` à la the [example in the `from_future` documentation](https://docs.ocean.dwavesys.com/en/stable/docs_dimod/reference/generated/dimod.SampleSet.from_future.html#dimod.SampleSet.from_future) may return `done() == True` before they're actually done.

**To Reproduce**
Consider the following code:
```Python
#! /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:
```bash
./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:
```bash
./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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.