Skip to content

Fix forest_fire notebook compatibility with Mesa 4 - #487

Open
lahari936 wants to merge 2 commits into
mesa:mainfrom
lahari936:fix-forest-fire-mesa4
Open

lahari936 wants to merge 2 commits into
mesa:mainfrom
lahari936:fix-forest-fire-mesa4

Conversation

@lahari936

Copy link
Copy Markdown

The notebook still used the Mesa 2-era batch running API and an old DataCollector attribute name, so it failed on the first import cell and again at every batch-run cell.

Verified against mesa 4.0.0a0, which is what CI installs via pip install mesa --pre:

  • mesa.batchrunner no longer exists, and neither does mesa.batch_run -- the whole batch runner was removed in Mesa 4. mesa.experimental.scenarios ships only Scenario in 4.0.0a0; run_scenarios is on Mesa main but not in any released version. The sweep is therefore an explicit loop over the density values, which reads clearly in a tutorial notebook and works on both Mesa 3 and Mesa 4.
  • fire.dc is now fire.datacollector.
  • The batch cells now build their own DataFrame, so the reported fraction keeps the BurnedOut name the surrounding text and plots already use.
  • The notebook's inline OrthogonalMooreGrid now takes random=self.random, matching forest_fire/model.py. Without it Mesa 4 warns that the model is not reproducible.

fire.run_model() is not removed in Mesa 4 -- it still runs the model until running goes false -- so those cells are unchanged.

Outputs were regenerated from a clean mesa 4.0.0a0 run, which also updates the prose about how many steps the fire takes to burn out.

Fixes #421

Thanks for opening a PR! Please click the Preview tab and select a PR template:

The notebook still used the Mesa 2-era batch running API and an old
DataCollector attribute name, so it failed on the first import cell and
again at every batch-run cell.

Verified against mesa 4.0.0a0, which is what CI installs via `pip install
mesa --pre`:

* `mesa.batchrunner` no longer exists, and neither does `mesa.batch_run` --
  the whole batch runner was removed in Mesa 4. `mesa.experimental.scenarios`
  ships only `Scenario` in 4.0.0a0; `run_scenarios` is on Mesa main but not
  in any released version. The sweep is therefore an explicit loop over the
  density values, which reads clearly in a tutorial notebook and works on
  both Mesa 3 and Mesa 4.
* `fire.dc` is now `fire.datacollector`.
* The batch cells now build their own DataFrame, so the reported fraction
  keeps the `BurnedOut` name the surrounding text and plots already use.
* The notebook's inline `OrthogonalMooreGrid` now takes `random=self.random`,
  matching `forest_fire/model.py`. Without it Mesa 4 warns that the model is
  not reproducible.

`fire.run_model()` is *not* removed in Mesa 4 -- it still runs the model
until `running` goes false -- so those cells are unchanged.

Outputs were regenerated from a clean mesa 4.0.0a0 run, which also updates
the prose about how many steps the fire takes to burn out.

Fixes mesa#421

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 28, 2026 17:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

pre-commit.ci failed on the regenerated notebook outputs: codespell reads
the base64 payload of the embedded plot PNGs as text and reports "fO" and
"wHN" as misspellings of "of" and "when".

Add both to .codespellignore, which already carries "nD" from the same kind
of false positive, and give the file the trailing newline it was missing so
the last entry stays on its own line.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

forest_fire notebook broken with Mesa 4

2 participants