dimod.binary.BinaryQuadraticModel.energy#

BinaryQuadraticModel.energy(sample, dtype: DTypeLike | None = None) float | floating | integer[source]#

Determine the energy of the given sample.

Parameters:
  • sample (samples_like) – Raw sample. samples_like is an extension of NumPy’s array_like structure. See as_samples().

  • dtype – Desired NumPy data type for the energy. Defaults to float64.

Returns:

The energy.

Examples

>>> bqm = dimod.BinaryQuadraticModel({}, {("x0", "x1"): -1}, "BINARY")
>>> bqm.energy({"x0": 1, "x1": 1})
-1.0

See also the example under energies().