osqp / osqp-python

Python interface for OSQP
https://osqp.org/
Apache License 2.0
109 stars 41 forks source link

Support nonzero scaling for C derivatives #82

Open vineetbansal opened 2 years ago

vineetbansal commented 2 years ago

Unless we set scaling=0 in the derivative unit tests, we observe different results in derivatives w.r.t. the Python implementation. Some helpful comments from Bart:

It makes sense that scaling has a special effect on the C side since data is rescaled there. However, the C side should unscale the results before returning them. Otherwise the differentiation will not work.

For the backward (adjoint) derivative, the results have the shape of the data. I suspect you just need to unscale them using the unscale_data function. (and use (dP, dq, dA, dl, du) instead of (P, q, A, l, u).

For the forward derivative, I believe you should use unscale_solution over (dx, dy) instead of (x, y).

vineetbansal commented 2 years ago

Update on this: scaling=0 is no longer a requirements for the unit tests. However, this is being done by unscaling P/q/l/u on the C side of things. A better/faster way may have to be found.