Open spakin opened 4 years ago
If you change ss.done()
to ss._future.done()
does the behaviour stay the same? Or do you get an AttributeError
?
The behavior stays the same.
Cool bug! Without an obvious fix.
When a sample set is constructed using from_future
, it saves that future as an attribute on itself. So if you change your first while loop to
while not all([ss.done() for ss in samplesets]):
pass
else:
print(samplesets[0].done(), type(samplesets[0]._future), samplesets[0]._future.done())
you'll see that the future created by executor.submit(...)
is claiming to be done, which SampleSet
is then propagating to you.
The reason that the ThreadPoolExecutor's future is claiming to be done is because it is executing the .sample
method, which is successfully sampling, then not blocking. So the executor is seeing that job as "done".
One thing you could try is make a new function
def submit_and_block(*args, **kwargs):
ss = sampler.sample(*args, **kwargs)
ss.resolve()
return ss
then use that
futures.append(executor.submit(submit_and_block, bqm, ...))
I just plugged that into my "real" code, and it works! Thanks for the workaround.
Description Jobs submitted asynchronously to a
DWaveSampler
à la the example in thefrom_future
documentation may returndone() == True
before they're actually done.To Reproduce Consider the following code:
Run it with
sampler = DWaveSampler()
as written. Then comment out that line, uncomment thesampler = 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:However, with
sampler = DWaveSampler()
, most of the time is attributed to accessinginfo
, which implies to me that the future is returningdone() == True
before the job is actually done, and ticklinginfo
is forcing the wait for completion:Environment: