Samples

Returned solutions and samples are described under Binary Quadratic Models.

sample_like Objects

as_samples(samples_like[, dtype, copy, order])

Convert a samples_like object to a NumPy array and list of labels.

SampleSet

class SampleSet(record, variables, info, vartype)[source]

Samples and any other data returned by dimod samplers.

Parameters
  • record (numpy.recarray) – A NumPy record array. Must have ‘sample’, ‘energy’ and ‘num_occurrences’ as fields. The ‘sample’ field should be a 2D NumPy array where each row is a sample and each column represents the value of a variable.

  • variables (iterable) – An iterable of variable labels, corresponding to columns in record.samples.

  • info (dict) – Information about the SampleSet as a whole, formatted as a dict.

  • 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'

Examples

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

>>> import numpy as np
...
>>> sampleset =  dimod.SampleSet.from_samples(np.ones(5, dtype='int8'),
...                                           'BINARY', 0)
>>> sampleset.variables
Variables([0, 1, 2, 3, 4])

Properties

SampleSet.first

Sample with the lowest-energy.

SampleSet.info

Dict of information about the SampleSet as a whole.

SampleSet.record

numpy.recarray containing the samples, energies, number of occurences, and other sample data.

SampleSet.variables

Variables of variable labels.

SampleSet.vartype

Vartype of the samples.

Methods

SampleSet.aggregate()

Create a new SampleSet with repeated samples aggregated.

SampleSet.append_variables(samples_like[, ...])

Deprecated in favor of dimod.append_variables.

SampleSet.change_vartype(vartype[, ...])

Return the SampleSet with the given vartype.

SampleSet.copy()

Create a shallow copy.

SampleSet.data([fields, sorted_by, name, ...])

Iterate over the data in the SampleSet.

SampleSet.done()

Return True if a pending computation is done.

SampleSet.filter(pred)

Return a new sampleset with rows filtered by the given predicate.

SampleSet.from_future(future[, result_hook])

Construct a SampleSet referencing the result of a future computation.

SampleSet.from_samples(samples_like, ...[, ...])

Build a SampleSet from raw samples.

SampleSet.from_samples_bqm(samples_like, ...)

Build a sample set from raw samples and a binary quadratic model.

SampleSet.from_serializable(obj)

Deserialize a SampleSet.

SampleSet.lowest([rtol, atol])

Return a sample set containing the lowest-energy samples.

SampleSet.resolve()

Ensure that the sampleset is resolved if constructed from a future.

SampleSet.relabel_variables(mapping[, inplace])

Relabel the variables of a SampleSet according to the specified mapping.

SampleSet.samples([n, sorted_by])

Return an iterable over the samples.

SampleSet.slice(*slice_args, **kwargs)

Create a new sample set with rows sliced according to standard Python slicing syntax.

SampleSet.to_pandas_dataframe([sample_column])

Convert a sample set to a Pandas DataFrame

SampleSet.to_serializable([use_bytes, ...])

Convert a SampleSet to a serializable object.

SampleSet.truncate(n[, sorted_by])

Create a new sample set with up to n rows.

Utility Functions

append_data_vectors(sampleset, **vectors)

Create a new SampleSet with additional fields in SampleSet.record.

append_variables(sampleset, samples_like[, ...])

Create a new SampleSet with the given variables and values.

concatenate(samplesets[, defaults])

Combine sample sets.