mesa-examples icon indicating copy to clipboard operation
mesa-examples copied to clipboard

Fix forest_fire notebook for Mesa 4 compatibility

Open Vanya-kapoor opened this issue 8 months ago • 5 comments

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.dc → fire.datacollector
  • Replace removed BatchRunner with mesa.batch_run()
  • Fix DataFrame column access: df.BurnedOut → df["Burned Out"]

Fixes #421 Related: #3132, #3270

Vanya-kapoor avatar Mar 20 '26 16:03 Vanya-kapoor

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!

Harshini2411 avatar Mar 20 '26 17:03 Harshini2411

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

Vanya-kapoor avatar Mar 21 '26 06:03 Vanya-kapoor

Keep your git history clean

codebreaker32 avatar Mar 21 '26 09:03 codebreaker32

Keep your git history clean

done @codebreaker32

Vanya-kapoor avatar Mar 21 '26 19:03 Vanya-kapoor

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

Vanya-kapoor avatar Mar 21 '26 19:03 Vanya-kapoor