Skip to content

Move animals over to the new configuration system#1116

Merged
davidorme merged 10 commits intodevelopfrom
1113-move-animals-over-to-the-new-configuration-system
Nov 2, 2025
Merged

Move animals over to the new configuration system#1116
davidorme merged 10 commits intodevelopfrom
1113-move-animals-over-to-the-new-configuration-system

Conversation

@davidorme
Copy link
Copy Markdown
Collaborator

@davidorme davidorme commented Oct 25, 2025

Description

Mostly this PR is:

  • Moving the animal model and its tests over to using the new Configuration object style.
  • Adding a doc page for the new AnimalModel configuration object, which has been updated slightly to better handle some trickier bits - writing DietType mostly.

However, there is also a deeper change in the model __init__. The current code looks like this:

def __init__(
self,
data: Data,
core_components: CoreComponents,
static: bool = False,
density_scaling_method: str = "madingley",
**kwargs: Any,
):
"""Animal init function.
The init function is used only to define class attributes. Any logic should be
handled in :fun:`~virtual_ecosystem.animal.animal_model._setup`.
"""
self.density_scaling_method = density_scaling_method
"""Which density scaling equations are used, "damuth" or "madingley"."""
self.model_constants: AnimalConsts = AnimalConsts(
density_scaling_method=self.density_scaling_method
)
"""Animal constants."""

The model arguments do not require that users provide a set of model constants. The constants are provided internally - the model __init__ creates a brand new set of constants with the appropriate density scaling but using all of the default values. So users can configure the density scaling but cannot configure anything else.

My solution here is to just use the existing setting inside the constants configuration section to set the method. I've replaced the density_scaling_method: str = "madingley" in __init__ with a required model_constants in _setup. That can then be passed in using _from_config. That also means defining the constants and scaling method in __init__ but delaying setting them until _setup: I think this is closer to how these methods should be defined - only attribute definitions in the __init__. With this setup, users can provide a complete configuration and change defaults and it will be respected by the model. At the moment it gets ignored.

Fixes #1113

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

@davidorme davidorme linked an issue Oct 25, 2025 that may be closed by this pull request
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Oct 26, 2025

Codecov Report

❌ Patch coverage is 96.22642% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.70%. Comparing base (51a5dfe) to head (397a0d4).

Files with missing lines Patch % Lines
...irtual_ecosystem/models/animal/functional_group.py 50.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1116      +/-   ##
===========================================
+ Coverage    94.63%   94.70%   +0.06%     
===========================================
  Files           90       90              
  Lines         7887     7887              
===========================================
+ Hits          7464     7469       +5     
+ Misses         423      418       -5     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@davidorme davidorme marked this pull request as ready for review October 26, 2025 15:11
@davidorme davidorme merged commit 2950f93 into develop Nov 2, 2025
13 checks passed
@davidorme davidorme deleted the 1113-move-animals-over-to-the-new-configuration-system branch November 2, 2025 13:23
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.

Move animals over to the new configuration system

3 participants