dimod.higherorder.utils.make_quadratic_cqm

make_quadratic_cqm(poly: Union[Mapping[Sequence[Hashable], Union[float, numpy.floating, numpy.integer]], dimod.higherorder.polynomial.BinaryPolynomial], vartype: Optional[dimod.vartypes.Vartype] = None, cqm: Optional[dimod.constrained.ConstrainedQuadraticModel] = None) dimod.constrained.ConstrainedQuadraticModel[source]

Create a constrained 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.

  • vartype

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

    If poly is a BinaryPolynomial , vartype is not required.

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

Examples

>>> poly = {(0,): -1, (1,): 1, (2,): 1.5, (0, 1): -1, (0, 1, 2): -2}
>>> cqm = dimod.make_quadratic_cqm(poly, dimod.SPIN)