Calling OSQP directly from cython


First of all, thanks to the developer for their amazing work!

My question is rather basic I think and reflects my unfamiliarity with Python and Cython if anything!

I was wondering, assuming that I have an iterative function written in Cython and now inside the inner loops I need to solve an optimization problem with OSQP … what would be the best way to call the solver directly within Cython?
I assume that if I were to simply plug in the Python interface the resulting code would be far from optimal and incur significant slowdowns … or am I completely off? The resulting C file is quite obscure to me to understand what’s going on :sweat_smile:

One way would be to follow this tutorial and use directly something like the OSQP C demo in a C function and then wrap the return values in a more useful struct to get everything I need back to Cython, but honestly that seems a lot of work and I was wondering if that would indeed be the best solution before embarking into that journey!

Actually, would a middle-ground of ‘taking inspiration’ from the OSQP class in the Python Interface and call directly the setup, update and solve methods on a _osqp.OSQP() object be effective at all in reducing overhead?

Thanks for any insight you can share :slight_smile:!