Skip to content

Latest commit

 

History

History
92 lines (82 loc) · 3.91 KB

File metadata and controls

92 lines (82 loc) · 3.91 KB

OptimizationProblems.jl Tutorial

In this tutorial, we will see how to access the problems in JuMP and ADNLPModel syntax. This package is subdivided in two submodules: PureJuMP for the JuMP problems, ADNLPProblems for the ADNLPModel problems.

Problems in JuMP syntax: PureJuMP

You can obtain the list of problems currently defined with OptimizationProblems.meta[!, :name].

using OptimizationProblems, OptimizationProblems.PureJuMP
problems = OptimizationProblems.meta[!, :name]
length(problems)

Then, it suffices to select any of this problem to get the JuMP model.

jump_model = zangwil3()

Note that certain problems are scalable, i.e., their size depends on parameters that can be modified. The list of those problems is available once again using meta:

var_problems = OptimizationProblems.meta[OptimizationProblems.meta.variable_nvar, :name]
length(var_problems)

Then, using the keyword n, it is possible to specify the targeted number of variables.

jump_model_12 = woods(n=12)
jump_model_120 = woods(n=120)

These problems can be converted as NLPModels via NLPModelsJuMP to facilitate evaluating objective, constraints and their derivatives.

using NLPModels, NLPModelsJuMP
nlp_model_120 = MathOptNLPModel(jump_model_120)
obj(nlp_model_120, zeros(120))

Problems in ADNLPModel syntax: ADNLPProblems

This package also offers ADNLPModel test problems. This is an optional dependency, so ADNLPModels has to be added first.

using ADNLPModels

You can obtain the list of problems currently defined with OptimizationProblems.meta[!, :name]:

using OptimizationProblems, OptimizationProblems.ADNLPProblems
problems = OptimizationProblems.meta[!, :name]
length(problems)

Similarly, to the PureJuMP models, it suffices to select any of these problems to get the model.

nlp = zangwil3()

Note that some of these problems are scalable, i.e., their size depends on some parameters that can be modified.

nlp_12 = woods(n=12)
nlp_120 = woods(n=120)

One of the advantages of these problems is that they are type-stable. Indeed, one can specify the output type with the keyword type as follows.

nlp16_12 = woods(n=12, type=Float16)

Then, all the API will be compatible with the specified type.

using NLPModels
obj(nlp16_12, zeros(Float16, 12))

Nonlinear Least Squares Problems (NLS)

Some problems are classified as nonlinear least squares (NLS). These problems may provide both an ADNLPModel and an ADNLSModel implementation, and dispatch to one or the other using the use_nls keyword argument, see arglina for a concrete example of this pattern.

Using ADNLSModel can be preferable when a solver exploits the least-squares structure directly (residual vector and Jacobian), which is often more efficient and numerically robust than treating the same problem as a generic nonlinear program (ADNLPModel).

To obtain the least squares model (ADNLSModel), use the use_nls=true keyword argument when constructing the problem:

lanczos1_nlp = lanczos1()
lanczos1_nls = lanczos1(use_nls=true)
typeof(lanczos1_nlp)
typeof(lanczos1_nls)

To list all NLS problems:

nls_problems = OptimizationProblems.meta[OptimizationProblems.meta.objtype .== :least_squares, :name]

To access the number of NLS equations for a problem:

OptimizationProblems.get_lanczos1_nls_nequ()