dimod.Response.samples¶
-
Response.samples(n=None, sorted_by='energy')[source]¶ Iterate over the samples in the response.
Parameters: - n (int, optional, default=None) – The maximum number of samples to provide. If None, all are provided.
- sorted_by (str/None, optional, default='energy') – Selects the data_vector used to sort the samples. If None, the samples are yielded in the order given by the samples matrix.
Yields: SampleView– A view object mapping the variable labels to their values. Acts like a read-only dict.Examples
This example iterates over the response samples of the dimod ExactSolver sampler.
>>> import dimod >>> response = dimod.ExactSolver().sample_ising({'a': -0.5, 'b': 1.0}, {('a', 'b'): -1}) >>> for sample in response.samples(): # sorted_by='energy' ... print(sample['a']==sample['b']) ... True False True False >>> for sample in response.samples(sorted_by=None): ... print(sample) ... {'a': -1, 'b': -1} {'a': 1, 'b': -1} {'a': 1, 'b': 1} {'a': -1, 'b': 1}