Agents abmexploration callback errors in "on hover"

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

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

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 …

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

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

1 Like

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

     [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> 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> 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!)

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

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

:+1: Done. Thanks very much. :slightly_smiling_face: