dwave.system.samplers.DWaveSampler.sample¶
-
DWaveSampler.
sample
(bqm, **parameters)¶ Samples from a binary quadratic model using an implemented sample method.
Examples
This example implements a placeholder Ising sampler and samples using the mixin binary quadratic model sampler.
>>> import dimod >>> class ImplementIsingSampler(dimod.Sampler): ... def sample_ising(self, h, J): ... return dimod.Response.from_dicts([{1: -1, 2: +1}], {'energy': [-1.0]}) # Placeholder ... @property ... def properties(self): ... return self._properties ... @property ... def parameters(self): ... return dict() ... >>> sampler = ImplementIsingSampler() >>> model = dimod.BinaryQuadraticModel({0: 1, 1: -1, 2: .5}, ... {(0, 1): .5, (1, 2): 1.5}, ... 1.4, ... dimod.SPIN) >>> response = sampler.sample(model) >>> print(response) [[-1 1]]