-
Notifications
You must be signed in to change notification settings - Fork 24
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
Support cesm workflow #131
Conversation
This is the script that generates a CUPiD config file based on an existing yaml file. I'm committing it as it was in Ingrid's cesm2_3_beta17 sandbox, for use with CUPiD at hash b402eba; I think it will need to be updated for more recent versions.
generate_cupid_config_file.py now relies on argparse to get a handful of commandline arguments instead of importing some CIME functions and determining these values on the fly (it'll be easy to set all these arguments when creating the template)
I added the
I'm not sure I like the location of the script, which is currently a new |
|
The original version of this code was placed in the CIME source tree, so it could easily import some CIME functions: from standard_script_setup import *
from CIME.case import Case Now that this script is owned by CUPiD, it would need a I do think we could replace
I think we want to keep it separate, especially if we are going to pass
👍 |
1. Only required command line argument is cesm root directory; also allows optional arguments for case directory (default is current dir) and cupid example (default is key_metrics) 2. Now gets case name and short-term archive directory from CESM Case class 3. Cleaned up comment inserted at top of config.yml
Got it, that makes sense. The renaming looks good, too. I'll let you work on that replacement, and then can you please ping me again for review when it's ready? |
This one is ready for review (note the default directory for
|
action="store", | ||
dest="cupid_example", | ||
default="key_metrics", | ||
help="CUPiD example to use as template for config.yml", |
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.
The default as key_metrics is great. Is it worthwhile to mention that the example choices are coupled_model and key_metrics? I'm not sure how many different examples we'll end up having?
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 a tough one -- I'd love to use the choices
argument of add_argument()
along with the os.walk()
function to list the subdirectories of CUPiD/examples/
, but we don't know where the examples/
directory is until we resolve --cesm-root
. The best option is probably to enforce this immediately after entering generate_cupid_config()
by ensuring that os.path.join(cupid_root, "examples", cupid_example)
is a directory and printing out a useful error message if it isn't?
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.
That makes sense that adding the choices
would entail using information we don't have yet. The suggestion you shared sounds great!
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.
The code in bb3f37d has the check and gives the following:
$ ./generate_cupid_config_for_cesm_case.py --cesm-root ${CESM_ROOT} --case-root ${CESM_ROOT}/cases/test_cupid_workflow.007 --cupid-example foo
Traceback (most recent call last):
File "${CESM_ROOT}/tools/CUPiD/helper_scripts/./generate_cupid_config_for_cesm_case.py", line 107, in <module>
generate_cupid_config(**args)
File "${CESM_ROOT}/tools/CUPiD/helper_scripts/./generate_cupid_config_for_cesm_case.py", line 62, in generate_cupid_config
raise KeyError(
KeyError: "--cupid-example must be a subdirectory of ${CESM_ROOT}/tools/CUPiD/examples (['coupled_model', 'key_metrics'])"
Note that both ilamb
and nblibrary
are left off the list of valid_examples
; eventually we'll probably reinstate ilamb
, but for now it doesn't have a config.yml
file. I'd really like to move nblibrary/
out of examples/
but that seems like a big thing to tackle in this PR :)
I should probably add text about 'foo' is not a valid option for --cupid-examples
; I'll get to that in the morning
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.
Sounds good!
Yes, let's move nblibrary out of examples after this PR is merged in.
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.
0888657 has the improved check:
$ ./generate_cupid_config_for_cesm_case.py --cesm-root ${CESM_ROOT} --cupid-example foo
Traceback (most recent call last):
File "${CESM_ROOT}/tools/CUPiD/helper_scripts/./generate_cupid_config_for_cesm_case.py", line 108, in <module>
generate_cupid_config(**args)
File "${CESM_ROOT}/tools/CUPiD/helper_scripts/./generate_cupid_config_for_cesm_case.py", line 63, in generate_cupid_config
raise KeyError(
KeyError: "argument --cupid-example: invalid choice 'foo' (choose from subdirectories of ${CESM_ROOT}/tools/CUPiD/examples: ['coupled_model', 'key_metrics'])"
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.
Fantastic!
"--case-root", | ||
action="store", | ||
dest="case_root", | ||
default=os.getcwd(), |
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.
It may also be worth logging information on what arguments were used?
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.
dba6bea adds information about the arguments to the comment section at the head of the new config.yml
; I think that's the best place to put it but I'm open to other suggestions. (If we use a print()
statement, then I think it will show up in the PBS log file generated by the case.cupid
job, but other queue managers might treat that output differently?)
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 seems like a good place-- especially since the config.yml file also says it's generated by the script, so all that information is in one area.
Just a few minor comments, and otherwise this looks good to me! |
generate_cupid_config_for_cesm_case.py now updates more global parameters (start_date, end_date, climo_nyears, as well as the base_ copies) and the time-series end_years. For now these values are hard-coded in with placeholders until we can get them from env_cupid.xml
I thought that not specifying a default value made it required, but really it just made the default None (which had all sorts of fun implications in the code)
We don't know the full list of valid values when parsing command line arguments, so this check needs to be done in the body of the python script
The header of the YAML file is a little bit bigger; in addition to mentioning the file was auto-generated, it includes each of the three arguments (cesm_root, case_root, and cupid_example)
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 looks great! Thanks for implementing this feature and making all those changes :)
Code changes that will be useful when running CUPiD via the CESM workflow.
All Submissions:
pre-commit
check)?New Feature Submissions:
Changes to Core Features: