# Write nonlinear model in separate file?

**URL:** <https://discourse.julialang.org/t/write-nonlinear-model-in-separate-file/4054>\
**Category:** General Usage\
**Created:** [June 2, 2017, 7:31am UTC](https://discourse.julialang.org/t/write-nonlinear-model-in-separate-file/4054 "2017-06-02T07:31:11Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![gopal2017](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gopal2017/32/31747_2.png) [@gopal2017](https://discourse.julialang.org/u/gopal2017)\
**Post date:** [June 2, 2017, 7:31am UTC](https://discourse.julialang.org/t/write-nonlinear-model-in-separate-file/4054/1 "2017-06-02T07:31:11Z")

</div>

For linear model we can use `writeLP(m::Model, filename::String)`. What macro we can use for nonlinear model? .LP file format won’t support.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [June 2, 2017, 8:01pm UTC](https://discourse.julialang.org/t/write-nonlinear-model-in-separate-file/4054/2 "2017-06-02T20:01:48Z")

</div>

You need to specify the context (which package you are using).

---

<div class="post-metadata">

**Author:** ![gopal2017](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gopal2017/32/31747_2.png) [@gopal2017](https://discourse.julialang.org/u/gopal2017)\
**Post date:** [June 3, 2017, 4:00am UTC](https://discourse.julialang.org/t/write-nonlinear-model-in-separate-file/4054/3 "2017-06-03T04:00:09Z")

</div>

Sure. I am using two separate files. One for Ipopt and other for NLopt. Please let me know the way to write nonlinear model to a file just like writeLP.

---

<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:** [June 3, 2017, 4:27am UTC](https://discourse.julialang.org/t/write-nonlinear-model-in-separate-file/4054/4 "2017-06-03T04:27:02Z")

</div>

You can use either AmplNLWriter (.nl) or CoinOptServices (.osil). What do you want to then do with the saved model?

---

<div class="post-metadata">

**Author:** ![gopal2017](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gopal2017/32/31747_2.png) [@gopal2017](https://discourse.julialang.org/u/gopal2017)\
**Post date:** [June 4, 2017, 4:15pm UTC](https://discourse.julialang.org/t/write-nonlinear-model-in-separate-file/4054/5 "2017-06-04T16:15:31Z")

</div>

It means I am supposed to install AmplNLWriter to print .nl file. Any prvision in Ipopt solver to print .nl file.

---

<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:** [June 6, 2017, 2:15am UTC](https://discourse.julialang.org/t/write-nonlinear-model-in-separate-file/4054/6 "2017-06-06T02:15:09Z")

</div>

You use the IpoptNLSolver described in the AmplNLWriter package documentation [https://github.com/JuliaOpt/AmplNLWriter.jl/#amplnlwriterjl](https://github.com/JuliaOpt/AmplNLWriter.jl/#amplnlwriterjl)

What are you trying to do with the .nl file once you have it?

---

<div class="post-metadata">

**Author:** ![gopal2017](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gopal2017/32/31747_2.png) [@gopal2017](https://discourse.julialang.org/u/gopal2017)\
**Post date:** [June 6, 2017, 6:36am UTC](https://discourse.julialang.org/t/write-nonlinear-model-in-separate-file/4054/7 "2017-06-06T06:36:56Z")

</div>

Hi,  
If I use IpoptSolver instead of IpoptNLSolver for nonlinear  
function. Will it work?

Thanks,

---

<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:** [June 7, 2017, 3:32pm UTC](https://discourse.julialang.org/t/write-nonlinear-model-in-separate-file/4054/8 "2017-06-07T15:32:55Z")

</div>

IpoptSolver uses in-memory API’s and does not write a file. IpoptNLSolver writes a .nl file.

You need to be more specific than “Will it work?” - what, exactly, are you trying to accomplish?

---

<div class="post-metadata">

**Author:** ![gopal2017](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gopal2017/32/31747_2.png) [@gopal2017](https://discourse.julialang.org/u/gopal2017)\
**Post date:** [June 7, 2017, 5:08pm UTC](https://discourse.julialang.org/t/write-nonlinear-model-in-separate-file/4054/9 "2017-06-07T17:08:27Z")

</div>

Thanks. Should I use IpoptSolver or IpoptNLSolver for non-linear problem?

---

<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:** [June 7, 2017, 5:17pm UTC](https://discourse.julialang.org/t/write-nonlinear-model-in-separate-file/4054/10 "2017-06-07T17:17:27Z")

</div>

You can try both and compare. IpoptSolver doesn’t have to write the model to a .nl file or read results back from a .sol file or incur the overhead of shelling out to a separate executable, but IpoptNLSolver uses the same C library as AMPL to evaluate function gradients, constraint Jacobian, etc so can sometimes perform a bit better than the pure-Julia automatic differentiation that IpoptSolver uses.

Note that for most sizable nonlinear problems of the type you would solve with JuMP, function evaluation is usually a minor portion of the total execution time. The sparse linear algebra operations inside Ipopt will take most of the time, and those will be the same between IpoptSolver and IpoptNLSolver.
