Skip to content

Conversation

@Tejasv-Singh
Copy link

Summary

This PR fixes the crash reported in #259 where running the Hotelling's Law example (app.py) on Python 3.12 failed. The crash was caused by two issues:

  1. A TypeError in SpaceDrawer because agents lacked a pos attribute (due to changes in how Mesa handles agent positions).
  2. An AttributeError caused by the base Agent class attempting to initialize self.pos = None, which conflicted with pos being defined as a read-only property in the subclasses.

Additionally, this PR updates requirements.txt to include missing dependencies required to run the example.

Fix Details

1. Agent Logic (agents.py)

I modified StoreAgent and ConsumerAgent to include a robust pos property:

  • Getter: Returns self.cell.coordinate (the modern Mesa standard) instead of relying on a stored attribute. It includes a check for self.cell to prevent errors before placement.
  • Setter: I added a setter that essentially "swallows" the assignment. This is necessary because the base Agent.__init__ method attempts to execute self.pos = None. Without this setter, the initialization fails with an AttributeError.

2. Dependencies (requirements.txt)

I found that a fresh environment installation failed to run because several imports were missing. I added:

  • solara
  • matplotlib
  • networkx
  • altair

Verification

I have verified this fix locally on Python 3.12.

  • Command: solara run app.py
  • Result: The application loads successfully.
  • Functionality: Verified that agents render on the grid, the simulation steps forward (tested up to step 40+), and charts populate correctly.

Screenshot of working simulation:
*
Screenshot_20260104_171456
*

Related Issue

Fixes #259

@tpike3
Copy link
Member

tpike3 commented Jan 6, 2026

@Tejasv-Singh I believe this was fixed with #283 but please let me know if I am misunderstanding, or you have any issues or concerns. Regardless, I have see a lot of items with you name so thank you for our interest and support of Mesa!

@Tejasv-Singh
Copy link
Author

@tpike3 Thanks for the feedback 🙌

I took a look at #283. While that PR prevents the crash by skipping agents with None positions, it effectively results in an empty map. My changes here ensure the agents actually render on the grid by correctly aliasing pos to the modern cell.coordinate standard (as seen in the screenshot above).

Additionally this PR updates requirements.txt, which is currently missing key dependencies (solara, altair, networkx). Without these, the example fails to launch entirely on a fresh environment.

would you prefer I keep this PR as is to fix the visualization and dependencies, or should I split the dependency updates into a separate PR?

and about the later part, thank you for creating this amazing community, I really find the environment really supporting here, I remember joining the meets back in june this year and I fell in love with how it is in here.

For the love of opensource 🫶

@tpike3
Copy link
Member

tpike3 commented Jan 6, 2026

@tpike3 Thanks for the feedback 🙌

I took a look at #283. While that PR prevents the crash by skipping agents with None positions, it effectively results in an empty map. My changes here ensure the agents actually render on the grid by correctly aliasing pos to the modern cell.coordinate standard (as seen in the screenshot above).

Additionally this PR updates requirements.txt, which is currently missing key dependencies (solara, altair, networkx). Without these, the example fails to launch entirely on a fresh environment.

would you prefer I keep this PR as is to fix the visualization and dependencies, or should I split the dependency updates into a separate PR?

and about the later part, thank you for creating this amazing community, I really find the environment really supporting here, I remember joining the meets back in june this year and I fell in love with how it is in here.

For the love of opensource 🫶

Thanks @Tejasv-Singh, doing a more comprehensive review (assisted by your comments), your solution does fix the core issue more effectively. Although this does make me wonder if our CellAgent needs some updates to handle cases like this, butt hat is a larger issues beyond the scope of the PR.

Regarding the requirements.txt there is an issue where you have scipysolara, however, instead of doing a requirements could you change the install in the readme to pip install mesa[rec] instead. There are two reasons for this:
1 - Helps reinforces to users the preferred way to install mesa
2 - Python standards prefer pyproject.toml (PEP 518,621), so in general we should not use requirements

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.

Cannot run app.py on python 3.12.4

2 participants