Repository navigation
Warn once per call for dict agent_portrayal - #3803
Merged
Merged
Conversation
The FutureWarning for returning a dict from agent_portrayal was raised inside the per-agent loop in collect_agent_data, so a model with a few thousand agents produced a few thousand identical warnings on every render. Under Solara that is once per step, which buries anything else in the console and slows the render down. Hoist it with a local flag in each of the three loops (both backends and mpl_space_drawing) so it fires on the first dict portrayal seen and not again for that call. The dict to AgentPortrayalStyle conversion is untouched, and the per-agent UserWarning about ignored keys is left as is since it can differ between agents. Closes mesa#3455
|
Performance benchmarks:
|
2 tasks
EwoutH
pushed a commit
that referenced
this pull request
Oct 28, 2026
The FutureWarning for returning a dict from agent_portrayal was raised inside the per-agent loop in collect_agent_data, so a model with a few thousand agents produced a few thousand identical warnings on every render. Under Solara that is once per step, which buries anything else in the console and slows the render down. Hoist it with a local flag in each of the three loops (both backends and mpl_space_drawing) so it fires on the first dict portrayal seen and not again for that call. The dict to AgentPortrayalStyle conversion is untouched, and the per-agent UserWarning about ignored keys is left as is since it can differ between agents. Closes #3455 (cherry picked from commit eed8b2a)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3455.
The FutureWarning that asks you to stop returning a dict from
agent_portrayalsits inside the per agent loop incollect_agent_data. With a few thousand agents you get a few thousand copies of the same message, and under Solara that repeats on every render, so the console fills up and drawing gets slower for no reason.This adds a local flag before each of the three loops (the matplotlib backend, the altair backend, and
mpl_space_drawing.collect_agent_data) and only warns the first time a dict portrayal turns up in that call. The dict toAgentPortrayalStyleconversion is unchanged, so nothing about the drawn output moves. I left the per agentUserWarningabout ignored keys alone, since different agents can return different extra keys and folding those together would drop information.Added tests that a multi agent dict portrayal produces exactly one FutureWarning at each of the three sites.
tests/visualizationpasses with-Werror.