Knitro_nlp stops at NaN values

66 views
Skip to first unread message

Jiarui Liu

unread,
Jan 4, 2022, 3:42:43 PM1/4/22
to Artelys Knitro forum
Hi!

I'm using knitro_nlp in matlab to minimize a non-convex objective function. For some extreme values, the objective function is NaN due to numerical underflow issues, and thus my user-supplied exact gradient is also NaN. I would like the optimizer to go to other points with non-NaN values, but instead it stops at NaN values. What would be the best way to solve this issue?  Thank you! 

Here's the output that I got:

=======================================
           Academic License
       (NOT FOR COMMERCIAL USE)
         Artelys Knitro 12.1.1
=======================================

Knitro presolve eliminated 0 variables and 0 constraints.

maxfevals:               100000
maxit:                   100000
opttol:                  1e-05
outlev:                  4
par_concurrent_evals:    0
xtol:                    1e-05
The problem is identified as bound constrained only.
Knitro changing algorithm from AUTO to 1.
Knitro changing bar_initpt from AUTO to 3.
Knitro changing bar_murule from AUTO to 4.
Knitro changing bar_penaltycons from AUTO to 0.
Knitro changing bar_penaltyrule from AUTO to 2.
Knitro changing bar_switchrule from AUTO to 0.
Knitro changing linesearch from AUTO to 2.
Knitro changing linsolver from AUTO to 2.
Knitro shifted start point to satisfy presolved bounds (4 variables).

Problem Characteristics                                 (   Presolved)
-----------------------
Objective goal:  Minimize
Objective type:  general
Number of variables:                                 13 (          13)
    bounded below only:                               4 (           4)
    bounded above only:                               0 (           0)
    bounded below and above:                          1 (           1)
    fixed:                                            0 (           0)
    free:                                             8 (           8)
Number of constraints:                                0 (           0)
    linear equalities:                                0 (           0)
    quadratic equalities:                             0 (           0)
    gen. nonlinear equalities:                        0 (           0)
    linear one-sided inequalities:                    0 (           0)
    quadratic one-sided inequalities:                 0 (           0)
    gen. nonlinear one-sided inequalities:            0 (           0)
    linear two-sided inequalities:                    0 (           0)
    quadratic two-sided inequalities:                 0 (           0)
    gen. nonlinear two-sided inequalities:            0 (           0)
Number of nonzeros in Jacobian:                       0 (           0)
Number of nonzeros in Hessian:                        0 (          91)

  Iter     fCount     Objective      FeasError   OptError    ||Step||    CGits
--------  --------  --------------  ----------  ----------  ----------  -------
       0         2    9.090245e+01   0.000e+00
       1         9    8.371066e+01   0.000e+00   1.059e+01   1.527e-01        0
       2        31    8.371066e+01   0.000e+00   1.059e+01   0.000e+00       15
       3        43    8.371066e+01   0.000e+00   1.059e+01   0.000e+00        5

EXIT: Primal feasible solution estimate cannot be improved; desired accuracy
      in dual feasibility could not be achieved.

Final Statistics
----------------
Final objective value               =                   -nan
Final feasibility error (abs / rel) =   0.00e+00 / 0.00e+00
Final optimality error  (abs / rel) =   1.06e+01 / 1.16e-01
# of iterations                     =          3
# of CG iterations                  =         24
# of function evaluations           =         54
# of gradient evaluations           =          3
Total program time (secs)           =    3654.68359 (    33.505 CPU time)
Time spent in evaluations (secs)    =    3654.20581

===============================================================================

Richard Waltz

unread,
Jan 4, 2022, 3:48:13 PM1/4/22
to Artelys Knitro forum

Hi,


The best approach is to set the lower and upper bounds on the variables (or impose other problem constraints) to exclude the region where the NaN evaluations occur.  Then you should set the user option 'honorbnds', 1 via the "knitro_options" function to enforce that all iterates stay inside the bounds throughout the optimization.  Otherwise you might try to modify your objective function so that it doesn't evaluate to NaN. You should also experiment with all four Knitro algorithms via the 'algorithm' option to see if a non-default algorithm works better.


If you want to share your model, we can try to take a look at it when we get a chance.


