Agents: UndefVarError: plotabm not defined

Executing the example Game of Life given in Agents (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.

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.

Try ] up. We just discontinued AgentsPlots

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

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?

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

pkg> gc

then

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

1 Like

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?

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

Here are my data you asked for

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:

(@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:

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

Hope this will help

Yep.

Output from ] st:

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 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:

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

I get the following error:

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

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.

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

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

I get this error:

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

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

@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!

Thanks!