Fix agent portrayal dict deprecation warnings in tests
Summary
This PR addresses part of issue #2904 (section 1.1) by eliminating FutureWarning messages related to deprecated dict-based agent portrayals in the visualization test suite.
Changes Made
- tests/test_examples_viz.py: Converted 9 agent portrayal functions to AgentPortrayalStyle.
- Fixed test_boltzmann_wealth_model (invalid color arg) and test_sugarscape_g1mt_model (flaky assertion).
- tests/test_solara_viz_updated.py: Converted dict-based portrayal to AgentPortrayalStyle.
- tests/test_backends.py: Updated to use AgentPortrayalStyle and added tests for deprecated dict-based portrayal wrapped with pytest.warns(FutureWarning) to verify backward compatibility.
Impact
- Eliminates FutureWarning: Returning a dict from agent_portrayal is deprecated messages from the test suite.
- Verifies deprecated dict-based portrayal still works (backward compatibility) while emitting the expected warning.
- All visualization tests passing.
- Code follows new Mesa API standards using AgentPortrayalStyle.
Testing
Ran the following tests successfully:
pytest tests/test_examples_viz.py tests/test_solara_viz_updated.py tests/test_backends.py -v
Result
All deprecation warnings related to agent portrayal are properly handled and visualization tests pass locally.
Thanks!
Would you like to give a shot at fixing all remaining agent_portrayal warnings?
Performance benchmarks:
| Model | Size | Init time [95% CI] | Run time [95% CI] |
|---|---|---|---|
| BoltzmannWealth | small | š“ +7.9% [+6.8%, +9.0%] | šµ -0.2% [-0.4%, -0.0%] |
| BoltzmannWealth | large | šµ -2.8% [-15.1%, +7.2%] | š“ +9.1% [+5.5%, +12.8%] |
| Schelling | small | šµ -0.3% [-0.5%, -0.1%] | šµ -0.6% [-0.8%, -0.4%] |
| Schelling | large | šµ +7.9% [-0.2%, +21.5%] | š“ +22.8% [+7.4%, +45.9%] |
| WolfSheep | small | šµ +0.1% [-0.2%, +0.4%] | šµ -1.6% [-1.7%, -1.5%] |
| WolfSheep | large | šµ +0.1% [-2.3%, +2.2%] | šµ +13.1% [-28.2%, +59.2%] |
| BoidFlockers | small | šµ -1.5% [-1.9%, -1.0%] | šµ +0.1% [-0.1%, +0.3%] |
| BoidFlockers | large | šµ -2.0% [-2.4%, -1.7%] | šµ -0.1% [-0.4%, +0.1%] |
Thanks!
Would you like to give a shot at fixing all remaining agent_portrayal warnings?
Sure, will try
Hey @EwoutH , please check if the fixes I applied are correct and worth merging this PR.
Hey @EwoutH verified the backward compatibilty too.
@Sahil-Chhoker I think it looks good, could you give a final check?
Hey @Sahil-Chhoker , I've updated the test to use color=agent.wealth. I came across a bug in mpl_space_drawing.py: the backend was attempting to copy the scalar color value (an integer in this case) directly to edgecolors, which caused Matplotlib to crash.
Iāve pushed a fix for that backend issue along with the updated test, so AgentPortrayalStyle now correctly handles scalar values for colormapping."
Let me know if I'm wrong or if I need to change anything.
Sorry for the delay @falloficarus22, and thanks for tracking the bug, this is indeed the right fix for it but can you make a separate PR with just the fix since this PR is only for the tests, first we'll merge the fix then this PR.
Sorry for the delay @falloficarus22, and thanks for tracking the bug, this is indeed the right fix for it but can you make a separate PR with just the fix since this PR is only for the tests, first we'll merge the fix then this PR.
Okay, will do.
Good Work!
Thanks!