# Error when enabeling automatic differentiation in Optim

**URL:** https://discourse.julialang.org/t/error-when-enabeling-automatic-differentiation-in-optim/5410
**Category:** Optimization (Mathematical)
**Tags:** optim
**Created:** [August 16, 2017, 2:07pm UTC](https://discourse.julialang.org/t/error-when-enabeling-automatic-differentiation-in-optim/5410 "2017-08-16T14:07:35Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![vgdev](https://avatars.discourse-cdn.com/v4/letter/v/47e85d/32.png) [@vgdev](https://discourse.julialang.org/u/vgdev)
#### Post date: [August 16, 2017, 2:07pm UTC](https://discourse.julialang.org/t/error-when-enabeling-automatic-differentiation-in-optim/5410/1 "2017-08-16T14:07:36Z")

</div>

I try to enable forward automatic differentiation to the Rosenbrock example in the documentation ([link](https://github.com/JuliaNLSolvers/Optim.jl/blob/master/docs/src/algo/autodiff.md)). When setting the `OnceDifferentiable` object I get an error:

```julia
od = OnceDifferentiable(f, initial_x; autodiff = :forward)

```

> MethodError: no method matching Optim.OnceDifferentiable(::#f, ::Array{Float64,1}; autodiff=:forward)  
> Closest candidates are:  
> Optim.OnceDifferentiable(::Any, ::Any, !Matched::Any) at…

Has there been made changes to how this is done, which has not been updated in the documentation?

---

<div class="post-metadata">

### Author: ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)
#### Post date: [August 16, 2017, 2:12pm UTC](https://discourse.julialang.org/t/error-when-enabeling-automatic-differentiation-in-optim/5410/2 "2017-08-16T14:12:21Z")

</div>

What versions of Optim and Julia do you have?  
Should work on Optim v0.9.x with Julia 0.6-

The API for earlier version was different.

---

<div class="post-metadata">

### Author: ![vgdev](https://avatars.discourse-cdn.com/v4/letter/v/47e85d/32.png) [@vgdev](https://discourse.julialang.org/u/vgdev)
#### Post date: [August 16, 2017, 2:22pm UTC](https://discourse.julialang.org/t/error-when-enabeling-automatic-differentiation-in-optim/5410/3 "2017-08-16T14:22:14Z")

</div>

Oh, actually I do not have the latest version, only v 0.7.8. But when I try `Pkg.update("Optim")` i get the following info:

> Package Optim was set to version 0.7.8, but a higher version 0.9.3 exists.  
> The update is prevented by explicit requirements constraints. Edit your REQUIRE file to change this.

How do I fix this, or in other words how do i edit the REQUIRE file? thx

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [August 16, 2017, 7:20pm UTC](https://discourse.julialang.org/t/error-when-enabeling-automatic-differentiation-in-optim/5410/4 "2017-08-16T19:20:33Z")

</div>

Your REQUIRE file is located in `~/.julia/v0.6` (on mac and linux, at least). On all platforms you should be able to find its folder with `Pkg.dir()`. Can you show us the contents of that file? For example, you can run `readlines(joinpath(Pkg.dir(), "REQUIRE"))`

---

<div class="post-metadata">

### Author: ![vgdev](https://avatars.discourse-cdn.com/v4/letter/v/47e85d/32.png) [@vgdev](https://discourse.julialang.org/u/vgdev)
#### Post date: [August 16, 2017, 7:29pm UTC](https://discourse.julialang.org/t/error-when-enabeling-automatic-differentiation-in-optim/5410/5 "2017-08-16T19:29:31Z")

</div>

I tried various things, including removing both LineSearches and Optim. But I was still not able to upgrade to the latest versions, so I ended up reinstalling Julia. Now it works.
