NaN and inf behaviour

Skip to first unread message


Jun 29, 2023, 5:54:29 PM6/29/23
to Artelys Knitro forum
Hello there!

What is the current behaviour of Knitro (as of 13.2) when the function, Jacobian, or Hessian encounters an inf or NaN? I saw in an old post, from 2015, that the solver will take a shorter step until a feasible answer is obtained. However, I see that the following return code is possible:

KN_RC_EVAL_ER:  This termination value indicates that an evaluation error occurred (e.g., divide by 0, taking the square root of a negative number), preventing the optimization from continuing.

Kind regards

Richard Waltz

Jun 29, 2023, 6:03:40 PM6/29/23

When the function evaluation produces inf or NaN, Knitro will take shorter steps until a solution estimate can be found where the functions are well-defined.  When the gradient/Jacobian/Hessian evaluation produces inf or NaN, Knitro terminates with an evaluation error message.  The distinction is that the function evaluation occurs for a "trial" solution estimate "x", and so it is easier to recover from since the function value at the current "x" should be well-defined.  On the other hand, a gradient/Jacobian/Hessian evaluation would occur at the current "x" and is more problematic (since Knitro uses derivative information to generate new solution estimates).

One way to try to avoid issues with evaluation errors is, if possible, to define finite lower and upper bounds on the variables in such a way that the functions, gradients, etc. are always well-defined inside these bounds, and then to set the option "honorbnds=1" in Knitro to ensure that all iterates generated during the solution process are within the defined variable bounds. See:

The "bar_feasible" option may also be helpful here:

-Richard Waltz

From: <> on behalf of TD <>
Sent: Thursday, June 29, 2023 2:47 PM
To: Artelys Knitro forum <>
Subject: [Knitro] NaN and inf behaviour
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
To unsubscribe from this group, send email to
For more options, visit this group at
Thank You,
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
To view this discussion on the web visit


Jun 29, 2023, 6:49:01 PM6/29/23
to Artelys Knitro forum
Thanks a lot for your quick and clear reply, Richard! Got it.

Kind regards
Reply all
Reply to author
0 new messages