Solving the same OCP multiple times gives different results C-interface

Hi, I am trying to use the C-interface in C++ for MPC and I encountered strange behaviour. When setting my initial state and the reference to 0 each iteration before solving (so each iteration it solves the same problem), it only manages to solve it twice and then HPIPM throws an error saying that it could not converge to a solution.
When resetting the solver in between iterations (even though this should not matter, warm-starting at the previous solution should result in a quick solve when the problem is exactly the same I would think), I get the following behavior (This is printing the control output each iteration):

This hints that some other solver attributes get reset whenever the QP solver fails, which are not reset using [modelname]_acados_reset(). I also noticed that the reset function takes an int reset_qp_solver_mem as imput, but is not used.

I validated the solver using the python interface, I do not get this behaviour there.

My C++ code is as follows:

void control() {
            astrobee_acados_reset(capsule,1); //The int is not used in astrobee_acados_reset()?
            // Set initial state
            ocp_nlp_constraints_model_set(nlp_config, nlp_dims, nlp_in, 0, "lbx", acados_in.x0);
            ocp_nlp_constraints_model_set(nlp_config, nlp_dims, nlp_in, 0, "ubx", acados_in.x0);

            // Set reference for each stage (xref are params)
            for(int stage=0; stage<=N; stage++) {
                astrobee_acados_update_params(capsule, stage, acados_in.xref[stage], NX);

            // Solve
            acados_status = astrobee_acados_solve(capsule);
            if (acados_status != ACADOS_SUCCESS)
                std::cout << "SOLVER FAILED: " << acados_status << "\n";

            // Extract control from output. Saved to our acados_out struct
            ocp_nlp_out_get(nlp_config, nlp_dims, nlp_out, 0, "u", &acados_out.u0);

Could the solver memory be causing thisbehaviour? If so, is there any way to reset the solver memory manually? Thanks for the help!


the solver of the QP solver memory is only implemented for HPIPM with partial condensing, see: acados/ at 186273da13f1c95c331612dba7faa02bff3cdd09 · acados/acados · GitHub

However, it should be possible to get the same behavior from python and C/C++.

Hopefully you find the issue!

It was a problem on my end. I initialised my xref with only N stages instead of N+1 :smiling_face_with_tear: Now everything works as it should.

Anyways thank you for the response!