dimod.QuadraticModel.reduce_quadratic#

QuadraticModel.reduce_quadratic(function: Callable, initializer: float | floating | integer | None = None) Any[source]#

Apply function of two arguments cumulatively to the quadratic biases.

Parameters:
  • function – Function of two arguments to apply to the quadratic biases.

  • initializer – Prefixed in the calculation to the iterable containing the quadratic biases or used as the default if no quadratic biases are set in the quadratic model.

Returns:

Result of applying the specified function to the quadratic biases.

Examples

>>> from dimod import QuadraticModel
>>> qm = QuadraticModel({'x': 0.5, 's': 1, 'i': 2},
...                     {('x', 'i'): 2, ('s', 'i'): 3}, 0.0,
...                     {'x': 'BINARY', 's': 'SPIN', 'i': 'INTEGER'})
>>> qm.reduce_quadratic(min)
2.0

For information on the related functional programming method see functools.reduce().