Skip to content
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

CIME usability problems when using it as a library #3393

Open
jgfouca opened this issue Feb 10, 2020 · 14 comments
Open

CIME usability problems when using it as a library #3393

jgfouca opened this issue Feb 10, 2020 · 14 comments

Comments

@jgfouca
Copy link
Contributor

jgfouca commented Feb 10, 2020

I've long thought that it would be nice to be able to interact with CIME via python, as a library, in addition to the current CLI. It turns out, I'm not the only one and I received indicators of interest for this capability from others in E3SM.

For example, a user should be able to do this:

from CIME.case          import Case
import CIME.build as build
 
caseroot = path_to_case_dir
with Case(caseroot, read_only=False) as case:
  case.create(create_args)
  case.case_setup(setup_args)
  build.case_build(build_args)
  case.submit(submit_args)

This works in theory, but in practice it's quite difficult. The main problem is that case.create takes a ton of arguments and, unlike the CLI which populates fields with reasonable defaults, the defaults to the create function are must less usable.

We should strive to make the defaults for all main CIME entry points be identical regardless of CLI vs. library use (and do this without duplication).

@jgfouca
Copy link
Contributor Author

jgfouca commented Feb 10, 2020

@PeterCaldwell

@jedwards4b
Copy link
Contributor

@jgfouca I do this and it works but I agree that the defaults aren't great.

@jedwards4b
Copy link
Contributor

@jgfouca
Copy link
Contributor Author

jgfouca commented Feb 10, 2020

Thanks, @jedwards4b . So there's interest on CESM side as well.

@billsacks
Copy link
Member

I have used this a little bit in https://github.com/ESCOMP/CTSM/tree/master/python/ctsm but only for some smallish things that don't depend on having a case:

machine.py:from CIME.utils import get_project  # pylint: disable=import-error
run_sys_tests.py:from CIME.test_utils import get_tests_from_xml  # pylint: disable=import-error
run_sys_tests.py:from CIME.cs_status_creator import create_cs_status  # pylint: disable=import-error

I have used this to create a wrapper on top of create_test that adds some functionality that aids the testing workflow of CTSM.

@PeterCaldwell
Copy link
Contributor

I just got E3SM to create, config, build, and run from python. Here's my script: https://gist.github.com/PeterCaldwell/97c23d143ed989caa85792122bcab204 . It wasn't that hard, but it was disappointingly awkward/clunky. Some comments:

  1. My initial attempt didn't work because driver=None by default and driver is assumed later to be a string, causing a slightly hard-to-debug error. Would people be comfortable making the default 'mct' or not giving it a default so the resulting error message is easier to understand?
  2. I'm used to seeing the contents of bld.log scroll by when I'm building. This doesn't happen when you call case.submit directly. I guess I can add this behavior to my python script, but I'm surprised it doesn't occur at the case.submit level.
  3. Behavior when you call case.create, then call it again is really weird: the code crashes with "CIME.utils.CIMEError: ERROR: locked: cannot make child group in file <case_root>/env_case.xml". This error occurs because CIME somehow deletes the existing case directory when you call case.create again. I wouldn't believe this, but the behavior is easy to reproduce. If you call case.create a 3rd time, it finishes with no problem because there wasn't a case already. This seems dangerous - can we fix it?

My goal is to create a python-based run script for E3SM folks to use to document exactly what they did in their run. We currently do that with shell scripts, but python would allow us to make our run scripts much cleaner by hiding standard utilities (like downloading the code from github) in utility functions. It would also be nice for launching perturbed physics ensembles.

@jedwards4b
Copy link
Contributor

@PeterCaldwell the example I provided is to build an ensemble.

@PeterCaldwell
Copy link
Contributor

Ah yes, I saw that. Nice! I'm confused how your case ran without specifying driver in case.create

@jedwards4b
Copy link
Contributor

Ah - it's using our cime5.6 branch which is before we introduced cime_driver. We should be able to change that default to something reasonable.

@PeterCaldwell
Copy link
Contributor

Gotcha, thanks!

@golaz
Copy link
Contributor

golaz commented Feb 25, 2021

Glad to see that this is being re-activated.

@github-actions
Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Jun 13, 2023
@jedwards4b
Copy link
Contributor

I have used this in for example https://github.com/jedwards4b/CESM2-Realtime-Forecast/blob/master/bin/buildcase.py I agree that the interface could be simplified.

@jgfouca jgfouca removed the Stale label Jun 13, 2023
@github-actions
Copy link
Contributor

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants