-
Notifications
You must be signed in to change notification settings - Fork 27
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
Add support for date-based restart frequency #363
Add support for date-based restart frequency #363
Conversation
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.
This is great! Thanks for the excellent work.
Sorry it has taken so long to finish this review.
I've still not tried it out with a model, which I would like to do, but I didn't want to hold you up and figured this review was long enough as it was.
Hello @jo-basevi! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2023-10-11 00:08:23 UTC |
874b99a
to
27fa74d
Compare
Main changes were removing Other changes were rewriting the calendar tests and added integration-like tests for parsing MOM restart files and the Other Notes Because the logic previously was to not delete the last Other things I got caught out on was the difference between If using frequency While The other thing to keep in mind is that the code currently uses the next kept restart as a reference for the next time interval. This means that restarts saved may not be uniformly a fixed frequency from the first restart if there's irregular time steps. For If instead there was a fixed frequency from the first restart, the restarts kept would be: |
Good catch. Yes i think How does this affect date based pruning though? We can keep
So this is just something that needs to be kept in mind by the user?
The restarts from above were monthly, so I'm confused by
Which is the same as above .. no?
I'm still not sure those restart numbers are correct, or if they are I understand why, so it's a bit hard to make an informed comment on this bit. Just some general questions:
|
Sorry that's my bad!! I deleted the list of restarts I was talking about. So here is the list of restarts I was referring to:
|
Yes, using 1YS would save the restart where current model run time is the earliest of each year.
Would that require saving the previous restart frequency as an enviroment variable? Changing to a longer As archive() runs after each experiment run, if there is greater than 1 restart to prune, that will indicate that either:
Instead of saving previous state, during setup and if archive is enabled, I could inspect what restarts it would prune (but not actually delete them..). If How does that sound? Running that check in setup would also have the benefit for any warnings regarding invalid |
Ok, an idea for an simple algorithm pattern to keep intermediate restarts is: restarts_to_prune = []
intermediate_restarts = []
for restart in restarts:
if restart_should_be_pruned():
# keep track of intermediate restarts
intermediate_restarts.append(intermediate_restarts)
else: # restart should be saved
# add prior intermediate restarts to the list of restarts_to_prune
restarts_to_prune.extend(intermediate_restarts)
intermediate_restarts = [] This will work for both integer and date_based frequency and wouldn't require a |
That sounds like a great idea, thanks. I definitely think there is potential for Bad ThingsTM to happen, and checks and emitting information to the user is a good idea. I definitely can see a use-case for someone to decide to change their But I think we want to make this sort of mass-deletion an interactive only option. So warn that lots of restarts would be the result of the next Specifying flags isn't something you can do as part of an automated run, so by default it has to be done interactively. |
- Move logic for deciding what restarts to prune to Experiment.prune_restarts() - Extend access-om2 and mom driver to parse restart files for a cftime datetime - Add functionality to calendar.py to parse date-based frequency values and add these intervals to different datetimes
- remove logic for Y,M frequency offsets as YS/MS may be sufficient in this case - rewrite/parametrize calendar tests - add tests for mom-driver parsing restart files - add integration tests for prune_restarts and access-om2 model driver - add documentation on date-based restart freq and restart_history - refactor make/list/del restart dir test code to common
… pruning - Moved restart parsing code in Mom driver to Fms so it can also work with Mom6 - Add checks to setup for invalid restart pruning configuration or warn if there's changes - add --force-prune-restarts flag to run and archive cmds - add restart_history as an override to how many latest restarts to keep
25b12e8
to
56f45da
Compare
New Changes Support for both mom5 and mom6 models
Intermediate restarts and restart_hisory
Force restart pruning
|
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.
Looks great, thanks for all the work.
A couple of comments, maybe a change, but otherwise good to go I think.
I was wrong when I said this was FMS based, I mean, they're all FMS based, and so end up using the same convention, but the naming of the file is in the model driver code, not FMS. Regardless I think it is the right decision to put the code in the FMS driver for the moment. I guess longer term the best option might be to put it in a mixin class and inherit that from the models that use |
- Allow regex to support restart/output dirs with counter > 999 - Add test cases for restart_history smaller/greater than restart_freq
e751869
to
bc0aa45
Compare
Thanks for the review @aidanheerdegen! I've added in the suggested changes and the small fix to counter > 999. Should close #372 |
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.
Looks great!
I've replied where appropriate and resolved all the conversations, so good to merge. |
Add support for date-based restart pruning in Payu - should close #358.
As suggested by @aidanheerdegen here, an option is to support a subset of pandas date offset frequency aliases:
So for example, if in
config.yaml
,Then the earliest restart of the year, every 5 years from the first restart will be retained.
During archive, the function
Experiment.prune_restarts()
would inspect each restart directory and return a list of restart directories that can removed using integer or date-based restart frequency. For date-based frequency, individual restart directory paths are passed to the model specific driver that can parse the restart files and return a cftime (or standard) datetime object.In this branch,
access-om2
has themodel.get_restart_datetime()
function implemented, which calls the mom'sget_restart_datetime()
which parses theocean_solo.res
file for the final datetime of the restart. I used this file as it is what is used in COSIMA's tidy_restarts script and it also contains information on what calendar it is using.Currently the month (M) and year (Y) frequencies are defined similar to adding relativedelta's month and years. So for example if a datetime was 15/01/2000, after adding an offset of '6M' it would be 15/07/2000. I have only just noticed that 'M' in pandas documentation is actually the end of the month.. Would the end of the month/year be more useful? Also, with the different cftime calendars M and Y could give unexpected results i.e with different day months. For example, I've got some logic for cftime's
360_day
,noleap
andall_leap
calendars but nothing yet for thejulian
calendar. Also would the start of month/year (MS/YS) frequencies be sufficient- Is M and Y frequencies even needed?Week, day, hour, minute frequencies may not be super useful or even necessary but they were easy to add as adding timedeltas is supported with both cftime and standard datetime calendars.
The first restart datetime is used as a point of reference for adding the first frequency interval. Then the next restart with a datetime at or after this checkpoint is kept and then becomes the reference when adding the next time interval. I think using the most recent "kept" datetime as a reference for the next checkpoint could be better than strict regular intervals from the earliest datetime. As the first restart could eventually be lost due to scratch timeouts and using "YS"/"MS" would still keep the earliest restarts in each year/month.
As one of the motivations for date-based restart frequencies was to make syncing restarts to a remote archive easier as payu would know what restarts could be stored permanently. A way to check if a restart would eventually be removed would be to see if the restart directory was in the list returned by
prune_restarts(from_n_restart=restart_history - 1, to_n_restart:self.counter)
whererestart_history
is the config.yaml or default value of how many latest restarts are kept.Any feedback, questions or suggestions is much appreciated!