dimod.SampleSet.to_serializable#
- SampleSet.to_serializable(use_bytes=False, bytes_type=<class 'bytes'>, pack_samples=True)[source]#
Convert a
SampleSet
to a serializable object.Note that the contents of the
SampleSet.info
field are assumed to be serializable.- Parameters:
use_bytes (bool, optional, default=False) – If True, a compact representation of the biases as bytes is used.
bytes_type (class, optional, default=bytes) – If use_bytes is True, this class is used to wrap the bytes objects in the serialization. Useful for Python 2 using BSON encoding, which does not accept the raw bytes type; bson.Binary can be used instead.
pack_samples (bool, optional, default=True) – Pack the samples using 1 bit per sample. Samples are never packed when
SampleSet.vartype
is ~ExtendedVartype.DISCRETE.
- Returns:
Object that can be serialized.
- Return type:
Examples
This example encodes using JSON.
>>> import json ... >>> samples = dimod.SampleSet.from_samples([-1, 1, -1], dimod.SPIN, energy=-.5) >>> s = json.dumps(samples.to_serializable())
See also