Best regards,

-Richard



Richard WALTZ
Senior Scientist
 
Artelys USA
 


From: kni...@googlegroups.com <kni...@googlegroups.com> on behalf of Jiarui Liu <jiaru...@gmail.com>
Sent: Tuesday, January 4, 2022 2:28:28 PM
To: Artelys Knitro forum
Subject: [Knitro] Knitro_nlp stops at NaN values
 
--
You received this message because you are subscribed to the Artelys "Knitro Nonlinear Optimization Solver" google group.
To post to this group, send email to kni...@googlegroups.com
To unsubscribe from this group, send email to knitro-un...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/knitro?hl=en
Thank You,
Artelys
http://www.artelys.com/en/optimization-tools/knitro
---
You received this message because you are subscribed to the Google Groups "Artelys Knitro forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knitro+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/knitro/ebacf796-ec76-4005-8db9-6e8ac50b39e2n%40googlegroups.com.

Jiarui

unread,
Jan 19, 2022, 12:31:11 PM1/19/22
to Artelys Knitro forum
Hi Richard,

Thanks for the answer! Since my objective is a complicated function of the variables, I don't have a good idea of what the bound should be. But I solved the issue by using multi-start with knitro_nlp.

A related question is that when I try to use parallel for multistart with knitro_nlp, I get the warning message: 'Parallel multi-start cannot be used in knitromatlab. Serial multi-start will be used.' This is the options that I'm using:

knitro_opts = knitro_options('algorithm',1, 'outlev', 4, 'gradopt', 1, 'hessopt', 2, 'maxfevals', 'maxit', 1e5, 'scale', 1, 'xtol', 1e-5, 'opttol', 1e-5, 'UseParallel', true, 'bar_maxcrossit',0, 'ms_enable', 1, 'ms_deterministic', 1, 'ms_maxsolves', 30,  'ms_num_to_save', 5,  'ms_savetol', 0.01, 'ms_terminate', 0, 'par_msnumthreads', 10, 'ms_maxbndrange', 5); 

[that, ~, eflag, output, ~, grad, hess]=knitro_nlp(f,x0,[],[],[],[],lb,ub,[],[],knitro_opts,[]);

Is there a way to use parallel multi-start? Thanks a lot!


Richard Waltz

unread,
Jan 19, 2022, 12:38:26 PM1/19/22
to Artelys Knitro forum

Hi,


Unfortunately the MATLAB Mex interface is not thread-safe so it is not possible to use the internal Knitro multi-start

procedure in parallel in knitromatlab.  You can, however, try to implement your own custom multi-start at the MATLAB level using the MATLAB provided parallel tools (i.e. using a MATLAB "parfor" loop).  This requires that you have the MATLAB Parallel Computing Toolbox however.  There is an example of how to do this in the Knitro distribution at  "knitromatlab/examples/exampleMultiStart.m".


Best regards,

-Richard


Richard WALTZ
Senior Scientist
 
Artelys USA
 


From: kni...@googlegroups.com <kni...@googlegroups.com> on behalf of Jiarui <jiaru...@gmail.com>
Sent: Wednesday, January 19, 2022 11:27:15 AM
To: Artelys Knitro forum
Subject: Re: [Knitro] Knitro_nlp stops at NaN values
 

Jiarui

unread,
Jan 21, 2022, 11:16:03 AM1/21/22
to Artelys Knitro forum
Thanks Richard!

I was looking through the example files in the knitro distribution under "knitromatlab/examples", but I couldn't find the example files for multistart. I see files such as: exampleMILP1.m; exampleMPEC1.m; exampleNLP1.m; etc. I'm using knitro 12.1.1. Maybe I'm looking at the wrong folder?

Richard Waltz

unread,
Jan 21, 2022, 11:19:34 AM1/21/22
to Artelys Knitro forum

Hi,

It may be that your version of Knitro pre-dates the inclusion of that example.  Attached is the example.

Best regards,

-Richard



Richard WALTZ
Senior Scientist
 
Artelys USA
 

Sent: Friday, January 21, 2022 10:12:26 AM
exampleMultiStart.m
Reply all
Reply to author
Forward
0 new messages