Conversation
There was a problem hiding this comment.
@xylar @chengzhuzhang I have more work to do, but I think I have the main idea of the refactor captured in this pull request and the corresponding E3SM-Project/zppy#642.
I should stress I haven't run this code yet. I still need to get the environments sorted out to be able to call zppy-interfaces from zppy. That is, while I think the main idea is captured here, there is still polishing/testing work left. However, I wanted to tag you here to allow for any further design input early on.
Specifically, my remaining action items:
- Create a
condadirectory and setup the yaml/toml files necessary to produce a dev environment. - Use
zppyto generate stand-alonetsandmpas_analysisoutput. - Run
global-time-seriesinterface in the dev environment on that output. - Run the
global_time_seriestask in zppy (i.e., make surezppycan correctly callzppy-interfaces). - Create a
tests/directory and add some integration tests.zppyshould simply test that it can invokezppy-interfaces global-time-series.zppy-interfaceshowever should test that Global Time Series plots actually generate correctly. As for unit tests, E3SM-Project/zppy#616 will do that once it's ported to this repo. - Add pre-commit checks
- Add documentation for this repo/package.
zppy-interfaces/__main__.py
Outdated
| if args.interface == "global_time_series": | ||
| global_time_series.global_time_series() |
There was a problem hiding this comment.
I'm following zstash's design here: have one arg parser for the package as a whole (e.g., https://github.com/E3SM-Project/zstash/blob/main/zstash/main.py#L34) and one each for the individual utilities [commands in zstash or interfaces in this package] (e.g., https://github.com/E3SM-Project/zstash/blob/main/zstash/create.py#L103)
The result is that calling the global time series code would be done via:
zppy-interfaces global-time-series <args>
There was a problem hiding this comment.
@forsyth2, this seems like a bit of a clunky interface to me. Since the tools don't have much to unify them, I would just given them individual entry points. You could give them a unique prefix like zi-global-time-series if you like.
zstash is a coherent package with clear subcommands similar to git or conda so it makes sense to use this kind of an approach there but I think zppy-interfaces doesn't clearly benefit in the same way.
There was a problem hiding this comment.
This is obviously just my opinion. You can stick with the zppy-intefaces main command with subcommands if you like.
There was a problem hiding this comment.
@xylar If we do completely separate commands, would it make more sense to have distinct dependency requirement lists too? (As opposed to a single dev.yml for all of zppy-interfaces). I'm not sure if that was something we had decided on.
There was a problem hiding this comment.
I could see several utilities being useful to multiple interfaces -- for example, the OutputViewer class for Global Time Series that E3SM-Project/zppy#616 will introduce will also be useful for adding Viewers to the PMP task in E3SM-Project/zppy#640. It follows that it may be useful to have a single dev environment for all of zppy-interfaces.
There was a problem hiding this comment.
@xylar If we do completely separate commands, would it make more sense to have distinct dependency requirement lists too? (As opposed to a single
dev.ymlfor all ofzppy-interfaces). I'm not sure if that was something we had decided on.
No, I would just have a single set of dependencies that covers the full package (all commands and any public functions, etc.).
There was a problem hiding this comment.
I could see several utilities being useful to multiple interfaces -- for example, the
OutputViewerclass for Global Time Series that E3SM-Project/zppy#616 will introduce will also be useful for adding Viewers to the PMP task in E3SM-Project/zppy#640. It follows that it may be useful to have a single dev environment for all ofzppy-interfaces.
Yes, and there should be a place for a common framework that includes things like this.
|
I made a few suggestions but this is looking great so far! you'll need some more "glue" like |
|
Thanks @xylar! |
forsyth2
left a comment
There was a problem hiding this comment.
Notes on latest changes
| import unittest | ||
| from typing import Any, Dict, List | ||
|
|
||
| from zppy_interfaces.global_time_series.coupled_global import ( |
There was a problem hiding this comment.
Need to figure out how to import the code properly to the tests.
I've moved many of the tests and the modularized/refactored functions from E3SM-Project/zppy#616 directly into this pull request. Specifically I've moved the changes that are more general refactoring and not specific to Land support or Viewer generation.
| coupled_global.coupled_global(parameters) | ||
|
|
||
|
|
||
| # TODO: replace command line arguments with _get_cfg_parameters, like https://github.com/E3SM-Project/e3sm_diags/blob/main/e3sm_diags/parser/core_parser.py#L809 |
There was a problem hiding this comment.
I do think a cfg would be cleaner, but I want to get this all working properly first before spending time on that.
forsyth2
left a comment
There was a problem hiding this comment.
Ok I think we're close to being able to replicate existing functionality using the split-repo approach.
3 issues remaining, noted as part of this review.
|
@forsyth2, haven't heard anything further on this. Has this just had to move to the back burner or are you stuck anywhere that @altheaden, @tomvothecoder or I could help with? |
@xylar Yes, competing priorities at the moment unfortunately. Hoping to get back to this sometime this week. |
While that's fine, it should also be possible to use the entry point after you've run |
Updating conda buildPreviously had this defined in Deleted that block. Ran Went to https://github.com/conda-forge/miniforge (full link was giving a security error) Now, this is at the end of my Wrapped that in a function to call myself rather than having it auto-run: Creating new environmentsTesting/debuggingRe: #1 (comment) -- running the entry point requires the parameters be passed in on the command line. (It runs the Edit python tests/integration/utils.py
zppy -c tests/integration/generated/test_min_case_global_time_series_original_8_chrysalis.cfg
# Wait for that to finish
cd /lcrc/group/e3sm/ac.forsyth2/zppy_min_case_global_time_series_original_8_output/test-642-working-env-20241121/v3.LR.historical_0051/post/scripts
cat global_time_series_1985-1995.o632171 That gives: In the Re: #1 (comment) -- the Made some edits in the cd /lcrc/group/e3sm/ac.forsyth2/zppy_min_case_global_time_series_original_8_output/test-642-working-env-20241121/v3.LR.historical_0051/post/scripts
rm -rf global_time_series_1985-1995* # Allow us to re-run just the global_time_series part
cd /home/ac.forsyth2/ez/zppy
pip install .
python tests/integration/utils.py
zppy -c tests/integration/generated/test_min_case_global_time_series_original_8_chrysalis.cfgThe Continued various debugging attempts on both the which seems to be the opposite problem. Looks like the issue is the args actually have to be defined with zppy successfully generating plots by calling zppy-interfacesActually got zppy to call zppy-interfaces successfully. Still have the TS error on the zppy-interfaces side though. After more debugging, was successful in getting plots to show up at https://web.lcrc.anl.gov/public/e3sm/diagnostic_output/ac.forsyth2/zppy_min_case_global_time_series_original_8_www/test-642-working-env-20241121/v3.LR.historical_0051/global_time_series/global_time_series_1985-1995_results/ |
Cleaning up the codeMade edits to both This included build updates for Rerun min-caseRerun the min-case to make sure everything still works: Edit Run unit tests
All unit tests are now passing. |
There was a problem hiding this comment.
I think I have the initial implementation of the zppy/zppy-interfaces refactor done.
[Required reviewers] @xylar @chengzhuzhang I'd like to get approval from both of you before merging this.
[Optional reviewers] @tomvothecoder @altheaden you may want to review the conda/build portions of this PR.
Remaining to-do
After the refactor PRs merge:
- Run
zppy's Weekly tests onmainto make sure everything is still working properly after the merges. - Adjust the land support/Viewer generation PR (E3SM-Project/zppy#616) accordingly
- Help integrate the PMP PR (E3SM-Project/zppy#640) accordingly
Add these as GitHub issues to get to later:
- Add documentation, according to https://docs.e3sm.org/zppy/_build/html/main/contributing.html#initial-setup-obsolete-for-reference-only. (Looks like it's better to do that as its own PR) [definitely need to do this before the Unified release!]
- Add option to specify parameters through cfg rather than command line. E.g., https://github.com/E3SM-Project/e3sm_diags/blob/main/e3sm_diags/parser/core_parser.py#L809
- Switch pre-commit checks to
ruff, as in https://github.com/xCDAT/xcdat/pull/702/files. - Rethink how testing is done in
zppy&zppy-interfaces.zppyshould simply test that it can invokezppy-interfaces global-time-series.zppy-interfaceshowever should test that Global Time Series plots actually generate correctly. Maybe havezppytest thatzppyis passing in the right parameters and then havezppy-interfacesactually do the image comparisons of the plots, using pre-generatedtsandmpas_analysisoutput.
Helpful details for reviewers
This is actually 2 PRs. This one and E3SM-Project/zppy#642.
zppy
- Anything under
tests/integration/generatedcan be ignored. Those are just auto-generated testing files. - I added a
global_time_series-specificenvironment_commandsto the test suite, so thatzppy-interfacescould be used.- This is reflected in the 6 template
cfgs (3 of these templates are "min-case" files which I use for debugging, and the other 3 are the big tests we run roughly weekly onmain. For this PR, I've been debugging with themin_case_global_time_series_original_8min-case.) - Also reflected in
tests/integration/utils.py(This file is used to make run-ablecfgs out of the templates).
- This is reflected in the 6 template
- I organized
zppy/templatesto be more logical.- There is now a subdirectory
zppy/templates/inclusionswhich is for adding text word-for-word. default.iniand the campaign files are now kept inzppy/defaults.zppy/examplesincludes files that aren't actually used anywhere and thus serve only as examples.- The
global_time_series-specific files (coupled_global.py,ocean_month.py,readTS.py) have been moved over tozppy-interfaces/zppy_interfaces/global_time_series, out of thezppyrepo completely. Note, thereadTS.pyfile has been included intocoupled_global.pyand other utilities have been pulled out into a newutils.py. - The
jinja2template bash scripts remain inzppy/templatesitself. - These directory changes can be seen throughout the PR, including in the unit test changes.
- There is now a subdirectory
- Much of
zppy/templates/global_time_series.bashhas been moved over tozppy_interfaces/global_time_series/__main__.pyaspythoncode rather thanbashcode.
zppy-interfaces
This PR
- Conda/build updates:
.flake8,.pre-commit-config.yaml,conda/dev.yml,pyproject.toml,zppy_interfaces/version.py - I noticed many changes in E3SM-Project/zppy#616 were actually more general and not specifically about Land support and/or Viewer generation. I've pulled out those changes (notably refactoring of
coupled_global.pyinto more concise, composable functions & testing those functions in unit tests)- Unit test:
tests/global_time_series/test_global_time_series.py zppy_interfaces/global_time_series/coupled_global.pyandzppy_interfaces/global_time_series/utils.pyreflect these changes.
- Unit test:
- The only entry point right now is
zi-global-time-serieswhich runszppy_interfaces/global_time_series/__main__.py main.- Please note that this modifies the case directory (only the
posts/subdirectory though), which could be seen as modifying the input. However, this was the case before the refactor as well. Pre-refactor, the case dir was defined to be{{ output }}, so we knew we were modifying the directory the user specified as output (which they could have set to be identical to{{ input }}). Now, we sort of assumeoutput dir = input dir = case dir, relying onzppyto pass in the right output dir. - The
if __name__ == "__main__":block of that file is for debugging manually, and is not called byzppy.
- Please note that this modifies the case directory (only the
tomvothecoder
left a comment
There was a problem hiding this comment.
My brief review of the DevOps related files with some comments and suggestions.
I recommend setting up a GH Actions build workflow similar to zppy that runs the pre-commit hooks and unit tests: https://github.com/E3SM-Project/zppy/blob/main/.github/workflows/build_workflow.yml
pyproject.toml
Outdated
| "Programming Language :: Python :: 3.11", | ||
| "Programming Language :: Python :: 3.12", | ||
| "Programming Language :: Python :: 3.13", | ||
|
|
|
Thanks @tomvothecoder! I've implemented your suggestions on both PRs. Details of testingThat gives a warning -- one we're already escaping -- but all tests pass After some edits to the |
|
Thanks for the reviews @xylar! |
chengzhuzhang
left a comment
There was a problem hiding this comment.
Hi @forsyth2 this is exciting change. Thanks for making it happening. I think @xylar and @tomvothecoder had solid reviews for DevOp codes. and things looks promising. I'm approving this PR, it addresses the initial implementation.
Regarding to usability, I'm wondering if it is general enough, for instance, does zi-global-time-series support land only simulation with easy syntax? Maybe the coupled_global.py can be polished a bit. Anyway, these can be addressed in a future PR.
|
Thanks @chengzhuzhang!
|
Thank you @forsyth2 , command line options are good to have as well, just we need to think through all the options and make them intuitive to use. |
|
I added the issues mentioned in #1 (review): #2, #3, #4, #5. I also redid the issue labels (the color tags) to match |
|
It looks like any remaining comments/concerns can be addressed in later pull requests, so I think it's safe to say we have the initial implementation done. I'm going to merge this PR and E3SM-Project/zppy#642. The plan after that is:
|
Initial implementation for
zppy-interfaces. Resolves discussion at E3SM-Project/zppy#641. Implements E3SM-Project/zppy#398.This pull request should be reviewed in conjunction with E3SM-Project/zppy#642.