dimod.testing.asserts.assert_sampleset_energies#
- assert_sampleset_energies(sampleset, bqm, precision=7)[source]#
Assert that each sample in the given sample set has the correct energy.
- Parameters:
sampleset (
SampleSet
) – Sample set as returned by a dimod sampler.bqm (
BinaryQuadraticModel
/BinaryPolynomial
) – The binary quadratic model (BQM) or binary polynomial used to generate the samples.precision (int, optional, default=7) – Equality of energy is tested by calculating the difference between the response’s sample energy and that returned by BQM’s
energy()
, rounding to the closest multiple of 10 to the power of minus precision.
- Raises:
AssertionError – If any of the samples in the sample set do not match
their associated energy. –
Examples
>>> import dimod.testing ... >>> sampler = dimod.ExactSolver() >>> bqm = dimod.BinaryQuadraticModel.from_ising({}, {(0, 1): -1}) >>> sampleset = sampler.sample(bqm) >>> dimod.testing.assert_response_energies(sampleset, bqm)