Agent Based Modeling in Julia

@bkamins Are you aware of the package Agents.jl ?

Yes, I am aware of it, but this package was started in Nov 2018, and this thread is from Aug 2018 :smile:.

This is a very nice package (I especially like that it has a full modelling and analysis workflow inbuilt).

However, the problem of dynamic dispatch is still there. Take e.g. an example from the docs:

mutable struct SchellingModel <: AbstractModel  # A model object should always be a subtype of AbstractModel
 space::AbstractSpace  # A space object, which is a field of the model object is always subtype of AbstractSpace
 agents::Array{AbstractAgent}  # a list of agents
 scheduler::Function
 min_to_be_happy::Integer  # minimum number of neighbors to be of the same kind so that they are happy
end

And you see that you will have dynamic dispatch any time you access space and scheduler variables or when you access elements of agents array.

1 Like

Do you see any way to overcome this problem?
I am going to do an ABM for my PhD and normally I will use NetLogoand Rbut I wanted to try to use Julia even if there is no good GUI to show the simulation. The problem is that this package is so new that using it is risky. Maybe I should try both tools in parallel.

I can see that @kavir actively maintains it so I think you should get response to your potential problems pretty fast. The “dynamic dispatch” issue is really a problem in very special cases - most of the time it should be OK.

Also if you run into something problematic that you have problem solving you can always ask on Discourse and most likely get some advice really fast.

3 Likes

Have a look at this discussion. I have been worried about the same problem but according to the benchmark (see link in the first post of the linked discussion) it’s actually not that terrible as soon as your methods are non-trivial.

Hi and thanks. Just to clarify, dynamic dispatch can happen only when you access the agents array. The space object contains an array of numbers representing agent positions. So it doesn’t matter whether there are multiple agents or not. As for the scheduler, its only reference to the list of agents is getting their length. I am not sure, but I don’t think getting the length of an Any array is slower than a fixed-type array.

2 Likes

Hi - this is what I meant (i.e. that there is “some dynamic dispatch”, but most likely it is not a problem in typical cases). Thank you :smile:.

3 Likes

We have updated Agents.jl to version 2.0. It is faster, simpler, more consice and more extendable. We hope that it can now become the standard for agent-based modelling in Julia.

For details: Agents.jl is now in version 2.0, with a massively more simplified API. See Agents.jl : Agent based modelling

8 Likes