# AutoForwardDiff() Error no method matching

**URL:** https://discourse.julialang.org/t/autoforwarddiff-error-no-method-matching/103854
**Category:** General Usage
**Tags:** optimization, forwarddiff
**Created:** [September 14, 2023, 2:01pm UTC](https://discourse.julialang.org/t/autoforwarddiff-error-no-method-matching/103854 "2023-09-14T14:01:01Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Francesco\_C](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/francesco_c/32/51943_2.png) [@Francesco\_C](https://discourse.julialang.org/u/Francesco_C)
#### Post date: [September 14, 2023, 2:01pm UTC](https://discourse.julialang.org/t/autoforwarddiff-error-no-method-matching/103854/1 "2023-09-14T14:01:02Z")

</div>

Hi, I am trying to replicate the main examples for the Optimization package

[https://docs.sciml.ai/Optimization/stable/getting\_started/](https://docs.sciml.ai/Optimization/stable/getting_started/)

However, when I try using the automatic differentiation _Optimization.AutoForwardDiff()_ I get an error. Next the code I am using

```julia
using Optimization
rosenbrock(u, p) = (p[1] - u[1])^2 + p[2] * (u[2] - u[1]^2)^2
u0 = zeros(2)
p = [1.0, 100.0]
using OptimizationOptimJL
using OptimizationBBO
using ForwardDiff
optf = OptimizationFunction(rosenbrock, Optimization.AutoForwardDiff())

```

The last line gives the following error

ERROR: MethodError: no method matching (OptimizationFunction{true})(::typeof(rosenbrock), ::AutoForwardDiff{nothing, Nothing})  
Closest candidates are:  
(OptimizationFunction{iip})(::Any) where iip at ~/.julia/packages/SciMLBase/QqtZA/src/scimlfunctions.jl:3583  
(OptimizationFunction{iip})(::Any, ::SciMLBase.AbstractADType; grad, hess, hv, cons, cons\_j, cons\_h, lag\_h, hess\_prototype, cons\_jac\_prototype, cons\_hess\_prototype, lag\_hess\_prototype, syms, paramsyms, observed, hess\_colorvec, cons\_jac\_colorvec, cons\_hess\_colorvec, lag\_hess\_colorvec, expr, cons\_expr, sys) where iip at ~/.julia/packages/SciMLBase/QqtZA/src/scimlfunctions.jl:3583  
Stacktrace:  
[1] OptimizationFunction(::Function, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})  
@ SciMLBase ~/.julia/packages/SciMLBase/QqtZA/src/scimlfunctions.jl:3581  
[2] OptimizationFunction(::Function, ::Vararg{Any})  
@ SciMLBase ~/.julia/packages/SciMLBase/QqtZA/src/scimlfunctions.jl:3581  
[3] top-level scope  
@ REPL[2]:1

---

<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: [September 14, 2023, 2:48pm UTC](https://discourse.julialang.org/t/autoforwarddiff-error-no-method-matching/103854/2 "2023-09-14T14:48:17Z")

</div>

Are you on the latest version? Julia v1.9? This seems to run fine:

```julia
using Optimization
rosenbrock(u, p) = (p[1] - u[1])^2 + p[2] * (u[2] - u[1]^2)^2
u0 = zeros(2)
p = [1.0, 100.0]
using ForwardDiff
optf = OptimizationFunction(rosenbrock, Optimization.AutoForwardDiff())

```

---

<div class="post-metadata">

### Author: ![trung](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/trung/32/49217_2.png) [@trung](https://discourse.julialang.org/u/trung)
#### Post date: [September 14, 2023, 5:55pm UTC](https://discourse.julialang.org/t/autoforwarddiff-error-no-method-matching/103854/3 "2023-09-14T17:55:23Z")

</div>

I copied and pasted the code that was posted, I do not have an error.

---

<div class="post-metadata">

### Author: ![Francesco\_C](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/francesco_c/32/51943_2.png) [@Francesco\_C](https://discourse.julialang.org/u/Francesco_C)
#### Post date: [September 14, 2023, 5:55pm UTC](https://discourse.julialang.org/t/autoforwarddiff-error-no-method-matching/103854/4 "2023-09-14T17:55:45Z")

</div>

I have just updated to v.1.9 but I am still getting the same error.

---

<div class="post-metadata">

### Author: ![trung](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/trung/32/49217_2.png) [@trung](https://discourse.julialang.org/u/trung)
#### Post date: [September 14, 2023, 5:58pm UTC](https://discourse.julialang.org/t/autoforwarddiff-error-no-method-matching/103854/5 "2023-09-14T17:58:45Z")

</div>

Have you updated all of the packages and rerun the code? You can do so by entering the Pkg REPL by pressing ] and type “update” in the REPL without the “” symbol.

---

<div class="post-metadata">

### Author: ![Francesco\_C](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/francesco_c/32/51943_2.png) [@Francesco\_C](https://discourse.julialang.org/u/Francesco_C)
#### Post date: [September 14, 2023, 6:16pm UTC](https://discourse.julialang.org/t/autoforwarddiff-error-no-method-matching/103854/6 "2023-09-14T18:16:11Z")

</div>

Done, same error.

---

<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: [September 14, 2023, 7:29pm UTC](https://discourse.julialang.org/t/autoforwarddiff-error-no-method-matching/103854/7 "2023-09-14T19:29:24Z")

</div>

Can you share `]st`?

---

<div class="post-metadata">

### Author: ![Francesco\_C](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/francesco_c/32/51943_2.png) [@Francesco\_C](https://discourse.julialang.org/u/Francesco_C)
#### Post date: [September 14, 2023, 7:48pm UTC](https://discourse.julialang.org/t/autoforwarddiff-error-no-method-matching/103854/8 "2023-09-14T19:48:47Z")

</div>

(@v1.9) pkg\> st  
Status `~/.julia/environments/v1.9/Project.toml`  
[336ed68f] CSV v0.10.11  
[a93c6f00] DataFrames v1.6.1  
⌃ [0c46a032] DifferentialEquations v7.6.0  
[31c24e10] Distributions v0.25.100  
[186dfeec] FEniCS v0.4.1  
[f6369f11] ForwardDiff v0.10.36  
[98e50ef6] JuliaFormatter v1.0.36  
[7f7a1694] Optimization v3.17.0  
[3e6eede4] OptimizationBBO v0.1.5  
[36348300] OptimizationOptimJL v0.1.9  
⌃ [1dea7af3] OrdinaryDiffEq v6.33.3  
[91a5bcdd] Plots v1.39.0  
[438e738f] PyCall v1.96.1  
⌃ [0bca4576] SciMLBase v1.81.0  
⌅ [2913bbd2] StatsBase v0.33.21  
[592b5752] Trapz v2.0.3  
[770da0de] UpdateJulia v0.4.2  
[955f2c64] VTKView v0.1.0  
[64499a7a] WriteVTK v1.18.0  
[3fa0cd96] REPL  
[9a3f8284] Random  
Info Packages marked with ⌃ and ⌅ have new versions available, but those with ⌅ are restricted by compatibility constraints from upgrading. To see why use `status --outdated`

---

<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: [September 14, 2023, 8:03pm UTC](https://discourse.julialang.org/t/autoforwarddiff-error-no-method-matching/103854/9 "2023-09-14T20:03:41Z")

</div>

SciMLBase is in the stone age. Maybe Try `]add SciMLBase@1.97` and see what it says. And try it in a new REPL session.

---

<div class="post-metadata">

### Author: ![Francesco\_C](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/francesco_c/32/51943_2.png) [@Francesco\_C](https://discourse.julialang.org/u/Francesco_C)
#### Post date: [September 14, 2023, 8:26pm UTC](https://discourse.julialang.org/t/autoforwarddiff-error-no-method-matching/103854/10 "2023-09-14T20:26:08Z")

</div>

It now works, thanks!

---

<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: [September 14, 2023, 10:00pm UTC](https://discourse.julialang.org/t/autoforwarddiff-error-no-method-matching/103854/11 "2023-09-14T22:00:01Z")

</div>

No problem. Yeah the `^` means an old package version, and usually if you’re having an issue that’s the first thing to check. The documentation always defaults to displaying the newest version, so if you’re on an older version you need to look for the older version of some documentation and… nobody does that 😅. So most weird issues tend to just be from accidentally being on an older version for some reason or another.
