dimod.Response.from_dicts¶
-
classmethod
Response.from_dicts(samples, data_vectors, vartype=None, info=None)[source]¶ Build a response from an iterable of dicts.
Parameters: - samples (iterable[dict]) – Iterable of samples where each sample is a dictionary (or Mapping).
- data_vectors (dict[field,
numpy.array/list]) – Additional per-sample data as a dict of vectors. Each vector is the same length as samples_matrix. The key ‘energy’ and its vector are required. - vartype (
Vartype, optional, default=None) – Vartype of the response. If not provided, vartype is inferred from the samples matrix if possible or a ValueError is raised. - info (dict, optional, default=None) – Information about the response as a whole formatted as a dict.
Returns: A dimod
Responseobject based on the input dicts.Return type: Raises: ValueError– If vartype is not provided and samples are all 1s, have more than two unique values, or have values of an unknown vartype.Examples
This example code snippet builds a response from an interable of samples and its corresponding dict of energies.
samples = [{'a': -1, 'b': +1}, {'a': +1, 'b': -1}] energies = [-1.0, -1.0] response = Response.from_dicts(samples, {'energy': energies})