dimod.SampleSet.from_future#
- classmethod SampleSet.from_future(future, result_hook=None)[source]#
Construct a
SampleSet
referencing the result of a future computation.- Parameters:
future (object) – Object that contains or will contain the information needed to construct a
SampleSet
. If future has adone()
method, this determines the value returned bySampleSet.done()
.result_hook (callable, optional) –
A function that is called to resolve the future. Must accept the future and return a
SampleSet
. If not provided, set todef result_hook(future): return future.result()
- Returns:
Notes
The future is resolved on the first read of any of the
SampleSet
properties.Examples
Run a dimod sampler on a single thread and load the returned future into
SampleSet
.>>> from concurrent.futures import ThreadPoolExecutor ... >>> bqm = dimod.BinaryQuadraticModel.from_ising({}, {('a', 'b'): -1}) >>> with ThreadPoolExecutor(max_workers=1) as executor: ... future = executor.submit(dimod.ExactSolver().sample, bqm) ... sampleset = dimod.SampleSet.from_future(future) >>> sampleset.first.energy