hybrid.core.State.from_sample#
- classmethod State.from_sample(sample, bqm, **kwargs)[source]#
Convenience method for constructing a state from a raw (dict) sample.
Energy is calculated from the binary quadratic model (BQM), and State.problem is also set to that BQM.
- Parameters:
sample (
dimod.SampleLike
) – A single sample. For recognized formats, seeSampleLike
.bqm (
dimod.BinaryQuadraticModel
) – Binary quadratic model compatible with the sample 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_sample({'a': -1, 'b': -1, 'c': -1}, bqm)