Hello,
For some real-time model-predicted control (MPC), I'm trying to figure out if cvxpy could be used for real-time control.
Therefore, I'm constructing a cvxpy minimization problem with cvxpy variables, constraints and parameters. I only construct this problem one time. Then I update the parameter values (param.value = ...) in my control loop without reconstructing the problem or any of the constraints or variables.
Using different solvers (ECOS, OSQP), I measured the time for the cvxpy.Problem.solve function call which is 100 ms:

prob.solve 0.109 (=100 ms)
When activating 'verbose=True' for cvxpy.Problem.solve, I can see in the terminal output that the actual solve time however is only 6 ms:

Runtime: 0.0062 seconds. (=6 ms)
Why is there such a big difference in processing time between the cvxpy.Problem.solve function call and the actual solver function, how could I reduce the function call overhead time? I assumed that just assigning values to parameters can be fast and would not have to internally 'recompile' anything for the solver?
cvxpy version: 1.0.24
Conda: 4.5.12 (Python 3.6.6, Win64)
my code: mpc.zip
Thanks,
Alexander Grau
Hey Alexander. CVXPY is not yet ready for real-time applications. We’re working on a new version of CVXPY (version 1.1) that’ll be better suited for your needs — it’ll make more intelligent use of parameters, and it’ll also support code generation for embedded optimization. So stay tuned — we don’t know when exactly 1.1 will be ready, but hopefully it’ll land sometime this year.
Thanks for the info :-)
You can close this issue if you like. I found the solution by using the ACADO code generator to generate a Python C extension for my MPC problem that can run even faster than realtime (only a few hundred microseconds per control step). I'm quite happy with the results :).
Maybe a future code generator for CVXPY could do the same, however I think it probably runs best when looking at specific optimization problems (MPC in my case).
my blog article about it: http://grauonline.de/wordpress/?page_id=3244

Most helpful comment
Hey Alexander. CVXPY is not yet ready for real-time applications. We’re working on a new version of CVXPY (version 1.1) that’ll be better suited for your needs — it’ll make more intelligent use of parameters, and it’ll also support code generation for embedded optimization. So stay tuned — we don’t know when exactly 1.1 will be ready, but hopefully it’ll land sometime this year.