Reference
Contents
Index
JSOSuite.optimizersJSOSuite.bmark_solversJSOSuite.feasible_pointJSOSuite.genericJSOSuite.isnlsJSOSuite.minimizeJSOSuite.multi_startJSOSuite.select_optimizersSolverCore.solve!
JSOSuite.optimizers — ConstantoptimizersDataFrame with the JSO-compliant solvers and their properties.
For each solver, the following are available:
name::String: name of the solver;name_solver::Symbol: name of the solver structure for in-place solve,:not_implementedif not implemented;name_parameters::Symbol: name of the parameter structure,:not_implementedif not implemented;name_pkg::String: name of the package implementing this solver or its NLPModel wrapper;solve_function::Symbol: name of the function;is_available::Bool:trueif the solver is available;bounds::Bool:trueif the solver can handle bound constraints;equalities::Bool:trueif the solver can handle equality constraints;inequalities::Bool:trueif the solver can handle inequality constraints;specialized_nls::Bool:trueif the solver has a specialized variant for nonlinear least squares;can_solve_nlp::Bool:trueif the solver can solve general problems. Some may only solve nonlinear least squares;nonlinear_obj::Bool:trueif the solver can handle nonlinear objective;nonlinear_con::Bool:trueif the solver can handle nonlinear constraints;double_precision_only::Bool:trueif the solver only handles double precision (Float64);highest_derivative::Int: order of the highest derivative used by the algorithm.
JSOSuite.bmark_solvers — Functionbmark_solvers(problems, solver_names::Vector{String}; kwargs...)
bmark_solvers(problems, solver_names::Vector{String}, solvers::Dict{Symbol, Function}; kwargs...)Wrapper to the function SolverBenchmark.bmark_solvers.
Arguments
problems: The set of problems to pass to the solver, as an iterable ofAbstractNLPModel;solver_names::Vector{String}: The names of the benchmarked solvers. They should be validJSOSuitenames, seeJSOSuite.solvers.namefor a list;solvers::solvers::Dict{Symbol, Function}: A dictionary of additional solvers to benchmark.
Output
A Dict{Symbol, DataFrame} of statistics.
Keyword Arguments
The following keywords available are passed to the JSOSuite solvers:
atol: absolute tolerance;rtol: relative tolerance;max_time: maximum number of seconds;max_eval: maximum number of cons + obj evaluations;verbose::Int = 0: if > 0, display iteration details everyverboseiteration.
All the remaining keyword arguments are passed to the function SolverBenchmark.bmark_solvers.
Examples
using ADNLPModels, JSOSuite, Logging, SolverBenchmark
nlps = (
ADNLPModel(x -> 100 * (x[2] - x[1]^2)^2 + (x[1] - 1)^2, [-1.2; 1.0]),
ADNLPModel(x -> 4 * (x[2] - x[1]^2)^2 + (x[1] - 1)^2, [-1.2; 1.0]),
)
names = ["LBFGS", "TRON"] # see `JSOSuite.optimizers.name` for the complete list
stats = with_logger(NullLogger()) do
bmark_solvers(nlps, names, atol = 1e-3, colstats = [:name, :nvar, :ncon, :status])
end
keys(stats)The second example shows how to add you own solver to the benchmark.
using ADNLPModels, JSOSolvers, JSOSuite, Logging, SolverBenchmark
nlps = (
ADNLPModel(x -> 100 * (x[2] - x[1]^2)^2 + (x[1] - 1)^2, [-1.2; 1.0]),
ADNLPModel(x -> 4 * (x[2] - x[1]^2)^2 + (x[1] - 1)^2, [-1.2; 1.0]),
)
names = ["LBFGS", "TRON"] # see `JSOSuite.optimizers.name` for the complete list
other_solvers = Dict{Symbol, Function}(
:test => nlp -> lbfgs(nlp; mem = 2, atol = 1e-3, verbose = 0),
)
stats = with_logger(NullLogger()) do
bmark_solvers(nlps, names, other_solvers, atol = 1e-3, colstats = [:name, :nvar, :ncon, :status])
end
keys(stats)JSOSuite.feasible_point — Functionstats = feasible_point(nlp::Union{AbstractNLPModel, JuMP.Model}; kwargs...)
stats = feasible_point(nlp::Union{AbstractNLPModel, JuMP.Model}, solver_name::Symbol; kwargs...)Compute a feasible point of the optimization problem nlp. The signature is the same as the function minimize.
Output
The value returned is a GenericExecutionStats, see SolverCore.jl, where the status, solution, primal_residual, iter and time are filled-in.
using ADNLPModels, JSOSuite
c(x) = [10 * (x[2] - x[1]^2); x[1] - 1]
b = zeros(2)
nlp = ADNLPModel(x -> 0.0, [-1.2; 1.0], c, b, b)
stats = feasible_point(nlp, verbose = 0)
statsJSOSuite.generic — FunctionChecker whether optimizers are Generic only
JSOSuite.isnls — Methodisnls(nlp::ADNLPModels.AbstractADNLPModel)
isnls(nlp::MathOptInterface.Nonlinear.Model)
isnls(nlp::JuMP.Model)
isnls(nlp::MathOptNLPModel)Check if the given model has a nonlinear least squares objective.
The function uses the package ExpressionTreeForge to get the expression tree of the objective function, then try to detect the least squares pattern. There is no guarantee that this function detects it accurately.
JSOSuite.minimize — Functionstats = minimize(nlp::Union{AbstractNLPModel, JuMP.Model}; kwargs...)Compute a local minimum of the optimization problem nlp.
stats = minimize(f::Function, x0::AbstractVector, args...; kwargs...)
stats = minimize(F::Function, x0::AbstractVector, nequ::Integer, args...; kwargs...)Define an NLPModel using ADNLPModel.
stats = minimize(c, H, c0 = c0, x0 = x0, name = name; kwargs...)
stats = minimize(c, H, lvar, uvar, c0 = c0, x0 = x0, name = name; kwargs...)
stats = minimize(c, H, A, lcon, ucon, c0 = c0, x0 = x0, name = name; kwargs...)
stats = minimize(c, H, lvar, uvar, A, lcon, ucon, c0 = c0, x0 = x0, name = name; kwargs...)Define a QuadraticModel using QuadraticModel.
The optimizer can be chosen as follows.
stats = minimize(optimizer_name::String, args...; kwargs...)JuMP.Model are converted in NLPModels via NLPModelsJuMP.jl.
If your optimization problem has a quadratic or linear objective and linear constraints consider using QuadraticModels.jl or LLSModels.jl for the model definition.
Keyword Arguments
All the keyword arguments are passed to the selected solver. Keywords available for all the solvers are given below:
atol: absolute tolerance;rtol: relative tolerance;max_time: maximum number of seconds;max_iter: maximum number of iterations;max_eval: maximum number of cons + obj evaluations;callback = (args...) -> nothing: callback called at each iteration;verbose::Int = 0: if > 0, display iteration details everyverboseiteration.
The following are specific to nonlinear least squares:
Fatol::T = √eps(T): absolute tolerance on the residual;Frtol::T = eps(T): relative tolerance on the residual, the algorithm stops when ‖F(xᵏ)‖ ≤ Fatol + Frtol * ‖F(x⁰)‖.
Further possible options are documented in each solver's documentation.
Callback
The callback is called at each iteration. The expected signature of the callback is callback(nlp, solver, stats), and its output is ignored. Changing any of the input arguments will affect the subsequent iterations. In particular, setting stats.status = :user will stop the algorithm. All relevant information should be available in nlp and solver.
Output
The value returned is a GenericExecutionStats, see SolverCore.jl.
Examples
using JSOSuite
stats = minimize(x -> 100 * (x[2] - x[1]^2)^2 + (x[1] - 1)^2, [-1.2; 1.0], verbose = 0)
statsThe list of available solver can be obtained using JSOSuite.optimizers[!, :name] or see select_optimizers.
using JSOSuite
stats = minimize("TRON", x -> 100 * (x[2] - x[1]^2)^2 + (x[1] - 1)^2, [-1.2; 1.0], verbose = 0)
statsSome optimizers are available after loading only.
using JSOSuite
# We minimize here a quadratic problem with bound-constraints
c = [1.0; 1.0]
H = [-2.0 0.0; 3.0 4.0]
uvar = [1.0; 1.0]
lvar = [0.0; 0.0]
x0 = [0.5; 0.5]
stats = minimize("TRON", c, H, lvar, uvar, x0 = x0, name = "bndqp_QP", verbose = 0)
statsJSOSuite.multi_start — Functionmulti_start(nlp::AbstractNLPModel; kwargs...)This function runs a simple optimization strategy that run local optimizers for several initial guesses.
Arguments
nlp::AbstractNLPModel{T, V}represents the model to solve, seeNLPModels.jl.
The keyword arguments may include
multi_solvers::Bool = false: If true it runs all the available solvers, one solver otherwise;skip_solvers::Vector{String} = String[]: Ifmulti_solversis true, the solvers in this list are skipped;N::Integer = get_nvar(nlp): number of additional initial guesses considered;max_time::Float64 = 60.0: maximum time limit in seconds;verbose::Integer = 0: if > 0, display iteration details everyverboseiteration.solver_verbose::Integer = 0: verbosity of the solver;strategy::Symbol = :random: strategy to compute a next initial guess in [:random].
Other keyword arguments are passed to the solvers.
JSOSuite.select_optimizers — Methodselect_optimizers(nlp::Union{AbstractNLPModel, JuMP.Model}, verbose = 1, highest_derivative_available::Integer = 2)Narrow the list of optimizers to solve nlp problem using highest_derivative_available.
This function checks whether the model has:
- linear or nonlinear constraints;
- unconstrained, bound constraints, equality constraints, inequality constraints;
- nonlinear or quadratic objective.
A linear or quadratic objective is detected if the type of nlp is a QuadraticModel or an LLSModel. The selection between a general optimization problem and a nonlinear least squares is done in minimize.
If no optimizers were selected, consider setting verbose to true to see what went wrong.
Output
selected_optimizers::DataFrame: A subset ofoptimizersadapted to the problemnlp.
See also minimize.
Examples
using ADNLPModels, JSOSuite
nlp = ADNLPModel(x -> 100 * (x[2] - x[1]^2)^2 + (x[1] - 1)^2, [-1.2; 1.0])
selected_optimizers = JSOSuite.select_optimizers(nlp)
print(selected_optimizers[!, :name])using ADNLPModels, JSOSuite
nlp = ADNLSModel(x -> [10 * (x[2] - x[1]^2), (x[1] - 1)], [-1.2; 1.0], 2)
selected_optimizers = JSOSuite.select_optimizers(nlp)
print(selected_optimizers[!, :name])SolverCore.solve! — Methodsolve!(solver::AbstractOptimizationSolver, model::Union{AbstractNLPModel, JuMP.Model}; kwargs...)
solve!(solver::AbstractOptimizationSolver, model::Union{AbstractNLPModel, JuMP.Model}, stats; kwargs...)JSOSuite extension of SolverCore.solve!. The first argument should be of type SolverCore.AbstractOptimizationSolver, see for instance JSOSuite.optimizers[!, :name_solver].