# What would you recommend for nolinear optimization with optional gradient and hessian

**URL:** https://discourse.julialang.org/t/what-would-you-recommend-for-nolinear-optimization-with-optional-gradient-and-hessian/41555
**Category:** Optimization (Mathematical)
**Tags:** optimization
**Created:** [June 16, 2020, 10:40pm UTC](https://discourse.julialang.org/t/what-would-you-recommend-for-nolinear-optimization-with-optional-gradient-and-hessian/41555 "2020-06-16T22:40:35Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![sunjin](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@sunjin](https://discourse.julialang.org/u/sunjin)
#### Post date: [June 16, 2020, 10:40pm UTC](https://discourse.julialang.org/t/what-would-you-recommend-for-nolinear-optimization-with-optional-gradient-and-hessian/41555/1 "2020-06-16T22:40:35Z")

</div>

Hi, I am solving a numerical box-constrained nonlinear optimization problem with hundreds of unknowns. I currently implemented only the objective function but not the gradient or hessian. However, I expect to do so in the future.  
I would like to get recommendations on a light-weighted optimization tool that takes optional gradient and hessian info, but can compute them numerically by itself if these are not available. I have had good experience with sequential quadratic programming, and would like it to be the underlying algorithm. I looked at several options, include optim and NLopt, neither allow me to skip the gradient function.  
So, what are my options? Do I have to implement gradients myself? Thanks a lot.

---

<div class="post-metadata">

### Author: ![abelsiqueira](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abelsiqueira/32/47269_2.png) [@abelsiqueira](https://discourse.julialang.org/u/abelsiqueira)
#### Post date: [June 17, 2020, 2:02am UTC](https://discourse.julialang.org/t/what-would-you-recommend-for-nolinear-optimization-with-optional-gradient-and-hessian/41555/2 "2020-06-17T02:02:21Z")

</div>

Hi @sunjin, the organization I’m part of, JuliaSmoothOptimizers, has an implementation of `tron` that handles box-constrained problems. You can define your problem and solve with `tron` with the following code:

```julia
using NLPModels, JSOSolvers
nlp = ADNLPModel(objective, x0, lvar, uvar) # NLPModels 0.13
output = tron(nlp)

```

This will use `ForwardDiff` to compute the derivatives internally. Alternatively, you can use some other tool to define your problem such as JuMP or AMPL and solve it the same way.

Finally, you can define your functions manually. It’s a longer code, but I have a video here: [JuliaSmoothOptimizers Tutorials - Defining your optimization model manually - part 1 - YouTube](https://www.youtube.com/watch?v=R5MU4fWTeho&feature=youtu.be)

Also, you can use `ipopt` instead of `tron`, by adding `NLPModelsIpopt` and calling `ipopt(nlp)`.

Obs.: Since the video came out, we’ve updated `ADNLPModel`, so the syntax is slightly different in NLPModels 0.12.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [June 17, 2020, 2:17am UTC](https://discourse.julialang.org/t/what-would-you-recommend-for-nolinear-optimization-with-optional-gradient-and-hessian/41555/3 "2020-06-17T02:17:39Z")

</div>

> [@sunjin](#):
>
> I would like to get recommendations on a light-weighted optimization tool that takes optional gradient and hessian info, but can compute them numerically by itself if these are not available. I have had good experience with sequential quadratic programming, and would like it to be the underlying algorithm. I looked at several options, include optim and NLopt, neither allow me to skip the gradient function.

Optim doesn’t require a gradient. Just call `optimize(f,u0)`

---

<div class="post-metadata">

### Author: ![sunjin](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@sunjin](https://discourse.julialang.org/u/sunjin)
#### Post date: [June 17, 2020, 3:39am UTC](https://discourse.julialang.org/t/what-would-you-recommend-for-nolinear-optimization-with-optional-gradient-and-hessian/41555/4 "2020-06-17T03:39:22Z")

</div>

Thank you. I will check it out.

---

<div class="post-metadata">

### Author: ![sunjin](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@sunjin](https://discourse.julialang.org/u/sunjin)
#### Post date: [June 17, 2020, 3:40am UTC](https://discourse.julialang.org/t/what-would-you-recommend-for-nolinear-optimization-with-optional-gradient-and-hessian/41555/5 "2020-06-17T03:40:33Z")

</div>

You are right. optim does seem to use finite difference if gradient is not avaliable.

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [June 17, 2020, 5:40am UTC](https://discourse.julialang.org/t/what-would-you-recommend-for-nolinear-optimization-with-optional-gradient-and-hessian/41555/6 "2020-06-17T05:40:52Z")

</div>

Optim has support for Forwarddiiff as well.
