nlp_grad_f failed: NaN detected for output grad_f_x -- How to debug?

2,490 views
Skip to first unread message

Fabian Kessler

unread,
Dec 15, 2020, 7:58:30 AM12/15/20
to CasADi
Hi everyone,

I'm currently implementing Gaussian Belief Space Planning with Model Predictive Control. Currently my solver for the Belief Space Planner is getting the following error if I put my time horizon (N) above 3 (i.e. 4 and onwards). Below my objective function behaves as expected. 

======================================================================
This is Ipopt version 3.12.3, running with linear solver mumps.
NOTE: Other linear solvers might be more efficient (see Ipopt documentation).

Number of nonzeros in equality constraint Jacobian...:       65
Number of nonzeros in inequality constraint Jacobian.:        0
Number of nonzeros in Lagrangian Hessian.............:       27

Error evaluating objective gradient at user provided starting point.
  No scaling factor for objective function computed!

Number of Iterations....: 0

Number of objective function evaluations             = 0
Number of objective gradient evaluations             = 1
Number of equality constraint evaluations            = 0
Number of inequality constraint evaluations          = 0
Number of equality constraint Jacobian evaluations   = 1
Number of inequality constraint Jacobian evaluations = 0
Number of Lagrangian Hessian evaluations             = 0
Total CPU secs in IPOPT (w/o function evaluations)   =      0.000
Total CPU secs in NLP function evaluations           =      0.000

EXIT: Invalid number in NLP function or derivative detected.
CasADi - 2020-12-15 13:05:42 WARNING("solver:nlp_grad_f failed: NaN detected for output grad_f_x, at (row 15, col 0).") [.../casadi/core/oracle_function.cpp:265]
CasADi - 2020-12-15 13:05:42 WARNING("solver:nlp_grad_f failed: NaN detected for output grad_f_x, at (row 15, col 0).") [.../casadi/core/oracle_function.cpp:265]
======================================================================

I'm aware that part of my code uses SQRT (e.g. sigmoid(sqrt((mu['x'] - mu[lms[i]])**2 + (mu['y'] - mu[lms[i+1]])**2) - t_max, alpha)) but should never evaluate to negative as everything gets squared before sqrt is taken.  

My OBJ function looks something like this:
Bildschirmfoto 2020-12-15 um 13.42.59.png

Any suggestions what is going wrong? How can I debug what exactly happens in the OBJ  gradient in Row 15 (i.e. NaN detected for output grad_f_x, at (row 15, col 0))? I tried the 'printme' function, but that can't be easily inserted on the gradient of the objective right?

Let me know if you need anymore information (i.e. specific lines of code / functions) to get an accurate assessment of my situation.

Best,
Fabian

Joris Gillis

unread,
Dec 15, 2020, 8:31:37 AM12/15/20
to CasADi
Dear Fabian,


Best regards,
  Joris

Fabian Kessler

unread,
Dec 15, 2020, 9:08:13 AM12/15/20
to CasADi
Dear Joris, 
thanks for your quick reply and the FAQ entry. 
It has actually solved my problem! The problem was not in the initialization of the state variables for X, but in the initialization of my controls U. Setting them to something else then 0 made it work. 

Best, 
Fabian 
Reply all
Reply to author
Forward
0 new messages