Write nonlinear model in separate file?


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.


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


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.


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


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


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

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


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



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?


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


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.