dimod.make_quadratic_cqm#
- make_quadratic_cqm(poly: Mapping[Sequence[Hashable], float | floating | integer] | BinaryPolynomial, vartype: Vartype | None = None, cqm: ConstrainedQuadraticModel | None = None) 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 aBinaryPolynomial
,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)