Repository navigation
Remove the legacy space drawing API - #4130
Merged
Merged
Conversation
SpaceRenderer has replaced the pre-3.3 space drawing API since Mesa 3.3, and 3.5.3 deprecates it (mesa#4064). Remove it for Mesa 4.0: - make_space_component, make_mpl_space_component, make_altair_space, SpaceMatplotlib, SpaceAltair, and the make_space_matplotlib and make_space_altair aliases - the mesa.visualization.mpl_space_drawing module (draw_space and the per-space helpers); the array helpers the matplotlib backend shared with it move into the backend SolaraViz(components="default") now draws the space with an Altair SpaceRenderer instead of make_altair_space. The pd_grid analysis notebook drew on its own subplot axes with draw_space. It now draws the moves with imshow, and uses the current PdGrid constructor and run_for, so it runs again. Tutorial 10, the overview and the tests use SpaceRenderer, and the migration guide has an entry for the removal. Assisted-by: Claude Opus 5.5
|
Performance benchmarks:
|
1 task done
quaquel
approved these changes
Nov 17, 2026
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.
Summary
Removes the space drawing API from before Mesa 3.3 from the 4.0 branch.
SpaceRendererhas replaced it since 3.3, and 3.5.3 deprecates it (#4064). Following #3330,maingets the removal directly rather than a backport of the deprecation.Removed:
make_space_component,make_mpl_space_component,make_altair_spaceSpaceMatplotlib,SpaceAltairmake_space_matplotlibandmake_space_altairaliasesmesa.visualization.mpl_space_drawingmodule:draw_space, the per-space helpers (draw_orthogonal_grid,draw_hex_grid, …), and itscollect_agent_dataMotive
Cleanup!
Implementation
MatplotlibBackendimported_to_numpy_argument_arrayfrommpl_space_drawing. That helper and_coerce_color_arraynow live inbackends/matplotlib_backend.py, and their tests moved totest_backends.py.SolaraViz(components="default")built its space withmake_altair_space. It now creates an AltairSpaceRendererwith a defaultAgentPortrayalStyle(agent id as tooltip), unless arendereris passed. The renderer is created once withsolara.use_memo, so re-renders don't replace it and model resets still go throughcopy_renderer. The docstring said this option was the default; it isn't (the default is[]), so that's corrected too.altair_components.pyandmatplotlib_components.pynow only hold the plot components.Usage Examples
The migration guide has a new 4.0 entry covering this and the
draw_space→renderer.canvascase.Additional Notes
pd_grid/analysis.ipynbdrew on its own subplot axes withdraw_space, whichSpaceRendererhas no public way to do. It now draws the moves withimshow. The notebook was already broken onmain(oldPdGrid(50, 50, "Sequential", rng=...)constructor andmodel.run), so it now usesPrisonersDilemmaScenarioandrun_foras well. I executed it, and it runs and plots correctly.overview.mdand tutorial 10 now useSpaceRenderer; the API page dropsmpl_space_drawing. Tutorial 10 executes. It still emits the existing dict-portrayalFutureWarning, which is unrelated to this PR.test_examples_viz.pyrenders throughSpaceRendererComponent; a new test coverscomponents="default"(Altair renderer, and an explicit renderer takes precedence).pytest tests/ -Werror -Wdefault::PendingDeprecationWarning: 1174 passed. The 9 Playwright tests intest_examples_viz.pycouldn't start a browser locally, so CI runs those; I rendered the new space component for all nine example models without a browser, before and after stepping, without errors. Pre-commit passes (Vale skipped locally).draw_hex_gridonmain, which this PR deletes; it would only still apply to3.5.x-maintenance.