-
Notifications
You must be signed in to change notification settings - Fork 26
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
Adding date based pruning for ESM #465
Adding date based pruning for ESM #465
Conversation
Hello @blimlim! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2024-07-26 02:46:27 UTC |
Thanks for opening this PR and running some tests! I think the testing is probably sufficient. There's integration-like tests for pruning logic using a couple years of restarts and using Testing has been a bit tricky with setting up Experiment classes which is needed to initialise Model classes. Current tests or functions probably need a rethink to make it more "unit"-ish and include mocking, but that's definitely outside of the scope of this PR! An potential option without creating new tests is to refactor so the def get_restart_datetime_using_mom_submodel(model, restart_path):
"""Given a model object and a restart path, check for
a MOM sub-model and use it's restart files to find a cftime datetime
(for date-based restart pruning)"""
for sub_model in model.expt.models:
if sub_model.model_type == 'mom' :
mom_restart_path = os.path.join(restart_path, sub_model.name)
return sub_model.get_restart_datetime(mom_restart_path)
raise NotImplementedError(
f'Cannot find mom sub-model: {model.model_type} date-based '
'restart pruning requires the mom sub-model to '
'determine restart dates'
) Then in access/access-om2 drivers: def get_restart_datetime(self, restart_path):
"""Given a restart path, parse the restart files and
return a cftime datetime (for date-based restart pruning)"""
# Use mom submodel to determine restart datetimes
get_restart_datetime_using_mom_submodel(model=self, restart_path=restart_path) Having a helper function outside of a That said, it's not a big issue and I'm sure the code you have added works, so I am happy to hit approve on this PR! |
Thanks for reviewing this! I think thats a great idea with the helper function, and it helps avoid copying the exact same code across the different models. I've had a go at copying that in and it still is working with the manual tests of ESM. Would you be happy to have a quick look through those changes? No rush though! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Re-approving the changes
Closes #464
This pull requests adds support for date based restart pruning for ESM1.5, which was previously implemented for the MOM models. As ESM1.5 uses MOM as a submodel, and produces the same ocean date files
ocean_solo.res
in the restart directories, I've just copied theget_restart_datetime
method frommom_mixin.py
intoaccess.py
.I've manually tested it with with different monthly and yearly restart frequencies. E.g. running in month long sections, with
restart_freq: 3MS
for a total of 10 month results in the following archive:Likewise running for 6 months with
restart_freq: 2MS
results inCreating a fake group of restart directories with yearly gaps in their
ocean_solo.res
dates, and running the pruning withrestart_freq: 7YS
also looks like it works (note that restart010 was the first of the fake directories):The implementation and manual tests are both a bit ad-hoc, and so it would be great to get another opinion on whether what's here is sufficient or if its better to try and do it differently.