Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
a0aab1c
tasks updated
JoeWaddell May 5, 2024
30e440e
added sobol sampler
JoeWaddell May 5, 2024
b5c7ef1
sobol1k run
JoeWaddell May 6, 2024
828b889
analytical methods and new input files
JoeWaddell May 13, 2024
40c8fba
analysis updates
JoeWaddell May 14, 2024
3acd668
analysis updates only inputs
JoeWaddell May 23, 2024
d5b4db0
inputs_to_collate analysis
JoeWaddell May 23, 2024
538b81a
outputs_to_collate
JoeWaddell May 23, 2024
693747f
analysis updates- bugfix
JoeWaddell May 24, 2024
c6be8cc
analyze SA updates
JoeWaddell Jun 5, 2024
3577b42
Merge branch 'main' into sobol
JoeWaddell Jun 27, 2024
908bfd1
updated inputs
JoeWaddell Jun 28, 2024
1f90393
morris analysis
JoeWaddell Jun 28, 2024
7e22e0d
input bound updates
JoeWaddell Jul 12, 2024
e29dee3
removed cull params from inputs, updated task manager metadata
JoeWaddell Jul 12, 2024
28d49e9
tasks update
JoeWaddell Jul 13, 2024
3e949b8
added minimum new stall size of 1
JoeWaddell Jul 17, 2024
9bc9c32
updated minimums in test sobol animal tasks
JoeWaddell Jul 17, 2024
159d605
minimum daily milk of 1 kg
JoeWaddell Jul 17, 2024
f9ff78b
added Catastrophic ration formulation error
JoeWaddell Jul 17, 2024
7a32110
added bound clipping
JoeWaddell Jul 17, 2024
570c8b4
analysis updates
JoeWaddell Jul 17, 2024
0f45153
ration fixes from other branches
JoeWaddell Jul 22, 2024
0ddee70
another task file
JoeWaddell Jul 22, 2024
af726fc
exploratory analysis updates
JoeWaddell Jul 29, 2024
96054f8
fix for gestation_length - AnimalBase.config["days_in_preg_when_dry"]
JoeWaddell Aug 1, 2024
f46ef5a
try_catch
matthew7838 Aug 2, 2024
35de46f
try_catch
matthew7838 Aug 2, 2024
ed9260f
return
matthew7838 Aug 8, 2024
338b782
Revert "return"
matthew7838 Aug 8, 2024
58e73cd
Revert "try_catch"
matthew7838 Aug 8, 2024
112e777
return
matthew7838 Aug 8, 2024
79735d6
checkout
matthew7838 Aug 8, 2024
16ee562
removing the try catch
matthew7838 Aug 8, 2024
ac9c764
input file updates
JoeWaddell Aug 10, 2024
1f4c513
Merge branch 'sobol' of https://github.com/RuminantFarmSystems/MASM i…
JoeWaddell Aug 10, 2024
64b0593
Merge branch 'dev' into sobol
JoeWaddell Aug 10, 2024
e71c439
Merge 64b05932504da818c87f75e4c5d744b09a793401 into ea84f288f884aa53f…
JoeWaddell Aug 10, 2024
1b256d5
Apply Black Formatting
github-actions[bot] Aug 10, 2024
51cc63e
Update badges on README
JoeWaddell Aug 10, 2024
2a17534
fixing lfkae8 errors
JoeWaddell Aug 10, 2024
7837069
Merge branch 'sobol' of https://github.com/RuminantFarmSystems/MASM i…
JoeWaddell Aug 10, 2024
3c77433
Merge 783706940e31bc1397102b60e9312a29321ac21f into ea84f288f884aa53f…
JoeWaddell Aug 10, 2024
61d3b51
Apply Black Formatting
github-actions[bot] Aug 10, 2024
8e8e2d8
Update badges on README
JoeWaddell Aug 10, 2024
d3b40fd
Merge branch 'dev' into sobol
JoeWaddell Aug 13, 2024
c839f58
Merge d3b40fde7a385654e0e00439cd20baffbb4b7733 into 1fac8c1b6231eb3a8…
JoeWaddell Aug 13, 2024
ba6cafa
Apply Black Formatting
github-actions[bot] Aug 13, 2024
dcb53b9
Update badges on README
JoeWaddell Aug 13, 2024
fdcbddc
updated optimizer to catch warnings and correct RUP
JoeWaddell Aug 14, 2024
1f164f2
updated MP calcs in ration driver
JoeWaddell Aug 14, 2024
b435f59
added catch in requirements for complex number
JoeWaddell Aug 14, 2024
e23fdcf
days_in_preg_when_dry temporary fix
JoeWaddell Aug 14, 2024
dfe133a
temp fix self.days_in_preg >= self.gestation_length
JoeWaddell Aug 14, 2024
ae2e0d6
changed days_in_preg_when_dry bound
JoeWaddell Aug 15, 2024
f059c5f
Merge branch 'dev' into sobol
JoeWaddell Aug 22, 2024
91be788
Merge f059c5ffb592174ba8c49bc71d749bb8bf1d0d80 into e3a36c4aeaa869f3b…
JoeWaddell Aug 22, 2024
8c5c301
Apply Black Formatting
github-actions[bot] Aug 22, 2024
d3e6ed7
Update badges on README
JoeWaddell Aug 22, 2024
9f3a26d
updated task file for benchmark
JoeWaddell Aug 22, 2024
39c2fc7
Merge branch 'sobol' of https://github.com/RuminantFarmSystems/MASM i…
JoeWaddell Aug 22, 2024
e792ed2
Merge 39c2fc773a593e9cd27b354743cac238ab02fd7b into e3a36c4aeaa869f3b…
JoeWaddell Aug 22, 2024
4105a44
Apply Black Formatting
github-actions[bot] Aug 22, 2024
5f41535
adjusted protein upper limit factor
JoeWaddell Aug 22, 2024
41f60cf
Merge 5f41535c2e3f07b854f68cd9194388e1daf5b032 into e3a36c4aeaa869f3b…
JoeWaddell Aug 22, 2024
befd0bf
Apply Black Formatting
github-actions[bot] Aug 22, 2024
6154655
updated feed prices
JoeWaddell Aug 24, 2024
2198d9f
Merge branch 'sobol' of https://github.com/RuminantFarmSystems/MASM i…
JoeWaddell Aug 24, 2024
efd501c
Create get_runtime.py
allisterakun Aug 28, 2024
1cde023
added crude util logic to accept numerical dict key
JoeWaddell Aug 28, 2024
053b3b0
updated crude in progress analytical scripts
JoeWaddell Aug 28, 2024
46c9785
updated tasks file and metadata
JoeWaddell Aug 28, 2024
22169d9
analytical updates
JoeWaddell Sep 18, 2024
b7d6afc
updated and reorganized analysis scripts
JoeWaddell Oct 2, 2024
c4e0c9f
updated for benchmarking
JoeWaddell Nov 25, 2024
e5c338f
updated names, balancing
JoeWaddell Nov 25, 2024
df11084
Merge branch 'dev' into sobol
JoeWaddell Jan 30, 2025
712a151
moved analytical scripts, archived old input sheets
JoeWaddell Jan 30, 2025
4cd1cc0
brought feed back to dev
JoeWaddell Jan 30, 2025
c467424
reverting defaults
JoeWaddell Jan 30, 2025
bafd5ba
Merge c467424f00846b13084c32fa015f6915b522acb3 into 72cb55044cb51716d…
JoeWaddell Jan 30, 2025
776ba0e
Apply Black Formatting
github-actions[bot] Jan 30, 2025
5ae3cae
Update badges on README
JoeWaddell Jan 30, 2025
6598021
updated useful analytical scripts, removed deprecated
JoeWaddell Jan 30, 2025
45f70a4
Merge branch 'sobol' of https://github.com/RuminantFarmSystems/MASM i…
JoeWaddell Jan 30, 2025
7d6a2e7
Merge 45f70a4b67f0120ad05cd42feff301d038ac5500 into 72cb55044cb51716d…
JoeWaddell Jan 30, 2025
ef45950
Apply Black Formatting
github-actions[bot] Jan 30, 2025
09540e1
removed debugging statements
JoeWaddell Jan 30, 2025
66c8a3b
Merge branch 'sobol' of https://github.com/RuminantFarmSystems/MASM i…
JoeWaddell Jan 30, 2025
ba5349c
Merge 66c8a3bce2d29a7484128ea9342393bef5e916af into 72cb55044cb51716d…
JoeWaddell Jan 30, 2025
67b5aa6
Apply Black Formatting
github-actions[bot] Jan 30, 2025
cdddff5
updating bounds
JoeWaddell Feb 4, 2025
a684903
Merge branch 'sobol' of https://github.com/RuminantFarmSystems/MASM i…
JoeWaddell Feb 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[![Flake8](https://img.shields.io/badge/Flake8-passed-brightgreen)](https://github.com/RuminantFarmSystems/MASM/actions/workflows/combined_format_lint_test_mypy.yml)
[![Pytest](https://img.shields.io/badge/Pytest-passed-brightgreen)](https://github.com/RuminantFarmSystems/MASM/actions/workflows/combined_format_lint_test_mypy.yml)
[![Coverage](https://img.shields.io/badge/Coverage-96%25-brightgreen)](https://github.com/RuminantFarmSystems/MASM/actions/workflows/combined_format_lint_test_mypy.yml)
[![Flake8](https://img.shields.io/badge/Flake8-failed-red)](https://github.com/RuminantFarmSystems/MASM/actions/workflows/combined_format_lint_test_mypy.yml)
[![Pytest](https://img.shields.io/badge/Pytest-failed-red)](https://github.com/RuminantFarmSystems/MASM/actions/workflows/combined_format_lint_test_mypy.yml)
[![Coverage](https://img.shields.io/badge/Coverage-%25-red)](https://github.com/RuminantFarmSystems/MASM/actions/workflows/combined_format_lint_test_mypy.yml)
[![Mypy](https://img.shields.io/badge/Mypy-3453%20errors-red)](https://github.com/RuminantFarmSystems/MASM/actions/workflows/combined_format_lint_test_mypy.yml)



# Vision
To support research and sustainable decision-making in ruminant animal production through a state-of-the-art, open-source modeling environment that is continuously adapting as technology and scientific knowledge advance.

Expand Down
2 changes: 1 addition & 1 deletion RUFAS/routines/animal/animal_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ def _calc_max_animal_spaces_per_pen(cls, num_stalls: int, max_stocking_density:
if num_stalls < 0 or max_stocking_density < 0:
raise ValueError("The number of stalls and maximum stocking density must be greater than or equal to 0.")

return int(num_stalls * max_stocking_density)
return max(int(num_stalls * max_stocking_density), 1)

@classmethod
def _calc_animal_space_shortage(cls, num_animals: int, pens: List[Pen]) -> int:
Expand Down
14 changes: 9 additions & 5 deletions RUFAS/routines/animal/life_cycle/cow.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def milking_update(self, sim_day: int, calving_interval: int | float) -> None:
Journal of Dairy Science, Volume 105, Issue 9, 2022,
Pages 7525-7538, ISSN 0022-0302.
"""
if self.days_in_preg == AnimalBase.config["days_in_preg_when_dry"]:
if self.days_in_preg >= AnimalBase.config["days_in_preg_when_dry"]:
self.milking = False
self.events.add_event(self.days_born, sim_day, const.DRY)
self.days_in_milk = 0
Expand Down Expand Up @@ -716,9 +716,13 @@ def get_bw_change(self, CI: int | float) -> float: # noqa
if self.days_in_preg == AnimalBase.config["days_in_preg_when_dry"] - 1:
self.tissue_changed = 40 * self.days_in_milk / 70 * math.exp(1 - self.days_in_milk / 70)
else: # dry period
bodyweight_tissue = self.tissue_changed / (
self.gestation_length - AnimalBase.config["days_in_preg_when_dry"]
)
# TODO
Copy link
Collaborator

Choose a reason for hiding this comment

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

If there's no linked issue to this, either the issue should be created or the comment should be deleted.

try:
bodyweight_tissue = self.tissue_changed / (
self.gestation_length - AnimalBase.config["days_in_preg_when_dry"]
)
except Exception as e:
bodyweight_tissue = 0.0
Comment on lines 724 to 725
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you're trying to catch division by zero error here. that could be more specific in the except statement.


return target_adg_cow + conceptus_growth + bodyweight_tissue

Expand Down Expand Up @@ -748,7 +752,7 @@ def update(self, sim_day: int, calving_interval: int | float) -> bool: # noqa
new_born = False
self.days_born += 1

if self.days_in_preg > 0 and self.days_in_preg == self.gestation_length:
if self.days_in_preg > 0 and self.days_in_preg >= self.gestation_length:
self._repro_state_manager.reset()
self.calves += 1
self.milking = True
Expand Down
2 changes: 1 addition & 1 deletion RUFAS/routines/animal/life_cycle/heiferIII.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def update(self, sim_day: int) -> bool:
self.body_weight = self.mature_body_weight
self.events.add_event(self.days_born, sim_day, const.MATURE_BODY_WEIGHT_REGULAR)

if self.days_in_preg == self.gestation_length:
if self.days_in_preg >= self.gestation_length:
self.days_born -= 1 # will be incremented again in next stage
cow_stage = True
return cow_stage
2 changes: 1 addition & 1 deletion RUFAS/routines/animal/life_cycle/life_cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def daily_update(
self._calculate_cull_reason_stats_percent()
self._calculate_percent_cow_per_parity()

self.daily_milk_production = sum(cow.estimated_daily_milk_produced for cow in cows)
self.daily_milk_production = max(1.0, sum(cow.estimated_daily_milk_produced for cow in cows))
self.dry_cows_daily_milk_production = sum(cow.estimated_daily_milk_produced for cow in cows if not cow.milking)
self.herd_milk_fat_kg = sum(cow.milk_fat_kg for cow in cows if cow.milking)
self.herd_milk_fat_percent = (self.herd_milk_fat_kg / self.daily_milk_production) * 100
Expand Down
2 changes: 2 additions & 0 deletions RUFAS/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def flatten_keys_to_nested_structure(input_dict: Dict[str, Any]) -> Dict[str, An
current.append([] if next_key_is_digit else {})
current = current[key]
else:
if key.startswith("numberaskey"):
key = key.replace("numberaskey", "")
if isinstance(current, list):
current = current[-1]
if key not in current:
Expand Down
22 changes: 22 additions & 0 deletions helpful_scripts/get_runtime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
This script simply checks the runtimes for all simulations that have been run.
Useful for benchmarking when running large batches of simulations, especially sensitivity analyses.
"""

import json
import os

import numpy as np

logs_dir = "output/logs/"

logs_files = [log_file for log_file in os.listdir(logs_dir) if "logs" in log_file and "benchmark" in log_file]

run_times = []

for log_file in logs_files:
with open(logs_dir + log_file) as log_fp:
log_dict = json.load(log_fp)
run_times.append(float(log_dict["SimulationEngine.simulate.total_simulation_time"]["values"][0].split(": ")[1]))

print(np.mean(run_times))
202 changes: 202 additions & 0 deletions input/data/animal/default_animal_100x.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
{
"herd_information": {
"calf_num": 800,
"heiferI_num": 4400,
"heiferII_num": 3800,
"heiferIII_num_springers": 500,
"cow_num": 10000,
"replace_num": 50000,
"herd_num": 10000,
"breed": "HO",
"parity_fractions": {
"1": 0.386,
"2": 0.281,
"3": 0.333
},
"annual_milk_yield": null
},
"herd_initialization": {
"initial_animal_num": 10000,
"simulation_days": 5000
},
"animal_config": {
"management_decisions": {
"breeding_start_day_h": 380,
"heifer_repro_method": "ED",
"cow_repro_method": "ED-TAI",
"semen_type": "conventional",
"days_in_preg_when_dry": 218,
"heifer_repro_cull_time": 500,
"do_not_breed_time": 185,
"cull_milk_production": 30,
"cow_times_milked_per_day": 3,
"milk_fat_percent": 4,
"milk_protein_percent": 3.2
},
"farm_level": {
"calf": {
"male_calf_rate_sexed_semen": 0.1,
"male_calf_rate_conventional_semen": 0.53,
"keep_female_calf_rate": 1,
"wean_day": 60,
"wean_length": 7,
"milk_type": "whole"
},
"repro": {
"voluntary_waiting_period": 50,
"conception_rate_decrease": 0.026,
"decrease_conception_rate_in_rebreeding": false,
"decrease_conception_rate_by_parity": false,
"avg_gestation_len": 276,
"std_gestation_len": 6,
"prefresh_day": 21,
"calving_interval": 400,
"heifers": {
"estrus_detection_rate": 0.9,
"estrus_conception_rate": 0.6,
"repro_sub_protocol": "5dCG2P",
"repro_sub_properties": {
"conception_rate": 0.6,
"estrus_detection_rate": 0.9
}
},
"cows": {
"estrus_detection_rate": 0.6,
"ED_conception_rate": 0.5,
"presynch_program": "Double OvSynch",
"presynch_program_start_day": 50,
"ovsynch_program": "OvSynch 56",
"ovsynch_program_start_day": 64,
"ovsynch_program_conception_rate": 0.6,
"resynch_program": "TAIafterPD"
}
},
"bodyweight": {
"birth_weight_avg_ho": 43.9,
"birth_weight_std_ho": 1,
"birth_weight_avg_je": 27.2,
"birth_weight_std_je": 1,
"target_heifer_preg_day": 399,
"mature_body_weight_avg": 740.1,
"mature_body_weight_std": 73.5
}
},
"from_literature": {
"repro": {
"preg_check_day_1": 32,
"preg_loss_rate_1": 0.02,
"preg_check_day_2": 60,
"preg_loss_rate_2": 0.096,
"preg_check_day_3": 200,
"preg_loss_rate_3": 0.017,
"avg_estrus_cycle_return": 23,
"std_estrus_cycle_return": 6,
"avg_estrus_cycle_heifer": 21,
"std_estrus_cycle_heifer": 2.5,
"avg_estrus_cycle_cow": 21,
"std_estrus_cycle_cow": 4,
"avg_estrus_cycle_after_pgf": 5,
"std_estrus_cycle_after_pgf": 2
},
"culling": {
"cull_day_count": [0, 5, 15, 45, 90, 135, 180, 225, 270, 330, 380, 430, 480, 530],
"feet_leg_cull": {
"probability": 0.1633,
"cull_day_prob": [0, 0.03, 0.08, 0.16, 0.25, 0.36, 0.48, 0.59, 0.69, 0.78, 0.85, 0.90, 0.95, 1]
},
"injury_cull": {
"probability": 0.2883,
"cull_day_prob": [0, 0.08, 0.18, 0.28, 0.38, 0.47, 0.56, 0.64, 0.71, 0.78, 0.85, 0.90, 0.95, 1]
},
"mastitis_cull": {
"probability": 0.2439,
"cull_day_prob": [0, 0.06, 0.12, 0.19, 0.30, 0.43, 0.56, 0.68, 0.78, 0.85, 0.90, 0.94, 0.97, 1]
},
"disease_cull": {
"probability": 0.1391,
"cull_day_prob": [0, 0.04, 0.12, 0.24, 0.34, 0.42, 0.50, 0.57, 0.64, 0.72, 0.81, 0.89, 0.95, 1]
},
"udder_cull": {
"probability": 0.0645,
"cull_day_prob": [0, 0.12, 0.24, 0.33, 0.41, 0.48, 0.55, 0.62, 0.68, 0.76, 0.82, 0.89, 0.95, 1]
},
"unknown_cull": {
"probability": 0.1009,
"cull_day_prob": [0, 0.05, 0.11, 0.18, 0.27, 0.37, 0.45, 0.54, 0.62, 0.70, 0.77, 0.84, 0.92, 1]
},
"parity_death_prob": [0.039,0.056,0.085,0.117],
"parity_cull_prob": [0.169, 0.233, 0.301, 0.408],
"death_day_prob": [0, 0.18, 0.32, 0.42, 0.48, 0.54, 0.60, 0.65, 0.70, 0.77, 0.83, 0.89, 0.95, 1]
},
"life_cycle": {
"still_birth_rate": 0.065
}
}
},
"methane_mitigation": {
"methane_mitigation_method": "None",
"methane_mitigation_additive_amount": 0,
"3-NOP_additive_amount": 70,
"monensin_additive_amount": 24,
"essential_oils_additive_amount": 0,
"seaweed_additive_amount": 0
},
"housing": "barn",
"pasture_concentrate": 0,
"methane_model": "IPCC",
"ration": {
"phosphorus_requirement_buffer": 0,
"user_input": false,
"formulation_interval": 30
},
"pen_information": [
{
"id": 0,
"pen_name": "",
"animal_combination": "CALF",
"vertical_dist_to_milking_parlor": 0.1,
"horizontal_dist_to_milking_parlor": 10,
"number_of_stalls": 3000,
"housing_type": "open air barn",
"pen_type": "freestall",
"max_stocking_density": 1.2,
"manure_management_scenario_id": 0
},
{
"id": 1,
"pen_name": "",
"animal_combination": "GROWING",
"vertical_dist_to_milking_parlor": 0.1,
"horizontal_dist_to_milking_parlor": 10,
"number_of_stalls": 12500,
"housing_type": "open air barn",
"pen_type": "freestall",
"max_stocking_density": 1.2,
"manure_management_scenario_id": 1
},
{
"id": 2,
"pen_name": "",
"animal_combination": "CLOSE_UP",
"vertical_dist_to_milking_parlor": 0.1,
"horizontal_dist_to_milking_parlor": 10,
"number_of_stalls": 6000,
"housing_type": "open air barn",
"pen_type": "freestall",
"max_stocking_density": 1.2,
"manure_management_scenario_id": 2
},
{
"id": 3,
"pen_name": "",
"animal_combination": "LAC_COW",
"vertical_dist_to_milking_parlor": 0.1,
"horizontal_dist_to_milking_parlor": 10,
"number_of_stalls": 15000,
"housing_type": "open air barn",
"pen_type": "freestall",
"max_stocking_density": 1.2,
"manure_management_scenario_id": 5
}
]
}
Loading