Skip to content

Backport fixes and enhancements for Mesa 3.5.2 - #4016

Merged
EwoutH merged 97 commits into
mesa:3.5.x-maintenancefrom
EwoutH:3.5.2-backport
Oct 28, 2026
Merged

EwoutH merged 97 commits into
mesa:3.5.x-maintenancefrom
EwoutH:3.5.2-backport

Conversation

@EwoutH

@EwoutH EwoutH commented Oct 28, 2026

Copy link
Copy Markdown
Member

Backports 85 PRs from main to 3.5.x-maintenance and bumps the version to 3.5.2, with release notes in HISTORY.md.

Scope is the same as 3.5.1: bug fixes, performance, docs fixes and small additive enhancements. 4.0-only work (Actions, meta-agents rewrite, scenario storage, ContinuousState, on_idle, select_random, …) is not included. Fixes that change results were included only when the 3.5.1 behaviour was clearly wrong (#3797, #3918, #3544, #3986).

Most commits are plain git cherry-pick -x. Test-only conflicts were resolved by keeping both sides.

Adapted for 3.5.x

Not backported

Testing

  • pytest tests/ -Werror -Wdefault::PendingDeprecationWarning -W "ignore:websockets.legacy is deprecated:DeprecationWarning": 765 passed, 1 skipped (local, Python 3.13). The Playwright browser tests in tests/examples/test_examples_viz.py were not run locally.
  • ruff check / ruff format --check: same results as the 3.5.x-maintenance base. One existing lint warning and 6 existing format diffs, none introduced here.
  • Docs were not built locally.

After merging, publish the v3.5.2 draft release.

AI use: the backport selection, cherry-picks, conflict resolution, adapted commits and release notes were prepared with Claude Code.

🤖 Generated with Claude Code

ShreyasN707 and others added 30 commits October 28, 2026 13:56
* Optimise _remove_agent

* Remove _agent_to_index

(cherry picked from commit 4140369)
Fixed minor typos and grammar issues in the Boltzmann Wealth Model tutorial.

(cherry picked from commit 2b23c16)
* docs: add clear run instructions for alliance_formation example

* docs: add clear run instructions for boid_flockers example

* docs: remove redundant mesa install and update run instructions

* docs: remove redundant install steps and standardize run instructions for boid_flockers example

* docs: standardize run instructions across Mesa examples

* docs: include recommended dependencies for running examples

---------

Co-authored-by: Tom Pike <[email protected]>
(cherry picked from commit 410c99a)
Co-authored-by: Sahil Chhoker <[email protected]>
(cherry picked from commit 06a3e8d)
…sa#3685)

Fixes a crash in the Altair-based space visualization when the model contains no agents.

(cherry picked from commit b387075)
Fixes mesa#3454

SolaraViz now validates upfront that model is an initialized instance,
not a class. The check fires before Solara's reactive system can swallow
the bad input, producing a clear, actionable error message.

Two cases are handled:
- SolaraViz(MyModel, ...) — bare class passed directly
- SolaraViz(solara.reactive(MyModel), ...) — class wrapped in reactive

Error message includes the concrete fix: 'Did you mean SolaraViz(MyModel(), ...)?'

This is a common migration mistake from ModularServer, which took a class.

Added tests in tests/visualization/test_solara_viz_class_validation.py.

(cherry picked from commit 74c3c79)
…sa#3671)

* Fix run_model_test capturing initial image instead of updated visualization

* Fix ValueError in get_k_nearest_agents when k >= number of agents

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix k>=n and empty space handling in ContinuousSpace

* Address review feedback: add warning for k>n, fix test setup, remove unrelated viz change

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jan Kwakkel <[email protected]>
(cherry picked from commit 9780c9f)
rishiiicreates and others added 21 commits October 28, 2026 14:17
mesa#3889)

Cell.add_agent previously set self.empty = False before verifying capacity,
leaving empty out of sync with is_empty when CellFullException was raised.
Now self.empty is set only after the agent is successfully appended.

Fixes mesa#3883

(cherry picked from commit 8b35f01)
…empty_cell() when grid is full (mesa#3500)

* fix: prevent IndexError and add clear error message in select_random_empty_cell() when grid is full

* fix: improve error handling using try catch in select_random_empty_cell() for full grids

* a small fix

---------

Co-authored-by: Jan Kwakkel <[email protected]>
(cherry picked from commit 0eaf588)
…method names in grid.py docstrings (mesa#3623)

(cherry picked from commit 26b1d18)
* Fix network crash error in matplotlib backend network drawing

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix remaining IndentationError and edgecolors length bug in matplotlib backend

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
(cherry picked from commit 8503a32)
…tasets (mesa#3892)

When a NumpyAgentDataSet was converted to a DataFrame or written to Parquet,
stacking agent_ids onto float data upcast agent_ids to float64 (e.g. 1.0, 2.0).
Now DataRecorder and ParquetDataRecorder explicitly preserve agent_id as an integer.

Fixes mesa#3871

(cherry picked from commit 786fcde)
…esa#3902)

* Raise IndexError for out-of-range negative indices in SignalingList

SignalingList.__setitem__ and __delitem__ normalize a negative integer
index by adding len(self.data) once, but never check the result. An index
below -len therefore stays negative after normalization and Python's own
wrap-around kicks in, so lst[-4] = x on a three-element list overwrites
the last element and del lst[-4] deletes it, instead of raising
IndexError like a plain list. A REPLACED/REMOVED signal is emitted for the
wrong element as well.

Bounds-check the normalized index and raise IndexError, matching list.

Fixes mesa#3901

* Match built-in list message for out-of-range del in SignalingList

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Revert "Match built-in list message for out-of-range del in SignalingList"

The built-in list raises "list assignment index out of range" for del
as well, so the original message already matched.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 9175791)
Some backported tests were written against main (4.0) or picked up
neighbouring 4.0-only tests when resolving conflicts:
- use HasObservables instead of HasEmitters (renamed in 4.0)
- use agent.pos instead of agent.position in backend test stubs
- add the missing pytest import in test_components_matplotlib.py
- drop tests for 4.0-only features (RUN_ENDED signal, AgentDataSet dirty
  flag) and a duplicated draw_property_layers call
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

(cherry picked from commit eed8b2a)
* mixed-face-colors patch

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update assertion for uniform result shape

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Tom Pike <[email protected]>
(cherry picked from commit f376606)
…tion.py

Backport of mesa#3434, adapted for 3.5.x (which has no mesa.exceptions module):
- DataCollector.get_model_vars_dataframe() and get_agent_vars_dataframe()
  raised UserWarning as an exception although the message says an empty
  DataFrame is returned. They now warn and return an empty DataFrame.
- Missing tables and missing columns raise ValueError (a subclass of the
  bare Exception used before) with the table/column name in the message.
- Fix the inverted 'is larger than' messages in Model.run_until() and
  Model._advance_time().
Backport of mesa#3486, applied by hand because the surrounding code was
renamed on main (HasObservables -> HasEmitters). Computed properties
depending on an ObservableList now update after in-place mutations.

(cherry picked from commit d8f5f1c)
Update version and release notes for the next patch release, Mesa 3.5.2.
@github-actions github-actions Bot added ci Release notes label docs Release notes label example Changes the examples or adds to them. experimental Release notes label testing Release notes label visualization labels Oct 28, 2026
@EwoutH
EwoutH merged commit 1574625 into mesa:3.5.x-maintenance Oct 28, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Release notes label docs Release notes label example Changes the examples or adds to them. experimental Release notes label testing Release notes label visualization

Projects

None yet

Development

Successfully merging this pull request may close these issues.