Skip to content
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

GraphSpace support for agent based models #11

Closed
fbanning opened this issue Jul 27, 2020 · 11 comments · Fixed by #114
Closed

GraphSpace support for agent based models #11

fbanning opened this issue Jul 27, 2020 · 11 comments · Fixed by #114
Assignees
Labels
Agents Concerning plotting of Agents.jl models enhancement New feature or request

Comments

@fbanning
Copy link
Member

The documentation of Agents.jl states that interactive applications of Agents.jl work for any agent based model. So I went ahead and tried it with two different GraphSpace() models and found out that this doesn't work.

interactive_abm() throws the following error in both cases:

MethodError: no method matching size(::GraphSpace{SimpleDiGraph{Int64}})
Closest candidates are:
  size(!Matched::BitArray{1}) at bitarray.jl:99
  size(!Matched::BitArray{1}, !Matched::Integer) at bitarray.jl:103
  size(!Matched::Core.Compiler.StmtRange) at show.jl:1849
  ...

What could be done to make this work? Do you need any more information to understand the case?

Thanks in advance!

@Datseris
Copy link
Member

Haha, sorry about that!!! What I say is totally wrong! They work for systems in GridSpace or ContinuousSpace!

To my understanding, what you would have to do is to port the graphplot recipe of Plots.jl to Makie.jl. You can ask in the Makie.jl Slack channel if anyone has any working implementation for plotting graphs.

So, in short: as soon as Makie has support for plotting graphs from LightGraphs.jl, then we can do this!

I'll change the wrong statement in the docs asap.

@Datseris
Copy link
Member

Also @SimonDanisch

@fbanning
Copy link
Member Author

Ah ok, that's roughly what I expected. Nice to know that GridSpace and ContinuousSpace do work indeed.

I'm not on Slack but will ask around on Zulip if somebody knows something about such efforts. I'm not familiar with Makie.jl myself (although I should really look into it...) so I personally wouldn't know where to start looking.

So to understand it correctly: interactive_abm solely relies on Makie functions for plotting? Nothing else needed? So once Makie can plot graphs from LightGraphs, we're all set to use them in our interactive abms?

@fbanning
Copy link
Member Author

fbanning commented Jul 27, 2020

I was referred to https://github.com/JuliaPlots/MakieRecipes.jl but it was unclear how complete that package is.
Here's the section of the examples related to graphs: http://juliaplots.org/MakieRecipes.jl/dev/literate/examples/#GraphRecipes-1
Do you know about it? @SimonDanisch definitely knows about this as he seems to have contributed to the package.

@Datseris Datseris added the help wanted Extra attention is needed label Mar 14, 2021
@Datseris Datseris changed the title GraphSpace() support for interactive_abm() GraphSpace support for agent based models Mar 14, 2021
@fbanning
Copy link
Member Author

fbanning commented Nov 8, 2021

Now that 16 months have passed, I think I want to carefully look into this issue again. Will see where it takes me. :)

@Datseris
Copy link
Member

Datseris commented Nov 8, 2021

Makie has graph plotting now I have actually used it already for my book. See here:

https://github.com/JuliaDynamics/NonlinearDynamicsTextbook/blob/master/figure_generation/10/10.2.jl

You can use this code as a start!

@fbanning
Copy link
Member Author

Makie has graph plotting now I have actually used it already for my book. See here:

https://github.com/JuliaDynamics/NonlinearDynamicsTextbook/blob/master/figure_generation/10/10.2.jl

You can use this code as a start!

How did you make GraphMakie work with LightGraphs? I get the following when trying a MWE:

julia> using LightGraphs, GraphMakie, GLMakie

julia> g = SimpleDiGraph(5, 20)
{5, 20} directed simple Int64 graph

julia> graphplot(g)
ERROR: MethodError: no method matching ne(::SimpleDiGraph{Int64})
Closest candidates are:
  ne(::Graphs.SimpleGraphs.AbstractSimpleGraph) at /home/fbanning/.julia/packages/Graphs/5lMKo/src/SimpleGraphs/SimpleGraphs.jl:119
  ne(::Graphs.AbstractGraph) at /home/fbanning/.julia/packages/Graphs/5lMKo/src/interface.jl:158
