# Flux gradient not defined

**URL:** <https://discourse.julialang.org/t/flux-gradient-not-defined/43559>\
**Category:** New to Julia\
**Tags:** flux\
**Created:** [July 23, 2020, 3:21pm UTC](https://discourse.julialang.org/t/flux-gradient-not-defined/43559 "2020-07-23T15:21:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![zazizoma](https://avatars.discourse-cdn.com/v4/letter/z/5f8ce5/32.png) [@zazizoma](https://discourse.julialang.org/u/zazizoma)\
**Post date:** [July 23, 2020, 3:21pm UTC](https://discourse.julialang.org/t/flux-gradient-not-defined/43559/1 "2020-07-23T15:21:12Z")

</div>

Hi, I’m attempting to build a basic perceptron using Flux, and starting with the tutorial code in the documentation here [[Gradients and Layers · Flux](https://fluxml.ai/Flux.jl/stable/models/basics/)].

Entering this code from the tutorial

> using Flux  
> f(x) = 3x^2 + 2x + 1;  
> df(x) = gradient(f, x)[1];

results in this error:

> UndefVarError: gradient not defined
> 
> Stacktrace:  
> [1] df(::Int64) at ./In[10]:3  
> [2] top-level scope at In[10]:4

How do I get the tutorial code to run correctly?

Many thanks!

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [July 23, 2020, 3:29pm UTC](https://discourse.julialang.org/t/flux-gradient-not-defined/43559/2 "2020-07-23T15:29:24Z")

</div>

What does `using Pkg; Pkg.status("Flux")` show?

---

<div class="post-metadata">

**Author:** ![zazizoma](https://avatars.discourse-cdn.com/v4/letter/z/5f8ce5/32.png) [@zazizoma](https://discourse.julialang.org/u/zazizoma)\
**Post date:** [July 23, 2020, 3:30pm UTC](https://discourse.julialang.org/t/flux-gradient-not-defined/43559/3 "2020-07-23T15:30:48Z")

</div>

> [@mbauman](#):
>
> `using Pkg; Pkg.status("Flux")`

```julia
Status `~/.julia/environments/v1.4/Project.toml`
  [587475ba] Flux v0.9.0

```

---

<div class="post-metadata">

**Author:** ![zazizoma](https://avatars.discourse-cdn.com/v4/letter/z/5f8ce5/32.png) [@zazizoma](https://discourse.julialang.org/u/zazizoma)\
**Post date:** [July 23, 2020, 3:33pm UTC](https://discourse.julialang.org/t/flux-gradient-not-defined/43559/4 "2020-07-23T15:33:20Z")

</div>

I installed this morning with

> ] add Flux

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [July 23, 2020, 3:46pm UTC](https://discourse.julialang.org/t/flux-gradient-not-defined/43559/5 "2020-07-23T15:46:33Z")

</div>

try `]up` The newest version of flux is `0.11.0` and `0.10.0` was a relatively breaking release

---

<div class="post-metadata">

**Author:** ![zazizoma](https://avatars.discourse-cdn.com/v4/letter/z/5f8ce5/32.png) [@zazizoma](https://discourse.julialang.org/u/zazizoma)\
**Post date:** [July 23, 2020, 3:57pm UTC](https://discourse.julialang.org/t/flux-gradient-not-defined/43559/6 "2020-07-23T15:57:20Z")

</div>

Thank you, that worked. I’d assumed installing would install latest version, _sigh_.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [July 23, 2020, 4:14pm UTC](https://discourse.julialang.org/t/flux-gradient-not-defined/43559/7 "2020-07-23T16:14:13Z")

</div>

Adding a package adds the most recent version compatible with your current packages (to try to prevent breakage). I’m not 100% sure if that’s the best solution, but I kind of like it.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [July 23, 2020, 5:14pm UTC](https://discourse.julialang.org/t/flux-gradient-not-defined/43559/8 "2020-07-23T17:14:44Z")

</div>

Wait I’m confused - doesn’t `]up` also restrict me to the “most recent version compatible with current packages”, i.e. run the same resolver? Are you saying `]add` and `]up` will pick different package versions for the same environment?

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [July 23, 2020, 5:34pm UTC](https://discourse.julialang.org/t/flux-gradient-not-defined/43559/9 "2020-07-23T17:34:17Z")

</div>

The difference is that `pkg"up"` will also upgrade all packages. If you have old versions of other packages that depend upon Flux, they might not be compatible with the newest release (and indeed likely weren’t).
