Difference between C++ and Python

Hi :wave:

I made an MPC using Acados in Python now I’m trying to use the C-generated code in my C++ framework. I have few questions/problems.

  • To test the C++ implementation I’m comparing the solutions of the Python vs C++ starting from the same data. I noticed that if I don’t set the weights in both the solutions coincide, but when I try to set the weights the solutions differ. I already checked the values in the W matrix and they are the same. I assume I’m doing something wrong. To set the weight I’m using ocp_nlp_cost_model_set().

  • In Python the solver is by default warm started with past solution if no other values are set right? Is it the same in C++ ?

  • When I call the generated code from C++ do I need to specify the setting I already put in the python at compilation time or are they saved? (e.g. hpipm_mode, qp_solver_warm_start, regularize_method )

Thanks for the help

Hi,

If you update the cost in both Python and C++, you should get the same result.
I would recommend checking which C functions are called in the Python interface. E.g. checking the cost_set functionality in Python indeed shows you taht ocp_nlp_cost_model_set is called.

yes, it is the same.

yes, those options are the same and part of the generated code.

Best,
Jonathan

Thanks for the clarification.
I was setting the last node cost to a W instead of W_e.
Best,
Lorenzo