jump-dev / Ipopt.jl

A Julia interface to the Ipopt nonlinear solver
https://github.com/coin-or/ipopt
Other
149 stars 58 forks source link

"double free or corruption" when providing duplicate hessian entries via MathOptInterface #376

Closed RedRussianBear closed 11 months ago

RedRussianBear commented 1 year ago

Hi, I'm using Ipopt with MathOptInterface to solve trajectory optimization problems. When I was providing hessians for the objective function with only diagonal elements, everything worked fine. However, now that I am also incorporating the constraint hessians by adding duplicate entries (I did this because it was easier and according to the MOI docs, "These indices are not required to be sorted and can contain duplicates, in which case the solver should combine the corresponding elements by adding them together.") the solver consistently crashes on the second iteration.

Am I doing something wrong, or is this an issue with the implementation?

This is Ipopt version 3.14.13, running with linear solver MUMPS 5.6.0.

Number of nonzeros in equality constraint Jacobian...:   549464
Number of nonzeros in inequality constraint Jacobian.:    71136
Number of nonzeros in Lagrangian Hessian.............:  2332800

Total number of variables............................:    42480
                     variables with only lower bounds:     6480
                variables with lower and upper bounds:    36000
                     variables with only upper bounds:        0
Total number of equality constraints.................:    36000
Total number of inequality constraints...............:     1260
        inequality constraints with only lower bounds:        0
   inequality constraints with lower and upper bounds:      180
        inequality constraints with only upper bounds:     1080

iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  1.2960210e+08 1.50e+05 1.00e+02  -1.0 0.00e+00    -  0.00e+00 0.00e+00   0
   1  1.3435130e+08 1.49e+05 1.01e+02  -1.0 3.93e+03  -2.0 9.99e-04 8.80e-03h  1
double free or corruption (!prev)

[35501] signal (6.-6): Aborted
in expression starting at /home/mkhrenov/Repositories/ADDOPT.jl/src/lpbf_example.jl:56
odow commented 1 year ago

Can you provide a reproducible example?

RedRussianBear commented 1 year ago

Hi, my apologies, while making simplified example for reproduction I figured out that the error was being caused by me accidentally providing out of bounds indices for the hessian structure in my main code, which is my fault. It would be nice though if this threw an error saying as much instead of the segfault.

Thanks!

odow commented 1 year ago

It would be nice though if this threw an error saying as much instead of the segfault.

This can be difficult, because the code is actually getting run from C (hence the segfault and no Julia bounds checking).

In general, I'd encourage you to use JuMP instead of MOI. If you're manually coding the Hessian sparsity and callbacks, it is too easy to make a mistake.

odow commented 11 months ago

Closing as expected behaviour.