JuliaDynamics / Agents.jl

Agent-based modeling framework in Julia
https://juliadynamics.github.io/Agents.jl/stable/
MIT License
764 stars 126 forks source link

The doc example for graph visualisation does not work #827

Closed AldoGl closed 1 year ago

AldoGl commented 1 year ago

Describe the bug The graph visualisation example given in the documentation gives an error.

The error I get is

ERROR: LoadError: UndefVarError: `graphplot!` not defined

Minimal Working Example

using Agents
using ColorTypes
using Graphs
using GLMakie

using Graphs: edges
using GraphMakie: Shell
using GraphMakie: graphplot!
using GraphMakie: graphplot

sir_model, sir_agent_step!, sir_model_step! = Models.sir()
city_size(agents_here) = 0.005 * length(agents_here)

function city_color(agents_here)
    return RGB(0.5 , 0.5, 0)
end

edge_color(model) = fill((:grey, 0.25), ne(model.space.graph))

function edge_width(model)
    w = zeros(ne(model.space.graph))
    for e in edges(model.space.graph)
        push!(w, 0.004 * length(model.space.stored_ids[e.src]))
        push!(w, 0.004 * length(model.space.stored_ids[e.dst]))
    end
    return w
end

graphplotkwargs = (
    layout = Shell(), # node positions
    arrow_show = false, # hide directions of graph edges
    edge_color = edge_color, # change edge colors and widths with own functions
    edge_width = edge_width,
    edge_plottype = :linesegments # needed for tapered edge widths
)

fig, ax, abmobs = abmplot(sir_model;
    agent_step! = sir_agent_step!, model_step! = sir_model_step!,
    as = city_size, ac = city_color, graphplotkwargs)

fig

Agents.jl version

v5.16.0

vtharmalingam commented 1 year ago

Team Agents.jl:

To begin, please receive my heartfelt gratitude and recognition for your valuable contributions and ongoing dedication towards developing Agents.jl and the impressive achievements you have attained thus far!

I had anticipated that the Julia ecosystem might offer a compelling substitute for well-known toolsets found in other programming languages. I was particularly drawn to the straightforward manner in which agents, models, step functions, and parameter scanning are defined. As a research student, I made the deliberate choice to learn Julia primarily due to the promising features of Agents.jl. Initially, things were going smoothly. However, I encountered numerous challenges, leading to the loss of two weekends as I tried to resolve issues related to getting abmplot, abm_plot, and similar functionalities to function correctly. Despite following the official sample codes and examples, I consistently encountered a range of error messages that further compounded the frustration.

For instance, with "Schelling" model, I got dismayed by this: image

Similarly for SIR model taken from doc page: image

Perhaps due to my limited familiarity with Julia (coming from a background in Python, C++, and R), I initially believed that utilizing the packages would be straightforward, but I might be mistaken. It appears that I need to grasp several underlying aspects. Even if I continue conducting my research using Julia and Agent-Based Modeling, I find myself uncertain about the essential factors to monitor to ensure I won't face similar uncertainties in the future.

I tried all resources like these, hoping to gain some traction, but did not help much:

Perhaps I'll acquire sufficient knowledge to make contributions to the project in the future if I understand and appreciate it more. It is just current challenges in getting my hands around that demotivates...

@Datseris / @Tortar / @AayushSabharwal : After evaluating the concerns raised, it's clear that you are among the most prominent contributors. Could you share any insights or recommendations on the above?

Thanks, Tharma

vtharmalingam commented 1 year ago

Here is my enviornment:

OS: Windows 11 Julia Pkg status: image

Tortar commented 1 year ago

Thanks for the many details of your report, I think the greatest part of these problems came to the transition from 5.14 to 5.15. In particular https://github.com/JuliaDynamics/Agents.jl/pull/817 . Running the code of the SIR model with Agents 5.14 I don't see your error @vtharmalingam

Tortar commented 1 year ago

There is also a deeper cause though: the visualization code has no tests currently, the only part of the library fortunately :-), so it is more difficult to know if something isn't working as expected, we should surely add some

Datseris commented 1 year ago

Thanks for the kind reports, we will get to work on them. But first of all, @vtharmalingam remove InteractiveDynamics. This package is deprecated, as in Julia 1.9 and Agents.jl 5.17 and later versions we have moved all plotting code to Agents.jl. So any bugfixes will come there and InteractiveDynamics as a package will not be getting any updates.

Datseris commented 1 year ago

(to be clear: this also means: use Julia 1.9 or latest and Agents.jl 5.17 or later)

vtharmalingam commented 1 year ago

Thank you very much! I managed to successfully run the model interactively by simply removing "InteractiveDynamics". This is truly fantastic! You all are doing an amazing job...

asgolovin commented 1 year ago

I'm unfortunately getting the same error message as @AldoGl with Agents 5.17.1 and Julia 1.9. It seems that GraphMakie is not listed as a dependency of Agents.jl, meaning that the graphplot! function is not defined. Any ideas how to fix this? @vtharmalingam, did you manage to run the MVE code from the issue?

asgolovin commented 1 year ago

I fixed the error by simply adding using GraphMakie and adding GraphMakie to the environment. I opened a PR with the changes :) https://github.com/JuliaDynamics/Agents.jl/pull/863

jlambvo commented 8 months ago

I'm running into the same problem with the latest build Agents v5.17.2.

Although it looks like the pull was merged, the abmplot.jl file that I have does not appear to have the GraphMakie include, and I do not have the new GraphAgentVisualization module.

@Tortar you did the most work on this, any idea what I'm missing to get this working? Thanks!

Tortar commented 8 months ago

Seems like it wasn't backported to v5.17.2 unfortunately, however you can use the dev version which is the upcoming version 6 where it works fine