Skip to content

cvxpy/mutate-problem-constraints

Rule mutate-problem-constraints
Pack CVXPY
Severity error
Fix none, edit by hand
Library versions every version

CVXPY's Problem.constraints returns a shallow copy of the list. Appending to that copy leaves the next solve unaware of the added constraint.

problem.constraints.append(x >= 1)
problem = cp.Problem(problem.objective, problem.constraints + [x >= 1])

The rule checks standalone list mutators such as append and clear, and writes or deletions through an index or slice of problem.constraints. A list saved to a variable can be edited and passed to a new problem.

Assemble the constraints before constructing the problem, or build a new problem with the updated list. A new problem has its own compilation cache.

CVXPY guide to changing a problem

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

CVXPY Problem.constraints returns a list copy. Include the updated constraints when constructing a Problem.

Browse the other rules of the CVXPY pack.