-
Notifications
You must be signed in to change notification settings - Fork 125
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
Multi Agent model implementation proposal #841
Comments
I had an idea so that to make the access to the right container for a given id faster than other possible strategies, namely how could However, this means that we can't use only |
@Datseris I'd like to know what you think about all of this when you have the time :-) |
Problem is that you are still using the same type (the integers) to get agents of different type, so your idea would also be type unstable. Limiting the |
But then again, it may be much more performant to have a tuple of dicts, each with concrete type, rather than having a dict of Union type. But I truly do not know, we would need to test a minimal implementation (which really shouldn't be too hard). |
BTW, although this is a different issue, I have been thinking that in version 6 we should rework the model interface so that the stepping functions are included in the model. This is how the rest of hte packages that use This would allow us to make a version where there is a different stepping function for each agent type (if that gives better performance), so that when iterating through agents we know what function to use with each and this way remove the necessity for dynamic dispatch. |
It seems that doing so we could apply the speed-up described in https://discourse.julialang.org/t/poor-time-performance-on-dict/9656/14 |
yes, that does seem promising. |
I found a blog post by Bogumił Kamiński which explains that a similar strategy can have huge benefits performance wise: https://juliasnippets.blogspot.com/2018/07/abc-of-abm-in-julia.html |
Another advantage of this is that we could (or the user could) group ids by type before interacting with the model with |
Yes I have thought of that before already. Use the modulo operation. Module as many types. So .e.,g if 4 types, we cound Ids by modulo 4. So that all ids whose mod 4 == 1 is type 1, etc. |
ok, maybe this is a better solution: https://discourse.julialang.org/t/what-materials-should-i-read-extending-the-compiler/106841/11 !! somewhat related: #492 |
right, i don't understand it but i hope you do! |
sorry wrong reply, I wanted to link this one: https://discourse.julialang.org/t/what-materials-should-i-read-extending-the-compiler/106841/9 |
but probably you are referring to this one, yes it's still a bit unclear if suitable but I wanted to let you know :-) |
It is known that Agents.jl suffers from dynamic dispatch when working with a high number of agents types. I think that now that we have an abstract interface to rely on and to implement we can try to solve the issue. Currently, we just have some workarounds: representing every type in only one struct, but this is unnatural, and wastes some RAM (and it is probably not as performant as the possible implementation described below)
I tried to use Virtual.jl and ManualDispatch.jl and custom macros to solve the problem, but to no avail, even though the first package seems actually suited to improve the matter it didn't work well (performance was worse) when I tried to make use of it.
So I think we have only the hard way to move forward on the issue: implement all the interface for a model where the main data structure is a tuple where each type is inside its own Dict/Vector. This should be even better in terms of performance than compressing in only one struct different agent types without the need to change anything.
The text was updated successfully, but these errors were encountered: