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
bqmis provided,vartypeis 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*1represents the product of0and1).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,1enforces the constraint for0*1).
- Return type:
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]