Repository navigation
Deprecate the legacy space drawing API in favour of SpaceRenderer - #4064
Conversation
draw_space, make_space_component, make_mpl_space_component and make_altair_space now raise a FutureWarning that points to SpaceRenderer and the migration guide, as agreed in mesa#4053. They will be removed in 4.0. Each implementation moved to a private function and the public name is a thin wrapper, so the SolaraViz default and SpaceMatplotlib, which use the legacy code internally, don't warn users who never called it.
The API docs render the public names, not the private implementations, so the Args sections and parameter names belong on draw_space, make_mpl_space_component and make_altair_space. Also test the SolaraViz internal path through components="default", which is where it calls make_altair_space; the components default is [].
|
It’s a bit weird to introduce a deprecation in a patch release (3.5.3). On the other hand the alternative is in place for a while. So maybe it’s fine. Let me think about this a bit. |
|
Makes sense. If a 3.6 is planned I'm happy to retarget it there, otherwise 3.5.3 at least gives users a warning before 4.0 removes it. |
|
Yeah let's just do 3.5.3. While it's not ideal to deprecate in a patch release, it's better than not doing it or doing it too late. Thanks for the PR, can you make it ready for a final review? |
|
It is indeed not in line with semantic versioning to deprecate stuff in patch releases. However, I would also find it strange if we have a 3.6 release with just a whole bunch of deprecations. So, I think that an argument can be made to do all the relevant deprecations prior to 4.0 as part of patch releases. |
|
Thanks both. Marked it ready. I also moved the overview and tutorial 10 to |
SpaceRenderer has replaced the pre-3.3 space drawing API since Mesa 3.3, and 3.5.3 deprecates it (#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.
Summary
Deprecates the legacy space drawing API on the 3.5 series, as agreed in #4053 (quaquel: "deprecate on 3.5.x and remove for 4", EwoutH: "Agreed").
SpaceRendererhas replaced it since 3.3.Deprecated, each with a
FutureWarningthat namesSpaceRendererand links the migration guide:draw_spacemake_space_componentmake_mpl_space_componentmake_altair_spacemake_space_matplotlibandmake_space_altair, which already warned but pointed to the functions aboveWhy this targets
3.5.x-maintenancemainas a backport.FutureWarningin a patch release only with a compelling reason. Here it is that Mesa 4.0 removes this API, agreed by both maintainers in Retire the legacy space drawing (draw_space, make_space_component) in Mesa 4? #4053.Implementation
SolaraViz(model, components="default")usesmake_altair_spaceinternally, andSpaceMatplotlibcallsdraw_spaceon every render. Warning in those functions directly would warn users who never called the legacy API. So each implementation moved to a private_name, the public name is a thin wrapper that warns and delegates, and internal callers use the private one:flowchart LR U["user code"] -->|"draw_space(), make_*_space...()"| W["public wrapper<br/>FutureWarning, once"] W --> P["_draw_space / _make_*_space<br/>(unchanged code)"] S["SolaraViz(components='default'),<br/>SpaceMatplotlib,<br/>make_space_component"] -->|"no warning"| PSolaraViz(model, components="default")SpaceMatplotlibBehaviour is otherwise unchanged; the function bodies only moved. The public names keep their full signatures and docstrings, with a
.. deprecated::note, so the API docs still show their arguments.Testing
tests/visualization/test_legacy_space_deprecation.py: each public name warns exactly once, at the caller, mentioningSpaceRenderer;SolaraViz(components="default")andSpaceMatplotlibdon't warn. I checked that both of these tests fail if the internal caller is switched back to the public name.test_draw_space,test_solara_viz_legacy.py) ignore only this deprecation message, so any other warning still fails them.pytest tests/ -Werror -Wdefault::PendingDeprecationWarning, 783 passed, 1 skipped (774 + 9 new; the branch was green before the change). Pre-commit passes.Docs
docs/overview.mdand tutorial 10 now useSpaceRenderer, so the docs don't trigger the new warning. I ran tutorial 10 with FutureWarnings as errors: it fails before this change and passes after.Notes
draw_orthogonal_grid,draw_hex_grid, ...) are public inmpl_space_drawingbut not exported frommesa.visualization. I left them without warnings and would remove them together withdraw_spacein 4.0.pd_grid/analysis.ipynbstill callsdraw_spaceon its own subplot axes, whichSpaceRendererhas no public way to do. I'd handle it in the 4.0 removal PR, together withSolaraViz(components="default"), which onmainstill builds its space withmake_altair_space.