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

Fix forest fire networkx dependency

Open GITUSERMANOLYA opened this issue 8 months ago • 11 comments

GSoC contributor checklist

Context & motivation

I am a beginner in open source, I went through many organizations and picked this particular organization and this particular project as it is simple and aligned with the skills I am good at.I was exploring the mesa-examples repository as part of my GSoC 2026 application for the Mesa Examples Revival project. I ran all 22 examples to understand the current state of the repo. When I ran the forest_fire example, I got a ModuleNotFoundError for networkx. I checked the requirements.txt and networkx was missing, so I added it.

What I learned

I learned how Python dependency management works with requirements.txt. I also learned how to use git rebase to clean up a PR branch, and how the GitHub PR review process works. This was my first open source contribution. I am polishing my basic knowledge of git commands. This gave me an exciting opportunity to learn and explore more of git and github and open source projects

Learning repo

🔗 My learning repo: https://github.com/GITUSERMANOLYA/GSoC-learning-space 🔗 Relevant model(s): N/A

Readiness checks

  • [x] This PR addresses an agreed-upon problem (linked issue or discussion with maintainer approval), or is a small/trivial fix
  • [x] I have read the contributing guide and deprecation policy
  • [x] I have performed a self-review
  • [x] Another GSoC contributor has reviewed this PR: @Harshini2411
  • [x] Tests pass locally
  • [x] Code is formatted

GITUSERMANOLYA avatar Mar 15 '26 13:03 GITUSERMANOLYA

Thanks for the PR. Could you git rebase it? It looks like it now changes a lot, which it probably doesn't.

EwoutH avatar Mar 15 '26 21:03 EwoutH

Thanks for the PR. Could you git rebase it? It looks like it now changes a lot, which it probably doesn't.

Hi! I'm new to using Git. I've rebased the branch. The diff only contains the single networkx line addition to requirements.txt. Let me know if anything else is needed!

GITUSERMANOLYA avatar Mar 16 '26 13:03 GITUSERMANOLYA

For some reason 3 other commits are included. I normally sync the upstream main branch and then rebase my PR branch on the upstream main branch.

EwoutH avatar Mar 16 '26 14:03 EwoutH

Hey! Reviewed this PR 👋 The fix itself is correct, networkx was definitely missing from requirements.txt and this is the right place to add it. One thing though your PR seems to have picked up 3 extra commits that aren't related to this fix (the CI update, M/M/c queue example, and README update). That's probably why the diff shows +312/-18 instead of just +1 line. @EwoutH already mentioned this too. You'd need to rebase onto upstream main to clean those up:

git remote add upstream https://github.com/projectmesa/mesa-examples
git fetch upstream
git rebase upstream/main
git push --force-with-lease origin fix-forest-fire-networkx-dependency

Once that's sorted the PR should be good to merge! Happy to take another look after the rebase 🙂

Harshini2411 avatar Mar 19 '26 20:03 Harshini2411

Done! Rebased onto upstream/main. The diff now shows only the single +networkx line addition.Thanks for the help!! EwoutH and Harshini2411!

GITUSERMANOLYA avatar Mar 20 '26 13:03 GITUSERMANOLYA

Looks good now! The rebase is clean, diff is exactly the one line it should be, and the fix is correct. LGTM and ready to merge! 🙌

Harshini2411 avatar Mar 20 '26 17:03 Harshini2411

I see forest_fire is based on Grid then why do we need networkx as dependency? Am I missing something?

codebreaker32 avatar Mar 22 '26 05:03 codebreaker32

the forest_fire model is a pure grid-based cellular automaton with no network or graph structure, so networkx shouldn't be needed anywhere in the code. The dependency looks like it was listed by mistake. @GITUSERMANOLYA can you confirm networkx isn't imported anywhere in the model or notebook? If so, this PR is correct in removing it.

Harshini2411 avatar Mar 23 '26 16:03 Harshini2411

Actually when I ran python -m solara run app.py in the forest_fire folder it threw ModuleNotFoundError: No module named 'networkx'. Adding networkx to requirements.txt fixes this error. Hence I mentioned this fix.

GITUSERMANOLYA avatar Mar 23 '26 16:03 GITUSERMANOLYA

checkout https://github.com/mesa/mesa/issues/3596

codebreaker32 avatar Mar 23 '26 16:03 codebreaker32

Good catch @codebreaker32! forest_fire doesn't use networkx directly, but the error still occurs because import mesa triggers a top-level import networkx via discrete_space to network.py. That said, you're right to question this adding it to requirements.txt is a workaround. The root fix is being tracked in projectmesa/mesa#3598, which moves the import lazily inside Network.init. Once that merges, this requirement may no longer be needed here.

Harshini2411 avatar Mar 25 '26 03:03 Harshini2411