# JuMP NL Baby Steps

**URL:** <https://discourse.julialang.org/t/jump-nl-baby-steps/10168>\
**Category:** Optimization (Mathematical)\
**Created:** [April 5, 2018, 12:04am UTC](https://discourse.julialang.org/t/jump-nl-baby-steps/10168 "2018-04-05T00:04:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [April 5, 2018, 12:04am UTC](https://discourse.julialang.org/t/jump-nl-baby-steps/10168/1 "2018-04-05T00:04:16Z")

</div>

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.

```julia
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??
end

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

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

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

```

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [April 5, 2018, 5:27am UTC](https://discourse.julialang.org/t/jump-nl-baby-steps/10168/2 "2018-04-05T05:27:15Z")

</div>

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

Knitro is commercial software and requires a license.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [April 5, 2018, 5:48am UTC](https://discourse.julialang.org/t/jump-nl-baby-steps/10168/3 "2018-04-05T05:48:35Z")

</div>

> [@iwelch](#):
>
> 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.

NLopt.jl has a pretty good set of methods.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [April 5, 2018, 8:25am UTC](https://discourse.julialang.org/t/jump-nl-baby-steps/10168/4 "2018-04-05T08:25:50Z")

</div>

`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](https://github.com/JuliaNLSolvers/Optim.jl) instead.

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [April 5, 2018, 4:50pm UTC](https://discourse.julialang.org/t/jump-nl-baby-steps/10168/5 "2018-04-05T16:50:15Z")

</div>

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
