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 a done() method, this determines the value returned by SampleSet.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 to

    def result_hook(future):
        return future.result()
    

Returns:

SampleSet

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