mesa icon indicating copy to clipboard operation
mesa copied to clipboard

Fix agent portrayal dict deprecation warnings in tests

Open falloficarus22 opened this issue 2 weeks ago • 5 comments

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.

falloficarus22 avatar Dec 08 '25 08:12 falloficarus22

Thanks!

Would you like to give a shot at fixing all remaining agent_portrayal warnings?

EwoutH avatar Dec 08 '25 08:12 EwoutH

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

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

Thanks!

Would you like to give a shot at fixing all remaining agent_portrayal warnings?

Sure, will try

falloficarus22 avatar Dec 08 '25 08:12 falloficarus22

Hey @EwoutH , please check if the fixes I applied are correct and worth merging this PR.

falloficarus22 avatar Dec 08 '25 11:12 falloficarus22

Hey @EwoutH verified the backward compatibilty too.

falloficarus22 avatar Dec 09 '25 03:12 falloficarus22

@Sahil-Chhoker I think it looks good, could you give a final check?

EwoutH avatar Dec 11 '25 10:12 EwoutH

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.

falloficarus22 avatar Dec 11 '25 11:12 falloficarus22

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.

Sahil-Chhoker avatar Dec 16 '25 05:12 Sahil-Chhoker

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.

falloficarus22 avatar Dec 16 '25 05:12 falloficarus22

Good Work!

Thanks!

falloficarus22 avatar Dec 16 '25 11:12 falloficarus22