# ANN: NLPModels.jl v0.1.0

**URL:** <https://discourse.julialang.org/t/ann-nlpmodels-jl-v0-1-0/1795>\
**Category:** Optimization (Mathematical)\
**Tags:** announcement\
**Created:** [January 31, 2017, 2:47am UTC](https://discourse.julialang.org/t/ann-nlpmodels-jl-v0-1-0/1795 "2017-01-31T02:47:16Z")\
**Posts on this page:** 8\
**Page:** 1

<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:** [January 31, 2017, 2:47am UTC](https://discourse.julialang.org/t/ann-nlpmodels-jl-v0-1-0/1795/1 "2017-01-31T02:47:16Z")

</div>

Hello everyone,

we’re happy to announce [NLPModels.jl](https://github.com/JuliaSmoothOptimizers/NLPModels.jl) v0.1.0, a package providing ways to create Nonlinear Programming Models with a standardized API. This allows the creation of algorithms that can rely on that API to access the objective and constraints functions and their derivatives.

The package provides a few models, and some extensions have already been made:

- **ADNLPModel:** A model using automatic differentiation;
- **SimpleNLPModel:** A simple wrapper for used defined functions;
- **MathProgNLPModel:** A model that converts [MathProgBase](https://github.com/JuliaOpt/MathProgBase.jl) models to NLPModels. Especially useful for [JuMP](https://github.com/JuliaOpt/JuMP.jl) models, such as the ones already created in [OptimizationProblems.jl](https://github.com/JuliaSmoothOptimizers/OptimizationProblems.jl);
- **CUTEstModel** from [CUTEst.jl](https://github.com/JuliaSmoothOptimizers/CUTEst.jl): A model created from the [Constrained and Unconstrained Testing Environment](https://ccpforge.cse.rl.ac.uk/gf/project/cutest/) library;
- **AmplModel** from [AmplNLReader.jl](https://github.com/JuliaSmoothOptimizers/AmplNLReader.jl): A model created from an [AMPL](http://ampl.com/) model.

A simple example (after installing `ForwardDiff`)

```julia
nlp = ADNLPModel(x -> (x[1] - 1)^2 + 100*(x[2] - x[1]^2)^2, [-1.2; 1.0])
x = nlp.meta.x0 # [-1.2; 1.0]
obj(nlp, x) # Returns f(x)
g(x) = grad(nlp, x) # Returns the gradient at x
H(x) = hess(nlp, x) # Returns the lower triangle of the Hessian at x

```

Check the [tutorial](http://juliasmoothoptimizers.github.io/NLPModels.jl/latest/tutorial.html) for more details, including an implementation of a Steepest Descent method using NLPModels.

* * *

Check our other packages too: [JuliaSmoothOptimizers](https://github.com/JuliaSmoothOptimizers)

Best,

Abel S. Siqueira

---

<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:** [January 31, 2017, 3:24am UTC](https://discourse.julialang.org/t/ann-nlpmodels-jl-v0-1-0/1795/2 "2017-01-31T03:24:59Z")

</div>

How do this differ from nonlinear models made in JuMP? (Not trying to be antagonistic, just curious)

---

<div class="post-metadata">

**Author:** ![ccoffrin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccoffrin/32/400_2.png) [@ccoffrin](https://discourse.julialang.org/u/ccoffrin)\
**Post date:** [January 31, 2017, 4:19am UTC](https://discourse.julialang.org/t/ann-nlpmodels-jl-v0-1-0/1795/3 "2017-01-31T04:19:51Z")

</div>

I’ll second the request for a compare and contrast to JuMP.

---

<div class="post-metadata">

**Author:** ![miles.lubin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miles.lubin/32/279_2.png) [@miles.lubin](https://discourse.julialang.org/u/miles.lubin)\
**Post date:** [January 31, 2017, 4:29am UTC](https://discourse.julialang.org/t/ann-nlpmodels-jl-v0-1-0/1795/4 "2017-01-31T04:29:15Z")

</div>

If I understand correctly, it’s an abstraction layer like MathProgBase but designed more specifically for writing NLP solvers.

---

<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:** [January 31, 2017, 10:57am UTC](https://discourse.julialang.org/t/ann-nlpmodels-jl-v0-1-0/1795/5 "2017-01-31T10:57:17Z")

</div>

Hello again.

Miles is correct, NLPModels is closer to MathProgBase than to JuMP, but we focus on Nonlinear Optimization, and on writing solvers.

The MPB way, from what I saw, is to create the functions a solver requires, and JuMP provides a way for the user to write something connecting to MPB.

The NLPModels way is to write solvers with an `AbstractNLPModel` as argument, and use the NLPModels API. Furthermore, there are some ways to create NLPModels, so the writer can test his solver on hand-written problems, JuMP-written problems and CUTEst problems.

To finalize, we also have a function called `NLPtoMPB` than converts a NLPModel to a MPB model. So there is some interchangeability. [In this example](https://github.com/JuliaSmoothOptimizers/CUTEst.jl/blob/master/test/test_mpb.jl) we solve a CUTEst problem using `Ipopt`.

---

<div class="post-metadata">

**Author:** ![tkelman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkelman/32/692_2.png) [@tkelman](https://discourse.julialang.org/u/tkelman)\
**Post date:** [February 1, 2017, 4:33am UTC](https://discourse.julialang.org/t/ann-nlpmodels-jl-v0-1-0/1795/6 "2017-02-01T04:33:53Z")

</div>

From my reading and some discussions of how NLPModels works and differs from MathProgBase, in terms of implementation, MPB specifies an API that all solvers implement and all user-facing modeling layers talk to solvers through. NLPModels also defines a concrete data structure, whereas in MPB each solver is free to implement its own type and store relevant data however it would like (closer to whichever solver API it happens to be wrapping, usually). Correct me if that’s a bad take on it.

---

<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:** [February 1, 2017, 11:06am UTC](https://discourse.julialang.org/t/ann-nlpmodels-jl-v0-1-0/1795/7 "2017-02-01T11:06:36Z")

</div>

Not sure from the MPB side, but I think so. Yes for the NLPModels. I think it would be clearer if we had a native Julia solver using MPB. [Here](https://github.com/JuliaSmoothOptimizers/Optimize.jl/blob/master/src/solver/trunk.jl)’s an example of a solver using NLPModels.

---

<div class="post-metadata">

**Author:** ![dpo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpo/32/3335_2.png) [@dpo](https://discourse.julialang.org/u/dpo)\
**Post date:** [February 2, 2017, 6:19pm UTC](https://discourse.julialang.org/t/ann-nlpmodels-jl-v0-1-0/1795/8 "2017-02-02T18:19:25Z")

</div>

Whereas JuMP is a modeling language, NLPModels is a model API that has worked well for us in the past and that can be relied upon when writing solvers in pure Julia. Compared to MPB, NLPModels mostly disconnects solver and model. It has a somewhat richer API that allows methods such as `objgrad()` for problems where computing the objective value and gradient together is more efficient than obtaining each separately. You can also, e.g., add slack variables to any model transparently. That said, the code is still young, so all comments and bug reports are most welcome.

As Abel mentioned, models may be loaded from [an AMPL nl file](https://github.com/JuliaSmoothOptimizers/AmplNLReader.jl), a [CUTEst SIF file](https://github.com/JuliaSmoothOptimizers/CUTEst.jl), a [JuMP model](https://github.com/JuliaSmoothOptimizers/OptimizationProblems.jl), [pure Julia functions](https://github.com/JuliaSmoothOptimizers/NLPModels.jl/blob/master/test/test_simple_model.jl), or from Julia functions that realize an interface with some other system. They can also be passed to an MPB-enabled solver.
