# Optim fails on v0.6

**URL:** https://discourse.julialang.org/t/optim-fails-on-v0-6/872
**Category:** General Usage
**Created:** [December 11, 2016, 9:41pm UTC](https://discourse.julialang.org/t/optim-fails-on-v0-6/872 "2016-12-11T21:41:11Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![pkofod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pkofod/32/2179_2.png) [@pkofod](https://discourse.julialang.org/u/pkofod)
#### Post date: [December 11, 2016, 9:41pm UTC](https://discourse.julialang.org/t/optim-fails-on-v0-6/872/1 "2016-12-11T21:41:12Z")

</div>

… and I’m not really sure why.

To keep things simple, we’ve simply used two macros to repeat some fields which are in all Optimizers. The approach is the following (with gradient descent as an example):

```julia
type GradientDescentState{T}
    @add_generic_fields
    x_previous::Array{T}
    g::Array{T}
    f_x_previous::T
    s::Array{T}
    @add_linesearch_fields
end

macro add_generic_fields()
    quote
        method_string::String
        n::Int64
        x::Array{T}
        f_x::T
        f_calls::Int64
        g_calls::Int64
        h_calls::Int64
    end
end

macro add_linesearch_fields()
    quote
        x_ls::Array{T}
        g_ls::Array{T}
        alpha::T
        mayterminate::Bool
        lsr::LineSearches.LineSearchResults
    end
end

```

On v0.4 and v0.5 this works fine, but on v0.6 this fails. See [Travis CI - Test and Deploy Your Code with Confidence](https://travis-ci.org/JuliaStats/KernelDensity.jl/jobs/182979846) and [http://pkg.julialang.org/logs/DiffEqParamEstim\_0.6.log](http://pkg.julialang.org/logs/DiffEqParamEstim_0.6.log) for packages whose tests fail on master due to Optim failing to be precompiled. We don’t support v0.6 at all yet, but I’d rather fix it now than later.

I can simply go back to repeating the field names in all Optimizer definitions, but I’m not really sure what the problem is or why it is prepending the `Optim.` in the `Optim.method_string` in the error. Any ideas?

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [December 11, 2016, 9:58pm UTC](https://discourse.julialang.org/t/optim-fails-on-v0-6/872/2 "2016-12-11T21:58:38Z")

</div>

Maybe the variables have to be escaped?

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [December 11, 2016, 11:03pm UTC](https://discourse.julialang.org/t/optim-fails-on-v0-6/872/3 "2016-12-11T23:03:31Z")

</div>

It’s a Optim bug due to missing `esc`.

---

<div class="post-metadata">

### Author: ![pkofod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pkofod/32/2179_2.png) [@pkofod](https://discourse.julialang.org/u/pkofod)
#### Post date: [December 12, 2016, 9:15am UTC](https://discourse.julialang.org/t/optim-fails-on-v0-6/872/4 "2016-12-12T09:15:24Z")

</div>

Thank you both, now it works. I wonder why it worked on v0.4-v0.5

(edit: well, almost… but I think it will work)  
(edit^2: it works… :))

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [December 12, 2016, 9:53am UTC](https://discourse.julialang.org/t/optim-fails-on-v0-6/872/5 "2016-12-12T09:53:06Z")

</div>

Bugfix for macro hygiene was recently merged.

---

<div class="post-metadata">

### Author: ![pkofod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pkofod/32/2179_2.png) [@pkofod](https://discourse.julialang.org/u/pkofod)
#### Post date: [December 12, 2016, 10:21am UTC](https://discourse.julialang.org/t/optim-fails-on-v0-6/872/6 "2016-12-12T10:21:12Z")

</div>

So now we can’t rely on bugs for functionality any more? 🙂

Thanks.
