ConstrainedQuadraticModel.num_quadratic_variables(vartype: Optional[Union[dimod.vartypes.Vartype, str, frozenset]] = None, *, include_objective: Optional[bool] = None) int[source]

Number of variables with at least one quadratic interaction in the constrained quadratic model.

Includes interactions in both the objective and any constraints.

  • vartype – Count only variables of the specified Vartype.

  • include_objective – Count also variables in the objective. Currently defaults to false.


The number of variables.


This example counts the two variables participating in interaction 3*i*k in constraint Constraint1 but not variable j’s interaction 2*i*j in the objective.

>>> cqm = dimod.ConstrainedQuadraticModel()
>>> i, j, k = dimod.Integers(["i", "j", "k"])
>>> cqm.set_objective(i - 2*i*j)
>>> cqm.add_constraint_from_comparison(3*i*k - 2*j <= 4, label="Constraint1")
>>> cqm.num_quadratic_variables()

Deprecated since version 0.10.14: In dimod 0.12.0 include_objective will default to true.