Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animal - Feature/multi grid no community #538

Merged
merged 72 commits into from
Dec 4, 2024

Conversation

TaranRallings
Copy link
Collaborator

@TaranRallings TaranRallings commented Aug 15, 2024

Description

Where to even begin! This is scandalously oversized rework of the entire animal module that has taken me over two months. I would never have chosen to do it this way but it happened organically in a manner that has taught me many lessons.
Mea culpa.

This rework combines two major changes:

  1. the implementation of multi-grid occupancy
  2. the removal of the AnimalCommunity class

Multi-grid occupancy equips each animal cohort with a territory of grid cells (list(int)) that they occupy simultaneously. They forage and deposit wastes uniformly across these cells. Carcasses produced from predation are deposited at the intersection of predator and prey territories. Territories are produced using breadth-first search but this can be made more sophisticated later.

The removal of the AnimalCommunity class is a major structural change. This class had been storing per-grid information on animal cohorts, waste pools, and the like as well as running cohort-specific methods in aggregate for those grid cells. Almost all of this functionality is now located within the AnimalModel class. Animal cohorts and waste pools are now stored as dictionaries in AnimalModel, tying the occupying lists to specific grid cell ids. The aggregating methods from AnimalCommunity have been modified to run over these dictionaries. Removing these community objects has, I hope, made the module significantly easier to understand.

I abandoned the AnimalTerritory class I had been exploring in an earlier implementation of multi-grid.

There are some significant changes to the litter system here as well as it was designed while I was mid re-work. The version I have is a little structurally different than Jacob's original but works the same.

There were some concerns with an earlier version about the amount of indexing going on in the foraging system. This is valid but I simply do not have the time to optimize the foraging system, especially with how behind I am after the rework. Hopefully the structural simplifications made here will simplify making such optimizations in the future, after the remaining required functionality is implemented.

The important files here are animal_model and animal_cohort but unfortunately little tweaks had to be made just about everywhere.

Fixes # (issue)

Type of change

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist

  • Make sure you've run the pre-commit checks: $ pre-commit run -a
  • All tests pass: $ poetry run pytest

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works
  • Relevant documentation reviewed and updated

…adds default classes for territory and community.
@codecov-commenter
Copy link

codecov-commenter commented Oct 30, 2024

Codecov Report

Attention: Patch coverage is 93.22034% with 24 lines in your changes missing coverage. Please review.

Project coverage is 94.69%. Comparing base (79d9635) to head (f46162a).
Report is 20 commits behind head on develop.

Files with missing lines Patch % Lines
virtual_ecosystem/models/animal/animal_cohorts.py 89.20% 15 Missing ⚠️
...rtual_ecosystem/models/animal/scaling_functions.py 85.29% 5 Missing ⚠️
virtual_ecosystem/models/animal/animal_model.py 97.59% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #538      +/-   ##
===========================================
- Coverage    95.16%   94.69%   -0.48%     
===========================================
  Files           74       73       -1     
  Lines         4409     4541     +132     
===========================================
+ Hits          4196     4300     +104     
- Misses         213      241      +28     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TaranRallings TaranRallings self-assigned this Oct 31, 2024
@TaranRallings TaranRallings marked this pull request as ready for review October 31, 2024 12:03
@TaranRallings TaranRallings requested review from dalonsoa, davidorme and jacobcook1995 and removed request for robewers01 October 31, 2024 12:31
Copy link
Collaborator

@jacobcook1995 jacobcook1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stuff that interfaces with the soil and litter is all fine by me

Copy link
Collaborator

@dalonsoa dalonsoa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR is massive, as we all know, and I've might have missed something, but it looks good overall.

I've left a couple of comments, but what really confuses me is the separation of concerns. What methods/information goes into the AnimalCohort and what goes into the AnimalModel (and before in the AnimalCommunity. I'm sure there's a pattern, but I just cannot see it.

@TaranRallings TaranRallings merged commit 8873031 into develop Dec 4, 2024
13 checks passed
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.

5 participants