Repository navigation
Fix #3597: safe Sheep.feed() when grass=False, add regression test - #3627
Merged
quaquel merged 2 commits intoMar 24, 2026
Merged
Conversation
5 of 6 tasks
|
Performance benchmarks:
|
quaquel
approved these changes
Mar 24, 2026
souro26
pushed a commit
to souro26/mesa
that referenced
this pull request
Mar 28, 2026
codebreaker32
pushed a commit
to codebreaker32/mesa
that referenced
this pull request
Apr 1, 2026
EwoutH
pushed a commit
that referenced
this pull request
Oct 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #3597 (partial — agent logic fix)
Sheep.feed()passed a bare generator tonext()with no default.When
grass=False, noGrassPatchagents are created, so the generatoris always empty and
next()raisesStopIterationon step 1.Zero impact on the
grass=Truepath.Tests added
test_wolf_sheep_grass_disabled— runs 10 steps withgrass=False,asserts no crash, confirms Wolves/Sheep in dataframe and Grass absent.
GSoC contributor checklist
Context & motivation
I was exploring the WolfSheep model to study predator-prey dynamics without the grass mechanic — a common variant in ABM literature. The model crashed immediately on the first step. Tracing the stack I found
next()with no default — a silent landmine that only explodes on non-default execution paths.What I learned
next(gen)with no default is dangerous on any code path that isn't the happy path — always pass a default. I also learned that Mesa's DataCollector is intentionally dynamic: reporters are only registered conditionally, so downstream code can never assume every key exists.Learning repo
🔗 My learning repo: https://github.com/DipayanDasgupta/GSoC-learning-space
🔗 Relevant model: https://github.com/DipayanDasgupta/GSoC-learning-space/tree/main/models/wolf_sheep_investigation
Readiness checks
-[x] Tests pass locally
ruff check . --fix)