dimod.ConstrainedQuadraticModel.is_almost_equal#

ConstrainedQuadraticModel.is_almost_equal(other: ConstrainedQuadraticModel, places: int = 7) bool[source]#

Test for near equality to a given constrained quadratic model.

All biases of the objective and constraints are compared.

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

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

Examples

>>> cqm1 = dimod.ConstrainedQuadraticModel.from_quadratic_model(
...   dimod.BinaryQuadraticModel({0: 0.1234}, {(0, 1): -1.1234}, 0, "BINARY"))
>>> cqm2 = dimod.ConstrainedQuadraticModel.from_quadratic_model(
...   dimod.BinaryQuadraticModel({0: 0.1232}, {(0, 1): -1.1229}, 0, "BINARY"))
>>> cqm1.is_almost_equal(cqm2, 4)
False
>>> cqm1.is_almost_equal(cqm2, 3)
True