# Agents: UndefVarError: plotabm not defined

**URL:** <https://discourse.julialang.org/t/agents-undefvarerror-plotabm-not-defined/54318>\
**Category:** General Usage\
**Tags:** agents\
**Created:** [January 31, 2021, 10:13am UTC](https://discourse.julialang.org/t/agents-undefvarerror-plotabm-not-defined/54318 "2021-01-31T10:13:11Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carsten](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@Carsten](https://discourse.julialang.org/u/Carsten)\
**Post date:** [January 31, 2021, 10:13am UTC](https://discourse.julialang.org/t/agents-undefvarerror-plotabm-not-defined/54318/1 "2021-01-31T10:13:11Z")

</div>

Executing the example _Game of Life_ given in Agents ([https://juliadynamics.github.io/Agents.jl/stable/examples/game\_of\_life\_2D\_CA/](https://juliadynamics.github.io/Agents.jl/stable/examples/game_of_life_2D_CA/)) I always get the error message: _UndefVarError: plotabm not defined_.  
I started the example from scratch.

```julia
using Plots
pyplot()
using Agents

```

and then following the code snippets given in that example. However, after start the animation I get the above mentioned error message: _UndefVarError: plotabm not defined_.

---

<div class="post-metadata">

**Author:** ![Libbum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/libbum/32/3935_2.png) [@Libbum](https://discourse.julialang.org/u/Libbum)\
**Post date:** [January 31, 2021, 2:05pm UTC](https://discourse.julialang.org/t/agents-undefvarerror-plotabm-not-defined/54318/2 "2021-01-31T14:05:10Z")

</div>

Try `] up`. We just discontinued AgentsPlots

---

<div class="post-metadata">

**Author:** ![Carsten](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@Carsten](https://discourse.julialang.org/u/Carsten)\
**Post date:** [January 31, 2021, 2:18pm UTC](https://discourse.julialang.org/t/agents-undefvarerror-plotabm-not-defined/54318/3 "2021-01-31T14:18:05Z")

</div>

Thank you for your prompt answer. Now I get the following error  
ERROR: KeyError: key “Zlib\_jll” not found

---

<div class="post-metadata">

**Author:** ![Libbum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/libbum/32/3935_2.png) [@Libbum](https://discourse.julialang.org/u/Libbum)\
**Post date:** [January 31, 2021, 3:18pm UTC](https://discourse.julialang.org/t/agents-undefvarerror-plotabm-not-defined/54318/4 "2021-01-31T15:18:04Z")

</div>

Hmm. That’s something else.

First, does everything work with `gr()`? If so, it’s something to do with your pyplot installation.

If it fails even when using gr, can you show me the output of `] st` and `] st -m`?

---

<div class="post-metadata">

**Author:** ![Carsten](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@Carsten](https://discourse.julialang.org/u/Carsten)\
**Post date:** [January 31, 2021, 4:43pm UTC](https://discourse.julialang.org/t/agents-undefvarerror-plotabm-not-defined/54318/5 "2021-01-31T16:43:37Z")

</div>

Now it seems to work.  
What I did:  
remove old packages including gc::

```julia
pkg> gc

```

then

```julia
pkg> add Zlib_jll
pkg> up
pkg> st
Status `C:\Users\benec\.julia\environments\v1.5\Project.toml`
  [46ada45e] Agents v4.0.3       
  [5ae59095] Colors v0.12.6      
  [41a84b80] ComplexValues v0.2.1
  [a93c6f00] DataFrames v0.22.5
  [0c46a032] DifferentialEquations v6.16.0
  [95701278] ImplicitEquations v1.0.4     
  [98e50ef6] JuliaFormatter v0.12.3       
  [2b0e0bc5] LanguageServer v3.2.0        
  [ae8d54c2] Luxor v2.7.0
  [5fb14364] OhMyREPL v0.5.10
  [65888b18] ParameterizedFunctions v5.9.0
  [91a5bcdd] Plots v1.10.2
  [3a141323] PolynomialRoots v1.0.0       
  [d330b81b] PyPlot v2.9.0
  [b3cc710f] StaticLint v4.5.0
  [83775a58] Zlib_jll v1.2.11+18
  [10745b16] Statistics
julia> using Agents

julia> using Plots

julia> gr()
Plots.GRBackend()

help?> plotabm
search: plotabm plotabm! plotattr plotarea plots_heatmap plots_heatmap!

  plotabm(model::ABM{<: ContinuousSpace}; ac, as, am, kwargs...)
  plotabm(model::ABM{<: DiscreteSpace}; ac, as, am, kwargs...)  
.....

```

applying pyplot() works too.

I have no idea why I got the error messages before.  
Nevertheless, thank you for your assistance

Carsten

---

<div class="post-metadata">

**Author:** ![jzkelter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jzkelter/32/22121_2.png) [@jzkelter](https://discourse.julialang.org/u/jzkelter)\
**Post date:** [February 19, 2021, 3:58am UTC](https://discourse.julialang.org/t/agents-undefvarerror-plotabm-not-defined/54318/6 "2021-02-19T03:58:21Z")

</div>

I’m getting the same error: `UndefVarError: plotabm not defined`  
I downloaded Agents.jl yesterday, after the discontinuation of AgentsPlots, but I tried `] up` anyway and it didn’t help. Any ideas?

---

<div class="post-metadata">

**Author:** ![Libbum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/libbum/32/3935_2.png) [@Libbum](https://discourse.julialang.org/u/Libbum)\
**Post date:** [February 19, 2021, 6:39am UTC](https://discourse.julialang.org/t/agents-undefvarerror-plotabm-not-defined/54318/7 "2021-02-19T06:39:34Z")

</div>

Will need to know what your environment looks like. Can you post the result of `] st` and your Julia version?

---

<div class="post-metadata">

**Author:** ![Carsten](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@Carsten](https://discourse.julialang.org/u/Carsten)\
**Post date:** [February 19, 2021, 9:10am UTC](https://discourse.julialang.org/t/agents-undefvarerror-plotabm-not-defined/54318/8 "2021-02-19T09:10:58Z")

</div>

Here are my data you asked for

```julia
Julia Version 1.5.3
Commit 788b2c77c1 (2020-11-09 13:37 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, znver1)
Environment:
  JULIA_EDITOR = "C:\Users\benec\AppData\Local\Programs\Microsoft VS Code\Code.exe"
  JULIA_NUM_THREADS =

```

and the loaded packages:

```julia
(@v1.5) pkg> st
Status `C:\Users\benec\.julia\environments\v1.5\Project.toml`
  [537997a7] AbstractPlotting v0.15.19
  [46ada45e] Agents v4.0.4
  [13f3f980] CairoMakie v0.3.16
  [5ae59095] Colors v0.12.6
  [41a84b80] ComplexValues v0.2.1
  [a93c6f00] DataFrames v0.22.5
  [0c46a032] DifferentialEquations v6.16.0
  [31c24e10] Distributions v0.24.14
  [634d3b9d] DrWatson v1.18.2
  [e9467ef8] GLMakie v0.1.27 `https://github.com/JuliaPlots/GLMakie.jl.git#master`
  [28b8d3ca] GR v0.54.0
  [95701278] ImplicitEquations v1.0.4
  [98e50ef6] JuliaFormatter v0.13.2
  [2b0e0bc5] LanguageServer v3.2.0
  [093fc24a] LightGraphs v1.3.5
  [ae8d54c2] Luxor v2.9.0
  [5fb14364] OhMyREPL v0.5.10
  [65888b18] ParameterizedFunctions v5.9.0
  [91a5bcdd] Plots v1.10.5 `https://github.com/JuliaPlots/Plots.jl.git#master`
  [3a141323] PolynomialRoots v1.0.0
  [d330b81b] PyPlot v2.9.0 `https://github.com/JuliaPy/PyPlot.jl.git#master`
  [b3cc710f] StaticLint v4.5.0
  [276b4fcb] WGLMakie v0.3.3
  [83775a58] Zlib_jll v1.2.11+18
  [37e2e46d] LinearAlgebra
  [9a3f8284] Random
  [10745b16] Statistics

```

especially when working with Agents.jl the following packages I am using:

```julia
using Agents
using Plots
pyplot()
using DataFrames
using Statistics
using Random
using LightGraphs
using Distributions
using DrWatson
using LinearAlgebra

```

Hope this will help

---

<div class="post-metadata">

**Author:** ![jzkelter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jzkelter/32/22121_2.png) [@jzkelter](https://discourse.julialang.org/u/jzkelter)\
**Post date:** [February 20, 2021, 11:25pm UTC](https://discourse.julialang.org/t/agents-undefvarerror-plotabm-not-defined/54318/9 "2021-02-20T23:25:26Z")

</div>

Yep.

Output from `] st`:

```julia
Status `~/.julia/environments/v1.5/Project.toml`
  [46ada45e] Agents v4.0.1
  [6e4b80f9] BenchmarkTools v0.5.0
  [7073ff75] IJulia v1.23.1
  [91a5bcdd] Plots v1.10.5
  [c3e4b0f8] Pluto v0.12.20
  [d330b81b] PyPlot v2.9.0
  [af85af4c] RowEchelon v0.2.1
  [90137ffa] StaticArrays v1.0.1

```

I see that the current version of Agents.jl is 4.0.4 and I have 4.0.1, however, when I run `] up Agents`, the version doesn’t get updated.

Julia version:

```julia
Julia Version 1.5.3
Commit 788b2c77c1 (2020-11-09 13:37 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.7.0)
  CPU: Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, skylake)

```

Also, when I try to use the @agent macro:

```julia
@agent SchellingAgent GridAgent{2}
    mood::Bool
    group::Int
end

```

I get the following error:

```julia
LoadError: MethodError: no method matching @agent(::LineNumberNode, ::Module, ::Symbol, ::Expr)
Closest candidates are:
  @agent(::LineNumberNode, ::Module, ::Any, ::Any, !Matched::Any) at /Users/jzkelter/.julia/packages/Agents/YADxD/src/core/agents.jl:59
in expression starting at In[12]:7

Stacktrace:
 [1] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1091

```

---

<div class="post-metadata">

**Author:** ![Libbum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/libbum/32/3935_2.png) [@Libbum](https://discourse.julialang.org/u/Libbum)\
**Post date:** [February 21, 2021, 9:38am UTC](https://discourse.julialang.org/t/agents-undefvarerror-plotabm-not-defined/54318/10 "2021-02-21T09:38:07Z")

</div>

OK. The fixes for those things are in the subsequent patches, so we need to get you on 4.0.4.

Why `] up` isn’t working is what we need to find out. Possibly there’s something in the manifest is causing issues.

Some things to try:

- Don’t use the global environment for everything. Create a folder for your project, cd to it and do `] activate .`, then `] add Agents` and the packages you need for the project.
- If you don’t want to do that, at least do `] activate --temp` and add Agents there to see if 4.0.4 will load in a clean environment.
- If either of these work it’s an issue with your manifest. Try removing Agents, do an update and add it again.

---

<div class="post-metadata">

**Author:** ![jzkelter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jzkelter/32/22121_2.png) [@jzkelter](https://discourse.julialang.org/u/jzkelter)\
**Post date:** [February 21, 2021, 7:10pm UTC](https://discourse.julialang.org/t/agents-undefvarerror-plotabm-not-defined/54318/11 "2021-02-21T19:10:17Z")

</div>

Great thanks. I tried what you suggested and there was some issue, because I could install 4.0.4 in a new environment. I ended up just reinstalling Julia from scratch and now `plotabm` is working.

However I still get an error with the @agent macro. When I run

```julia
@agent SchellingAgent GridAgent{2}
    mood::Bool
    group::Int
end

```

I get this error:

```julia
LoadError: MethodError: no method matching @agent(::LineNumberNode, ::Module, ::Symbol, ::Expr)
Closest candidates are:
  @agent(::LineNumberNode, ::Module, ::Any, ::Any, !Matched::Any) at /Users/jzkelter/.julia/packages/Agents/BfSXk/src/core/agents.jl:59
in expression starting at In[13]:7

Stacktrace:
 [1] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1091

```

---

<div class="post-metadata">

**Author:** ![Libbum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/libbum/32/3935_2.png) [@Libbum](https://discourse.julialang.org/u/Libbum)\
**Post date:** [February 21, 2021, 7:19pm UTC](https://discourse.julialang.org/t/agents-undefvarerror-plotabm-not-defined/54318/12 "2021-02-21T19:19:40Z")

</div>

Ah, sorry I didn’t see this before. `begin` is missing in the macro:

```julia
@agent SchellingAgent GridAgent{2} begin
    mood::Bool
    group::Int
end

```

And that’s wrong in the documentation, so my fault. I’ll update that now!

---

<div class="post-metadata">

**Author:** ![jzkelter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jzkelter/32/22121_2.png) [@jzkelter](https://discourse.julialang.org/u/jzkelter)\
**Post date:** [February 23, 2021, 3:15am UTC](https://discourse.julialang.org/t/agents-undefvarerror-plotabm-not-defined/54318/13 "2021-02-23T03:15:42Z")

</div>

Thanks!
