Samples#
Returned solutions and samples are described under Binary Quadratic Models.
sample_like Objects#
|
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#
Sample with the lowest-energy. |
|
Dict of information about the |
|
|
|
|
|
|
Methods#
Create a new SampleSet with repeated samples aggregated. |
|
|
Deprecated in favor of dimod.append_variables. |
|
Return the |
Create a shallow copy. |
|
|
Iterate over the data in the |
Return True if a pending computation is done. |
|
|
Return a new sampleset with rows filtered by the given predicate. |
|
Construct a |
|
Build a |
|
Build a sample set from raw samples and a binary quadratic model. |
|
Build a sample set from raw samples and a constrained quadratic model. |
Deserialize a |
|
|
Return a sample set containing the lowest-energy samples. |
Ensure that the sampleset is resolved if constructed from a future. |
|
|
Relabel the variables of a |
|
Return an iterable over the samples. |
|
Create a new sample set with rows sliced according to standard Python slicing syntax. |
|
Convert a sample set to a Pandas DataFrame. |
|
Convert a |
|
Create a new sample set with up to n rows. |
Utility Functions#
|
Create a new |
|
Create a new |
|
Combine sample sets. |
|
Return a new sample set with the given variables removed. |
|
Return a new sample set with only the given variables. |
Printing#
- Formatter(**kwargs)[source]#
Sets formatting for printing
SampleSet
objects.- Parameters:
width (int, optional, default=79) – Maximum number of characters to a single line.
depth (int, optional, default=None) – Maximum number of rows printed. Summation is used if exceeded. Default is unlimited.
sorted_by (str/None, optional, default='energy') – Selects the field used to sort samples when printing sample sets. If None, samples are printed in record order.
Examples
>>> from dimod.serialization.format import Formatter >>> sampleset = dimod.SampleSet.from_samples(([-1, 1], ['a', 'b']), dimod.SPIN, energy=1) >>> Formatter(width=45).fprint(sampleset) a b energy num_oc. 0 -1 +1 1 1 ['SPIN', 1 rows, 1 samples, 2 variables] >>> Formatter(width=30).fprint(sampleset) a b energy num_oc. 0 -1 +1 1 1 ['SPIN', 1 rows, 1 samples, 2 variables]
- set_printoptions(**kwargs)[source]#
Set print options globally.
- Parameters:
width (int, optional, default=79) – Maximum number of characters to a single line.
depth (int, optional, default=None) – Maximum number of rows printed. Summation is used if exceeded. Default is unlimited.
sorted_by (str/None, optional, default='energy') – Selects the field used to sort the samples when printing sample sets. If None, samples are printed in record order.
Note
All arguments must be provided as keyword arguments.