dimod.make_quadratic#

make_quadratic(poly: Mapping[Sequence[Hashable], float | floating | integer] | BinaryPolynomial, strength: float, vartype: Vartype | None = None, bqm: BinaryQuadraticModel | None = None) BinaryQuadraticModel[source]#

Create a binary quadratic model from a higher order polynomial.

Parameters:
  • poly – Either a polynomial, as a dict of form {term: bias, …}, where term is a tuple of one or more variables and bias the associated bias, or a BinaryPolynomial.

  • strength – Energy penalty for violating the product constraint. Insufficient strength can result in the binary quadratic model not having the same minimizations as the polynomial.

  • vartype

    Variable type for the binary quadratic model. Accepted input values:

    If bqm is provided, vartype is not required.

  • bqm – Terms of the reduced polynomial are added to this binary quadratic model. If not provided, a new binary quadratic model is created.

Examples

>>> poly = {(0,): -1, (1,): 1, (2,): 1.5, (0, 1): -1, (0, 1, 2): -2}
>>> bqm = dimod.make_quadratic(poly, 5.0, dimod.SPIN)