fix: migrate codebase to Mesa 4.x API (resolves mesa.space removal)#153
fix: migrate codebase to Mesa 4.x API (resolves mesa.space removal)#153abhinavk0220 wants to merge 6 commits intomesa:mainfrom
Conversation
…rely, breaking the full test suite.This commit migrates all affected files to the new APIs.Changes:- Replace MultiGrid/SingleGrid imports with OrthogonalMooreGrid from mesa.discrete_space- Replace old ContinuousSpace(x_max, y_max) with new dimensions-based API- Fix agent placement to use cell-based API (agent.cell = grid._cells[pos])- Fix neighbor lookup using get_neighborhood + coordinate set matching- Fix model.steps -> model.step (renamed in Mesa 4.x)- Remove seed= kwarg from Model.__init__ calls (mesa_signals compat fix)- Fix record_model.py self.steps -> self.stepAll 203 tests now passing.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…ools.py to use Mesa 4.x cell-based API- Replace place_agent() with agent.cell = grid._cells[pos]- Fix ContinuousSpace boundary/torus tests for new API behavior- Remove SingleGrid|MultiGrid references from inbuilt_tools.py- All 262 tests passing
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
…Schelling's (1971) classic segregation model using LLM agentsinstead of a fixed tolerance threshold.Each agent reasons in natural language about its neighborhood compositionand decides whether to stay ('happy') or relocate ('unhappy'). Thisproduces richer segregation dynamics than the classical threshold rule.Includes:- SchellingAgent extending LLMAgent with CoT reasoning- LLMSchellingModel on OrthogonalMooreGrid with torus=True- Segregation index metric tracked over time- SolaraViz with grid plot, happiness chart, and segregation index- README with comparison table vs classical Schelling modelReference: Schelling, T.C. (1971). Dynamic models of segregation.Journal of Mathematical Sociology, 1(2), 143-186.Related: mesa/mesa-llm#153
|
Hey this looks cool, |
|
I'm not fully up to date with the latest mesa 4.x changes... @wang-boyu what do you think about this ? |
|
Hey Jay! To test against Mesa 4.x, install Mesa directly from Then install mesa-llm dependencies: Then run the test suite: The key Mesa 4.x changes that affect mesa-llm are:
Happy to help if you run into issues! 🙂 |
|
Hi Colin! Happy to provide more context for wang-boyu's review. The key Mesa 4.x breaking changes this PR addresses:
All 203 tests passing after migration. Happy to answer any |
|
I was trying to understand changes you made I am not getting that 'hell' named file you have created or might generated. |
| OrthogonalMooreGrid, | ||
| OrthogonalVonNeumannGrid, | ||
| ) | ||
| from mesa.space import ( |
There was a problem hiding this comment.
Replaced mesa.space imports with mesa.discrete_space and
mesa.experimental.continuous_space throughout. The ContinuousSpace
API also changed old positional args (x_max, y_max) replaced with
dimensions=[[0,x],[0,y]] keyword API. Agent placement migrated from
grid.place_agent() to cell-based API: cell.add_agent(agent) +
agent.cell = cell.
|
A few things worth noting for the review:
|
Closes #152
Summary
Mesa 4.x removed
mesa.spaceentirely. This PR migrates the full codebase to the new Mesa 4.x APIs so that mesa-llm works with the current version of Mesa.Changes
MultiGrid/SingleGridwithOrthogonalMooreGridfrommesa.discrete_spaceContinuousSpace(x_max, y_max)with newdimensions-based APIagent.cell = grid._cells[pos])get_neighborhood()+ coordinate set matchingmodel.steps→model.step(renamed in Mesa 4.x)Model.__init__(seed=...)kwarg incompatibility withmesa_signalsTesting
All 203 tests passing after migration:
Notes
Tested against Mesa 4.x dev installed from source.
GSoC contributor checklist
Context & motivation
Mesa 4.x removed
mesa.spaceentirely with no deprecation warningany project depending on it simply breaks at import time. I discovered
this while trying to run mesa-llm examples and getting immediate
ImportError. This PR is the full migration of the codebase to thenew Mesa 4.x spatial API.
What I learned
Mesa 4.x's new discrete space architecture is fundamentally different
from the old API not just renamed imports but a completely different
cell-based model where agents live in cells rather than coordinates.
Understanding this required reading Mesa's source code directly, not
just the migration guide. The most subtle change was the coordinate
convention difference between
OrthogonalMooreGrid._cells(x,y) andthe internal
connectionsdict (row,col) a distinction that causedagents to move in the wrong direction and required a separate fix in
PR #195.
Learning repo
🔗 My learning repo: https://github.com/abhinavk0220/GSoC-learning-space
🔗 Relevant model(s): https://github.com/abhinavk0220/GSoC-learning-space/tree/main/models
Readiness checks
ruff check . --fix)