dimod.QuadraticModel.is_almost_equal#

QuadraticModel.is_almost_equal(other: 'QuadraticModel' | 'BinaryQuadraticModel' | Bias, places: int = 7) bool[source]#

Test for near equality to all biases of a given quadratic model.

Parameters:
  • other – Quadratic model with which to compare biases.

  • places – Number of decimal places to which the Python round() function calculates approximate equality.

Examples

>>> from dimod import QuadraticModel
>>> qm1 = QuadraticModel({'x': 0.0, 'i': 0.1234}, {('i', 'x'): -1.1234},
...                      0.0, {'x': 'BINARY', 'i': 'INTEGER'})
>>> qm2 = QuadraticModel({'x': 0.0, 'i': 0.1232}, {('i', 'x'): -1.1229},
...                      0.0, {'x': 'BINARY', 'i': 'INTEGER'})
>>> qm1.is_almost_equal(qm2, 4)
False
>>> qm1.is_almost_equal(qm2, 3)
True