cvxpy: ValueError: 'shape' elements cannot be negative
Describe the bug Hi, I’m running cvxvpy on a big data set here at work, and all of a sudden I get the following error message:
Traceback (most recent call last):
File "C:/git/RAP.Muni.Optimizer.Api/DTC_Testing.py", line 821, in DTC_MultiRunner
prob.solve(solver=cvx.CBC, maximumNodes=12000, maximumSeconds=220)
File "C:\Users\aardem\AppData\Local\Continuum\anaconda3\lib\site-packages\cvxpy\problems\problem.py", line 362, in solve
result = solve_func(self, *args, **kwargs)
File "C:\Users\aardem\AppData\Local\Continuum\anaconda3\lib\site-packages\cvxpy\problems\problem.py", line 787, in _solve
data, solving_chain, inverse_data = self.get_problem_data(solver, gp)
File "C:\Users\aardem\AppData\Local\Continuum\anaconda3\lib\site-packages\cvxpy\problems\problem.py", line 512, in get_problem_data
data, inverse_data = solving_chain.apply(self, verbose_aa = self.verbose_aa)
File "C:\Users\aardem\AppData\Local\Continuum\anaconda3\lib\site-packages\cvxpy\reductions\chain.py", line 99, in apply
problem, inv = r.apply(problem)
File "C:\Users\aardem\AppData\Local\Continuum\anaconda3\lib\site-packages\cvxpy\reductions\dcp2cone\cone_matrix_stuffing.py", line 222, in apply
params_to_problem_data = extractor.affine(expr_list)
File "C:\Users\aardem\AppData\Local\Continuum\anaconda3\lib\site-packages\cvxpy\utilities\coeff_extractor.py", line 90, in affine
num_rows)
File "C:\Users\aardem\AppData\Local\Continuum\anaconda3\lib\site-packages\cvxpy\cvxcore\python\canonInterface.py", line 246, in get_problem_matrix
(V, (I, J)), shape=(constr_length*(var_length+1), param_size_plus_one))
File "C:\Users\aardem\AppData\Local\Continuum\anaconda3\lib\site-packages\scipy\sparse\compressed.py", line 106, in __init__
other = self.__class__(coo_matrix(arg1, shape=shape))
File "C:\Users\aardem\AppData\Local\Continuum\anaconda3\lib\site-packages\scipy\sparse\coo.py", line 185, in __init__
self._shape = check_shape((M, N))
File "C:\Users\aardem\AppData\Local\Continuum\anaconda3\lib\site-packages\scipy\sparse\sputils.py", line 321, in check_shape
raise ValueError("'shape' elements cannot be negative")
ValueError: 'shape' elements cannot be negative
It’s impossible for me to share the underlying data since it’s confidential customer data. How can we try to find the root case of the problem?
To Reproduce I simply run
prob = cvx.Problem(objfun, constraints=conslist)
prob.solve(solver=cvx.CBC, maximumNodes=12000, maximumSeconds=220)
Expected behavior All I need is a solution (feasible or unfeasible) but I get a bug / error message.
Output If applicable, include program output. If reporting a program crash, please include the entire stack trace.
Version
- OS: Windows 7
- CVXPY Version: version = “1.1.0a1”
Additional context Add any other context about the problem here.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16
I had similar problem few months ago, and I think this problem originates from numpy sparce matrices that cvxpy is using. I don’t remember the details, but somewhere we call reshape function with -1 parameter. Numpy then calls np.prod function that fails on windows machines if the integer product goes beyond 2^32. This problem happens only in Windows OS and doesn’t effect Linux systems. I suggest that to fix this the matrix reshape dimension should be calculated beforehand, and by not using -1 parameter. If someone want’s to replicate this error good way is to use inpainting example in cvxpy.org. Use image size ~512 to replicate because smaller images might not fail.