dimod.reference.samplers.RandomSampler.sample¶
-
RandomSampler.sample(bqm, num_reads=10)[source]¶ Give random samples for a binary quadratic model.
Parameters: - bqm (
BinaryQuadraticModel) – Binary quadratic model to be sampled from. - num_reads (int, optional) – Number of reads.
Returns: A dimod
Responseobject.Return type: Notes
For each variable in each sample, the value is chosen by a coin flip.
Examples
This example provides samples for a two-variable Ising model.
>>> import dimod >>> sampler = dimod.RandomSampler() >>> h = {0: -1, 1: -1} >>> J = {(0, 1): -1} >>> bqm = dimod.BinaryQuadraticModel(h, J, -0.5, dimod.SPIN) >>> response = sampler.sample(bqm, num_reads=3) >>> len(response) 3 >>> response.data_vectors['energy'] array([ 0.5, -3.5, 0.5])
- bqm (