dimod.SampleSet.from_future¶
-
classmethod
SampleSet.from_future(future, result_hook=None)[source]¶ Construct a
SampleSetreferencing 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
SampleSetproperties.Examples
Run a dimod sampler on a single thread and load the returned future into
SampleSet.>>> import dimod >>> 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.record rec.array([([-1, -1], -1., 1), ([ 1, -1], 1., 1), ([ 1, 1], -1., 1), ([-1, 1], 1., 1)], dtype=[('sample', 'i1', (2,)), ('energy', '<f8'), ('num_occurrences', '<i8')])
- future (object) – Object that contains or will contain the information needed to construct a