Skip to content

Fix forest_fire notebook for Mesa 4 compatibility#422

Open
Vanya-kapoor wants to merge 1 commit intomesa:mainfrom
Vanya-kapoor:migrate-forest-fire-mesa4
Open

Fix forest_fire notebook for Mesa 4 compatibility#422
Vanya-kapoor wants to merge 1 commit intomesa:mainfrom
Vanya-kapoor:migrate-forest-fire-mesa4

Conversation

@Vanya-kapoor
Copy link

Fixes forest_fire notebook to work with Mesa 4, replacing removed
and deprecated APIs.

Changes:

  • Replace deprecated imports (BatchRunner, mesa.datacollection)
    with import mesa and import pandas as pd
  • Replace deprecated fire.run_model() with
    while fire.running: fire.step()
  • Fix fire.dcfire.datacollector
  • Replace removed BatchRunner with mesa.batch_run()
  • Fix DataFrame column access: df.BurnedOutdf["Burned Out"]

Fixes #421
Related: #3132, #3270

@Harshini2411
Copy link

Hey, good work on this! The migration approach is solid and you've got the right idea. Just a couple of things to sort out before it's ready to merge:

The big ones:

  • DataCollector is never imported. The model still uses it directly but the import cell only has import mesa and import pandas as pd. You'll get a NameError when you run it. Either add from mesa.datacollection import DataCollector or switch to mesa.DataCollector(...) in the model.
  • df["BurnedOut"] needs to be df["Burned Out"] (with a space). The reporter key in DataCollector is Burned Out, so that's what batch_run will name the column. Without the space it'll throw a KeyError.

Smaller things:

  • There's a # this is fix by vanya comment left in deffuant_weisbuch/model.py worth removing before merging!
  • The notebook still has the old error tracebacks in some cells. Could you do a clean run in a Mesa 4 environment and recommit with fresh outputs?

Once those are fixed this should be good to go!

@Vanya-kapoor
Copy link
Author

Thanks for your feedback.I have made the changes please see to it

@Vanya-kapoor Vanya-kapoor reopened this Mar 21, 2026
@codebreaker32
Copy link
Collaborator

Keep your git history clean

- Replace AgentSet.to_list() with list(self.agents)
- Replace deprecated BatchRunner with mesa.batch_run()
- Fix DataCollector import and DataFrame column name
- Clean notebook outputs

Fixes
@Vanya-kapoor Vanya-kapoor force-pushed the migrate-forest-fire-mesa4 branch from 7d33948 to 3a53352 Compare March 21, 2026 19:10
@Vanya-kapoor
Copy link
Author

Keep your git history clean

done @codebreaker32

@Vanya-kapoor
Copy link
Author

@EwoutH @jackiekazil @catherinedevlin this pr is ready to be merged!

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

3 participants