Skip to content

[Animal] Add Warning for Milk Production Reduction#3099

Open
allisterakun wants to merge 17 commits into
devfrom
milk_production_reduction_warnings
Open

[Animal] Add Warning for Milk Production Reduction#3099
allisterakun wants to merge 17 commits into
devfrom
milk_production_reduction_warnings

Conversation

@allisterakun

@allisterakun allisterakun commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Adds a summary warning in HerdManager.formulate_rations() when any cows have had their milk production reduced due to ration formulation failure, reporting the number of affected animals and the average reduction in kg.

Context

Issue(s) closed by this pull request: closes #1874.

What

  • Added a milk production reduction warning at the end of formulate_rations() in herd_manager.py. After all pens have been reformulated, the method checks if any cows have a milk_production_reduction > 0. If so, it logs a warning via OutputManager.add_warning() with the number of affected animals, the average reduction amount (in kg, formatted to 2 decimal places), and the simulation day.

Why

When a ration cannot be formulated for a cow, the model reduces the cow's milk production to lower nutrient requirements and make formulation feasible. While the reduction amount is collected in the output variables, this was not immediately evident to the user during the simulation. Adding a once-per-ration-formulation-interval warning alerts users that milk production has been reduced, how many animals were affected, and by how much on average, making the behavior transparent without requiring the user to inspect output variables.

How

At the end of formulate_rations(), after all pens have been reformulated, a list comprehension filters self.cows for any cow with milk_production.milk_production_reduction > 0. If the list is non-empty, the average reduction is computed and a warning is logged via self.om.add_warning(). This runs once per ration formulation interval call, summarizing all affected cows in a single warning rather than emitting per-animal warnings.

Test plan

Input Changes

  • N/A

Output Changes

  • N/A

Filter

@github-actions

Copy link
Copy Markdown
Contributor

Current Coverage: 99%

Mypy errors on milk_production_reduction_warnings branch: 1144
Mypy errors on dev branch: 1144
No difference in error counts

@github-actions

Copy link
Copy Markdown
Contributor

🚨 Please update the changelog. This PR cannot be merged until changelog.md is updated.

@github-actions

Copy link
Copy Markdown
Contributor

Current Coverage: %

Mypy errors on milk_production_reduction_warnings branch: 1144
Mypy errors on dev branch: 1144
No difference in error counts

@github-actions

Copy link
Copy Markdown
Contributor

🚨 Some tests have failed.

@allisterakun
allisterakun marked this pull request as ready for review June 16, 2026 13:33
@github-actions

Copy link
Copy Markdown
Contributor

Current Coverage: 99%

Mypy errors on milk_production_reduction_warnings branch: 1144
Mypy errors on dev branch: 1144
No difference in error counts

@allisterakun
allisterakun requested a review from JoeWaddell June 16, 2026 14:14
@allisterakun
allisterakun requested a review from jadamchick July 15, 2026 14:24
@github-actions

Copy link
Copy Markdown
Contributor

Current Coverage: 99%

Mypy errors on milk_production_reduction_warnings branch: 1136
Mypy errors on dev branch: 1136
No difference in error counts

@github-actions

Copy link
Copy Markdown
Contributor

🚨 Please update the changelog. This PR cannot be merged until changelog_WIP.md is updated.

@gmg228 gmg228 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks pretty straightforward to me.
I was easily able to test and successfully view the warning after toying with
(ration formulation (mild/moderate changes), threshold changes of reduced milk production coinciding with extreme ration changes, etc).

This is a clean solution that seems to function well.
Thank you!

@github-actions

Copy link
Copy Markdown
Contributor

Current Coverage: 99%

Mypy errors on milk_production_reduction_warnings branch: 1136
Mypy errors on dev branch: 1136
No difference in error counts

@github-actions

Copy link
Copy Markdown
Contributor

🚨 Please update the changelog. This PR cannot be merged until changelog_WIP.md is updated.

@ew3361zh ew3361zh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm!

Don't forget to update the WIP changelog.

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.

Add warning if milk production is below ideal as predicted by lactation curve

3 participants