dwave-system icon indicating copy to clipboard operation
dwave-system copied to clipboard

Turn DWaveSampler into context manager

Open randomir opened this issue 7 years ago • 2 comments

Blocked by https://github.com/dwavesystems/dwave-system/issues/77.

randomir avatar Jul 19 '18 18:07 randomir

One thing we could do is only keep the thread pool open if inside a context. So

sampler = DWaveSampler()
sampler.sample_ising(...)
sampler.sample_ising(...)

would be equivalent (from a cloud-client perspective) to

with DWaveSampler() as sampler:
    sampler.sample_ising(...)
with DWaveSampler() as sampler:
    sampler.sample_ising(...)

where as

with DWaveSampler() as sampler:
    sampler.sample_ising(...)
    sampler.sample_ising(...)

would only open one thread pool.

However this would impact performance pretty significantly in the case of multiple calls outside of a context manager. Probably better to do the singleton threadpool mentioned by @randomir in https://github.com/dwavesystems/dwave-system/issues/171#issuecomment-480991050.

arcondello avatar Sep 30 '19 22:09 arcondello

@arcondello, I think we'll soon have singleton threadpools, as they are related to https://github.com/dwavesystems/dwave-cloud-client/issues/326.

randomir avatar Oct 01 '19 18:10 randomir