Refactor hex_snowflake example to store environment state in a NumPy array#382
Refactor hex_snowflake example to store environment state in a NumPy array#382ShreyasN707 wants to merge 3 commits intomesa:mainfrom
hex_snowflake example to store environment state in a NumPy array#382Conversation
|
Thanks for the PR, looks like a cool model. Could you:
|
|
I think if you git rebase the PR the tests should pass |
78a9d7d to
7c65ef3
Compare
|
@EwoutH Thanks for the guidance! After rebasing the PR, all the tests are now passing successfully. |
himanksingh2024-svg
left a comment
There was a problem hiding this comment.
Peer review of PR #382:
✅ Verified the problem — current hex_snowflake fails with AttributeError: module 'mesa' has no attribute 'visualization' due to deprecated APIs
✅ Shreyas's refactor moves state from agents to NumPy array on model — aligns with Issue #366
✅ Cell class correctly simplified to lightweight visualization wrapper
✅ Code is clean and readable
✅ This is a necessary refactor to modernize the example
Good work Shreyas! The current example is broken so this fix is needed.
|
@himanksingh2024-svg thanks for the review. Have you actually ran the visualisation code? |
|
@EwoutH Honest answer — I ran the original run.py which failed with the deprecated API error, which confirmed the problem exists. I didn't checkout Shreyas's branch to test the new visualization. Let me do that properly now. |
|
Checked out the branch and ran solara run run.py locally. It fails with AttributeError: module 'mesa' has no attribute 'visualization' — server.py still uses mesa.visualization.CanvasHexGrid which was removed in Mesa 4.0. The array refactor in the model looks good, but the visualization needs updating before this can run. Happy to help if needed! |
Thanks for checking ! @EwoutH should I update this PR to add a Solara-based |
|
Both are okay, what you prefer |
|
I would prefer a separate PR, as this pr is to address array refactor of the example. That will also keep the PRs clean. |
|
@himanksingh2024-svg A proper review needs to be a bit more in-depth. See for some pointers: |
himanksingh2024-svg
left a comment
There was a problem hiding this comment.
Reviewed against #390 checklist. Array refactor in model.py is clean — state_grid and is_considered correctly moved to NumPy arrays on the model, removing per-agent state storage. portrayal.py correctly reads from model.state_grid. Ran locally: visualization fails with AttributeError: mesa.visualization — server.py still uses deprecated CanvasHexGrid. Model logic is sound; visualization fix being tracked in a separate PR.


This PR refactors the hex_snowflake example so that environment state is stored in a NumPy array on the model rather than inside individual patch agents.
Previously each grid position created a Cell agent that stored simulation state (state, is_considered, _next_state). These values represent environment state, not independent agent behavior.
Following the approach discussed in Issue #366, this state is now stored centrally on the model while Cell agents are retained as lightweight wrappers for visualization.
Key Changes
Cell agents no longer store simulation state.
They now exist only to provide coordinates for visualization.
NumPygridOutcome
The simulation behavior is unchanged, but:
environment state is centralized
patch agents no longer hold simulation state
the example follows the same pattern introduced in the forest_fire refactor
Does it belong?
Is it correct and current?
rngseedIs it clean?