NLPModels.jl
NLPModels, similarly to Optimization.jl itself, provides a standardized modeling interface for representing Non-Linear Programs that facilitates using different solvers on the same problem. The Optimization.jl extension of NLPModels aims to provide a thin translation layer to make NLPModels, the main export of the package, compatible with the optimizers in the Optimization.jl ecosystem.
Installation: NLPModels.jl
To translate an NLPModel, install the OptimizationNLPModels package:
import Pkg;
Pkg.add("OptimizationNLPModels")The package NLPModels.jl itself contains no optimizers or models. Several packages provide optimization problem (CUTEst.jl, NLPModelsTest.jl) which can then be solved with any optimizer supported by Optimization.jl
Usage
For example, solving a problem defined in NLPModelsTest with Ipopt.jl. First, install the packages like so:
import Pkg;
Pkg.add("NLPModelsTest", "Ipopt")We instantiate problem 10 in the Hock–Schittkowski optimization suite available from NLPModelsTest as HS10, then translate it to an OptimizationProblem.
using OptimizationNLPModels, OptimizationBase, NLPModelsTest, Ipopt
using OptimizationBase: OptimizationProblem
nlpmodel = NLPModelsTest.HS10()
prob = OptimizationProblem(nlpmodel, AutoForwardDiff())OptimizationProblem. In-place: true
u0: 2-element Vector{Float64}:
-10.0
10.0which can now be solved like any other OptimizationProblem:
sol = solve(prob, Ipopt.Optimizer())retcode: Success
u: 2-element Vector{Float64}:
-5.547032851145213e-15
1.0000000024923896Reexported NLPModels.jl API
using OptimizationNLPModels brings the following names into scope. They are owned and documented by NLPModels.jl; this package only re-exports them.
- Model types:
AbstractNLPModel,AbstractNLSModel - Metadata and counters:
NLPModelMeta,NLSMeta,Counters,NLSCounters - The
NLPModelsmodule itself
NLPModels' evaluation interface — obj, grad, cons, hess, jprod! and the roughly two hundred other functions — is deliberately not re-exported: the whole point of this package is that OptimizationFunction calls them for you. Reach them through the module, as NLPModels.obj(model, x).
Anything else from NLPModels.jl must be imported from NLPModels directly.
API
Problems represented as NLPModels can be used to create OptimizationProblems and OptimizationFunction.
OptimizationNLPModels.NLPModelsAdaptor — Type
NLPModelsAdaptor(cache, meta, counters)NLPModels.jl adapter that exposes an OptimizationCache as an NLPModels.AbstractNLPModel.
OptimizationNLPModels.build_nlpmodel_meta — Function
build_nlpmodel_meta(cache)Build an NLPModels.NLPModelMeta object from an Optimization.jl cache, including variable bounds, constraint bounds, initial values, and Jacobian/Hessian sparsity counts.