View Currently Stored Matrices / Vectors in OSQP() Object

Suppose that I set up an OSQP object (e.g. in Python):

m = osqp.OSQP()

m.setup(P=P, A=A, u=u) # For some appropriately defined P, A, u

After setup, does the object m have a method or attribute that returns what matrices / vectors it currently has stored? For example, being able to print out the currently stored values of P, A, u would be useful, but I can’t find any syntax letting me do this.

Use case: The documentation for updating only some elements of problem matrices (e.g. via m.update(Px=Px_new, Px_idx=Px_new_idx)) is a little difficult to understand. It would be nice to have some way to print the model’s matrices after updating them to check whether they were updated correctly.

In the Matlab interface there is a hidden option that is only accessible directly via the compiled mex function osqp_mex (i.e. not through the user API osqp.m), which we use for dumping the internal workspace for codegen purposes. In Matlab you can therefore do this:

m = osqp();
out = osqp_mex('get_workspace',m.objectHandle);

Note that I set scaling = false since otherwise the matrices in the out object will not match the data you passed as user input. You can then see the internal CSC representation for your data, e.g. in

Something similar probably also works in python, since it has a similar hook for dumping the internal workspace during codegen. In particular, it happens right here.

Note that the feature above is undocumented and might disappear in a future release. We are considering rewriting the codegen feature to use a common C implementation so we can support across all interfaces.

1 Like