# Hyperparameters to tune/try when getting ITERATION\_LIMIT, NUMERICAL\_ERROR for nonlinear optimization

**URL:** <https://discourse.julialang.org/t/hyperparameters-to-tune-try-when-getting-iteration-limit-numerical-error-for-nonlinear-optimization/75232>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [January 26, 2022, 3:27pm UTC](https://discourse.julialang.org/t/hyperparameters-to-tune-try-when-getting-iteration-limit-numerical-error-for-nonlinear-optimization/75232 "2022-01-26T15:27:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_Shen1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevin_shen1/32/33160_2.png) [@Kevin\_Shen1](https://discourse.julialang.org/u/Kevin_Shen1)\
**Post date:** [January 26, 2022, 3:27pm UTC](https://discourse.julialang.org/t/hyperparameters-to-tune-try-when-getting-iteration-limit-numerical-error-for-nonlinear-optimization/75232/1 "2022-01-26T15:27:25Z")

</div>

Generally what hyperparameters should one try when getting the above two exit codes? I tried increasing max\_iter to 10,000 which noticeably slowed down the optimization but I’m still getting ITERATION\_LIMIT. One thing I’m not 100% sure is whether Ipopt is by-default running a first-order or second-order gradient method?

Note: I’m running optmiization multiple times and based on different initialization/objective parameter values, get either ITERATION\_LIMIT or NUMERICAL\_ERROR.

Hoping there are some generic solutions to try before providing more details about my specific use-case. Code:

```julia
model = Model(Ipopt.Optimizer)
  
tolerance = 1e-7
@variable(model, 1-tolerance>= x[1:4] >= 0+tolerance)
x0 = rand(.......
set_start_value.(x, x0)
  
@constraint(model, ........)
  
# my_objective(x...) = .........
  
register(model, :mobj, length(x), my_objective; autodiff = true)
@NLobjective(model, Min, mobj(x...))
  
optimize!(model)

```

---

<div class="post-metadata">

**Author:** ![Kevin\_Shen1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevin_shen1/32/33160_2.png) [@Kevin\_Shen1](https://discourse.julialang.org/u/Kevin_Shen1)\
**Post date:** [January 26, 2022, 4:23pm UTC](https://discourse.julialang.org/t/hyperparameters-to-tune-try-when-getting-iteration-limit-numerical-error-for-nonlinear-optimization/75232/2 "2022-01-26T16:23:54Z")

</div>

Answering my own question. I solved this by using NLopt (with LD\_SLSQP) instead of Ipopt. It seems to work much better out of the box which is better for noobies. It also allowed me to remove the tolerance hack.

```julia
model = Model(NLopt.Optimizer)
set_optimizer_attribute(model, "algorithm", :LD_SLSQP)
  
@variable(model, 1>= x[1:4] >= 0)
x0 = rand(.......
set_start_value.(x, x0)
  
@constraint(model, ........)
  
# my_objective(x...) = .........
  
register(model, :mobj, length(x), my_objective; autodiff = true)
@NLobjective(model, Min, mobj(x...))
  
JuMP.optimize!(model)

```

---

<div class="post-metadata">

**Author:** ![cvanaret](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cvanaret/32/11594_2.png) [@cvanaret](https://discourse.julialang.org/u/cvanaret)\
**Post date:** [January 26, 2022, 4:27pm UTC](https://discourse.julialang.org/t/hyperparameters-to-tune-try-when-getting-iteration-limit-numerical-error-for-nonlinear-optimization/75232/3 "2022-01-26T16:27:40Z")

</div>

If your model is twice-differentiable, Ipopt will use exact Hessians. **Edit! See post below**

Since you left out the definition of your functions, we can’t say why Ipopt is struggling. Good that it worked with SLSQP anyway!

---

<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:** [January 26, 2022, 7:48pm UTC](https://discourse.julialang.org/t/hyperparameters-to-tune-try-when-getting-iteration-limit-numerical-error-for-nonlinear-optimization/75232/4 "2022-01-26T19:48:29Z")

</div>

Just one small correction: Ipopt won’t use exact hessians if you pass a multi-variate user-defined function: [https://github.com/jump-dev/JuMP.jl/issues/1198](https://github.com/jump-dev/JuMP.jl/issues/1198).
