Tim-Salzmann / l4casadi

Use PyTorch Models with CasADi for data-driven optimization or learning-based optimal control. Supports Acados.
MIT License
350 stars 23 forks source link

Support for the `infeasible problem detected`. #44

Closed xueminchi closed 1 month ago

xueminchi commented 1 month ago

Hi, @Tim-Salzmann

I designed a predictive controller following your previous instructions in the example simple_nlp.py. The problem is very simple. A system tries to avoid a circle obstacle and reach the goal.

The code runs without major issues, but after several iterations, it reports Infeasible_Problem_Detected. I tested the same scenario using an analytical model instead of the model defined by PyTorch and l4casadi, and it works without triggering this infeasibility. I wonder if there might be a problem with my constraint formulation.

To reproduce the issue, I have attached the script (only one .py file inside the zip format). It requires the following packages: casadi, numpy, torch, matplotlib, and l4casadi, so it should be easy to run.

Best, Xuemin casadi_mpc_torch.zip

Tim-Salzmann commented 1 month ago

Hi,

Infeasible_Problem_Detected is the solver struggling. This can be due to your model being evaluated in areas where it produces unexpected results.

As an example, your training data might include input x=1 and x=1.1 and will produce the right result but, in theory, could produce the completely wrong result for x=1.05, which your analytical model will not. This might not be exactly the case but it demonstrates how a trained model can diverge from an analytical model.

Best Tim

gy2256 commented 1 month ago

To check if your constraints are satisfied, you can add slack variables to each constraint and minimize them by including the slack variables as part of the cost function. Ideally, all slack variables should be zero.

xueminchi commented 1 month ago

Thanks. Indeed, both the accuracy of the learned model and the formulation of the problem will affect the final gradient-based solver to converge.