Skip to content

Deprecate the legacy space drawing API in favour of SpaceRenderer - #4064

Merged
quaquel merged 3 commits into
mesa:3.5.x-maintenancefrom
AshNicolus:deprecate-legacy-space-drawing
Nov 12, 2026
Merged

quaquel merged 3 commits into
mesa:3.5.x-maintenancefrom
AshNicolus:deprecate-legacy-space-drawing

Conversation

@AshNicolus

@AshNicolus AshNicolus commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

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"). SpaceRenderer has replaced it since 3.3.

Deprecated, each with a FutureWarning that names SpaceRenderer and links the migration guide:

  • draw_space
  • make_space_component
  • make_mpl_space_component
  • make_altair_space
  • the old aliases make_space_matplotlib and make_space_altair, which already warned but pointed to the functions above

Why this targets 3.5.x-maintenance

Implementation

SolaraViz(model, components="default") uses make_altair_space internally, and SpaceMatplotlib calls draw_space on 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"| P
Loading
Call FutureWarnings
each of the 6 public names exactly 1, attributed to the caller's line
SolaraViz(model, components="default") 0
rendering SpaceMatplotlib 0

Behaviour 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

  • New tests/visualization/test_legacy_space_deprecation.py: each public name warns exactly once, at the caller, mentioning SpaceRenderer; SolaraViz(components="default") and SpaceMatplotlib don't warn. I checked that both of these tests fail if the internal caller is switched back to the public name.
  • The existing legacy tests (test_draw_space, test_solara_viz_legacy.py) ignore only this deprecation message, so any other warning still fails them.
  • Full suite on this branch: 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.md and tutorial 10 now use SpaceRenderer, 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.
  • The migration guide keeps the old calls on purpose, as the "before" examples.

Notes

  • Targets 3.5.3, as agreed above.
  • The per-space helpers (draw_orthogonal_grid, draw_hex_grid, ...) are public in mpl_space_drawing but not exported from mesa.visualization. I left them without warnings and would remove them together with draw_space in 4.0.
  • pd_grid/analysis.ipynb still calls draw_space on its own subplot axes, which SpaceRenderer has no public way to do. I'd handle it in the 4.0 removal PR, together with SolaraViz(components="default"), which on main still builds its space with make_altair_space.
  • No version bump or release notes, since those are added when the patch release is made.

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.
@github-actions github-actions Bot added testing Release notes label visualization labels Nov 10, 2026
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 [].
@EwoutH

EwoutH commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

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.

@AshNicolus

Copy link
Copy Markdown
Contributor Author

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.

@EwoutH

EwoutH commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

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?

@quaquel

quaquel commented Nov 10, 2026

Copy link
Copy Markdown
Member

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.

@github-actions github-actions Bot added the docs Release notes label label Nov 11, 2026
@AshNicolus
AshNicolus marked this pull request as ready for review November 11, 2026 10:13
@AshNicolus

Copy link
Copy Markdown
Contributor Author

Thanks both. Marked it ready. I also moved the overview and tutorial 10 to SpaceRenderer so the docs don't show the new warning. The pd_grid analysis notebook still uses draw_space on its own axes, so I've left that for the 4.0 removal.

@quaquel quaquel added deprecation When a new deprecation is introduced and removed testing Release notes label labels Nov 12, 2026
@quaquel
quaquel merged commit 89f3bee into mesa:3.5.x-maintenance Nov 12, 2026
15 of 17 checks passed
@github-actions github-actions Bot added the testing Release notes label label Nov 12, 2026
EwoutH added a commit that referenced this pull request Nov 18, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deprecation When a new deprecation is introduced docs Release notes label testing Release notes label visualization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants