Slack Variable Values


Is there any way to extract the values of the slack variables after solving?

I find the stability of my problem in the QP solver (“partial_condensing_hpipm” with Python templating) is very sensitive to the slack variable weights. (Stability in the sense that it runs consistently without crashing with exit code 3: NaN in the computations). I’m testing out different configurations for my terminal constraint set, so trying to get an idea of the order of magnitude I should be tuning my zl_e/Zl_e/zu_e/Zu_e.


Hi Ben,

I just implemented a getters for the slacks, you can try it out on this branch:

This is how to use them:

Let me know if that works for you :slight_smile:


Thanks for the quick turnaround Jonathan! Got it working easily and its interesting to see. It looks like it grabs all the slack variables for the soft path constraints currently, but not the slack variables on the terminal soft constraints (like sl_e / su_e ). Would it be possible to implement the same getter function for this terminal set of slacks? (I have a few additional soft constraints there)

There is no special case for the last stage in this getter.
The following should do what you want:

sl_e = acados_ocp_solver.get(N, "sl")
su_e = acados_ocp_solver.get(N, "su")

The stage argument, here N is classic 0 based indexing.

Yep you’re right, it was just a for loop range error on my part. All looks good now, thanks again!


I am using acados on Matlab, and have build my problem using the examples of wind_turbine and pendulum on cart model. I am also trying to retrieve the slack variable values using similar commands as mentioned in the above solution. If I understand correctly then the above solution is for python and since I am using Matlab I tried using:
sl = ocp.get('sl')
and I get the following error:
ocp_get: field sl not supported, supported values are: x, u, z, pi, sens_x, sens_u, sens_pi, status, sqp_iter, time_tot, time_lin, time_reg, time_qp_sol, stat, qp_solver_cond_H, qp_solver_A

Does Matlab support getting the slack variable values? Can I know what are sens_x, sens_u, sens_pi ?


Hi @smit,

you are right, these getters were missing in the Matlab interface.
I just added them to my most recent PR:

This commit shows how to use them:

Let me know if that works for you.
I think for the structure of the forum it would be a preferable to open a new topic with descriptive title next time.


They should be the sensitivites of the x, u, pi respectively, you can only get them after calling
ocp.eval_param_sens(field, stage, index);

That should be better documented, but I never used it myself.