Skip to content

nested task error: UndefVarError: Point2f0 not defined in `AgentsVisualizations #1168

@jeetsukumaran

Description

@jeetsukumaran

Describe the bug

When using ContinuousSpace models, hovering over an agent or clicking it to get the information label results in ``nested task error: UndefVarError: Point2f0 not defined in `AgentsVisualizations```

using Revise
using Logging
GLMakie.Screen(...)

julia> Error in callback:
TaskFailedException
Stacktrace:
  [1] check_channel_state
    @ ./channels.jl:188 [inlined]
  [2] put!
    @ ./channels.jl:356 [inlined]
  [3] (::Makie.var"#1390#1394"{Channel{Nothing}})(::Tuple{Float64, Float64}, ::Tuple{Float64, Float64})
    @ Makie ~/.julia/packages/Makie/FUAHr/src/interaction/inspector.jl:301
  [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 ~/.julia/packages/Observables/YdEbO/src/Observables.jl:420
  [7] #invokelatest#2
    @ ./essentials.jl:1055 [inlined]
  [8] invokelatest
    @ ./essentials.jl:1052 [inlined]
  [9] notify
    @ ~/.julia/packages/Observables/YdEbO/src/Observables.jl:206 [inlined]
 [10] setindex!(observable::Observable, val::Any)
    @ Observables ~/.julia/packages/Observables/YdEbO/src/Observables.jl:123
 [11] (::GLMakie.MousePositionUpdater)(::Makie.TickState)
    @ GLMakie ~/.julia/packages/GLMakie/1dQSN/src/events.jl:6
 [12] #invokelatest#2
    @ ./essentials.jl:1055 [inlined]
 [13] invokelatest
    @ ./essentials.jl:1052 [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/1dQSN/src/screen.jl:547
 [17] on_demand_renderloop(screen::GLMakie.Screen{GLFW.Window})
    @ GLMakie ~/.julia/packages/GLMakie/1dQSN/src/screen.jl:1038
 [18] renderloop(screen::GLMakie.Screen{GLFW.Window})
    @ GLMakie ~/.julia/packages/GLMakie/1dQSN/src/screen.jl:1066
 [19] (::GLMakie.var"#79#80"{GLMakie.Screen{GLFW.Window}})()
    @ GLMakie ~/.julia/packages/GLMakie/1dQSN/src/screen.jl:927

    nested task error: UndefVarError: `Point2f0` not defined in `AgentsVisualizations`
    Suggestion: check for spelling errors or missing imports.
    Stacktrace:
     [1] show_data(inspector::DataInspector, p::Plot{AgentsVisualizations._abmplot, Tuple{ABMObservable{Observable{StandardABM{ContinuousSpace{2, true, Float64, typeof(Agents.no_vel_update)}, Bird, Dict{Int64, Bird}, Tuple{DataType}, typeof(agent_step!), typeof(dummystep), Agents.Schedulers.Randomly, Nothing, MersenneTwister}}, Nothing, Nothing, Nothing, Nothing, Bool, Observable{Int64}, Observable{Tuple{Base.RefValue{Int64}, Vector{Int64}}}}}}, idx::UInt32, source::Mesh{Tuple{GeometryBasics.Mesh{2, Float32, GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}, (:position,), Tuple{Vector{Point{2, Float32}}}, Vector{GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}}}}})
       @ AgentsVisualizations ~/.julia/packages/Agents/WuWeG/ext/AgentsVisualizations/src/spaces/abstract.jl:116
     [2] show_data_recursion(inspector::DataInspector, plot::Plot{AgentsVisualizations._abmplot, Tuple{ABMObservable{Observable{StandardABM{ContinuousSpace{2, true, Float64, typeof(Agents.no_vel_update)}, Bird, Dict{Int64, Bird}, Tuple{DataType}, typeof(agent_step!), typeof(dummystep), Agents.Schedulers.Randomly, Nothing, MersenneTwister}}, Nothing, Nothing, Nothing, Nothing, Bool, Observable{Int64}, Observable{Tuple{Base.RefValue{Int64}, Vector{Int64}}}}}}, idx::UInt32, source::Mesh{Tuple{GeometryBasics.Mesh{2, Float32, GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}, (:position,), Tuple{Vector{Point{2, Float32}}}, Vector{GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}}}}})
       @ Makie ~/.julia/packages/Makie/FUAHr/src/interaction/inspector.jl:373
     [3] show_data_recursion(inspector::DataInspector, plot::Poly{Tuple{Vector{GeometryBasics.Polygon{2, Float32}}}}, idx::UInt32, source::Mesh{Tuple{GeometryBasics.Mesh{2, Float32, GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}, (:position,), Tuple{Vector{Point{2, Float32}}}, Vector{GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}}}}})
       @ Makie ~/.julia/packages/Makie/FUAHr/src/interaction/inspector.jl:365
     [4] show_data_recursion(inspector::DataInspector, plot::Mesh{Tuple{Vector{GeometryBasics.Mesh{2, Float32, GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}, (:position,), Tuple{Vector{Point{2, Float32}}}, Vector{GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}}}}}}, idx::UInt32, source::Mesh{Tuple{GeometryBasics.Mesh{2, Float32, GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}, (:position,), Tuple{Vector{Point{2, Float32}}}, Vector{GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}}}}})
       @ Makie ~/.julia/packages/Makie/FUAHr/src/interaction/inspector.jl:365
     [5] show_data_recursion(inspector::DataInspector, plot::Mesh{Tuple{GeometryBasics.Mesh{2, Float32, GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}, (:position,), Tuple{Vector{Point{2, Float32}}}, Vector{GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}}}}}, idx::UInt32)
       @ Makie ~/.julia/packages/Makie/FUAHr/src/interaction/inspector.jl:343
     [6] on_hover(inspector::DataInspector)
       @ Makie ~/.julia/packages/Makie/FUAHr/src/interaction/inspector.jl:326
     [7] (::Makie.var"#1389#1393"{Scene, DataInspector})(ch::Channel{Nothing})
       @ Makie ~/.julia/packages/Makie/FUAHr/src/interaction/inspector.jl:291
     [8] (::Base.var"#739#740"{Makie.var"#1389#1393"{Scene, DataInspector}, Channel{Nothing}})()
       @ Base ./channels.jl:142
Error in callback:
TaskFailedException
Stacktrace:
  [1] check_channel_state
    @ ./channels.jl:188 [inlined]
  [2] put!
    @ ./channels.jl:356 [inlined]
  [3] (::Makie.var"#1390#1394"{Channel{Nothing}})(::Tuple{Float64, Float64}, ::Tuple{Float64, Float64})
    @ Makie ~/.julia/packages/Makie/FUAHr/src/interaction/inspector.jl:301
  [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 ~/.julia/packages/Observables/YdEbO/src/Observables.jl:420
  [7] #invokelatest#2
    @ ./essentials.jl:1055 [inlined]
  [8] invokelatest
    @ ./essentials.jl:1052 [inlined]
  [9] notify
    @ ~/.julia/packages/Observables/YdEbO/src/Observables.jl:206 [inlined]
 [10] setindex!(observable::Observable, val::Any)
    @ Observables ~/.julia/packages/Observables/YdEbO/src/Observables.jl:123
 [11] (::GLMakie.MousePositionUpdater)(::Makie.TickState)
    @ GLMakie ~/.julia/packages/GLMakie/1dQSN/src/events.jl:6
 [12] #invokelatest#2
    @ ./essentials.jl:1055 [inlined]
 [13] invokelatest
    @ ./essentials.jl:1052 [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/1dQSN/src/screen.jl:547
 [17] on_demand_renderloop(screen::GLMakie.Screen{GLFW.Window})
    @ GLMakie ~/.julia/packages/GLMakie/1dQSN/src/screen.jl:1038
 [18] renderloop(screen::GLMakie.Screen{GLFW.Window})
    @ GLMakie ~/.julia/packages/GLMakie/1dQSN/src/screen.jl:1066
 [19] (::GLMakie.var"#79#80"{GLMakie.Screen{GLFW.Window}})()
    @ GLMakie ~/.julia/packages/GLMakie/1dQSN/src/screen.jl:927

    nested task error: UndefVarError: `Point2f0` not defined in `AgentsVisualizations`
    Suggestion: check for spelling errors or missing imports.
    Stacktrace:
     [1] show_data(inspector::DataInspector, p::Plot{AgentsVisualizations._abmplot, Tuple{ABMObservable{Observable{StandardABM{ContinuousSpace{2, true, Float64, typeof(Agents.no_vel_update)}, Bird, Dict{Int64, Bird}, Tuple{DataType}, typeof(agent_step!), typeof(dummystep), Agents.Schedulers.Randomly, Nothing, MersenneTwister}}, Nothing, Nothing, Nothing, Nothing, Bool, Observable{Int64}, Observable{Tuple{Base.RefValue{Int64}, Vector{Int64}}}}}}, idx::UInt32, source::Mesh{Tuple{GeometryBasics.Mesh{2, Float32, GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}, (:position,), Tuple{Vector{Point{2, Float32}}}, Vector{GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}}}}})
       @ AgentsVisualizations ~/.julia/packages/Agents/WuWeG/ext/AgentsVisualizations/src/spaces/abstract.jl:116
     [2] show_data_recursion(inspector::DataInspector, plot::Plot{AgentsVisualizations._abmplot, Tuple{ABMObservable{Observable{StandardABM{ContinuousSpace{2, true, Float64, typeof(Agents.no_vel_update)}, Bird, Dict{Int64, Bird}, Tuple{DataType}, typeof(agent_step!), typeof(dummystep), Agents.Schedulers.Randomly, Nothing, MersenneTwister}}, Nothing, Nothing, Nothing, Nothing, Bool, Observable{Int64}, Observable{Tuple{Base.RefValue{Int64}, Vector{Int64}}}}}}, idx::UInt32, source::Mesh{Tuple{GeometryBasics.Mesh{2, Float32, GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}, (:position,), Tuple{Vector{Point{2, Float32}}}, Vector{GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}}}}})
       @ Makie ~/.julia/packages/Makie/FUAHr/src/interaction/inspector.jl:373
     [3] show_data_recursion(inspector::DataInspector, plot::Poly{Tuple{Vector{GeometryBasics.Polygon{2, Float32}}}}, idx::UInt32, source::Mesh{Tuple{GeometryBasics.Mesh{2, Float32, GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}, (:position,), Tuple{Vector{Point{2, Float32}}}, Vector{GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}}}}})
       @ Makie ~/.julia/packages/Makie/FUAHr/src/interaction/inspector.jl:365
     [4] show_data_recursion(inspector::DataInspector, plot::Mesh{Tuple{Vector{GeometryBasics.Mesh{2, Float32, GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}, (:position,), Tuple{Vector{Point{2, Float32}}}, Vector{GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}}}}}}, idx::UInt32, source::Mesh{Tuple{GeometryBasics.Mesh{2, Float32, GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}, (:position,), Tuple{Vector{Point{2, Float32}}}, Vector{GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}}}}})
       @ Makie ~/.julia/packages/Makie/FUAHr/src/interaction/inspector.jl:365
     [5] show_data_recursion(inspector::DataInspector, plot::Mesh{Tuple{GeometryBasics.Mesh{2, Float32, GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}, (:position,), Tuple{Vector{Point{2, Float32}}}, Vector{GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}}}}}, idx::UInt32)
       @ Makie ~/.julia/packages/Makie/FUAHr/src/interaction/inspector.jl:343
     [6] on_hover(inspector::DataInspector)
       @ Makie ~/.julia/packages/Makie/FUAHr/src/interaction/inspector.jl:326
     [7] (::Makie.var"#1389#1393"{Scene, DataInspector})(ch::Channel{Nothing})
       @ Makie ~/.julia/packages/Makie/FUAHr/src/interaction/inspector.jl:291
     [8] (::Base.var"#739#740"{Makie.var"#1389#1393"{Scene, DataInspector}, Channel{Nothing}})()
       @ Base ./channels.jl:142

Minimal Working Example

using Agents
using GLMakie
using Random, LinearAlgebra

@agent struct Bird(ContinuousAgent{2,Float64})
    speed::Float64
    cohere_factor::Float64
    separation::Float64
    separate_factor::Float64
    match_factor::Float64
    visual_distance::Float64
end

function initialize_model(;
    n_birds = 100,
    speed = 1.5,
    cohere_factor = 0.1,
    separation = 2.0,
    separate_factor = 0.25,
    match_factor = 0.04,
    visual_distance = 5.0,
    extent = (100, 100),
    seed = 42,
)
    space2d = ContinuousSpace(extent; spacing = visual_distance/1.5)
    rng = Random.MersenneTwister(seed)

    model = StandardABM(Bird, space2d; rng, agent_step!, scheduler = Schedulers.Randomly())
    for _ in 1:n_birds
        vel = rand(abmrng(model), SVector{2}) * 2 .- 1
        add_agent!(
            model,
            vel,
            speed,
            cohere_factor,
            separation,
            separate_factor,
            match_factor,
            visual_distance,
        )
    end
    return model
end

function agent_step!(bird, model)
    # Obtain the ids of neighbors within the bird's visual distance
    neighbor_ids = nearby_ids(bird, model, bird.visual_distance)
    N = 0
    match = separate = cohere = (0.0, 0.0)
    # Calculate behaviour properties based on neighbors
    for id in neighbor_ids
        N += 1
        neighbor = model[id].pos
        heading = get_direction(bird.pos, neighbor, model)

        # `cohere` computes the average position of neighboring birds
        cohere = cohere .+ heading
        if euclidean_distance(bird.pos, neighbor, model) < bird.separation
            # `separate` repels the bird away from neighboring birds
            separate = separate .- heading
        end
        # `match` computes the average trajectory of neighboring birds
        match = match .+ model[id].vel
    end
    N = max(N, 1)
    # Normalise results based on model input and neighbor count
    cohere = cohere ./ N .* bird.cohere_factor
    separate = separate ./ N .* bird.separate_factor
    match = match ./ N .* bird.match_factor
    # Compute velocity based on rules defined above
    bird.vel = (bird.vel .+ cohere .+ separate .+ match) ./ 2
    bird.vel = bird.vel ./ norm(bird.vel)
    # Move bird according to new velocity and speed
    move_agent!(bird, model, bird.speed)
end

model = initialize_model()

const bird_polygon = Makie.Polygon(Point2f[(-1, -1), (2, 0), (-1, 1)])
function bird_marker(b::Bird)
    φ = atan(b.vel[2], b.vel[1]) #+ π/2 + π
    rotate_polygon(bird_polygon, φ)
end
m = abmexploration(
    model;
    agent_marker = bird_marker,
)
display(m[1])

Agents.jl version

[46ada45e] Agents v6.2.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions