OptimizationSNOPT.jl connects SNOPT,
a commercial solver for large, sparse, constrained nonlinear optimization problems, to
Optimization.jl. A problem defined as an
OptimizationProblem is solved with SNOPT by passing SnoptOptimizer() to solve,
and the derivatives come from any automatic differentiation backend that
Optimization.jl supports.
With OptimizationSNOPT.jl, the same problem can be solved with SNOPT and with the
other Optimization.jl solvers. The package is built on
SNOPT.jl, which wraps the three SNOPT
interfaces snOptA, snOptB and snOptC; use SNOPT.jl directly for linear
constraints given separately, finite-difference derivatives estimated by SNOPT, or warm
and hot starts.
OptimizationSNOPT.jl needs Julia 1.11 or later and a licensed SNOPT 7.7 library,
libsnopt7, that includes the snopt-interface
C functions. OptimizationSNOPT.jl does not include SNOPT; the library and the license
are available from the SNOPT distributors.
using Pkg
Pkg.add("OptimizationSNOPT")Before starting Julia, set SNOPTDIR to the directory that contains the library:
export SNOPTDIR=/path/to/snopt/libThe installation guide gives the Windows commands and the setup check.
Minimize the Rosenbrock function, with the gradient from ForwardDiff.jl:
julia> using OptimizationSNOPT
julia> rosenbrock(x, p) = (p[1] - x[1])^2 + p[2] * (x[2] - x[1]^2)^2;
julia> f = OptimizationFunction(rosenbrock, AutoForwardDiff());
julia> prob = OptimizationProblem(f, [0.0, 0.0], [1.0, 100.0]);
julia> sol = solve(prob, SnoptOptimizer());
julia> sol.retcode
ReturnCode.Success = 1
julia> round.(sol.u; digits = 6)
2-element Vector{Float64}:
1.0
1.0For bounds and nonlinear constraints, pass lb, ub, lcons and ucons to
OptimizationProblem and cons to OptimizationFunction, as the
getting started tutorial
shows.
The documentation starts with a tutorial on bounds, nonlinear constraints and sparse Jacobians. It then gives how-to guides for solver options, monitoring and repeated solves, explains how SNOPT results map to Optimization.jl, and ends with the API reference.
- One Julia process runs one SNOPT solve at a time. Use several processes for parallel solves.
- The constraint Jacobian is dense unless the backend is sparse, for example
AutoSparse(AutoForwardDiff()), orcons_jac_prototypegives its pattern. - Integer variables are relaxed to continuous variables, with a warning.
Solver behaviour lists all limits.
OptimizationSNOPT.jl is released under the MIT License. SNOPT is a separate commercial product with its own license, and its binaries are not distributed with this package.