dimod.ConstrainedQuadraticModel.num_biases#
- ConstrainedQuadraticModel.num_biases(vartype: Vartype | str | frozenset | None = None, *, linear_only: bool = False) int [source]#
Number of biases in the constrained quadratic model.
Includes biases in both the objective and any constraints.
- Parameters:
vartype – Count only variables of the specified
Vartype
.linear_only – Count only linear biases.
- Returns:
The number of biases.
Examples
This example counts the three linear biases (including a linear bias implicitly set to zero for variable
y
) and two quadratic baises.>>> cqm = dimod.ConstrainedQuadraticModel() >>> i = dimod.Integer("i") >>> x, y = dimod.Binaries(["x", "y"]) >>> cqm.set_objective(2*x + 3*i - x*y + i*x) >>> cqm.num_biases() 5