Fix logic issues in predator prey model and tune parameters#27
Fix logic issues in predator prey model and tune parameters#27tkoskela wants to merge 8 commits intocarpentries-incubator:mainfrom
Conversation
Thank you!Thank you for your pull request 😃 🤖 This automated message can help you check the rendered files in your submission for clarity. If you have any questions, please feel free to open an issue in {sandpaper}. If you have files that automatically render output (e.g. R Markdown), then you should check for the following:
Rendered Changes🔍 Inspect the changes: https://github.com/carpentries-incubator/pando-python/compare/md-outputs..md-outputs-PR-27 The following changes were observed in the rendered markdown documents: What does this mean?If you have source files that require output and figures to be generated (e.g. R Markdown), then it is important to make sure the generated figures and output are reproducible. This output provides a way for you to inspect the output in a diff-friendly manner so that it's easy to see the changes that occur due to new software versions or randomisation. ⏱️ Updated at 2026-02-21 08:18:31 +0000 |
|
Thanks @tkoskela for looking into this. Yep—it’s very tricky to tune the parameters to give nice results, but this is certainly a big improvement over the previous version. A couple of notes:
|
|
More than happy to defer to @JostMigenda's judgement on approving this, looks reasonable at a glance. Please, remember to briefly review the instructor notes/solution incase anything subtle has changed there. I think the original code was heavily inspired by our FLAMEGPU Python tutorial, which is probably inspired by a common simple agent-based model. Though that subtle bug looks like something FLAMEGPU would handle natively so it's almost certainly my mistake. https://github.com/FLAMEGPU/FLAMEGPU2-tutorial-python Thanks for supporting this project! |
This comment was marked as outdated.
This comment was marked as outdated.
Yeah, I was using Copilot for tuning the parameters. I get your point about the comments, they're not very useful and I've removed them and fixed the formatting. |
|
The function-level profiling results remained qualitatively fairly similar, so I made just a few small tweaks to the text but kept screenshots of profiling results unchanged. Line-level profiling results changed a bit more, so I had to update the outputs as well as the exercise text. These commits should now cover all follow-on changes resulting from the logic fix and is ready for review. |
There was a problem hiding this comment.
Yeah this looks so much better.
| if c: | ||
| children.append(c) | ||
| self.predators.extend(children) | ||
| self.prey.extend(children) |
There was a problem hiding this comment.
Still such a dumb mistake.
| ``` | ||
|
|
||
| Given that the following line 289 only has a relative 0.6% time, it can be understood that the vast majority of times the condition `prey.life < PREY_HUNGER_THRESH` is evaluated it does not proceed. | ||
| Given that the following line 289 only has a relative 4.8% time, it can be understood that the vast majority of times the condition `prey.life < PREY_HUNGER_THRESH` is evaluated it does not proceed. |
There was a problem hiding this comment.
Re-reading this, perhaps it would be more correct to refer to hits than %time. 271 million vs 61m.
20% through rate, so less significant that the time difference. 🤷♂️
Robadob
left a comment
There was a problem hiding this comment.
Changes look thorough, I added one suggested tweak (more-so to the original text). However after writing the comment (profiling-lines.md:502) I'm in two minds about it. See what you think.
Ensure prey (1) have children, which (2) aren’t predators
Also delete empty lines in the script to ensure line numbers match those shown in screen shots
135452c to
fa0f039
Compare
|
I've rebased to resolve the two conflicts (junk conflicts around Please squash, or atleast clean up the history before merge. Feel free to delete my contribution tags from any commit comments, all I've done is housekeeping. |
I sat down with @JostMigenda in a workshop and had a go at tuning the parameters of the predator prey model to get it to oscillate between predator and prey populations. It is not quite there yet, the prey still all die, but works a bit better.