Stacktrace:
  [1] find_edge_paths(g::SimpleDiGraph{Int64}, attr::Attributes, pos::Vector{Point{2, Float32}})
    @ GraphMakie ~/.julia/packages/GraphMakie/tEQ8U/src/recipes.jl:307
  [2] (::GraphMakie.var"#16#32"{Combined{GraphMakie.graphplot, Tuple{SimpleDiGraph{Int64}}}, Observable{SimpleDiGraph{Int64}}})(pos::Vector{Point{2, Float32}}, s::MakieCore.Automatic, d::MakieCore.Automatic, w::MakieCore.Automatic)
    @ GraphMakie ~/.julia/packages/GraphMakie/tEQ8U/src/recipes.jl:162
  [3] lift(::Function, ::Observable{Any}, ::Observable{Any}, ::Vararg{Observable{Any}, N} where N; kw::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Makie ~/.julia/packages/Makie/gQOQF/src/interaction/nodes.jl:13
  [4] lift(::Function, ::Observable{Any}, ::Observable{Any}, ::Observable{Any}, ::Vararg{Observable{Any}, N} where N)
    @ Makie ~/.julia/packages/Makie/gQOQF/src/interaction/nodes.jl:10
  [5] plot!(gp::Combined{GraphMakie.graphplot, Tuple{SimpleDiGraph{Int64}}})
    @ GraphMakie ~/.julia/packages/GraphMakie/tEQ8U/src/recipes.jl:160
  [6] plot!(scene::Scene, P::Type{Combined{GraphMakie.graphplot, Tuple{SimpleDiGraph{Int64}}}}, attributes::Attributes, input::Tuple{Observable{SimpleDiGraph{Int64}}}, args::Observable{Tuple{SimpleDiGraph{Int64}}})
    @ Makie ~/.julia/packages/Makie/gQOQF/src/interfaces.jl:428
  [7] plot!(scene::Scene, P::Type{Combined{GraphMakie.graphplot, ArgType} where ArgType}, attributes::Attributes, args::SimpleDiGraph{Int64}; kw_attributes::Base.Iterators.Pairs{Symbol, Bool, Tuple{Symbol}, NamedTuple{(:show_axis,), Tuple{Bool}}})
    @ Makie ~/.julia/packages/Makie/gQOQF/src/interfaces.jl:339
  [8] plot(P::Type{Combined{GraphMakie.graphplot, ArgType} where ArgType}, args::SimpleDiGraph{Int64}; axis::NamedTuple{(), Tuple{}}, figure::NamedTuple{(), Tuple{}}, kw_attributes::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Makie ~/.julia/packages/Makie/gQOQF/src/figureplotting.jl:28
  [9] plot
    @ ~/.julia/packages/Makie/gQOQF/src/figureplotting.jl:18 [inlined]
 [10] graphplot(args::SimpleDiGraph{Int64}; attributes::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ GraphMakie ~/.julia/packages/MakieCore/S8PkO/src/recipes.jl:31
 [11] graphplot(args::SimpleDiGraph{Int64})
    @ GraphMakie ~/.julia/packages/MakieCore/S8PkO/src/recipes.jl:31
 [12] top-level scope
    @ REPL[4]:1

@fbanning
Copy link
Member Author

fbanning commented Jan 13, 2022

Ah just found this post saying

!!! note "about Graphs.jl and LightGraphs.jl" Starting from v0.3 GraphMakie.jl switches from LightGraphs.jl to Graphs.jl as the for the underlying graph package. See this discourse post for more information. If you want to use LightGraphs.jl please specifically ] add GraphMakie@0.2!

Could you tell me the reasons for choosing LightGraphs.jl over Graphs.jl as a dependency for Agents.jl? I suppose it's just a bit lighter in functionality (as the name suggests) and therefore faster to precompile. Is that correct?

Edit: Just saw that the dep in Agents.jl has been changed to Graphs.jl as well. Will continue my work on adding GraphSpace to the abmplot recipe with the Agents.jl#master then, I suppose.

@Datseris
Copy link
Member

Datseris commented Jan 13, 2022

LightGraphs.jl is deprecated and abandoned, Graphs.jl is literally its continuation. There are absolutely no reasons to be using Graphs.jl instead of LightGraphs.jl at the moment.

EDIT: t h e o t h e r w a y a r o u n d

@fbanning
Copy link
Member Author

There are absolutely no reasons to be using Graphs.jl instead of LightGraphs.jl at the moment.

You mean the other way around, right? :D Anyways, I agree.

@fbanning
Copy link
Member Author

fbanning commented Nov 2, 2022

I'm going to pick up work on this again. Want to have basic support for GraphSpace since I need it anyways for my own work.

@fbanning fbanning self-assigned this Nov 2, 2022
@fbanning fbanning added enhancement New feature or request Agents Concerning plotting of Agents.jl models and removed help wanted Extra attention is needed labels Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Agents Concerning plotting of Agents.jl models enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants