[Ipopt-tickets] [Ipopt] #187: Unpredictable behavior in Matlab interface if gradient function outputs sparse vector

Ipopt coin-trac at coin-or.org
Thu Nov 8 16:07:48 EST 2012


#187: Unpredictable behavior in Matlab interface if gradient function outputs
sparse vector
-------------------+------------------------
Reporter:  guest   |      Owner:  ipopt-team
    Type:  defect  |     Status:  new
Priority:  high    |  Component:  Ipopt
 Version:  3.10    |   Severity:  normal
Keywords:  matlab  |
-------------------+------------------------
 If the gradient function returns a sparse vector, the Matlab interface can
 have unpredictable behavior - sometimes returning "EXIT: Invalid number in
 NLP function or derivative detected," sometimes Restoration failed,
 sometimes "Cutting back alpha due to evaluation error," etc.

 This happens because mxGetPr on a sparse mxArray returns a pointer to the
 array of nonzero values, which may have a valid range of memory addresses
 shorter than the length of the underlying vector. Accessing the
 uninitialized memory addresses leads to unpredictable and non-repeatable
 results.

 The attached patch tests if the output of the gradient callback is sparse,
 and if so I use mexCallMATLAB to have Matlab convert the vector to full.
 This may not be the fastest method of doing so, but it's simpler and more
 general than other methods I could think of. We could alternately issue a
 warning or error if the gradient returns a sparse vector, and force the
 user to change his or her code.

 I'm attaching a test example to reproduce the issue. It's a trivial
 unconstrained QP using an example sparse matrix from a Matlab demo for the
 Hessian. funcs.gradient = @(x) A*x works with trunk R2115, but
 funcs.gradient = @(x) sparse(A*x) leads to unpredictable behavior.

 I'm also fixing a separate issue with ipoptoptions.cpp in this patch. If
 the options input does not have an "ipopt" field, then the ptr input to
 IpoptOptions::IpoptOptions will be NULL, and calling mxIsStruct(NULL)
 leads to a segfault. You can reproduce this by uncommenting line 17 in the
 attached m file.

 -Tony Kelman

-- 
Ticket URL: <https://projects.coin-or.org/ticket/187>
Ipopt <http://projects.coin-or.org/Ipopt>
Interior-point optimizer for nonlinear programs.



More information about the Ipopt-tickets mailing list