1

I am trying to run an optimization using CVXPY for a large problem. I'm trying to optimize the L1 norm of some of the entries of a $100\times 100$ matrix, under constraints that restrict the set of feasible matrices to a $100(99)/2=4950$ dimensional afine subspace. This has worked for smaller versions of the problem, but when I try to run it for square matrices of side $100$ the process starts returning only NaNs. I'm not sure what could be causing this problem. Also any tips on better tools to use for this kind of problem would be appreciated.

Update: I noticed the optimization does work if I put the full L1 norm as the objective, but it doesn't when I use this method to restrict which entries of the matrix I want to minimize in an L1 sense.

I stated the problem in CVXPY as:

vx = cvxpy.Variable(n**2)
objective = cvxpy.Minimize(cvx.norm(cvx.multiply(zero_inds, vx), 1))
constraints = [A@vx == b]
prob = cvxpy.Problem(objective, constraints)
result = prob.solve(verbose=True)

Where n=100, A is a $100^2 \times \frac{100\cdot 101}{2}$ dense constraint matrix and b is a vector. Also zero-inds is a vector containing the entries of the matrix that I want to minimize. The output I get is:

===============================================================================
                                     CVXPY                                     
                                     v1.3.1                                    
===============================================================================
(CVXPY) may 30 11:10:09 : Your problem has 10000 variables, 1 constraints, and 0 parameters.
(CVXPY) may 30 11:10:09 : It is compliant with the following grammars: DCP, DQCP
(CVXPY) may 30 11:10:09 : (If you need to solve this problem multiple times, but with different data, consider using parameters.)
(CVXPY) may 30 11:10:09 : CVXPY will first compile your problem; then, it will invoke a numerical solver to obtain a solution.
-------------------------------------------------------------------------------
                                  Compilation                                  
-------------------------------------------------------------------------------
(CVXPY) may 30 11:10:09 : Compiling problem (target solver=ECOS).
(CVXPY) may 30 11:10:09 : Reduction chain: Dcp2Cone -> CvxAttr2Constr -> ConeMatrixStuffing -> ECOS
(CVXPY) may 30 11:10:09 : Applying reduction Dcp2Cone
(CVXPY) may 30 11:10:09 : Applying reduction CvxAttr2Constr
(CVXPY) may 30 11:10:09 : Applying reduction ConeMatrixStuffing
(CVXPY) may 30 11:10:29 : Applying reduction ECOS
(CVXPY) may 30 11:10:40 : Finished problem compilation (took 3.112e+01 seconds).
-------------------------------------------------------------------------------
                                Numerical solver                               
-------------------------------------------------------------------------------
(CVXPY) may 30 11:10:40 : Invoking solver ECOS  to obtain a solution.

ECOS 2.0.7 - (C) embotech GmbH, Zurich Switzerland, 2012-15. Web: www.embotech.com/ECOS

It     pcost       dcost      gap   pres   dres    k/t    mu     step   sigma     IR    |   BT
 0  +0.000e+00  -0.000e+00  +1e+04  8e-01  1e-02  1e+00  5e-01    ---    ---    1  1  - |  -  - 
 1  -3.405e-04  +1.751e-06  +1e+02  4e-02  1e-04  1e-02  6e-03  0.9890  1e-04   1  0  0 |  0  0
 2  -3.185e-06  +3.883e-08  +1e+00  5e-04  1e-06  1e-04  6e-05  0.9890  1e-04   1  1  1 |  0  0
 3  -2.882e-08  +6.458e-10  +1e-02  5e-06  2e-08  1e-06  7e-07  0.9890  1e-04   1  1  1 |  0  0
 4   -nan   +nan  +nan  -nan  -nan  nan  nan  0.9890  1e-04   0  0  0 |  0  0
 5   -nan   +nan  +nan  -nan  -nan  -nan  -nan  0.9890  1e-04   0  0  0 |  0  0
 6   -nan   +nan  +nan  -nan  -nan  nan  nan  0.9890  1e-04   0  0  0 |  0  0
 7   -nan   +nan  +nan  -nan  -nan  -nan  -nan  0.9890  1e-04   0  0  0 |  0  0
 8   -nan   +nan  +nan  -nan  -nan  nan  nan  0.9890  1e-04   0  0  0 |  0  0
 9   -nan   +nan  +nan  -nan  -nan  -nan  -nan  0.9890  1e-04   0  0  0 |  0  0
10   -nan   +nan  +nan  -nan  -nan  nan  nan  0.9890  1e-04   0  0  0 |  0  0

I eventually kill the process since it seems to continue returning NaNs indefinitely. I checked whether it might be a memory problem but in the system monitor I keep seeing 5-6Gb of free space out of 16Gb. Thanks!

xu_pi
  • 11
  • 2
  • 1
    It looks like the ECOS solver is giving up. You likely have some nasty numerical data. Try a different solver or try to fix the scaling of your problem. – Michal Adamaszek Jun 05 '23 at 07:03
  • @MichalAdamaszek Thanks! Yes, I tried the SCS solver and it works a lot better. – xu_pi Jun 06 '23 at 16:57

0 Answers0