snopt / snopt-matlab

Matlab interface for sparse nonlinear optimizer SNOPT
MIT License
56 stars 23 forks source link

SNOPTA EXIT 40 -- terminated after numerical difficulties #19

Open Xiaobing-Shen opened 3 years ago

Xiaobing-Shen commented 3 years ago

When I use snopt to solve a nonlinear problem, it always shows “SNOPTA EXIT 40 -- terminated after numerical difficulties” even I give the optimal solution as the initial solution.

Here is the output:

============================================================= 
NetFlow: Solving Network flow using SNOPT ... Using initial solution

 ==============================
 S N O P T  7.7.7    (Feb 2021)
 ==============================

 Begin  NetFlow NLP problem

 SNSPEC EXIT 100 -- finished successfully
 SNSPEC INFO 101 -- SPECS file read

 Trial version of SNOPT -- for evaluation or academic purposes only

 SNMEMA EXIT 100 -- finished successfully
 SNMEMA INFO 104 -- memory requirements estimated

 Trial version of SNOPT -- for evaluation or academic purposes only

 Scale option  0

 Nonlinear constraints      53     Linear constraints       1
 Nonlinear variables        74     Linear variables         0
 Jacobian  variables        74     Objective variables     32
 Total constraints          54     Total variables         74

 The user has defined     262   out of     262   first  derivatives

 Itn      0: Hessian set to a scaled identity matrix
 Itn      0: LU partial  pivoting tols       2.00      2.00
 Itn      0: LU partial  pivoting tols       1.41      1.41
 Itn      0: LU partial  pivoting tols       1.19      1.19
 Itn      0: LU partial  pivoting tols       1.09      1.09
 Itn      0: LU partial  pivoting tols       1.04      1.04
 Itn      0: LU partial  pivoting tols       1.02      1.02
 Itn      0: LU partial  pivoting tols       1.01      1.01
 Itn      0: LU rook     pivoting tols       3.99      3.99
 Itn      0: LU rook     pivoting tols       2.00      2.00
 Itn      0: LU rook     pivoting tols       1.41      1.41
 Itn      0: LU rook     pivoting tols       1.19      1.19
 Itn      0: LU rook     pivoting tols       1.09      1.09
 Itn      0: LU rook     pivoting tols       1.04      1.04
 Itn      0: LU rook     pivoting tols       1.02      1.02
 Itn      0: LU rook     pivoting tols       1.01      1.01

 SNOPTA EXIT  40 -- terminated after numerical difficulties
 SNOPTA INFO  44 -- ill-conditioned null-space basis

 Problem name                 NetFlow
 No. of iterations                   0   Objective            4.6637562225E+01
 No. of major iterations             0   Linear    obj. term  0.0000000000E+00
 Penalty parameter           0.000E+00   Nonlinear obj. term  4.6637562225E+01
 User function calls (total)         2
 No. of degenerate steps             0   Percentage                       0.00
 Max x                       3 6.7E+01   Max pi                      1     NaN
 Max Primal infeas          99 1.1E-16   Max Dual infeas            25Infinity
 Nonlinear constraint violn    1.1E-16

 Solution printed on file  10

 Time for MPS input                             0.00 seconds
 Time for solving problem                       0.00 seconds
 Time for solution output                       0.00 seconds
 Time for constraint functions                  0.00 seconds
 Time for objective function                    0.00 seconds

It seems it runs nothing. Can anyone help me with this?

gnowzil commented 3 years ago

Looks like there are some NaNs/Infinity coming from the calculations, possibly causing the problems.

I would recommend running again with the following options to help debug:

   Print   frequency               1
   Summary frequency               1
   System information            Yes
   Verify level                    3
   Major Print level              11
   Minor print level              11
   Solution                      Yes

Verify level 3 in particular will check your derivatives. You should look at the output to make sure all of the derivatives are "ok". Any potentially incorrect derivatives will be marked with "bad?" in the output.

Xiaobing-Shen commented 3 years ago

Thanks for your suggestions. I just checked the derivative and found the following information.


 Itn      0: Making the linear rows feasible
 Itn      0: Feasible linear rows
 Itn      0: PP1.  Minimizing  Norm(x-x0)
 Itn      0: Feasible norm(x-x0) problem

        Minor NonOpt  LP mult  LP Step            LP objective
            0                                    0.0000000E+00

 Itn      0: PP1.  Norm(x-x0) approximately minimized  (0.00E+00)

 The user has defined     262   out of     262   first  derivatives

 SNOPTA EXIT  50 -- error in the user-supplied functions
 SNOPTA INFO  51 -- incorrect objective  derivatives

 Problem name                 NetFlow
 No. of iterations                   0   Objective            6.5000000000E+01
 No. of major iterations             0   Linear    obj. term  0.0000000000E+00
 Penalty parameter          -1.111E+04   Nonlinear obj. term  6.5000000000E+01
 User function calls (total)        76
 No. of degenerate steps             0   Percentage                       0.00
 Max x                       3 6.7E+01   Max pi                      1 0.0E+00
 Max Primal infeas          81 7.8E+01   Max Dual infeas            32 1.9E-01
 Nonlinear constraint violn    7.8E+01

My objective function is $$f(x) = c\sqrt{x}$$ and I used $\frac{c}{2}*\max(x, 1e-6)^{-1/2}$ as the gradient. I do not know why the information shows that the objective derivatives is incorrect.

gnowzil commented 3 years ago

Look inside the print output file and check which derivatives are incorrect.

If you don't have an output file, then re-run with options.printfile set to an output file name (e.g., options.printfile = 'myoutput.out').

Xiaobing-Shen commented 3 years ago

Hi @gnowzil ,

I corrected the objective function and its gradient. From the .out file, all of my derivatives are OK. But the problem is I still got the

SNOPTA EXIT  40 -- terminated after numerical difficulties
 SNOPTA INFO  41 -- current point cannot be improved

Does that means this initial point is a local minimum and we cannot improve it?

Here is my .out file.

NetFlowSQP.log

gnowzil commented 3 years ago

It looks like there is still an issue with your objective gradient. I see the following in your output

XXX  The objective  gradients seem to be incorrect.

 Gradient projected in one direction   1.60007623746E-03
 Difference approximation              1.34250615375E+02
Xiaobing-Shen commented 3 years ago

Sometimes, the .out will show the objective gradient is wrong. But when the objective gradient is ok, I got the same exit info.

NetFlowSQP.log