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

**URL:** https://discourse.julialang.org/t/agents-jl-agentsplots-jl-interactivechaos-jl-errors/42941
**Category:** Modelling & Simulations
**Tags:** agents
**Created:** [July 12, 2020, 1:12pm UTC](https://discourse.julialang.org/t/agents-jl-agentsplots-jl-interactivechaos-jl-errors/42941 "2020-07-12T13:12:25Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)
#### Post date: [July 12, 2020, 1:12pm UTC](https://discourse.julialang.org/t/agents-jl-agentsplots-jl-interactivechaos-jl-errors/42941/1 "2020-07-12T13:12:25Z")

</div>

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:

```julia
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:

```julia
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:

```julia
using InteractiveChaos

?interactive_abm()

search: interactive_poincaresos interactive_orbitdiagram InteractiveChaos

Couldn't find interactive_abm
Perhaps you meant InteractiveChaos

```

---

<div class="post-metadata">

### Author: ![fbanning](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fbanning/32/14972_2.png) [@fbanning](https://discourse.julialang.org/u/fbanning)
#### Post date: [July 14, 2020, 12:49pm UTC](https://discourse.julialang.org/t/agents-jl-agentsplots-jl-interactivechaos-jl-errors/42941/2 "2020-07-14T12:49:04Z")

</div>

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

> [@mthelm85](#):
>
> Furthermore, after loading `InteractiveChaos` I don’t have access to the `interactive_abm` function

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](https://github.com/JuliaDynamics/InteractiveChaos.jl/blob/master/src/agents/agents.jl) ) and should work as expected.

---

<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: [July 15, 2020, 2:23pm UTC](https://discourse.julialang.org/t/agents-jl-agentsplots-jl-interactivechaos-jl-errors/42941/3 "2020-07-15T14:23:22Z")

</div>

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](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](https://github.com/JuliaDynamics/InteractiveChaos.jl/issues/9)
