# Help debugging \`nlopt failure: -1\` errors

**URL:** <https://discourse.julialang.org/t/help-debugging-nlopt-failure-1-errors/11907>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [June 24, 2018, 12:23pm UTC](https://discourse.julialang.org/t/help-debugging-nlopt-failure-1-errors/11907 "2018-06-24T12:23:29Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [June 24, 2018, 12:23pm UTC](https://discourse.julialang.org/t/help-debugging-nlopt-failure-1-errors/11907/1 "2018-06-24T12:23:29Z")

</div>

Any tips on debugging `nlopt failure: -1` errors? There is no information in the error message to understand what happened. Sometimes I have found that this occurs because I am computing something wrong in the gradient. But in other occasions I just can’t tell what happened. Is there a list of possible issues that can lead to this error?

---

<div class="post-metadata">

**Author:** ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)\
**Post date:** [June 24, 2018, 12:41pm UTC](https://discourse.julialang.org/t/help-debugging-nlopt-failure-1-errors/11907/2 "2018-06-24T12:41:47Z")

</div>

It looks like that string is defined [here](https://github.com/JuliaOpt/NLopt.jl/blob/master/src/NLopt.jl#L266) and the function `chk` is called on setting parameters. I don’t think the C library is more specific than that.

I do have the same problem from time to time, for instance trying to set constraints on algorithms that do not take any and I would also benefit from finer error messages.

---

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [June 24, 2018, 1:02pm UTC](https://discourse.julialang.org/t/help-debugging-nlopt-failure-1-errors/11907/3 "2018-06-24T13:02:22Z")

</div>

In my particular scenario, I don’t have any constrains, and I am using `:LD_LBFGS`.

---

<div class="post-metadata">

**Author:** ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)\
**Post date:** [June 25, 2018, 4:57am UTC](https://discourse.julialang.org/t/help-debugging-nlopt-failure-1-errors/11907/4 "2018-06-25T04:57:29Z")

</div>

What is the cause of your errors?

---

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [June 25, 2018, 7:28am UTC](https://discourse.julialang.org/t/help-debugging-nlopt-failure-1-errors/11907/5 "2018-06-25T07:28:22Z")

</div>

I don’t know, that’s the problem. I already checked that the gradient is being computed correctly, and that it does not go to infinity. I’m not sure what else could be the cause of this.

---

<div class="post-metadata">

**Author:** ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)\
**Post date:** [June 25, 2018, 9:28am UTC](https://discourse.julialang.org/t/help-debugging-nlopt-failure-1-errors/11907/6 "2018-06-25T09:28:38Z")

</div>

Can you post the code?

---

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [June 25, 2018, 9:56am UTC](https://discourse.julialang.org/t/help-debugging-nlopt-failure-1-errors/11907/7 "2018-06-25T09:56:38Z")

</div>

I fear it is a very complicated optimization problem. That’s why I framed the question a bit more generally. I am interested in all the possible issues that could give raise to the `nlopt failure: -1` error, or at least the most common causes, if such a list is possible.

---

<div class="post-metadata">

**Author:** ![mrapo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrapo/32/3911_2.png) [@mrapo](https://discourse.julialang.org/u/mrapo)\
**Post date:** [June 26, 2018, 7:38am UTC](https://discourse.julialang.org/t/help-debugging-nlopt-failure-1-errors/11907/8 "2018-06-26T07:38:39Z")

</div>

I’m experiencing the same issue. I also have a pretty complicated optimization problem with 5 constraint functions. I’m using the LD\_SLSQP algorithm.

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [June 26, 2018, 10:41am UTC](https://discourse.julialang.org/t/help-debugging-nlopt-failure-1-errors/11907/9 "2018-06-26T10:41:33Z")

</div>

Do similar problems arise with a different solver (e.g. Ipopt)?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [June 26, 2018, 1:29pm UTC](https://discourse.julialang.org/t/help-debugging-nlopt-failure-1-errors/11907/10 "2018-06-26T13:29:47Z")

</div>

> [@e3c6](#):
>
> interested in all the possible issues that could give raise to the `nlopt failure: -1` error, or at least the most common causes, if such a list is possible.

The most common cause is that your gradient is wrong, and so the algorithm gives up.

---

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [June 26, 2018, 1:36pm UTC](https://discourse.julialang.org/t/help-debugging-nlopt-failure-1-errors/11907/11 "2018-06-26T13:36:05Z")

</div>

So if I use autodiff I should never get this error. I will try that and see.
