hybrid.core.State.from_samples#

classmethod State.from_samples(samples, bqm, **kwargs)[source]#

Convenience method for constructing a state from raw (dict) samples.

Per-sample energy is calculated from the binary quadratic model (BQM), and State.problem is set to the BQM.

Parameters:
  • samples (dimod.SamplesLike) – Collection of samples. For recognized formats, see SamplesLike.

  • bqm (dimod.BinaryQuadraticModel) – Binary quadratic model compatible with samples provided.

  • **kwargs – Arbitrary state variables to be set.

Example

>>> import dimod
>>> bqm = dimod.BQM.from_ising({}, {'ab': 0.5, 'bc': 0.5, 'ca': 0.5})
>>> state = State.from_samples([{'a': -1, 'b': -1, 'c': -1},
...                             {'a': -1, 'b': -1, 'c': 1}], bqm)