pythoncvxpy

CVXPY returning `Strict inequalities are not allowed.` with no strict inequalities


I've got a script

import cvxpy

x, y = cvxpy.Variable(), cvxpy.Variable()

prob = cvxpy.Problem(cvxpy.Minimize(
    cvxpy.norm2(1, cvxpy.quad_over_lin(x, cvxpy.sqrt(y)))
    ), [y >= 0])

print(prob.is_dcp())

When I run this, I get

File "/Users/pavel/Desktop/dcp.py", line 6, in <module>
    cvxpy.norm2(1, cvxpy.quad_over_lin(cvxpy.square(x), cvxpy.sqrt(y)))
  File "/Users/pavel/Library/Python/3.9/lib/python/site-packages/cvxpy/atoms/norm.py", line 97, in norm2
    return norm(x, p=2, axis=axis)
  File "/Users/pavel/Library/Python/3.9/lib/python/site-packages/cvxpy/atoms/norm.py", line 71, in norm
    return norm1(x, axis=axis, keepdims=keepdims)
  File "/Users/pavel/Library/Python/3.9/lib/python/site-packages/cvxpy/atoms/axis_atom.py", line 36, in __init__
    super(AxisAtom, self).__init__(expr)
  File "/Users/pavel/Library/Python/3.9/lib/python/site-packages/cvxpy/atoms/atom.py", line 50, in __init__
    self.validate_arguments()
  File "/Users/pavel/Library/Python/3.9/lib/python/site-packages/cvxpy/atoms/axis_atom.py", line 60, in validate_arguments
    if self.axis is not None and self.axis > self.args[0].ndim:
  File "/Users/pavel/Library/Python/3.9/lib/python/site-packages/cvxpy/expressions/expression.py", line 740, in __gt__
    raise NotImplementedError("Strict inequalities are not allowed.")
NotImplementedError: Strict inequalities are not allowed.

despite there being no strict inequalities defined in my problem. There are other threads about how this can happen when you're not using CVXPY atoms, but here that's all I'm using. What's going on?


Solution

  • I think I figured it out. The norm2 doesn't take two things. It takes the vector only, so I need to stack:

    cvxpy.norm2(cvxpy.vstack((1, cvxpy.quad_over_lin(x, cvxpy.sqrt(y)))))