JuMP NL Baby Steps


I am now diving into another interesting Julia 0.6.2 area—non-linear non-quadratic (unconstrained) optimization with JuMP 0.18.1. The documentation is partly nice and easy, partly difficult. This is because the different optimizers are external—and there are many of them, so I am not even sure which one I am supposed to chase down. Beginner’s help appreciated.

  1. Logically, why does getvalue not require the model’s name?

  2. What packages are recommended for no-derivatives simplex, steepest-descent, conjugate priors, and Newton-Raphson (which seem to be the standard workhorses). I would like to start with the dumbest, slowest, most robust optimizers first, and then work my way up.

  3. I think there is something wrong with KNITRO 0.4.0 under macOS. despite successful Pkg.add("KNITRO"), I get ERROR: LoadError: error compiling loadproblem!: error compiling Type: could not load library “libknitro” dlopen(libknitro.dylib, 1): image not found

  4. I have had better luck with Ipopt. At least I could get it to run! Alas, I could not figure out a method that would allow autodiff=FALSE. In the simple example below, because my function (nearneghyperbola) has two kinks, IPopt probably gets confused. more worrisome, it does not seem to recognize that it has gotten it wrong—I think it claims to have found a minimum, which it has not. A check around the optimum should tell it this.

using JuMP, Ipopt

nearneghyperbola( a... ) = prod( -1.0./(abs.( collect(a) .+ 3) + 1e-2) )

function learn_nl_jump(userfun, n)
    mymdl = JuMP.Model( solver=Ipopt.IpoptSolver() )
    JuMP.register( mymdl, :userfun, n, userfun, autodiff=true )
    @JuMP.variable( mymdl, -100 <= x[1:n] <= 100 )
    JuMP.setNLobjective( mymdl, :Min, Expr(:call, :userfun, [x[i] for i=1:n]...) )
    JuMP.solve( mymdl )
    return [ getvalue(x[i]) for i=1:n ]        ## why does getvalue not refer to mymdl??

xopt= learn_nl_jump(nearneghyperbola, 3)

println( "x^* =: ", xopt, "\n")
println( "minimum f(x^*)= ", nearneghyperbola(xopt...) )
println( "f(neg 3s)= ", nearneghyperbola(-3, -3, -3) )

output on my machine is

EXIT: Solved To Acceptable Level.
x^* =: [-99.9897, -99.9897, 94.0]

minimum f(x^*)= -1.0955764466765225e-6
f(neg 3s)= -1.0e6


If you have a smallish number of variables, you may be able to use IntervalOptimisation.jl.

Knitro is commercial software and requires a license.


NLopt.jl has a pretty good set of methods.


getvalue doesn’t need mymdl as an argument as each variable stores a reference to the model (try x[1].m). However you shouldn’t rely on this behaviour remaining in future versions of JuMP.

If you are solving unconstrained problems, you probably want to use Optim.jl instead.


thanks, everyone. looks like I was using a hammer for a screw. onto NLopt.jl and Optim.jl next…

the KNITRO one was just a weird glitch. repeatable twice, but on the third install, as I wanted to prepare a github issue to alert them, it worked. wth??

regards, /iaw