dimod.SampleSet.from_samples

classmethod SampleSet.from_samples(samples_like, vartype, energy, info=None, num_occurrences=None, aggregate_samples=False, sort_labels=True, **vectors)[source]

Build a SampleSet from raw samples.

Parameters:
  • samples_like – A collection of raw samples. ‘samples_like’ is an extension of NumPy’s array_like. See as_samples().
  • vartype (Vartype/str/set) –

    Variable type for the SampleSet. Accepted input values:

    • Vartype.SPIN, 'SPIN', {-1, 1}
    • Vartype.BINARY, 'BINARY', {0, 1}
    • ExtendedVartype.DISCRETE, 'DISCRETE'
  • energy (array_like) – Vector of energies.
  • info (dict, optional) – Information about the SampleSet as a whole formatted as a dict.
  • num_occurrences (array_like, optional) – Number of occurrences for each sample. If not provided, defaults to a vector of 1s.
  • aggregate_samples (bool, optional, default=False) – If True, all samples in returned SampleSet are unique, with num_occurrences accounting for any duplicate samples in samples_like.
  • sort_labels (bool, optional, default=True) – Return SampleSet.variables in sorted order. For mixed (unsortable) types, the given order is maintained.
  • **vectors (array_like) – Other per-sample data.
Returns:

SampleSet

Examples

This example creates a SampleSet out of a samples_like object (a dict).

>>> import numpy as np
...
>>> sampleset = dimod.SampleSet.from_samples(
...   dimod.as_samples({'a': 0, 'b': 1, 'c': 0}), 'BINARY', 0)
>>> sampleset.variables
Variables(['a', 'b', 'c'])