# Debugging in Ipopt without JuMP

**URL:** https://discourse.julialang.org/t/debugging-in-ipopt-without-jump/83384
**Category:** Optimization (Mathematical)
**Tags:** ipopt
**Created:** [June 27, 2022, 7:16am UTC](https://discourse.julialang.org/t/debugging-in-ipopt-without-jump/83384 "2022-06-27T07:16:12Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Itzahack23](https://avatars.discourse-cdn.com/v4/letter/i/aca169/32.png) [@Itzahack23](https://discourse.julialang.org/u/Itzahack23)
#### Post date: [June 27, 2022, 7:16am UTC](https://discourse.julialang.org/t/debugging-in-ipopt-without-jump/83384/1 "2022-06-27T07:16:12Z")

</div>

Hi all,  
I am trying to solve a constrained optimization problem by using Ipopt “without” using JuMP as I want to see how the performance changes by giving the gradient and hessian information.  
I am referring to the C wrapper example in Ipopt.jl.

Actually, when I use JuMP + Ipopt, the problem is not solved correctly, and I found that the number of nonzero elements in Lagrangian Hessian is much larger than the number theoretically derived.  
This is another reason why I don’t want to use JuMP + Ipopt.

The unfortunate thing is that Ipopt stops due to segfault.  
My main question is how I can check the source of segfault.  
REPL just says that a segfault happened.  
What is the proper way of debugging while I am using a package written in another language?  
If you also know another good solver in which we can provide the gradient and hessian information as in Ipopt without JuMP, I really appreciate it.

Thanks.

---

<div class="post-metadata">

### Author: ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)
#### Post date: [June 27, 2022, 10:37am UTC](https://discourse.julialang.org/t/debugging-in-ipopt-without-jump/83384/2 "2022-06-27T10:37:58Z")

</div>

Welcome. You may be interested in this past post:

> [@Survey of Non-Linear Optimization Modeling Layers in Julia](https://discourse.julialang.org/t/survey-of-non-linear-optimization-modeling-layers-in-julia/78168):
>
> I am doing a survey of the NLP modeling layers in Julia to see which might be applicable to the kinds of problems that I regularly solve. I have the following basic requirements of the modeling layer, Support for non-convex functions for the objective Support for a system non-convex equality and inequality constraint functions (the equality constraints usually cannot be expressed explicitly as a manifold) Support for polynomial and transcendental functions (e.g. x^2\*y^3,sin(x)) Some kind of a…

I’m moving your post to the more relevant Optimization category where you might get more expert attention.

> [@Itzahack23](#):
>
> Actually, when I use JuMP + Ipopt, the problem is not solved correctly, and I found that the number of nonzero elements in Lagrangian Hessian is much larger than the number theoretically derived.

If you can share a reproducible example, this would be of interest to JuMP developers to potentially identify an issue.

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [June 27, 2022, 5:35pm UTC](https://discourse.julialang.org/t/debugging-in-ipopt-without-jump/83384/3 "2022-06-27T17:35:18Z")

</div>

> The unfortunate thing is that Ipopt stops due to segfault.

Did you follow the warnings here?

> **[GitHub - jump-dev/Ipopt.jl: Julia interface to the Ipopt nonlinear solver](https://github.com/jump-dev/Ipopt.jl#c-interface-wrapper)**
>
> Julia interface to the Ipopt nonlinear solver. Contribute to jump-dev/Ipopt.jl development by creating an account on GitHub.

It’s hard to say more without a reproducible example.

> the problem is not solved correctly

What happened? It found a suboptimal solution? Or it converged to an infeasible point?

> I found that the number of nonzero elements in Lagrangian Hessian is much larger than the number theoretically derived.

Yes. JuMP computes the hessian in a way that causes repeated elements in the hessian, but this is not a performance problem. JuMP still computes the true sparse hessian.

---

<div class="post-metadata">

### Author: ![Itzahack23](https://avatars.discourse-cdn.com/v4/letter/i/aca169/32.png) [@Itzahack23](https://discourse.julialang.org/u/Itzahack23)
#### Post date: [June 28, 2022, 2:09am UTC](https://discourse.julialang.org/t/debugging-in-ipopt-without-jump/83384/4 "2022-06-28T02:09:00Z")

</div>

Hi @jd-foster and @odow,  
Thank you for your replies.

I understand that a reproducible example helps to improve our conversation. But as I am trying to solve a complicated problem, it will take time to convert it into a simple version for showing on this post.

On the other hand, I would like to ask about the warnings pointed out by @odow.

I read the warning and checked the C wrapper example in `test` folder before.  
My understanding of the warning is as follows.  
It seems that `values == nothing` happens at the beginning of the optimization so as to specify which elements in the jacobian and hessian are nonzero in Ipopt and we do not specify the value of ‘values’ in any line in the example.  
Therefore, as long as we do not try to access the elements of `x` in a conditional branch, say starting from line 88, the warned situation does not occur.  
And I do not write a code in which I access the elements of `x` in a conditional branch starting by `values == nothing`.  
Thus I am thinking that the cause of segfault does not come from this.  
Do I misunderstand the warning? Or is there another situation the warning is effective?

By the way, when I use JuMP + Ipopt, the optimization stops as it converges to an infeasible point.

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [June 28, 2022, 2:36am UTC](https://discourse.julialang.org/t/debugging-in-ipopt-without-jump/83384/5 "2022-06-28T02:36:19Z")

</div>

> I understand that a reproducible example helps to improve our conversation

If you are manually constructing the callbacks, there are a lot of things that can go wrong. It’s hard to say more without code. A segfault usually means that you did something wrong in the callback. Did you compute the correct number of non-zeros? Does the structure of your non-zeros remain constant over the iterations? Did you fill them in in the correct order?

> By the way, when I use JuMP + Ipopt, the optimization stops as it converges to an infeasible point.

If you know the problem has a feasible solution, that usually means your starting point was far from feasibility. Try passing a feasible starting point. You can use `set_start_value(x, value)` in JuMP to set the starting point.

---

<div class="post-metadata">

### Author: ![Itzahack23](https://avatars.discourse-cdn.com/v4/letter/i/aca169/32.png) [@Itzahack23](https://discourse.julialang.org/u/Itzahack23)
#### Post date: [June 29, 2022, 1:48am UTC](https://discourse.julialang.org/t/debugging-in-ipopt-without-jump/83384/6 "2022-06-29T01:48:56Z")

</div>

Hi @odow,

Actually, I rechecked my code based on your advice and found a mistake.  
Now Ipopt works without Jump.

Thank you for your replies!
