# Solve problems starting from corresponding .nl files

**URL:** <https://discourse.julialang.org/t/solve-problems-starting-from-corresponding-nl-files/91306>\
**Category:** Optimization (Mathematical)\
**Tags:** question, optimization, nonlinear\
**Created:** [December 6, 2022, 2:46pm UTC](https://discourse.julialang.org/t/solve-problems-starting-from-corresponding-nl-files/91306 "2022-12-06T14:46:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luca](https://avatars.discourse-cdn.com/v4/letter/l/51bf81/32.png) [@Luca](https://discourse.julialang.org/u/Luca)\
**Post date:** [December 6, 2022, 2:46pm UTC](https://discourse.julialang.org/t/solve-problems-starting-from-corresponding-nl-files/91306/1 "2022-12-06T14:46:11Z")

</div>

Dear all,

I want to solve a bunch of nonlinear optimization problems, whose nl. files are available. Hence I would like to charge the .nl files directly in Julia and solve the corresponding problem with a nonlinear solver like Ipopt. Do you know if there is a way to realize it?

Thanks very much. All your support is really appreciated!

---

<div class="post-metadata">

**Author:** ![tmigot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tmigot/32/23914_2.png) [@tmigot](https://discourse.julialang.org/u/tmigot)\
**Post date:** [December 6, 2022, 3:02pm UTC](https://discourse.julialang.org/t/solve-problems-starting-from-corresponding-nl-files/91306/2 "2022-12-06T15:02:07Z")

</div>

Hi @Luca

You can use [AmplNLReader.jl](https://github.com/JuliaSmoothOptimizers/AmplNLReader.jl) and [NLPModelsIpopt.jl](https://github.com/JuliaSmoothOptimizers/NLPModelsIpopt.jl) wrapper to Ipopt.

For instance:

```julia
using AmplNLReader, NLPModelsIpopt

hs33 = AmplModel("hs033.nl")
ipopt(hs33)

```

---

<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:** [December 6, 2022, 3:04pm UTC](https://discourse.julialang.org/t/solve-problems-starting-from-corresponding-nl-files/91306/3 "2022-12-06T15:04:58Z")

</div>

Hi Luca,

You can use AmplNLReader.jl ([https://juliasmoothoptimizers.github.io/AmplNLReader.jl/stable/](https://juliasmoothoptimizers.github.io/AmplNLReader.jl/stable/)).  
Also, check this tutorial on how to call NLPModelsIpopt.jl: [https://juliasmoothoptimizers.github.io/tutorials/solve-an-optimization-problem-with-ipopt/](https://juliasmoothoptimizers.github.io/tutorials/solve-an-optimization-problem-with-ipopt/)

Best,

---

<div class="post-metadata">

**Author:** ![Luca](https://avatars.discourse-cdn.com/v4/letter/l/51bf81/32.png) [@Luca](https://discourse.julialang.org/u/Luca)\
**Post date:** [December 6, 2022, 3:19pm UTC](https://discourse.julialang.org/t/solve-problems-starting-from-corresponding-nl-files/91306/4 "2022-12-06T15:19:14Z")

</div>

Thanks for the the quick answers! I would like to use also bonmin, couenne, and shot as solvers since there are integer variables in my model. Is it possible too? I check [GitHub - jump-dev/AmplNLWriter.jl: Julia interface to AMPL-enabled solvers](https://github.com/jump-dev/AmplNLWriter.jl).

---

<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:** [December 6, 2022, 6:51pm UTC](https://discourse.julialang.org/t/solve-problems-starting-from-corresponding-nl-files/91306/5 "2022-12-06T18:51:41Z")

</div>

With JuMP, you’re after something like this:

```julia
using JuMP, AmplNLWriter, Bonmin_jll
model = read_from_file("file.nl")
set_optimizer(model, () -> AmplNLWriter.Optimizer(Bonmin_jll.amplexe))
optimize!(model)

```

---

<div class="post-metadata">

**Author:** ![Luca](https://avatars.discourse-cdn.com/v4/letter/l/51bf81/32.png) [@Luca](https://discourse.julialang.org/u/Luca)\
**Post date:** [December 8, 2022, 10:30am UTC](https://discourse.julialang.org/t/solve-problems-starting-from-corresponding-nl-files/91306/6 "2022-12-08T10:30:39Z")

</div>

Thanks for your answer. I tried the following code:

```julia
using JuMP, AmplNLWriter, SHOT_jll

model1 = MOI.FileFormats.Model(format = MOI.FileFormats.FORMAT_NL)
model = read_from_file(model1, "instance_15_3_1_0.nl")
set_optimizer(model, () -> AmplNLWriter.Optimizer(SHOT_jll.amplexe))
optimize!(model)

```

but I obtain the following error:

```julia
ERROR: LoadError: UndefVarError: FORMAT_NL not defined

```

---

<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:** [December 8, 2022, 6:16pm UTC](https://discourse.julialang.org/t/solve-problems-starting-from-corresponding-nl-files/91306/7 "2022-12-08T18:16:09Z")

</div>

Your code is not what I wrote?

> FORMAT\_NL not defined

This suggests you have an old version of MathOptInterface installed.

Try what I wrote, and if that doesn’t work, update your packages.

---

<div class="post-metadata">

**Author:** ![Luca](https://avatars.discourse-cdn.com/v4/letter/l/51bf81/32.png) [@Luca](https://discourse.julialang.org/u/Luca)\
**Post date:** [December 13, 2022, 10:03am UTC](https://discourse.julialang.org/t/solve-problems-starting-from-corresponding-nl-files/91306/8 "2022-12-13T10:03:15Z")

</div>

I have update all Julia packages. I tried your code and it works! Thanks you so much!
