High-level API
SNOPT.SnoptStatusSNOPT.SnoptBasisSNOPT.SnoptResultSNOPT.find_snopt_libSNOPT.has_snoptSNOPT.snoptSNOPT.status_from_code
Solve a problem
SNOPT.snopt — Function
snopt(eval_obj, eval_grad, x0; lb = nothing, ub = nothing,
eval_con = nothing, eval_jac = nothing, lcon = nothing, ucon = nothing,
J = nothing, options = nothing, callback = nothing, snlog = nothing,
snstop = nothing, printfile = "", summfile = "", start = "Cold",
basis = nothing, name = "Julia") -> SnoptResultMinimize eval_obj(x) subject to variable bounds and optional nonlinear constraints, and return a SnoptResult. x0 and the bound arrays are not changed. See Getting started.
Arguments
eval_obj(x): return the objective value.eval_grad(g, x): write every entry of the objective gradient intog.x0: starting point, nonempty and finite, of lengthn.
Keywords
lb,ub: variable bounds, scalars or vectors of lengthn.nothingand±Infmean no bound.eval_con(c, x),eval_jac(vals, x): write themconstraint values intocand the Jacobian entries intovals, in the order ofJ.nzval.lcon,ucon: constraint bounds of lengthm; equal values give an equality. Give them together witheval_conandeval_jac.J: sparsity pattern of them × nJacobian, aSparseMatrixCSC;nothingmeans dense.options: vector ofname => valuepairs; see Set solver options.callback,snlog,snstop: monitoring functions. A return value offalsefromcallbackorsnstopstops the solve; the return value ofsnlogis ignored. See Monitor and stop a solve.start,basis:"Warm"with theSnoptBasisof an earlier result starts from that basis. See Warm and hot starts.printfile,summfile: paths of the SNOPT log and summary;""writes no file.name: problem name in the SNOPT log, at most 8 bytes.
Throws an ArgumentError for invalid input, such as a NaN bound, crossed bounds, a wrong array length, an unknown option or start = "Hot". An error in a user function is thrown again after the workspace is closed.
SNOPT.SnoptResult — Type
SnoptResultResult of snopt.
Check status before using x, for example result.status == SnoptStatus.Optimal.
Fields
status: outcome of the solve, aSnoptStatusvalue;Int(status)is the SNOPT status code.objective: objective value atx.x: solution, lengthn.lambda: Lagrange multipliers, one per variable and then one per constraint.num_inf: number of bounds and constraints that are still violated.sum_inf: sum of these violations.iterations: total number of minor iterations.major_itns: number of major iterations.run_time: CPU time of the solve reported by SNOPT, in seconds.memory:SnoptMemoryused to size the workspace.basis:SnoptBasisfor a warm start.
If a callback function stopped the solve before SNOPT started, basis contains no information and the iteration counts are zero.
SNOPT.SnoptBasis — Type
SnoptBasisBasis at the end of a solve, for a warm start with snopt.
Pass result.basis as the basis keyword of a later call, together with start = "Warm". See Warm and hot starts and Solver concepts.
Fields
hs: basis state of each variable and slack variable (Int32), lengthn + m.nS: number of superbasic variables.n: number of variables.m: number of constraint rows;1for a problem without constraints.
Status
SNOPT.SnoptStatus — Module
SnoptStatusStatus of a SNOPT solve. Each value of type SnoptStatus.T is a SNOPT 7.7 status code: SnoptStatus.T(51) gives SnoptStatus.IncorrectObjectiveDerivatives, and Int gives the code back. The tens digit is the group, so Int(status) ÷ 10 == 1 holds for every infeasible outcome. SnoptStatus.Unknown (0) stands for a code that the SNOPT 7.7 user guide does not list. Solver concepts describes each group.
Examples
julia> SnoptStatus.T(51)
SnoptStatus.IncorrectObjectiveDerivatives = 51
julia> Int(SnoptStatus.TimeLimit)
34SNOPT.status_from_code — Function
SNOPT.status_from_code(code::Integer) -> SnoptStatus.TReturn the SnoptStatus value of the SNOPT status code code, or SnoptStatus.Unknown for a code that the SNOPT 7.7 user guide does not list. Unlike SnoptStatus.T(code), it never throws, so it is safe to call on the code returned by snopt!, snopta!, snoptb! or snoptc!.
Library setup
These functions are not exported. Call them as SNOPT.has_snopt() and SNOPT.find_snopt_lib().
SNOPT.has_snopt — Function
has_snopt() -> BoolReturn true if SNOPT.jl found a usable SNOPT library when the package was loaded.
If this is false, each solve throws an error. Use SNOPT.find_snopt_lib to find the cause, and see Troubleshooting.
SNOPT.find_snopt_lib — Function
find_snopt_lib() -> StringReturn the absolute path of a usable libsnopt7, or "" if none is found.
A library is usable if it loads and has every C function that SNOPT.jl calls. The search checks SNOPTDIR, then LD_LIBRARY_PATH, DYLD_LIBRARY_PATH (macOS) or PATH (Windows), then the default locations of the system loader. It warns if SNOPTDIR is set but holds no usable library.
SNOPT.jl runs this search once at load time and stores the result in SNOPT.libsnopt7; a later call does not change it, so restart Julia after fixing the setup. See also SNOPT.has_snopt.