JuliaDynamics / Agents.jl

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

Add a dynamic version of agents #1070

Open Tortar opened 3 weeks ago

Tortar commented 3 weeks ago

Saw this package: https://github.com/AntonOresten/DynamicStructs.jl

We could maybe incorporate it in Agents.jl to offer a dynamic version of an @agent which can have new attributes over time, to be added with

@agent [:static/:dynamic] struct NewAgent(GridAgent{2})
    ...
end

:static being the old version and the default. This seems like a cool feature, provided that it is easy to integrate.

Datseris commented 3 weeks ago

Hm I am concerned about the performance implications this has... The implementation in that package is actually rather simple. A dict with symbol keys is added to the type. We can do this here as well, but the better question is should we? It would likely have terrible performance plus it is also easy for a user to do this on their own no? Anyone can make an additional properties dictionary for the agents.

Tortar commented 3 weeks ago

yes sure, it's simple, the point to me is that it reduces the boilerplate needed to do it by yourself, so it's mostly for convenience. That package also implements an interface, apart from using a dictionary as a field. Sure, even this is not that difficult, but it would require some more code to do also that yourself. It will surely cause some performance degradation though. But you can always go back to :static mode if that is not affordable.

Datseris commented 3 weeks ago

In this discussion we are not putting any weight on the cost of the impact this has on the learning curve. Sure, for you it's simple to just add another concept to grasp, static or dynamic, but when one learns the agents macro they have to learn all of them at once. And the macro is already somehing non trivial.

I guess you can document this new feature at the end of the existing docstring as a new section. That probably will be enough.

I am not a fan of introducing new macros though such as that has macro. Macros put a heavy load on the learning curve. Which is the minimal functionality that we need here?

Tortar commented 2 weeks ago

I guess you can document this new feature at the end of the existing docstring as a new section. That probably will be enough.

Exactly, we can just do that. I think it won't need much more than that.

Which is the minimal functionality that we need here?

I think that :dynamic will allow the simulation be more Python-style in the sense that an agent will be more flexible, and not everything should be declared beforehand. Surely there are alternative, but allowing a different flavour/style is good in my opinion. At the same time now the macro is much smarter, I would say it won't be easy to replicate it in its current form by a user.

Datseris commented 2 weeks ago

First of all, let's think if this feature is useful: in what kind of simulation do you foresee requiring to add completely new properties to an agent, in a way that can't be done in an existing dictionary property?

I am trying to think a simulation where I would need to add completely new, and unexpected, properties to agents, but I can't think of something.