Agents.jl Interactive Plot

Hi,
I am trying to learn how to use the package Agents.jl. Even if I just started, I already like it a lot.
I am following this explanation from the documentation for doing interactive plots.
Everything seems to work fine, but when I hover with the mouse over the plot, my REPL spits out a lot of those errors

nested task error: BoundsError: attempt to access 30×30 Matrix{Int64} at index [30, 16, 0]

Is this expected, is it a bug or am I doing something wrong?

Of course I am happy to provide more information if you need it or if my question is too vague.
I am using Julia 1.10 and this is my environment:

Status `~/ownCloud/BP_Sim/Project.toml`
  [46ada45e] Agents v6.1.8
  [13f3f980] CairoMakie v0.12.13
  [e9467ef8] GLMakie v0.10.13
  [2913bbd2] StatsBase v0.34.3

Thanks in advance.

Can’t say anything without any code I am afraid… Looks like you have a 3D space but you are plotting a 2D slice of it?

But thanks for the positive feedback!

Right, this was my first thought too. So I thought I was doing something wrong, and this is why I just tried copy-pasting the code provided in the documentation I linked in my question. The error still appears and so I decided to ask in the Discourse. Here is the full code copy-pasted from the various snippet in the documentation, executed in a new vscode session (new file, new environment, etc…).

using GLMakie
using Agents
using AgentsExampleZoo

model = AgentsExampleZoo.daisyworld(;
    solar_luminosity = 1.0, solar_change = 0.0, scenario = :change
)

model

daisycolor(a) = a.breed
agent_size = 20
agent_marker = '✿'
agentsplotkwargs = (strokewidth = 1.0,) # add stroke around each agent

heatarray = :temperature
heatkwargs = (colorrange = (-20, 60), colormap = :thermal)
plotkwargs = (;
    agent_color = daisycolor, agent_size, agent_marker,
    agentsplotkwargs = (strokewidth = 1.0,),
    heatarray, heatkwargs
)

fig, ax, abmobs = abmplot(model; add_controls = true, plotkwargs...)
fig

Information about my installation:

julia> versioninfo()
Julia Version 1.10.5
Commit 6f3fdf7b362 (2024-08-27 14:19 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 12 × AMD Ryzen 5 PRO 4650U with Radeon Graphics
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, znver2)
Threads: 12 default, 0 interactive, 6 GC (on 12 virtual cores)
Environment:
  JULIA_EDITOR = code

Information about the environment:

(testing) pkg> status
Status `~/projects/testing/Project.toml`
  [46ada45e] Agents v6.1.8
  [88acaeb2] AgentsExampleZoo v0.1.2
  [e9467ef8] GLMakie v0.10.13

Error that keeps getting spammed (with high frequency) while hovering with the mouse over the GLMakie window, even without clicking. I should also repeat that this error does not seem to be “fatal”: clicking on the “step model”, “run model”, “reset model” seems to work as expected.

nested task error: BoundsError: attempt to access 30×30 Matrix{Int64} at index [15, 1, 0]
    Stacktrace:
      [1] getindex
        @ ./essentials.jl:14 [inlined]
      [2] id_in_position
        @ ~/.julia/packages/Agents/rX42e/src/spaces/grid_single.jl:77 [inlined]
      [3] ids_to_inspect
        @ ~/.julia/packages/Agents/rX42e/ext/AgentsVisualizations/src/spaces/grid.jl:31 [inlined]
      [4] agent2string(model::StandardABM{GridSpaceSingle{2, true}, AgentsExampleZoo.Daisy, Dict{Int64, AgentsExampleZoo.Daisy}, Tuple{DataType}, typeof(AgentsExampleZoo.daisy_step!), typeof(AgentsExampleZoo.daisyworld_step!), typeof(Agents.Schedulers.fastest), Dict{Symbol, Any}, Random.MersenneTwister}, pos::Tuple{Int64, Int64, Int64})
        @ AgentsVisualizations ~/.julia/packages/Agents/rX42e/ext/AgentsVisualizations/src/spaces/abstract.jl:143
      [5] show_data(inspector::DataInspector, p::Plot{AgentsVisualizations._abmplot, Tuple{ABMObservable{Observable{StandardABM{GridSpaceSingle{2, true}, AgentsExampleZoo.Daisy, Dict{Int64, AgentsExampleZoo.Daisy}, Tuple{DataType}, typeof(AgentsExampleZoo.daisy_step!), typeof(AgentsExampleZoo.daisyworld_step!), typeof(Agents.Schedulers.fastest), Dict{Symbol, Any}, Random.MersenneTwister}}, Nothing, Nothing, Nothing, Nothing, Bool, Observable{Int64}, Observable{Tuple{Base.RefValue{Int64}, Vector{Int64}}}}}}, idx::UInt32, source::Scatter{Tuple{Vector{Point{2, Float32}}}})
        @ AgentsVisualizations ~/.julia/packages/Agents/rX42e/ext/AgentsVisualizations/src/spaces/abstract.jl:101
      [6] show_data_recursion(inspector::DataInspector, plot::Plot{AgentsVisualizations._abmplot, Tuple{ABMObservable{Observable{StandardABM{GridSpaceSingle{2, true}, AgentsExampleZoo.Daisy, Dict{Int64, AgentsExampleZoo.Daisy}, Tuple{DataType}, typeof(AgentsExampleZoo.daisy_step!), typeof(AgentsExampleZoo.daisyworld_step!), typeof(Agents.Schedulers.fastest), Dict{Symbol, Any}, Random.MersenneTwister}}, Nothing, Nothing, Nothing, Nothing, Bool, Observable{Int64}, Observable{Tuple{Base.RefValue{Int64}, Vector{Int64}}}}}}, idx::UInt32, source::Scatter{Tuple{Vector{Point{2, Float32}}}})
        @ Makie ~/.julia/packages/Makie/YkotL/src/interaction/inspector.jl:370
      [7] show_data_recursion(inspector::DataInspector, plot::Scatter{Tuple{Vector{Point{2, Float32}}}}, idx::UInt32)
        @ Makie ~/.julia/packages/Makie/YkotL/src/interaction/inspector.jl:340
      [8] (::Makie.var"#1398#1399"{DataInspector, Scene})()
        @ Makie ~/.julia/packages/Makie/YkotL/src/interaction/inspector.jl:317
      [9] lock(f::Makie.var"#1398#1399"{DataInspector, Scene}, l::ReentrantLock)
        @ Base ./lock.jl:229
     [10] on_hover
        @ ~/.julia/packages/Makie/YkotL/src/interaction/inspector.jl:309 [inlined]
     [11] (::Makie.var"#1390#1394"{DataInspector})(ch::Channel{Nothing})
        @ Makie ~/.julia/packages/Makie/YkotL/src/interaction/inspector.jl:286
     [12] (::Base.var"#651#652"{Makie.var"#1390#1394"{DataInspector}, Channel{Nothing}})()
        @ Base ./channels.jl:142
