High-level API

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") -> SnoptResult

Minimize 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 into g.
  • x0: starting point, nonempty and finite, of length n.

Keywords

  • lb, ub: variable bounds, scalars or vectors of length n. nothing and ±Inf mean no bound.
  • eval_con(c, x), eval_jac(vals, x): write the m constraint values into c and the Jacobian entries into vals, in the order of J.nzval.
  • lcon, ucon: constraint bounds of length m; equal values give an equality. Give them together with eval_con and eval_jac.
  • J: sparsity pattern of the m × n Jacobian, a SparseMatrixCSC; nothing means dense.
  • options: vector of name => value pairs; see Set solver options.
  • callback, snlog, snstop: monitoring functions. A return value of false from callback or snstop stops the solve; the return value of snlog is ignored. See Monitor and stop a solve.
  • start, basis: "Warm" with the SnoptBasis of 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.

source
SNOPT.SnoptResult — Type
SnoptResult

Result of snopt.

Check status before using x, for example result.status == SnoptStatus.Optimal.

Fields

  • status: outcome of the solve, a SnoptStatus value; Int(status) is the SNOPT status code.
  • objective: objective value at x.
  • x: solution, length n.
  • 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: SnoptMemory used to size the workspace.
  • basis: SnoptBasis for a warm start.

If a callback function stopped the solve before SNOPT started, basis contains no information and the iteration counts are zero.

source
SNOPT.SnoptBasis — Type
SnoptBasis

Basis 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), length n + m.
  • nS: number of superbasic variables.
  • n: number of variables.
  • m: number of constraint rows; 1 for a problem without constraints.
source

Status

SNOPT.SnoptStatus — Module
SnoptStatus

Status 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)
34
source
SNOPT.status_from_code — Function
SNOPT.status_from_code(code::Integer) -> SnoptStatus.T

Return 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!.

source

Library setup

These functions are not exported. Call them as SNOPT.has_snopt() and SNOPT.find_snopt_lib().

SNOPT.find_snopt_lib — Function
find_snopt_lib() -> String

Return 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.

source