Fix Ignored Dict Keys in Agent Portrayal
Summary
Fixed UserWarnings caused by using incorrect keys (s, c, linecolors) in agent portrayal dictionaries within tests and clarified documentation.
Bug / Issue #2904
The issue was that tests/test_components_matplotlib.py was using Matplotlib-style keys (s, c) in the dictionary returned by agent_portrayal, which are not recognized by Mesa's mpl_space_drawing module. This led to multiple UserWarning: The following keys from the returned dict were ignored messages during testing. Additionally, the documentation in mpl_space_drawing.py needed consistent formatting for valid keys.
Implementation
- Tests: Updated tests/test_components_matplotlib.py to use the correct keys expected by
mpl_space_drawing:- Replaced
"s"with"size". - Replaced
"c"with"color". - Replaced
"linecolors"with"edgecolors".
- Replaced
- Documentation: Updated the docstring in mesa/visualization/mpl_space_drawing.py to consistently quote all valid keys (
"size","color", etc.) for better readability and accuracy.
Testing
- Ran
pytest tests/test_components_matplotlib.py -W alwaysand verified that theUserWarning: The following keys from the returned dict were ignoredmessages are no longer present. - Confirmed that all tests in the file pass successfully.
Additional Notes
This ensures that the tests follow the recommended way of defining agent portrayals and keeps the test output clean.
Performance benchmarks:
| Model | Size | Init time [95% CI] | Run time [95% CI] |
|---|---|---|---|
| BoltzmannWealth | small | šµ +1.3% [+0.2%, +2.3%] | šµ +2.4% [+2.2%, +2.7%] |
| BoltzmannWealth | large | šµ -6.7% [-17.4%, +1.9%] | šµ -0.6% [-2.3%, +1.0%] |
| Schelling | small | šµ +0.3% [+0.0%, +0.6%] | šµ +0.6% [+0.3%, +0.9%] |
| Schelling | large | šµ +0.5% [-17.8%, +22.4%] | šµ +14.4% [-0.3%, +39.1%] |
| WolfSheep | small | šµ -0.1% [-0.4%, +0.2%] | šµ +2.2% [+1.9%, +2.5%] |
| WolfSheep | large | šµ -10.9% [-36.5%, +8.0%] | šµ +12.6% [-9.9%, +40.1%] |
| BoidFlockers | small | šµ +1.3% [+0.5%, +2.3%] | šµ +0.0% [-0.2%, +0.2%] |
| BoidFlockers | large | šµ +1.7% [+1.1%, +2.3%] | šµ -0.1% [-0.4%, +0.2%] |
@EwoutH is there any changes i need to make?
It looks like the PR is now basically empty? https://github.com/projectmesa/mesa/pull/2918/files
It looks like the PR is now basically empty? https://github.com/projectmesa/mesa/pull/2918/files
oh yes! after syncing with main most of my earlier changes were already included, so the PR ended up small. Iām still on it, but if this is too minor to keep open, just let me know.