Skip to content

tests: Update agent portrayals to use AgentPortrayalStyle#2909

Merged
EwoutH merged 1 commit intomesa:mainfrom
Tejasv-Singh:fix-issue-2904-portrayal-deprecation
Dec 3, 2025
Merged

tests: Update agent portrayals to use AgentPortrayalStyle#2909
EwoutH merged 1 commit intomesa:mainfrom
Tejasv-Singh:fix-issue-2904-portrayal-deprecation

Conversation

@Tejasv-Singh
Copy link
Copy Markdown
Contributor

PR: Migrate Test Agent Portrayals to AgentPortrayalStyle (Part of #2904)

This PR updates tests/test_components_matplotlib.py to use the new AgentPortrayalStyle API rather than legacy dict-based portrayals.
It reduces deprecation warnings and ensures the test suite reflects the modern visualization interface.


🔧 Issue Reference

Linked: #2904 — Migration away from deprecated dict-based agent portrayals toward AgentPortrayalStyle.

Previously, several tests defined agent_portrayal functions returning dicts like:

{"s": 10, "c": "tab:blue", ...}

These have been deprecated. The visualization system now expects an AgentPortrayalStyle instance, leading to noisy warnings and inconsistencies in the test suite.


🛠️ Implementation Details

✔ Updated Imports

from mesa.visualization.components import AgentPortrayalStyle

✔ Refactored Test Portrayal Functions

All portrayal functions in tests/test_components_matplotlib.py have been updated to return AgentPortrayalStyle instead of dicts.

✔ Key Mappings (Legacy → New API)

Old Dict Key | New AgentPortrayalStyle Field -- | -- s | size c | color linewidths | linewidths linecolors | edgecolors

These mappings preserve the previous semantics—same markers, colors, sizes, and alpha values.


🧪 Testing

Executed focused test suites:

pytest tests/test_components_matplotlib.py tests/test_backends.py

✅ Result

  • 21 tests passed

  • Only pre-existing warnings remain

  • No new errors introduced

  • Tests now exercise the updated portrayal API cleanly


📌 Notes

  • This PR intentionally targets only the test layer, aligning with the incremental migration plan discussed in Tracking issue: Resolve test suite warnings #2904.

  • Core visualization code already supports AgentPortrayalStyle; these changes ensure tests validate the new API correctly.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 2, 2025

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔴 +8.3% [+6.9%, +9.6%] 🔵 +0.6% [+0.5%, +0.8%]
BoltzmannWealth large 🔵 +3.2% [+2.9%, +3.6%] 🔴 +14.4% [+13.1%, +15.6%]
Schelling small 🔵 +1.3% [+1.1%, +1.5%] 🔵 +2.3% [+2.0%, +2.5%]
Schelling large 🔵 +1.4% [+0.5%, +2.5%] 🔵 +6.9% [+2.4%, +12.0%]
WolfSheep small 🔵 +0.6% [+0.4%, +0.9%] 🔵 +2.0% [+1.8%, +2.2%]
WolfSheep large 🔵 +0.1% [-1.8%, +2.0%] 🔵 +3.9% [+0.9%, +7.5%]
BoidFlockers small 🔵 -0.7% [-1.3%, -0.0%] 🔵 -1.3% [-1.6%, -1.1%]
BoidFlockers large 🔵 -0.8% [-1.2%, -0.4%] 🔵 -1.3% [-1.7%, -1.0%]

@EwoutH EwoutH requested a review from Sahil-Chhoker December 2, 2025 15:12
@EwoutH EwoutH added the testing Release notes label label Dec 2, 2025
@EwoutH EwoutH merged commit 40592d3 into mesa:main Dec 3, 2025
13 checks passed
@EwoutH
Copy link
Copy Markdown
Member

EwoutH commented Dec 3, 2025

Thanks!

@EwoutH EwoutH changed the title Fix #2904: Update agent portrayals in tests to use AgentPortrayalStyle tests: Update agent portrayals to use AgentPortrayalStyle Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants