dimod.binary.BinaryQuadraticModel.to_serializable#

BinaryQuadraticModel.to_serializable(*, use_bytes: bool = False, bias_dtype: None = None, bytes_type: ~typing.Callable = <class 'bytes'>) Dict[source]#

Convert the binary quadratic model to a serializable object.

Parameters:
  • use_bytes – If True, a compact representation representing the biases as bytes is used. Uses tobytes(). This will prevent the returned dict from being JSON serialized, but it can be serialized with BSON.

  • bytes_type – This class will be used to wrap the bytes objects in the serialization if use_bytes is true.

Returns:

An object that can be serialized.

Examples

Encode using JSON

>>> import json
...
>>> bqm = dimod.BinaryQuadraticModel({'a': -1.0, 'b': 1.0},
...                                  {('a', 'b'): -1.0},
...                                  0.0,
...                                  dimod.SPIN)
>>> s = json.dumps(bqm.to_serializable())

See also

from_serializable()

json.dumps(), json.dump() JSON encoding functions

Deprecated since version 0.10.0: The bias_dtype keyword argument will be removed in 0.12.0. Does nothing.