joptimise.jl
(Fr: j'optimise) is a Julia wrapper to Ipopt and SNOPT for solving nonlinear programming problems with gradient methods.
Parts borrowed from Snow.jl and SNOPT7.jl.
Ipopt
, FiniteDiff
, ForwardDiff
, ReverseDiff
, SparseArrays
For using SNOPT
, users must also have an active license.
Usage on native Windows is discouraged; setting up a Julia environment on WSL seems to work well with SNOPT. Set as environment variables in ~/.bashrc
(working on WSL):
export SNOPT_LICENSE="$HOME/path-to/snopt7.lic"
export SNOPT_SO="$HOME/path-to/libsnopt7/libsnopt7.so"
Then, internally, the SNOPT library is called via
const snoptlib = ENV["SNOPT_SO"]
(@v1.6) pkg> dev https://github.com/Yuricst/joptimise.git
Import module, define objective function which mutates the constraint value g
and returns the objective value:
using joptimise
function rosenbrock!(g, x)
# compute objective
f = (1 - x[1])^2 + 100*(x[2] - x[1]^2)^2
# constraint
g[1] = x[1]^2 + x[2]^2 - 1.0
return f
end
# initial guess
x0 = [4.0; 4.0]
# bounds on variables
lx = [-5.0; -5.0]
ux = [5.0; 5.0]
# bounds on constraints
lg = [0.0]
ug = [0.0]
# number of constraints
ng = 1
then call SNOPT
sn_options = Dict(
"Major feasibility tolerance" => 1.e-6,
"Major optimality tolerance" => 1.e-6,
"Minor feasibility tolerance" => 1.e-6,
"Major iterations limit" => 1000,
"Major print level" => 1,
)
xopt, fopt, info = minimize(rosenbrock!, x0, ng; lx=lx, ux=ux, lg=lg, ug=ug, solver="snopt", options=sn_options)
or IPOPT
ip_options = Dict(
"max_iter" => 2500,
"tol" => 1e-6,
"print_level" => 5,
)
xopt, fopt, info = minimize(rosenbrock!, x0, ng; lx=lx, ux=ux, lg=lg, ug=ug, solver="ipopt", options=ip_options)
By default, minimize()
will compute derivatives of the objective and constraints using forward finite-difference from ForwardDiff
. This may be altered to central-difference, forward-mode or reverse-mode AD from ForwardDiff
or ReverseDiff
. This is passed as the kwargs derivatives
; the possible options are ForwardFD()
, CentralFD()
, ForwardAD()
, or ReverseAD()
. For example, if using forward-mode AD,
xopt, fopt, info = minimize(rosenbrock!, x0, ng; lx=lx, ux=ux, lg=lg, ug=ug, solver="snopt", options=sn_options, derivatives=ForwardAD())
- user-specified derivative
- optional output file using SNOPT