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

Add RandomActivationByBreed from Sugarscape example to available schedulers in time.py #900

Closed
majdal opened this issue Aug 29, 2020 · 16 comments

Comments

@majdal
Copy link
Contributor

majdal commented Aug 29, 2020

What's the problem this feature will solve?
Sometimes you need to step() each breed of agent separately. The Sugarscape example already has a scheduler that takes care of that use case: RandomActivationByBreed. It makes sense for it to be merged into the schedulers available by default in time.py.

Describe the solution you'd like
Copy RandomActivationByBreed into time.py. The class might require some adjustment to work with the DataCollector class, since the agent_reporters loop over all agents in the schedule, regardless of breed, which will inevitably raise a bunch of AttributeError exceptions.

Alternatively we could subclass the DataCollector class to make it collect by breed.

Additional context
It might be interesting to also have a StagedActivationByBreed scheduler.

@rht
Copy link
Contributor

rht commented Apr 8, 2021

Agents.jl has a very concise implementation of something equivalent to RandomActivationByBreed: https://github.com/JuliaDynamics/Agents.jl/blob/48f71a3b438e8cdcbb562067f5877e52cf0a6e5d/src/core/schedule.jl#L85. I wonder if we can replicate the design in Python.

@rht
Copy link
Contributor

rht commented Apr 14, 2021

From the discussion in JuliaDynamics/ABMFrameworksComparison#2, it turns out that Agents.jl's by_type generates a list of list agent ids, where the first index of this list of list signifies agent types. This is inefficient, and looks like Agents.jl developers are looking to revamp their multiple-type schedulers as discussed in JuliaDynamics/Agents.jl#445.

I think the solution is going to look similar to the Sugarscape example's RandomActivationByBreed.

Note that not including RandomActivationByBreed in Mesa by default has costed Mesa a lot of LOC increase in the benchmark vs Agents.jl, NetLogo, and MASON.

@tpike3
Copy link
Member

tpike3 commented Apr 14, 2021

I agree I think a bybreed option should be default in Mesa.

@rht
Copy link
Contributor

rht commented Apr 15, 2021

RandomActivationByType seems to be a more general name.

@rht
Copy link
Contributor

rht commented Apr 15, 2021

This is the benchmark: https://juliadynamics.github.io/Agents.jl/stable/comparison/.

@EwoutH
Copy link
Member

EwoutH commented Jan 17, 2022

@tpike3 @jackiekazil @rht I think having proper multi-type agent support would increase the value of Mesa quite a bit. Implementing a RandomActivationByType scheduler as proposed above should be an easy first step.

NetLogo also supports different types of agents (called breeds), so it can be essential to porting some models.

@tpike3
Copy link
Member

tpike3 commented Jan 17, 2022

@EwoutH I absolutely agree if you are interested in working on it, that would be a great contribution :)

@EwoutH
Copy link
Member

EwoutH commented Jan 21, 2022

I might do some work on it next week. One thing I already noticed it that it will require some work on the DataCollector code, since that assumes "The schedule has an agent list called agents".

@tpike3
Copy link
Member

tpike3 commented Jan 21, 2022

@EwoutH My dissertation worked with sugarscape (sugar and spice trading model) and I don't remember adjusting the datacollector being that laborious. May not be helpful, but here is the code repo schedule and the whole repo with a data analysis notebook. I adjusted from the activiationbybreed example (although it should be by RandomActivationByType as you noted)

@rht
Copy link
Contributor

rht commented Jan 22, 2022

My dissertation worked with sugarscape (sugar and spice trading model) ...

TIL! @tpike3 what do you think of adding various models of Sugarscape to the examples? E.g. {G,M,T}, not just constang growback.

@EwoutH
Copy link
Member

EwoutH commented Jan 22, 2022

@tpike3 Thanks for the links! I see you implemented recorder functions for each model. Looks doable, but also non-trivial.

@EwoutH
Copy link
Member

EwoutH commented Jan 22, 2022

I think I wrote a working DataCollector implementation with multiple agent-types.

The next problem I just encountered is that the ChartModule in ChartVisualization.py can't handle agent-level variables yet. This is listed as an TODO, but not yet implemented.

@EwoutH
Copy link
Member

EwoutH commented Jan 22, 2022

I misdirected some energy to a proof of concept: #1142

Please feel free to comment on both the architecture and specific implementation. I will try to spin up some production ready code over the next week.

@tpike3
Copy link
Member

tpike3 commented Jan 23, 2022

TIL! @tpike3 what do you think of adding various models of Sugarscape to the examples? E.g. {G,M,T}, not just constang growback.

@rht absolutely, once we get activation by type I think I can spin up some of the other variations pretty quick.

This only tangentially related (more a point of interest) when I did the sugar and spice variation, I could replicate all the results but the signature of trading volume. My best guess is still the way the underlying code is handled between python and basic. But never had a chance to really unpack it.

@rht
Copy link
Contributor

rht commented Feb 24, 2022

This will be closed by #1162.

@rht
Copy link
Contributor

rht commented Apr 16, 2022

#1162 has been merged a while ago; I forgot to close this issue.

@rht rht closed this as completed Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants