You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When specifying a CVXPY problem with parameters, we can define a domain of validity for these parameters (e.g., requiring positivity). It seems to me that CVXPY layers can override this domain silently (e.g., by setting a negative value to a parameter that is supposed to be positive).
import cvxpy as cp
import torch
from cvxpylayers.torch import CvxpyLayer
n, m = 2, 3
x = cp.Variable(n)
A = cp.Parameter((m, n))
# b = cp.Parameter(m)
b = cp.Parameter(m, pos=True) # b is now a vector of positive numbers
constraints = [x >= 0]
objective = cp.Minimize(0.5 * cp.pnorm(A @ x - b, p=1))
problem = cp.Problem(objective, constraints)
assert problem.is_dpp()
cvxpylayer = CvxpyLayer(problem, parameters=[A, b], variables=[x])
A_tch = torch.randn(m, n, requires_grad=True)
# b_th = torch.randn(m, requires_grad=True)
b_tch = -abs(torch.randn(m, requires_grad=True)) # b_th is now a tensor of negative numbers
solution, = cvxpylayer(A_tch, b_tch)
solution.sum().backward()
The above code will work, but shouldn't it trigger an error saying that b_tch and/or b should be positive ?
The text was updated successfully, but these errors were encountered:
Hi,
When specifying a CVXPY problem with parameters, we can define a domain of validity for these parameters (e.g., requiring positivity). It seems to me that CVXPY layers can override this domain silently (e.g., by setting a negative value to a parameter that is supposed to be positive).
For example, if we modify the toy example on the main webpage of cvxpylayers such that
The above code will work, but shouldn't it trigger an error saying that b_tch and/or b should be positive ?
The text was updated successfully, but these errors were encountered: