# Agents abmexploration callback errors in "on hover"

**URL:** <https://discourse.julialang.org/t/agents-abmexploration-callback-errors-in-on-hover/124675>\
**Category:** Modelling & Simulations\
**Tags:** question, agents\
**Created:** [January 11, 2025, 2:18pm UTC](https://discourse.julialang.org/t/agents-abmexploration-callback-errors-in-on-hover/124675 "2025-01-11T14:18:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niall](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niall/32/22517_2.png) [@Niall](https://discourse.julialang.org/u/Niall)\
**Post date:** [January 11, 2025, 2:18pm UTC](https://discourse.julialang.org/t/agents-abmexploration-callback-errors-in-on-hover/124675/1 "2025-01-11T14:18:09Z")

</div>

Hi. I’m struggling a bit with understanding all the details of using abmexploration with the Agents package. I got occasional crashes with small models, but they greatly increased with large numbers of agents. Finally, I realised that the error arose when my cursor accidentally hovered over an agent. Here is the stripped down code that reproduces the error. include() this code, bring the abmexploration window into focus, then hover over the single agent, and … bingo - crash!

Can anyone please help?

Thanks! 😀

```julia
module Ecosystem
using Agents, GLMakie

@agent struct Turtle(ContinuousAgent{2,Float64})
end

function agent_step!( me::Turtle, model)
    return
end

abm = StandardABM( Turtle, ContinuousSpace((60,60)); agent_step!)
add_agent!( abm; vel=[1,1])
playground, _ = abmexploration( abm)
display(playground)
end

```

---

<div class="post-metadata">

**Author:** ![Niall](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niall/32/22517_2.png) [@Niall](https://discourse.julialang.org/u/Niall)\
**Post date:** [January 12, 2025, 6:49am UTC](https://discourse.julialang.org/t/agents-abmexploration-callback-errors-in-on-hover/124675/2 "2025-01-12T06:49:37Z")

</div>

I’m sorry - I should have included more information: The Agents package version is 6.2.1, and the error report is so ginormous that it bursts the bounds of my console, but its flavour is given by this outtake …

```julia
Error in callback:
TaskFailedException
Stacktrace:
  [1] check_channel_state
    @ .\channels.jl:188 [inlined]
  [2] put!
    @ .\channels.jl:356 [inlined]
  [3] (::Makie.var"#1326#1330"{Channel{Nothing}})(::Tuple{Float64, Float64}, ::Tuple{Float64, Float64})
    @ Makie C:\Users\hswt136nia\.julia\packages\Makie\Y3ABD\src\interaction\inspector.jl:296
  [4] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::@Kwargs{})
    @ Base .\essentials.jl:1055
  [5] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base .\essentials.jl:1052
  [6] (::Observables.OnAny)(value::Any)
    @ Observables C:\Users\hswt136nia\.julia\packages\Observables\YdEbO\src\Observables.jl:420
  [7] #invokelatest#2
    @ .\essentials.jl:1055 [inlined]
  [8] invokelatest
    @ .\essentials.jl:1052 [inlined]
  [9] notify
    @ C:\Users\hswt136nia\.julia\packages\Observables\YdEbO\src\Observables.jl:206 [inlined]
 [10] setindex!
    @ C:\Users\hswt136nia\.julia\packages\Observables\YdEbO\src\Observables.jl:123 [inlined]
 [11] (::GLMakie.MousePositionUpdater)(::Makie.TickState)
    @ GLMakie C:\Users\hswt136nia\.julia\packages\GLMakie\TH3rf\src\events.jl:6
 [12] #invokelatest#2
    @ .\essentials.jl:1055 [inlined]
 [13] invokelatest
    @ .\essentials.jl:1052 [inlined]
 [14] notify
    @ C:\Users\hswt136nia\.julia\packages\Observables\YdEbO\src\Observables.jl:206 [inlined]
 [15] setindex!
    @ C:\Users\hswt136nia\.julia\packages\Observables\YdEbO\src\Observables.jl:123 [inlined]
 [16] pollevents(screen::GLMakie.Screen{GLFW.Window}, frame_state::Makie.TickState)
    @ GLMakie C:\Users\hswt136nia\.julia\packages\GLMakie\TH3rf\src\screen.jl:486
 [17] on_demand_renderloop(screen::GLMakie.Screen{GLFW.Window})
    @ GLMakie C:\Users\hswt136nia\.julia\packages\GLMakie\TH3rf\src\screen.jl:935
 [18] renderloop(screen::GLMakie.Screen{GLFW.Window})
    @ GLMakie C:\Users\hswt136nia\.julia\packages\GLMakie\TH3rf\src\screen.jl:963
 [19] (::GLMakie.var"#71#72"{GLMakie.Screen{GLFW.Window}})()
    @ GLMakie C:\Users\hswt136nia\.julia\packages\GLMakie\TH3rf\src\screen.jl:823

    nested task error: DimensionMismatch: arrays could not be broadcast to a common size
    Stacktrace:
      [1] _bcs1(a::StaticArrays.SOneTo{2}, b::StaticArrays.SOneTo{3})
        @ StaticArrays C:\Users\hswt136nia\.julia\packages\StaticArrays\SA4kA\src\broadcast.jl:77
      [2] _bcs(shape::Tuple{StaticArrays.SOneTo{2}}, newshape::Tuple{StaticArrays.SOneTo{3}})
        @ Base.Broadcast .\broadcast.jl:517
      [3] broadcast_shape(::Tuple{StaticArrays.SOneTo{2}}, ::Tuple{StaticArrays.SOneTo{3}})
        @ Base.Broadcast .\broadcast.jl:511
      [4] static_combine_axes
        @ C:\Users\hswt136nia\.julia\packages\StaticArrays\SA4kA\src\broadcast.jl:20 [inlined]
      [5] _axes(bc::Base.Broadcast.Broadcasted{StaticArraysCore.StaticArrayStyle{1}, Nothing, typeof(-), Tuple{StaticArraysCore.SVector{2, Float64}, Tuple{Float64, Float64, Float64}}}, ::Nothing)
        @ StaticArrays C:\Users\hswt136nia\.julia\packages\StaticArrays\SA4kA\src\broadcast.jl:25
      [6] axes
        @ .\broadcast.jl:234 [inlined]
      [7] static_axes(A::Base.Broadcast.Broadcasted{StaticArraysCore.StaticArrayStyle{1}, Nothing, typeof(-), Tuple{StaticArraysCore.SVector{2, Float64}, Tuple{Float64, Float64, Float64}}})
        @ StaticArrays C:\Users\hswt136nia\.julia\packages\StaticArrays\SA4kA\src\broadcast.jl:22
      [8] static_combine_axes(A::Base.Broadcast.Broadcasted{StaticArraysCore.StaticArrayStyle{1}, Nothing, typeof(-), Tuple{StaticArraysCore.SVector{2, Float64}, Tuple{Float64, Float64, Float64}}})
        @ StaticArrays C:\Users\hswt136nia\.julia\packages\StaticArrays\SA4kA\src\broadcast.jl:21
      [9] static_combine_axes
        @ C:\Users\hswt136nia\.julia\packages\StaticArrays\SA4kA\src\broadcast.jl:20 [inlined]
     [10] _axes(bc::Base.Broadcast.Broadcasted{StaticArraysCore.StaticArrayStyle{1}, Nothing, typeof(min), Tuple{Tuple{Float64, Float64, Float64}, Base.Broadcast.Broadcasted{StaticArraysCore.StaticArrayStyle{1}, Nothing, typeof(-), Tuple{StaticArraysCore.SVector{2, Float64}, Tuple{Float64, Float64, Float64}}}}}, ::Nothing)
        @ StaticArrays C:\Users\hswt136nia\.julia\packages\StaticArrays\SA4kA\src\broadcast.jl:25
     [11] axes
        @ .\broadcast.jl:234 [inlined]
     [12] static_axes(A::Base.Broadcast.Broadcasted{StaticArraysCore.StaticArrayStyle{1}, Nothing, typeof(min), Tuple{Tuple{Float64, Float64, Float64}, Base.Broadcast.Broadcasted{StaticArraysCore.StaticArrayStyle{1}, Nothing, typeof(-), Tuple{StaticArraysCore.SVector{2, Float64}, Tuple{Float64, 
Float64, Float64}}}}})
        @ StaticArrays C:\Users\hswt136nia\.julia\packages\StaticArrays\SA4kA\src\broadcast.jl:22
     [13] static_combine_axes (repeats 2 times)
        @ C:\Users\hswt136nia\.julia\packages\StaticArrays\SA4kA\src\broadcast.jl:20 [inlined]
     [14] instantiate
        @ C:\Users\hswt136nia\.julia\packages\StaticArrays\SA4kA\src\broadcast.jl:32 [inlined]
     [15] materialize
        @ .\broadcast.jl:867 [inlined]
     [16] euclidean_distance(p1::Tuple{Float64, Float64, Float64}, p2::Tuple{Float64, Float64, Float64}, space::Agents.ContinuousSpace{2, true, Float64, typeof(Agents.no_vel_update)})
        @ Agents C:\Users\hswt136nia\.julia\packages\Agents\kk40C\src\spaces\utilities.jl:42
     [17] euclidean_distance(p1::Tuple{Float64, Float64, Float64}, p2::Tuple{Float64, Float64, Float64}, model::Agents.StandardABM{Agents.ContinuousSpace{2, true, Float64, typeof(Agents.no_vel_update)}, Main.Ecosystem.Turtle, Dict{Int64, Main.Ecosystem.Turtle}, Tuple{DataType}, typeof(Main.Ecosystem.agent_step!), typeof(Agents.dummystep), typeof(Agents.Schedulers.fastest), Nothing, Random.TaskLocalRNG})
        @ Agents C:\Users\hswt136nia\.julia\packages\Agents\kk40C\src\spaces\utilities.jl:26
     [18] distance_from_cell_center(pos::Tuple{Float64, Float64, Float64}, model::Agents.StandardABM{Agents.ContinuousSpace{2, true, Float64, typeof(Agents.no_vel_update)}, Main.Ecosystem.Turtle, Dict{Int64, Main.Ecosystem.Turtle}, Tuple{DataType}, typeof(Main.Ecosystem.agent_step!), typeof(Agents.dummystep), typeof(Agents.Schedulers.fastest), Nothing, Random.TaskLocalRNG})
        @ Agents C:\Users\hswt136nia\.julia\packages\Agents\kk40C\src\spaces\continuous.jl:119
     [19] nearby_ids_approx(pos::Tuple{Float64, Float64, Float64}, model::Agents.StandardABM{Agents.ContinuousSpace{2, true, Float64, typeof(Agents.no_vel_update)}, Main.Ecosystem.Turtle, Dict{Int64, Main.Ecosystem.Turtle}, Tuple{DataType}, typeof(Main.Ecosystem.agent_step!), typeof(Agents.dummystep), typeof(Agents.Schedulers.fastest), Nothing, Random.TaskLocalRNG}, r::Float64)
        @ Agents C:\Users\hswt136nia\.julia\packages\Agents\kk40C\src\spaces\continuous.jl:217
     [20] nearby_ids_exact(pos::Tuple{Float64, Float64, Float64}, model::Agents.StandardABM{Agents.ContinuousSpace{2, true, Float64, typeof(Agents.no_vel_update)}, Main.Ecosystem.Turtle, Dict{Int64, Main.Ecosystem.Turtle}, Tuple{DataType}, typeof(Main.Ecosystem.agent_step!), typeof(Agents.dummystep), typeof(Agents.Schedulers.fastest), Nothing, Random.TaskLocalRNG}, r::Float64)
        @ Agents C:\Users\hswt136nia\.julia\packages\Agents\kk40C\src\spaces\continuous.jl:231
     [21] ids_to_inspect(model::Agents.StandardABM{Agents.ContinuousSpace{2, true, Float64, typeof(Agents.no_vel_update)}, Main.Ecosystem.Turtle, Dict{Int64, Main.Ecosystem.Turtle}, Tuple{DataType}, typeof(Main.Ecosystem.agent_step!), typeof(Agents.dummystep), typeof(Agents.Schedulers.fastest), 
Nothing, Random.TaskLocalRNG}, pos::Tuple{Float64, Float64, Float64})
        @ AgentsVisualizations C:\Users\hswt136nia\.julia\packages\Agents\kk40C\ext\AgentsVisualizations\src\spaces\continuous.jl:43
     [22] agent2string(model::Agents.StandardABM{Agents.ContinuousSpace{2, true, Float64, typeof(Agents.no_vel_update)}, Main.Ecosystem.Turtle, Dict{Int64, Main.Ecosystem.Turtle}, Tuple{DataType}, typeof(Main.Ecosystem.agent_step!), typeof(Agents.dummystep), typeof(Agents.Schedulers.fastest), Nothing, Random.TaskLocalRNG}, pos::Tuple{Float64, Float64, Float64})
        @ AgentsVisualizations C:\Users\hswt136nia\.julia\packages\Agents\kk40C\ext\AgentsVisualizations\src\spaces\abstract.jl:143
     [23] show_data(inspector::Makie.DataInspector, p::MakieCore.Plot{AgentsVisualizations._abmplot, Tuple{Agents.ABMObservable{Observables.Observable{Agents.StandardABM{Agents.ContinuousSpace{2, true, Float64, typeof(Agents.no_vel_update)}, Main.Ecosystem.Turtle, Dict{Int64, Main.Ecosystem.Turtle}, Tuple{DataType}, typeof(Main.Ecosystem.agent_step!), typeof(Agents.dummystep), typeof(Agents.Schedulers.fastest), Nothing, Random.TaskLocalRNG}}, Nothing, Nothing, Nothing, Nothing, Bool, Observables.Observable{Int64}, Observables.Observable{Tuple{Base.RefValue{Int64}, Vector{Int64}}}}}}, idx::UInt32, source::MakieCore.Scatter{Tuple{Vector{GeometryBasics.Point{2, Float32}}}})
        @ AgentsVisualizations C:\Users\hswt136nia\.julia\packages\Agents\kk40C\ext\AgentsVisualizations\src\spaces\abstract.jl:101
     [24] show_data_recursion(inspector::Makie.DataInspector, plot::MakieCore.Plot{AgentsVisualizations._abmplot, Tuple{Agents.ABMObservable{Observables.Observable{Agents.StandardABM{Agents.ContinuousSpace{2, true, Float64, typeof(Agents.no_vel_update)}, Main.Ecosystem.Turtle, Dict{Int64, Main.Ecosystem.Turtle}, Tuple{DataType}, typeof(Main.Ecosystem.agent_step!), typeof(Agents.dummystep), typeof(Agents.Schedulers.fastest), Nothing, Random.TaskLocalRNG}}, Nothing, Nothing, Nothing, Nothing, Bool, Observables.Observable{Int64}, Observables.Observable{Tuple{Base.RefValue{Int64}, Vector{Int64}}}}}}, idx::UInt32, source::MakieCore.Scatter{Tuple{Vector{GeometryBasics.Point{2, Float32}}}})
        @ Makie C:\Users\hswt136nia\.julia\packages\Makie\Y3ABD\src\interaction\inspector.jl:373
     [25] show_data_recursion(inspector::Makie.DataInspector, plot::MakieCore.Scatter{Tuple{Vector{GeometryBasics.Point{2, Float32}}}}, idx::UInt32) @ Makie C:\Users\hswt136nia\.julia\packages\Makie\Y3ABD\src\interaction\inspector.jl:343
     [26] on_hover(inspector::Makie.DataInspector)
        @ Makie C:\Users\hswt136nia\.julia\packages\Makie\Y3ABD\src\interaction\inspector.jl:321
     [27] (::Makie.var"#1325#1329"{Makie.Scene, Makie.DataInspector})(ch::Channel{Nothing})
        @ Makie C:\Users\hswt136nia\.julia\packages\Makie\Y3ABD\src\interaction\inspector.jl:286
     [28] (::Base.var"#739#740"{Makie.var"#1325#1329"{Makie.Scene, Makie.DataInspector}, Channel{Nothing}})()
        @ Base .\channels.jl:142

```

---

<div class="post-metadata">

**Author:** ![Niall](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niall/32/22517_2.png) [@Niall](https://discourse.julialang.org/u/Niall)\
**Post date:** [January 16, 2025, 8:16am UTC](https://discourse.julialang.org/t/agents-abmexploration-callback-errors-in-on-hover/124675/3 "2025-01-16T08:16:56Z")

</div>

Well, it’s been 5 days and 37 view now, and there have been no replies to this. Unfortunately, it’s holding up my rollout of a course that I am shortly due to hold, so I’m getting a little worried. Can anyone perhaps confirm that my problem is reproducible? It could be that it’s linked to some aspect of my particular installation. Thanks. 🙂

---

<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:** [January 16, 2025, 9:00am UTC](https://discourse.julialang.org/t/agents-abmexploration-callback-errors-in-on-hover/124675/4 "2025-01-16T09:00:54Z")

</div>

I can reproduce the error, although I don’t have to hover over the agent, as soon as I do anything with the GLMakie window I get the error.

The error is also not that large, it’s just in the callback so it’s triggered on any interaction with the window (including for me, after it’s been triggered once, if I just move my cursor within the window).

It looks like Agents is internally calling

```julia
     [16] euclidean_distance(p1::Tuple{Float64, Float64, Float64}, p2::Tuple{Float64, Float64, Float64}, space::ContinuousSpace{2, true, Float64, typeof(Agents.no_vel_update)})
        @ Agents (...)

```

and there’s some dimension mismatch in this - maybe either `ContinuousSpace((60,60))` or `vel=[1,1]` needs to have a different dimension in the specification of the model? Never used `Agents`, so I’m not sure.

Another observation: `step!`ing the model seems to work fine:

```julia
julia> abm = StandardABM( Turtle, ContinuousSpace((60,60)); agent_step!)
StandardABM with 0 agents of type Turtle
 agents container: Dict
 space: periodic continuous space with [60.0, 60.0] extent and spacing=3.0
 scheduler: fastest

julia> add_agent!( abm; vel=[1,1])
Turtle(1, [56.9564055166526, 42.67224492219528], [1.0, 1.0])

julia> step!(abm)
StandardABM with 1 agents of type Turtle
 agents container: Dict
 space: periodic continuous space with [60.0, 60.0] extent and spacing=3.0
 scheduler: fastest

```

and when I do

```julia
julia> playground, _ = abmexploration( abm);

julia> display(playground)

```

after having `step!`ed the model I don’t get the error any longer (although the model also doesn’t seem to do anything when I interact with the buttons/sliders in the window? Not sure what this model should be doing tbh as, again, I don’t know anything about `Agents`!)

---

<div class="post-metadata">

**Author:** ![Niall](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niall/32/22517_2.png) [@Niall](https://discourse.julialang.org/u/Niall)\
**Post date:** [January 16, 2025, 1:10pm UTC](https://discourse.julialang.org/t/agents-abmexploration-callback-errors-in-on-hover/124675/5 "2025-01-16T13:10:42Z")

</div>

Wonderful! Thanks very much, @nilshg. I’ll set to work investigating all this information.

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [January 16, 2025, 1:17pm UTC](https://discourse.julialang.org/t/agents-abmexploration-callback-errors-in-on-hover/124675/6 "2025-01-16T13:17:57Z")

</div>

@Niall can you report this as an issue in the Agents.jl GitHub repo? It may be a Makie issue - the way the covert information from the screen. In Agents.jl you are using 2D stuff and we check internally, so this should be fine.

---

<div class="post-metadata">

**Author:** ![Niall](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niall/32/22517_2.png) [@Niall](https://discourse.julialang.org/u/Niall)\
**Post date:** [January 16, 2025, 4:25pm UTC](https://discourse.julialang.org/t/agents-abmexploration-callback-errors-in-on-hover/124675/7 "2025-01-16T16:25:04Z")

</div>

👍 Done. Thanks very much. 🙂

---

<div class="post-metadata">

**Author:** ![Niall](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niall/32/22517_2.png) [@Niall](https://discourse.julialang.org/u/Niall)\
**Post date:** [January 22, 2025, 10:38am UTC](https://discourse.julialang.org/t/agents-abmexploration-callback-errors-in-on-hover/124675/8 "2025-01-22T10:38:18Z")

</div>

I’m not sure how this works. I reported the issue, but there’s been no answer back so far. I have to deliver this course for March, so I’m continuing for the moment without allowing the mouse to interact with the abmexploration window. However, there appear to be further issues with data collection. If I delete the agent, abmexploration has problems reinitialising the model:

```julia
module Ecosystem
using Agents, GLMakie

@agent struct Turtle(ContinuousAgent{2,Float64})
end

function agent_step!( me::Turtle, model)
    remove_agent!( me, model)
    return
end

xvel( me::Turtle) = me.vel[1]

abm = StandardABM( Turtle, ContinuousSpace((60,60)); agent_step!)
add_agent!( abm; vel=[1,1])
playground, _ = abmexploration( abm; adata=[(xvel, sum)])
display(playground)
end

```

Running the model `abm` then clicking on Reset Model yields the error:

```julia
DimensionMismatch: arrays could not be broadcast to a common size: a has axes Base.OneTo(3) and b has axes Base.OneTo(2)

```

Whereas clicking on Clear Data yields:

```julia
ArgumentError: Model must have at least one agent to initialize data collection

```

This certainly makes sense, since I’ve deleted the single agent during the initial model run; however, I don’t see how to replace this agent on reinitialisation. Is this an issue or am I missing something?
