Any difference between class-based osqp solver vs a mex solver generated from codegen

I’m doing a simulation for MPC problem using osqp solver in two ways.

  1. using a class-based osqp solver
  2. using a mex solver generated from codegen of class-based osqp solver.

Firstly, the class-based osqp solver works really fine with good speed. Then, I generated a mex solver using codegen function of the osqp class and then applied it to the same problem. I used the exactly same setting for code generation. At this time, the solver speed was too slow. What I found so far is as follows:
Class-based solver returns solution within fairly small number of iteration. However, a mex solver, quite often but not always, returns the solution after the maximum iteration, 4000. I’m wondering why the mex solver has so slow convergence rate. Any big difference between the class-based osqp solver and a mex solver generated from codegen? How can I get the same solution from the two methods with same speeds?

1 Like

I found how to solve this problem by myself after spending several hours. The problem comes from the settings. When I use the class-based osqp solver, I run the following statement.

prob.setup(P, q, A, l, b, ‘alpha’, 1,‘verbose’,0);

If I check the setting using “prob.current_settings”, adaptive_rho_interval is 0. After solving the osqp problem once by calling

res = prob.solve();

interestingly, adaptive_rho_inverval has been changed to 25.

When I generate the mex file (emosqp) using codegen function, I use exactly the same setting as above. However, I don’t call prob.solve() because I just want to generate the mex file. In this case, adaptive_rho_interval remain 0. This difference in adaptive_rho_interval makes the huge difference in the solver speed. I think it is somewhat strange that the setting is changed automatically without user’s intervention. Anyway, now I feel happy that I have the same results after changing the value of adaptive_rho_interval to 25 manually. I hope my reply can be of some help.

1 Like