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.

Returns:

A binary quadratic model with three types of variables:

  • Original variables: Variables mapped directly from the input polynomial (e.g., 0, 1, 12).

  • Product variables: Intermediate variables introduced to reduce higher-order terms, representing the product of two variables. These are typically named by joining the original variables (e.g., 0*1 represents the product of 0 and 1).

  • Auxiliary variables: Variables introduced to enforce the penalty constraints that ensure the mathematical relationship of the product variables holds true at the ground state (e.g., aux0,1 enforces the constraint for 0*1).

Return type:

BinaryQuadraticModel

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)
>>> list(bqm.variables)
[0, 1, '0*1', 'aux0,1', 2]