-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
abmplot
fails when 1) number of agents changes over time and 2) custom agent_size
function is used
#1035
Comments
abmplot
fails when 1) number of agents changes over time and 2) custom agent_size function is usedabmplot
fails when 1) number of agents changes over time and 2) custom agent_size
function is used
since you are using Agents 6.0 syntax, you have a old GLMakie version installed somehow probably |
Thank you for your quick response. I also use GLMakie v0.9.11 (and Makie v0.20.10 if this is relevant). |
ah no sorry, didn't see that in your reproducer, yes the error is there also for me :-) |
I investigated a bit the issue and I'm unsure of what could be the cause because this works instead: using Agents, GLMakie
@agent struct Particle(ContinuousAgent{2,Float64}) end
function build_model()
space = ContinuousSpace((1, 1))
model = StandardABM(Particle, space; agent_step! = particle_step!)
for i = 1:100
pos = Tuple(rand(2))
vel = Tuple(rand(2))
add_agent!(Particle(i, pos, vel), model)
end
return model
end
function particle_step!(p, model)
randomwalk!(p, model, 1.0)
if rand() < 0.5
remove_agent!(p, model) # Number of agents changes here.
end
end
p_color(p::Particle) = :red
model = build_model()
figure, ax, abmobs = abmplot(model; add_controls = true, agent_color = p_color)
resize!(figure, 1200, 800)
wait(display(figure)) which is strange because internally |
I am trying to find where in the source code the UPDATE of plotted agents is done. I cannot, unfortunately. If you can find where the update of the scatterplot is done in the source code please paste a link here and I ll have a look. |
Thanks again for your analysis. I am not sure if I can help but I looked in the sources and found in
and before
|
Hm, I do not know the solution. I thought it was a concurrency issue with makie. Where one vector (eg size) is updated and a plot update is triggered before the other vector (e.g. color) is updated, leading to missmatch of dimensions. However, normally the plotting code works fine with agents being deleted, we have many examples and animations where this occur and agents have different colors. What is fundamentally different in this MWE that makes it not work...? Is it really that the size is different? If we run e.g., the rock paper scissors example where each type also has different size, would we get the same error...? |
yes, tried, we get the same error. I think I found a github issue and PR which describe the culprit of this: MakieOrg/Makie.jl#3658 and JuliaGizmos/Observables.jl#109 |
great, thanks! |
We can also solve this on our side by the way. Instead of using
it is actually super sipmle to change the source code to do that. |
Describe the bug
I have a simulation where I remove agents by chance (by
remove_agent!
). I also define a custom function (p_size
) for an agent's size provided toabmplot
. When I run the simulation (see MWE below), an exception is thrown:See also full stack trace at the end.
What am I doing wrong?
PS: Thank you very much for the
Agents.jl
package! I am really happy to use it.Minimal Working Example
Here's the example. Please note that the example works when the custom agent_size function
p_size
is not used -- see comments at the end of the example.Agents.jl version
Agents v6.0.12 with Julia 1.10.2 and Linux Ubuntu 22.04.
Full stack trace
The text was updated successfully, but these errors were encountered: