"NaN in solution detected" - is the problem infeasible?

Hi :wave:,

I have been using acados (with HPIPM) for a few months now and it’s quite impressive what I can throw at it and it will solve!

Right now I am trying to figure out why it can’t handle certain problems and what the error codes actually mean. I looked through the forum and superficially skimmed some source and I still have some doubts regarding what it means when we get

QP solver returned error status 3

As pointed out here, this corresponds to hpipm's

NAN_SOL, // NaN in solution detected

To alleviate this kind of error it was suggested to use LM regularization, this helps but does not explain what is going on. My doubt comes from the fact that the solver fails in the same way if I set up a problem that is certainly infeasible. The only difference is how many QP/SQP iterations occur before it fails.

I checked that there are no NaNs in the failing QP by setting print_level = 3. Should I check if the QP constraints actually define an empty set? Is this implied by the NAN_SOL failure?

I hope to get some insights so that I can improve my formulation to avoid this in the first place.

Thanks in advance :pray:

PS: I think this is quite a general question, but in case it matters, I am using the python interface with a discrete system. I am also using the version tagged 0.1.7 which is the latest “release” on Github as master introduced some changes that broke some of my code.


It is important to distinguish the infeasibility of the NLP and the QP subproblems.
The QP may become infeasible within the SQP method.
LM regularization leads to smaller steps in the SQP method.
Thus, if you start at a feasible iterate it is less likely that a step moves the next iterate into a region where the QP subproblem is infeasible.
Also, trying different initialization might be worth trying.

I am planning to make a new release this month. If you have some problem upgrading to the latest master branch, let me know, and I will look into it before the next release. I am on holiday next week though.


Thank you Jonathan, I think I got it now. Let me try to recap:

NaN in HPIPM solution (NAN_SOL, status 3) → the current QP is infeasible.

This does not mean the OCP itself is infeasible, and is the intended way to terminate. To enable the solver to successfully find a solution it can help to adjust the SQP parameters.

So my follow up question: Is there a built-in way to detect if the current solution is feasible for the OCP even if the last QP fails? It would be useful for my application to “carry on” sub-optimally in that case. I suppose I could manually check the residuals against the tolerances? Are the residuals from ‘.get_residuals()’ of the NLP or of the latest QP?

Is it worth updating for improvements to the core of the system? (Interface improvements are not so useful to me at the moment as I am almost done with this project). About the “breaking changes” I experienced:
I am using the ocp attribute of AcadosNlpSolver in python after solver generation to map betweenCasadi names of parameters/states/inputs and their corresponding indices in the arrays, so that I don’t have to worry about the indices changing and I can easily add/remove states without refactoring. I imagine there is probably another way to get these but when it was removed I just stuck to the old version.

Thanks in advance, enjoy your holiday!

I think you summed it up pretty well.

Regarding your follow-up questions:

No, there is no built-in way to do this, but checking the residuals is the way to go and very easy.

Note that if there are NaNs in the QP solution, the QP solver might be corrupted with them.
I recently added the option to reset the solver from Python, such that memory is reset to default values and NaNs are overwritten.

They are the residuals of the NLP.
However, I recently added this option in Python:
which can be used to also get the residuals of the QP solution.

I remember I readded this, so maybe you can give the latest version a try.

That being said, I hope it is worth for you to update to the latest version :slight_smile: