Non-linear Sparse Constraint Jacobians
Description
The documentation regarding the constraint Jacobians mentions, "However, we have currently assumed that each of the blocks with an X in is a dense sub-block. pyOptSparse allows each of the sub-blocks to itself be sparse."
If I am passing a constraint Jacobian to a non-linear constraint as a simplified pyOptSparse sparse matrix format, the following error is shown, "pyOptSparse Error: The number of nonzero elements for constraint group 'constraint_1' with respect to var_1 was not the correct size. The supplied Jacobian has 1450 nonzero entries, but must contain 526350 nonzero entries." However, the number of nonzero elements in the Jacobian is 1450; the other entries are 0. The shape (725, 726) of the Jacobian is correct. Does the constraint Jacobians to a non-linear sub-block always have to be dense, or can it also be sparse?
I am having the same issue. It is a little strange that a sparse library cannot support sparse input matrices. Can sparsity not be enforced within constraint or variable "groups"?
Hmm I'm fairly sure this should work but something is definitely broken it seems. I'll flag it as a bug and see if I can do some debugging in the next few days.
I think I know what was going wrong. The jac variable needs to be set when defining the constraint through addConsGroup in order to define the correct structure for the sparse jacobian that is provided by the input sens function.
I think this could be made a little clearer in the section on specifying jacobians. You do mention it in the constraint section, but the example that is given is for an explicitly linear Jacobian, so it seems like jac is only needed for that case (rather than whenever the jacobian is user-specified.
Oh yes the jac kwarg needs to be set to specify the sparsity of the sub-block. If not supplied the sub-block will be assumed to be dense. Is it working for you?
I'll note down the following improvements to be made:
- Update docstring
- Update the Jacobian section of the docs
- Add an example that uses a sparse Jacobian
- Add some tests for this case
Yes, it's working now! Those changes to the docs should make it much clearer.