Tuesday, June 27, 2023

CVXPY DCP errors

CVXPY is a popular tool to model and solve convex optimization problems. Sometimes, it throws a "DCP" error, even for convex problems. DCP stands for Disciplined Convex Programming, the underlying framework for working with guaranteed convex models. The error says: I can not verify this is convex.  

Here are some small examples of convex objectives (under minimization) one would expect to work.

ObjectiveCVXPY codeResultNotes
\[\color{darkred}x^T \color{darkred}x\]x.T@xDCP errorprint shows minimize x@x, i.e. transpose is dropped
\[\color{darkred}x^T \color{darkred}x\]x@xDCP error
\[\color{darkred}x^T \color{darkred}x\]cp.sum_squares(x)transformed into quad_over_lin(x, 1.0)
\[\color{darkred}x^T \color{darkblue}Q \color{darkred}x\]x.T@Q@xtransformed into QuadForm(x,Q)
\[\color{darkred}y:=\color{darkred}x-\color{darkblue}p\]\[\color{darkred}x^T \color{darkblue}Q \color{darkred}y\]y=x-p
DCP error
\[\color{darkred}x^T \color{darkblue}Q \color{darkred}x - \color{darkred}x^T \color{darkblue}Q \color{darkblue}p\]x.T@Q@x - x.T@Q@pfirst term transformed into QuadForm(x,Q)

Not everything makes sense to me. I am not sure why x.T@x is not properly recognized, but x.T@Q@x is.