Agents.jl/AgentsPlots.jl/InteractiveChaos.jl errors

I’m trying to build a simple model and I’m experiencing some errors that I’m unable to debug. Here’s the code I’m running:

using Agents
using AgentsPlots
using Distributions
using LightGraphs

mutable struct EmployerAgent <: AbstractAgent
    id::Int
    pos::Int
    compliant::Bool
end

function initialize(
        num_agents = 100,
        graph_edges = 50,
        p_compliance = 0.9,
        p_inv_net = 0.03,
        p_inv_solo = 0.01
)
    space = GraphSpace(SimpleGraph(num_agents, graph_edges))
    properties = Dict(
        :p_compliance => Bernoulli(p_compliance),
        :p_inv_net => Bernoulli(p_inv_net),
        :p_inv_solo => Bernoulli(p_inv_solo)
    )
    model = ABM(EmployerAgent, space; properties = properties)
    for n in 1:num_agents
        agent = EmployerAgent(n, n, rand(model.properties[:p_compliance]))
        add_agent_single!(agent, model)
    end
    return model
end;

agent_color(x) = x[1].compliant == 0 ? :red : :green

model = initialize()
plotabm(model; ac=agent_color)

Most of the time that I call plotabm it works, but every 4th or 5th call (seemingly at random) it returns this:

AssertionError: length(node_weights) == n

Stacktrace:
 [1] macro expansion at C:\Users\mthel\.julia\packages\GraphRecipes\kYXc4\src\graphs.jl:378 [inlined]
 [2] apply_recipe(::Dict{Symbol,Any}, ::GraphRecipes.GraphPlot) at C:\Users\mthel\.julia\packages\RecipesBase\jcXIg\src\RecipesBase.jl:281
 [3] _process_userrecipes!(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{GraphRecipes.GraphPlot}) at C:\Users\mthel\.julia\packages\RecipesPipeline\5RD7m\src\user_recipe.jl:35
 [4] recipe_pipeline!(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{GraphRecipes.GraphPlot}) at C:\Users\mthel\.julia\packages\RecipesPipeline\5RD7m\src\RecipesPipeline.jl:68
 [5] _plot!(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{GraphRecipes.GraphPlot}) at C:\Users\mthel\.julia\packages\Plots\jpF9l\src\plot.jl:167
 [6] plot(::GraphRecipes.GraphPlot; kw::Base.Iterators.Pairs{Symbol,Any,NTuple{6,Symbol},NamedTuple{(:node_weights, :nodeshape, :nodecolor, :color, :markerstrokecolor, :markerstrokewidth),Tuple{Array{Float64,1},Array{Any,1},Array{Any,1},String,String,Float64}}}) at C:\Users\mthel\.julia\packages\Plots\jpF9l\src\plot.jl:57
 [7] #graphplot#82 at C:\Users\mthel\.julia\packages\RecipesBase\jcXIg\src\RecipesBase.jl:356 [inlined]
 [8] plotabm(::AgentBasedModel{EmployerAgent,GraphSpace{SimpleGraph{Int64}},typeof(fastest),Dict{Symbol,Bernoulli{Float64}}}; ac::typeof(agent_color), as::typeof(length), am::AgentsPlots.var"#16#20", kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at C:\Users\mthel\.julia\packages\AgentsPlots\XAIQ4\src\graph.jl:29
 [9] top-level scope at In[11]:2

It appears that the error is in the plot generation so I’m not sure if this is an AgentsPlots.jl issue or if my code would be expected to randomly break like this for some reason (due to my own error).

Furthermore, after loading InteractiveChaos I don’t have access to the interactive_abm function:

using InteractiveChaos

?interactive_abm()

search: interactive_poincaresos interactive_orbitdiagram InteractiveChaos

Couldn't find interactive_abm
Perhaps you meant InteractiveChaos

I’ve read through your ABM code and it seems fine to me. I think this is a problem with AgentsPlots.

I was able to replicate this. However, it’s possible to access interactive_orbitdiagram but not interactive_abm. The docstring for interactive_abm seems to exist (see https://github.com/JuliaDynamics/InteractiveChaos.jl/blob/master/src/agents/agents.jl ) and should work as expected.

1 Like

Hi, just saw this. Before going into the context, @mthelm85 if you have a question or problem with a Julia package (at least for those in JuliaDynamics), you are more likely to get help faster by simply posting this directly on the appropriate GitHub page.


Your first problem should be discussed in https://github.com/JuliaDynamics/AgentsPlots.jl , please open an issue. The main point is to see whether this problem is truly from AgentsPlots and not from the graph plot recipe of Plots.jl.


Your second problem comes because (I believe) you are not in the appropriate version, see here: https://github.com/JuliaDynamics/InteractiveChaos.jl/issues/9

1 Like