Skip to content

examples: Add Activation Order and Grid Type selectors to EpsteinCivilViolence#2955

Merged
quaquel merged 7 commits intomesa:mainfrom
Nithurshen:feat/epstein-activation-grid-selectors
Dec 18, 2025
Merged

examples: Add Activation Order and Grid Type selectors to EpsteinCivilViolence#2955
quaquel merged 7 commits intomesa:mainfrom
Nithurshen:feat/epstein-activation-grid-selectors

Conversation

@Nithurshen
Copy link
Copy Markdown
Contributor

@Nithurshen Nithurshen commented Dec 16, 2025

Summary

This PR adds interactive selectors to the EpsteinCivilViolence example, allowing users to dynamically choose the Activation Order (Random vs. Sequential) and Grid Type (Moore vs. Von Neumann) directly from the Solara GUI.

Motive

In the discussion for PR #2408, maintainer @quaquel noted that the activation order (Random vs. Sequential) significantly impacts model stability and suggested making it a user input. Additionally, it was observed that swapping the grid topology (Moore vs. Von Neumann) drastically changes agent behavior. Exposing these parameters allows users to explore these dynamics easily without modifying the code.

Implementation

  • model.py: Updated EpsteinCivilViolence.__init__ to accept activation_order and grid_type arguments. Added logic to initialize the corresponding Grid class (OrthogonalMooreGrid or OrthogonalVonNeumannGrid) and handle the scheduling logic in the step() method.

  • app.py: Added activation_order and grid_type to model_params as Select widgets, enabling the dropdown menus in the Solara sidebar.

  • model.py : Updated docstrings to reflect the new parameters.

Usage Examples

Before:
before

After:
after

Run the example:

solara run mesa/examples/advanced/epstein_civil_violence/app.py

In the sidebar, use the Activation Order dropdown to switch between "Random" and "Sequential".

Use the Grid Type dropdown to switch between "Moore" (8 neighbors) and "Von Neumann" (4 neighbors).

Additional Notes

  • Defaults are set to Von Neumann and Random to match the behavior established in recent updates.

  • "Sequential" activation relies on self.agents.do("step"), while "Random" uses self.agents.shuffle_do("step").

@github-actions
Copy link
Copy Markdown

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 -1.4% [-1.9%, -0.8%] 🔵 -1.5% [-1.7%, -1.4%]
BoltzmannWealth large 🔵 +0.8% [-1.3%, +4.5%] 🔵 -3.1% [-4.1%, -2.1%]
Schelling small 🔵 -0.6% [-1.5%, +0.4%] 🔵 -0.9% [-1.4%, -0.4%]
Schelling large 🔵 -1.0% [-4.1%, +3.1%] 🔵 -2.3% [-3.8%, -0.7%]
WolfSheep small 🔵 -3.8% [-5.8%, -2.0%] 🔵 -0.2% [-0.5%, +0.0%]
WolfSheep large 🔵 -2.7% [-3.3%, -2.1%] 🟢 -6.9% [-7.7%, -6.0%]
BoidFlockers small 🔵 +1.0% [+0.5%, +1.5%] 🔵 +1.3% [+1.1%, +1.5%]
BoidFlockers large 🔵 +1.1% [+0.9%, +1.4%] 🔵 +1.2% [+1.0%, +1.3%]

@Nithurshen
Copy link
Copy Markdown
Contributor Author

The doc build failed on tutorials/1_adding_space.ipynb with a 'Cell is full' error, which seems unrelated to my changes in the Epstein example.

self.grid = mesa.discrete_space.OrthogonalVonNeumannGrid(
(width, height), capacity=1, torus=True, random=self.random
)
if grid_type == "Moore":
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider changing both this if else statement and the one in step to a match case structure:

match activation_order:
    case "Von Neumann":
        pass. # your original if code
    case "Moore"
        pass #your original else code
    case _:
        raise ValueError("unknown value of activation_order")

This ensures that we get a value error if an invalid value is passed.

Copy link
Copy Markdown
Contributor Author

@Nithurshen Nithurshen Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Please review it now.

@quaquel
Copy link
Copy Markdown
Member

quaquel commented Dec 18, 2025

Thanks for this. I have merged main back into your branch which should solve the failing docs. I also have one suggestion. Looks good to me otherwise.

@EwoutH EwoutH added the example Changes the examples or adds to them. label Dec 18, 2025
@EwoutH
Copy link
Copy Markdown
Member

EwoutH commented Dec 18, 2025

Thanks for the PR! I appreciated the really clean diff and detailed description with screenshots.

@EwoutH EwoutH changed the title feat: Add Activation Order and Grid Type selectors to EpsteinCivilViolence examples: Add Activation Order and Grid Type selectors to EpsteinCivilViolence Dec 18, 2025
@Nithurshen Nithurshen requested a review from quaquel December 18, 2025 13:25
@quaquel quaquel merged commit b20f6dc into mesa:main Dec 18, 2025
11 of 13 checks passed
@quaquel
Copy link
Copy Markdown
Member

quaquel commented Dec 18, 2025

Thanks!

@Nithurshen Nithurshen deleted the feat/epstein-activation-grid-selectors branch December 18, 2025 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

example Changes the examples or adds to them.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants