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

Replace RandomActivation and SimultaneousActivation schedulers with AgentSet functionality #161

Merged
merged 9 commits into from
Aug 19, 2024

Conversation

EwoutH
Copy link
Member

@EwoutH EwoutH commented Aug 17, 2024

This PR replace all the RandomActivation and SimultaneousActivation schedulers used in the example models with AgentSet functionality. This simplifies models and allows for easier and more flexible modification of these models. It algins the examples with the current best practices in Mesa.

RandomActivation (b7f67c7)

The RandomActivation schedulers were removed, and in the Model.step() function the schedule step was replaced with an AgentSet operation, like:

-        self.schedule.step()
+        self.agents.shuffle().do("step")

The following RandomActivation schedulers were removed:

  • bank_reserves
  • boid_flockers
  • boltzmann_wealth_model
  • boltzmann_wealth_model_experimental
  • boltzmann_wealth_model_network
  • caching_and_replay
  • charts
  • el_farol
  • epstein_civil_violence
  • forest_fire
  • hotelling_law
  • schelling
  • shape_example
  • virus_on_network

SimultaneousActivation (7e396fe)

To remove the SimultaneousActivation schedulers, the Agent methods were renamed from step() and advance() to more descriptive functions. The model step was updated accordingly:

-        self.schedule.step()
+        self.agents.do("determine_state")
+        self.agents.do("assume_state")

The following SimultaneousActivation schedulers were removed:

  • hex_snowflake
  • color_patches
  • conways_game_of_life

Relevant tickets

@EwoutH
Copy link
Member Author

EwoutH commented Aug 17, 2024

And believe it or not, the final error is the DataCollector that tries to gather attributes from agents that don't have said attributes.

@EwoutH EwoutH force-pushed the replace_schedulers branch from 0f572c8 to 3d94b69 Compare August 17, 2024 21:08
EwoutH added 8 commits August 17, 2024 23:11
Replace all usages of model.schedule.agents with the use of the model.agents AgentSet in all examples.
Replace the old RandomActivation scheduler with AgentSet functionality. self.agents.shuffle.do("step") is equivalent and self.schedule.step() with an RandomActivation scheduler, and model behavior should not change.
The SimultaneousActivation scheduler used a "step" and "advanced" function in the Agent. These have been renamed for each model to be more descriptive (like "determine_state" and "assume_state"), and then the model step was replace by something like:
        self.agents.do("determine_state")
        self.agents.do("assume_state")

Docstring was also updated accordingly.
Schedulers don't exist anymore, so we don't need to add agents anymore.

Agents are automatically added to model.agents on Agent initialisation.
These models use complex schedulers which warrant an separate PR.
It doesn't have a step function and there is only one, so it shouldn't be an Agent, just an Python object.
@EwoutH EwoutH force-pushed the replace_schedulers branch from f1cf42b to bd60c41 Compare August 17, 2024 21:14
@EwoutH EwoutH marked this pull request as ready for review August 17, 2024 21:14
@EwoutH EwoutH changed the title Replace schedulers with AgentSet functionality Replace RandomActivation and SimultaneousActivation schedulers with AgentSet functionality Aug 17, 2024
@EwoutH
Copy link
Member Author

EwoutH commented Aug 17, 2024

I updated the PR description and title and cleaned up the commit history as far as feasible.

Looking forward to reviews!

@rht
Copy link
Contributor

rht commented Aug 18, 2024

Other than the 2 comments, everything else LGTM. Feel free to rebase and merge after they had been addressed.

@EwoutH EwoutH force-pushed the replace_schedulers branch from fa1aee4 to ffa0958 Compare August 18, 2024 08:39
@EwoutH
Copy link
Member Author

EwoutH commented Aug 19, 2024

With rht’s approval I’m going to merge this.

@jackiekazil and @tpike3 I would still love your take, if you have any feedback let me know.

@EwoutH EwoutH merged commit 0ebc4d1 into projectmesa:main Aug 19, 2024
3 checks passed
EwoutH added a commit to EwoutH/mesa-examples that referenced this pull request Aug 22, 2024
…lity

This commit reverts PR projectmesa#161 projectmesa#161

That PR assumed that time advancement would be done automatically, like proposed in projectmesa/mesa#2223

We encountered some underlying issues with time, which we couldn't resolve in time.
EwoutH added a commit that referenced this pull request Aug 22, 2024
This commit reverts PR #161 #161

That PR assumed that time advancement would be done automatically, like proposed in projectmesa/mesa#2223

We encountered some underlying issues with time, which we couldn't resolve in time.
EwoutH added a commit to EwoutH/mesa-examples that referenced this pull request Aug 30, 2024
EwoutH added a commit to EwoutH/mesa-examples that referenced this pull request Aug 30, 2024
…onality

This reinstates PR projectmesa#161 after the previous revert.
EwoutH added a commit to EwoutH/mesa-examples that referenced this pull request Aug 30, 2024
…onality

This reinstates PR projectmesa#161 after the previous revert.
EwoutH added a commit to EwoutH/mesa-examples that referenced this pull request Aug 30, 2024
…onality

This reinstates PR projectmesa#161 after the previous revert.
EwoutH added a commit to EwoutH/mesa-examples that referenced this pull request Sep 20, 2024
…onality

This reinstates PR projectmesa#161 after the previous revert.
EwoutH added a commit to projectmesa/mesa that referenced this pull request Oct 12, 2024
This commit reverts PR #161 projectmesa/mesa-examples#161

That PR assumed that time advancement would be done automatically, like proposed in #2223

We encountered some underlying issues with time, which we couldn't resolve in time.
EwoutH added a commit to projectmesa/mesa that referenced this pull request Oct 12, 2024
This commit reverts PR #161 projectmesa/mesa-examples#161

That PR assumed that time advancement would be done automatically, like proposed in #2223

We encountered some underlying issues with time, which we couldn't resolve in time.
EwoutH added a commit to EwoutH/mesa that referenced this pull request Oct 15, 2024
…lity (projectmesa#170)

This commit reverts PR projectmesa#161 projectmesa/mesa-examples#161

That PR assumed that time advancement would be done automatically, like proposed in projectmesa#2223

We encountered some underlying issues with time, which we couldn't resolve in time.
EwoutH added a commit to EwoutH/mesa that referenced this pull request Oct 15, 2024
…lity (projectmesa#170)

This commit reverts PR projectmesa#161 projectmesa/mesa-examples#161

That PR assumed that time advancement would be done automatically, like proposed in projectmesa#2223

We encountered some underlying issues with time, which we couldn't resolve in time.
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

Successfully merging this pull request may close these issues.

2 participants