mesa icon indicating copy to clipboard operation
mesa copied to clipboard

Fix Ignored Dict Keys in Agent Portrayal

Open ShreyasN707 opened this issue 3 weeks ago • 4 comments

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".
  • 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 always and verified that the UserWarning: The following keys from the returned dict were ignored messages 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.

ShreyasN707 avatar Dec 03 '25 18:12 ShreyasN707

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%]

github-actions[bot] avatar Dec 03 '25 19:12 github-actions[bot]

@EwoutH is there any changes i need to make?

ShreyasN707 avatar Dec 05 '25 16:12 ShreyasN707

It looks like the PR is now basically empty? https://github.com/projectmesa/mesa/pull/2918/files

EwoutH avatar Dec 07 '25 07:12 EwoutH

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.

ShreyasN707 avatar Dec 07 '25 10:12 ShreyasN707