Error in callback:
TaskFailedException
Stacktrace:
  [1] check_channel_state
    @ ./channels.jl:188 [inlined]
  [2] put!
    @ ./channels.jl:340 [inlined]
  [3] (::Makie.var"#1391#1395"{Channel{Nothing}})(::Tuple{Float64, Float64}, ::Tuple{Float64, Float64})
    @ Makie ~/.julia/packages/Makie/YkotL/src/interaction/inspector.jl:291
  [4] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::@Kwargs{})
    @ Base ./essentials.jl:892
  [5] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base ./essentials.jl:889
  [6] (::Observables.OnAny)(value::Any)
    @ Observables ~/.julia/packages/Observables/YdEbO/src/Observables.jl:420
  [7] #invokelatest#2
    @ ./essentials.jl:892 [inlined]
  [8] invokelatest
    @ ./essentials.jl:889 [inlined]
  [9] notify
    @ ~/.julia/packages/Observables/YdEbO/src/Observables.jl:206 [inlined]
 [10] setindex!
    @ ~/.julia/packages/Observables/YdEbO/src/Observables.jl:123 [inlined]
 [11] (::GLMakie.MousePositionUpdater)(::Makie.TickState)
    @ GLMakie ~/.julia/packages/GLMakie/NAHlI/src/events.jl:6
 [12] #invokelatest#2
    @ ./essentials.jl:892 [inlined]
 [13] invokelatest
    @ ./essentials.jl:889 [inlined]
 [14] notify
    @ ~/.julia/packages/Observables/YdEbO/src/Observables.jl:206 [inlined]
 [15] setindex!
    @ ~/.julia/packages/Observables/YdEbO/src/Observables.jl:123 [inlined]
 [16] pollevents(screen::GLMakie.Screen{GLFW.Window}, frame_state::Makie.TickState)
    @ GLMakie ~/.julia/packages/GLMakie/NAHlI/src/screen.jl:484
 [17] on_demand_renderloop(screen::GLMakie.Screen{GLFW.Window})
    @ GLMakie ~/.julia/packages/GLMakie/NAHlI/src/screen.jl:982
 [18] renderloop(screen::GLMakie.Screen{GLFW.Window})
    @ GLMakie ~/.julia/packages/GLMakie/NAHlI/src/screen.jl:1010
 [19] (::GLMakie.var"#72#73"{GLMakie.Screen{GLFW.Window}})()
    @ GLMakie ~/.julia/packages/GLMakie/NAHlI/src/screen.jl:870

The above output should be the complete error, but maybe I missed the exact start and end: since it keeps getting spammed I couldn’t say exactly what is the beginning (but the above should be a whole “period”).

Thanks, can you open an issue at Agents.jl github page with this? It could be that something in the Example Zoo for DaisyWorld wasn’t updated with a new version, or it could be a genuine bug.

Ok, I will. I’d like to stress that first time I noticed the error I was implementing my own model, so my code had nothing to do with the Example Zoo package. But I was following the same guide, so I guess this leaves open the option that they instruction on the documentation are outdated (other than a genuine bug of course). Should I mark you last reply as solution?

You should post a link to the issue you opened and mark that post as a solution

CU!

George

Github issue opened here