dimod.QuadraticModel.energy#
- QuadraticModel.energy(sample, dtype=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:
Energy for the sample.
Examples
>>> from dimod import QuadraticModel, Binary >>> qm = QuadraticModel() >>> qm.add_variables_from('BINARY', ['x', 'y']) >>> qm.add_quadratic('x', 'y', -2) >>> qm.energy([{'x': 1, 'y': 1}]) -2.0