Skip to content

fix(python): resolve submodule paths and support nested CESM checkouts (resolves #2658, #3552) - #4207

Merged
slevis-lmwg merged 9 commits into
ESCOMP:b4b-devfrom
johnpaulalex:fix/2658-ccs-config-path
Oct 26, 2026
Merged

slevis-lmwg merged 9 commits into
ESCOMP:b4b-devfrom
johnpaulalex:fix/2658-ccs-config-path

Conversation

@johnpaulalex

@johnpaulalex johnpaulalex commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Issues Resolved


Summary of Changes

(sorry github's markdown parsing appears to be buggy below)

  1. 32c268eb1 refactor(path_utils): Renamed standalone_only parameter to ctsm_only across path_utils, test suites, and run_sys_tests.

    Clearer rename, no-op.

2. **`1f845a87c` `fix(path_utils)`**: Resolved `ccs_config` in standalone CTSM and CESM checkouts, updated `run_tower`, `tower_site`, `gen_mksurfdata_namelist`, and added comprehensive path resolution unit tests (resolves #2658).

 *Added new robust path_utils methods to find CTSM/CESM paths, and called them from various scripts.*

3. **`211a991db` `fix(subset_data)`**: Resolved top-level CESM root in `subset_data` and Python tools (resolves #3552).
*Description is a lie, this is just formatting fixes (making CI happy).*

Added After Review

  1. 0fca53217 fix(path_utils): Ignore empty submodule dirs

    If git isn't going to check out a submodule, it still creates the submodule directory (apparently to reserve it, in case you check it out later). So we can't simply check for existence of a submodule subdir, we need to look for files in it.


5. **`a6ae10439` `fix(python)`**: Update specific scripts to use more path_utils
  • lilac_make_runtime_inputs.py was missing the add_cime_to_path that all the other scripts already have, to find CIME.
  • subset_data.py: resolve user_nl_clm from CTSM root and user_nl_datm_streams from
    enclosing CESM root (if present) in setup_user_mods(). Added unit tests too.

6. **`244e2778c` `test(sys)`**: Use proper paths in script test suites for standalone and CESM layouts

Two tests needed more calls to path_utils


7. 36aec48cc test(fsurdat_modifier): Fix 'short config' test to be able to be run from any directory

This one is orthogonal to everything else, it just gets all the system tests working again.


Answer Impact

Note

Bit-for-bit (B4B): This pull request contains purely Python infrastructure, path utility, and test harness changes. Zero Fortran or scientific model code was modified. Simulation answers are completely unchanged.


Verification & Test Results

The changes have been tested on derecho in both a standalone CTSM and a CTSM-within-CESM repo:

  • python/run_ctsm_py_tests -s -p 'python/ctsm/test/test_sys*.py'
  • python/run_ctsm_py_tests -u
  • ./tools/site_and_regional/subset_data region
    --lat1 -12 --lat2 -7 --lon1 291 --lon2 299
    --create-mesh --create-domain --create-surface
    --surf-year 2000 --create-user-mods
    --outdir /tmp/subset_out --user-mods-dir /tmp/subset_usermods
    --inputdata-dir python
    --cfg-file python/ctsm/test/testinputs/subset_data_amazon.cfg
    --overwrite --reg TMP
  • python/ctsm/site_and_regional/run_tower.py
    --neon-sites ABBY
    --setup-only
    --output-root /tmp/tower_out
  • python/ctsm/add_super_testlists.py
    --check-only
    --testlist-file cime_config/testdefs/testlist_clm.xml

(The run_ctsm_py_tests -s system test pattern was to avoid the pre-existing CIME test breakage that's now fixed in ESMCI/cime#5067).

The repo dirs on derecho were:

  • /glade/work/jpalex/src/CTSM/worktree_issue2658
  • /glade/work/jpalex/src/cesm/components/clm

AI Disclosure

Used Antigravity 2.0.


Requirements before merge:

  • I have followed the CTSM contribution guidelines.
  • The code in this PR branch builds with no errors.
  • The code in this PR branch runs with no errors. Briefly describe tested configuration(s): Python unit and system test suites across standalone CTSM and nested CESM checkouts on Derecho.
  • This either (a) does not change answers, (b) it only changes answers at roundoff level, or (c) I have performed a scientific evaluation of the answer changes. Which?: (a) Does not change answers (pure toolchain fix).
  • I have reviewed relevant parts of the CLM documentation Tech Note or User's Guide to determine if anything needs to be changed or added. If it does, describe: No changes required.
  • This PR either (a) does not create a need to update the documentation or (b) includes required documentation updates (see guidelines for contributing documentation). Which?: (a) Does not require documentation updates.

@johnpaulalex johnpaulalex changed the title fix(path_utils,subset_data): resolve ccs_config and CESM root paths in Python tools (resolves #2658, #3552) fix(path_utils): resolve ccs_config and CESM root paths in Python tools (resolves #2658, #3552) Sep 13, 2026
@johnpaulalex johnpaulalex changed the title fix(path_utils): resolve ccs_config and CESM root paths in Python tools (resolves #2658, #3552) fix(path_utils): resolve C(E|T)SM root paths in Python tools (resolves #2658, #3552) Sep 13, 2026
@johnpaulalex
johnpaulalex force-pushed the fix/2658-ccs-config-path branch 2 times, most recently from f2b43d2 to 7e24a94 Compare September 13, 2026 13:54
@johnpaulalex
johnpaulalex force-pushed the fix/2658-ccs-config-path branch 4 times, most recently from e3a8344 to 85aafae Compare September 13, 2026 14:12
@johnpaulalex
johnpaulalex force-pushed the fix/2658-ccs-config-path branch from 85aafae to 211a991 Compare September 13, 2026 14:18
@wwieder wwieder added the next this should get some attention in the next week or two. Normally each Thursday SE meeting. label Sep 24, 2026
@wwieder
wwieder requested a review from slevis-lmwg September 24, 2026 16:30
@wwieder wwieder added enhancement new capability or improved behavior of existing capability priority: high High priority to fix/merge soon, e.g., because it is a problem in important configurations usability Improve or clarify user-facing options and removed next this should get some attention in the next week or two. Normally each Thursday SE meeting. labels Sep 24, 2026
@wwieder

wwieder commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

This seems like a helpful contribution, thanks @johnpaulalex. @slevis-lmwg will you work with @johnpaulalex to merge this?

@slevis-lmwg

Copy link
Copy Markdown
Contributor

@mvdebolskiy commented that the changes needed here already exist as functions or routines in CIME's python tools.

Matvey,

  • pls correct my statement if I'm wrong
  • could you quickly review @johnpaulalex's PR to point out your specific concerns?
  • from my quick review, the PR looks fine (I still need to test it), but I am not familiar with the CIME functions that might shorten this PR

@mvdebolskiy

mvdebolskiy commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

@slevis-lmwg nvm. I thought you can grab xml variables from cime itself, but you can't. There are bootstrap routines in cime itself to figure out where it is and set CIMEROOT. and config_files.xml in cime point to SRCROOT and everything else is set from there.

@slevis-lmwg

Copy link
Copy Markdown
Contributor

Testing on derecho shows failures, so I will bounce this PR back to you @johnpaulalex.

OK ./run_ctsm_py_tests -u

FAIL ./run_ctsm_py_tests -s with failures in two scripts

  • ctsm/test/test_sys_gen_mksurfdata_jobscript_multi.py ONE FAIL
  • ctsm/test/test_sys_gen_mksurfdata_namelist.py FIVE FAILS
  • To replicate my work so as to troubleshoot the failures, conda activate ctsm_pylib and run the command that I ran from the /python directory.

FAIL ./run_sys_tests -s clm_pymods -c ctsm5.4.058 --skip-generate

FAIL FSURDATMODIFYCTSM_D_Mmpi-serial_Ld1.5x5_amazon.I2000Clm50SpRsGs.derecho_gnu BASELINE ctsm5.4.058: DIFF
PEND SETPARAMFILE_Ld5.f10_f10_mg37.I1850Clm60BgcCrujra.derecho_gnu.clm-default RUN
FAIL MKSURFDATAESMF_P128x1.f10_f10_mg37.I1850Clm50BgcCrop.derecho_intel SHAREDLIB_BUILD

I suggest troubleshooting this last list of failures after you fix the six ctsm_py_tests failures above. I hope that fixing the ctsm_py_tests failures will resolve the last failure listed here. When you're ready to replicate this work, conda activate ctsm_pylib and run the command that I ran from the /ctsm directory of this branch. Then watch for results in the generated tests_* directory by running ./cs.status.fails there.

@slevis-lmwg slevis-lmwg moved this from Todo to Stalled in LMWG: Sprint Planning Board Sep 24, 2026
@johnpaulalex

Copy link
Copy Markdown
Contributor Author

Hey @slevis-lmwg ,

I think those failures are orthogonal to this PR. but maybe needs its own PR? And there are layers and layers to the system tests issues, please bear with me.

Apparently the python failure occurred because your derecho worktree didn't have tags fetched:

$ git -c safe.directory='\*' -C /glade/work/slevis/git_people/johnpaulalex/2658-ccs-config-path tag | wc -l
0
$ git -c safe.directory='\*' -C /glade/work/slevis/git_people/johnpaulalex/2658-ccs-config-path describe
fatal: No names found, cannot describe anything.

The latter error is what you saw per /glade/derecho/scratch/slevis/tests_0924-171910de/MKSURFDATAESMF_P128x1.f10_f10_mg37.I1850Clm50BgcCrop.derecho_intel.C.0924-171910de_int/TestStatus.log.

I wasn't aware tag-fetching was even a thing but AI says "When people create personal forks, or checkouts/worktrees with selective refspecs, git often skips tag propagation unless --tags is explicitly fetched."

I got the same error on my derecho worktree (apparently because it, like your git_people/ subdir, was cloned from my github fork, which itself has no tags). But then running

git fetch --tags https://github.com/ESCOMP/CTSM.git

made it all work.

Two angles:

  1. is there a process change for me/you/everyone that would cause tags to always be present? Am I missing something there? It sounds I can't make my fork automatically fetch all the tags, but can manually fetch them.
  2. I can update gen_mksurfdata_namelist.py to pass in '--always' to 'git describe', which will make it return success if there are no tags. (I'd have to check if the ensuing code gets upset if there are no tags returned). iiuc the tag is just written to a namelist which then finds it way to 'version' metadata info in some output netcdf files. Does that sound ok - shall I make another PR for that?

For the system tests:

  1. I reran the last system test and it got past the gen_mksurfdata_namelist stage, so that's good. But then the build still failed because it couldn't find libraries/FTorch. AI makes me think it shouldn't be looking for FTorch yet, there's conflict: "Upstream b4b-dev recently updated components/cmeps to tag cmeps1.1.69. In that new CMEPS version (components/cmeps/cime_config/config_component.xml), CMEPS added FTorch to the default CASE_SUPPORT_LIBRARIES list for all CESM cases:
xml

<entry id="CASE_SUPPORT_LIBRARIES">
  <values>
    <value cime_model="cesm">gptl,pio,csm_share,FTorch,CDEPS</value>
  </values>
</entry>

In a full CESM checkout, libraries/FTorch exists at the CESM root, but in a standalone CTSM checkout, it is not present in .gitmodules." Looks like ftorch was briefly added to CTSM but then removed in #3214. Should I worry about this? I get the impression things are in flux with FTorch, I've been working on #3228 to help bring it in). But to make this test go, I could hack my CTSM to have that library; or I could turn off USE_FTORCH in that test case I think...

  1. do I need to look at the other system test failure , the first line with the baseline diff? AI says "Exactly 2 fields differed: atmImp_Faxa_ndep1 and atmImp_Faxa_ndep2 (atmospheric nitrogen deposition imported from the data atmosphere model DATM via CDEPS).
    How much did they differ?
atmImp_Faxa_ndep1:
  Value:    7.876382375033280E-12 vs 7.876382375033280E-12
  RMS diff: 3.1E-28 (relative diff: 7.5E-17)
  Matching decimal digits: 15.8 digits

It is a roundoff difference in the 16th decimal place at machine precision (~1e-16). " (and ndep2 was the same)

AI further asserts - please forgive its hyperbole, and I'm not sure it's right, but thinking you might know off-the-bat:"

  1. b4b-dev IS 100% Bit-for-Bit With ctsm5.4.058!
    In Samuel's subsequent test run on Derecho (/glade/derecho/scratch/slevis/tests_0924-183541de/):
text
PASS FSURDATMODIFYCTSM_D_Mmpi-serial_Ld1.5x5_amazon.I2000Clm50SpRsGs.derecho_gnu NLCOMP
PASS FSURDATMODIFYCTSM_D_Mmpi-serial_Ld1.5x5_amazon.I2000Clm50SpRsGs.derecho_gnu BASELINE ctsm5.4.058:

Both NLCOMP and BASELINE ctsm5.4.058 PASSED completely!

  1. Why Did It Fail in Samuel's Test of Our PR?
    In his test of our PR (tests_0924-171910de/SRCROOT_GIT_STATUS), Samuel's submodules were out of sync:
s  ccs_config   ccs_config_cesm1.0.83 (out of sync with .gitmodules ccs_config_cesm1.0.88)
s  cime         cime6.2.2             (out of sync with .gitmodules cime6.5.5)
s  cmeps        cmeps1.1.47           (out of sync with .gitmodules cmeps1.1.69)
s  cdeps        cdeps1.0.96           (out of sync with .gitmodules cdeps1.0.109)
s  share        share1.1.20           (out of sync with .gitmodules share1.1.21)

Because he tested with stale, un-updated submodules from an older tree:

His old cmeps1.1.47 wrote the old nuopc.runconfig (MED_model: cmeps instead of cesm), failing NLCOMP.
His old cdeps1.0.96 had that 16th-decimal-place roundoff in nitrogen deposition against the ctsm5.4.058 baseline."

So: I could hack up ftorch and rerun the suite, just to verify the above is true...but there's one more systemic issue that I've been meaning to ask someone about - I can't access the baseline files on derecho:

"The baseline directory on Glade is owned by the NCAR internal group cgdtss with 750 permissions (drwxr-s---+):

text
drwxr-s---+ 287 erik cgdtss 65536 Sep 17 14:26 /glade/campaign/cgd/tss/ctsm_baselines/ctsm5.4.058

Your account (jpalex) is in group ncar / p93300041, but not cgdtss, so ls or reading the baseline files directly gives Permission denied."

Ok. That's a lot. happy to chat offline if that helps.

@slevis-lmwg

slevis-lmwg commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

@johnpaulalex thank you, and I'm sorry.

  1. I'm embarrassed that I didn't catch that my submodules were out of sync. Usually I type ./bin/git-fleximod update first thing. And then I use git status more often than necessary. In this case I didn't for whatever reason, so I missed all that...
  2. I see what you mean about not having tags fetched. I resolved that a little differently:
git remote add escomp https://github.com/ESCOMP/ctsm.git
git fetch escomp

The news seems good so far:
OK ./run_ctsm_py_tests -u
OK ./run_ctsm_py_tests -s

@slevis-lmwg

Copy link
Copy Markdown
Contributor

From my CESM checkout, ./run_ctsm_py_tests -u fails with ModuleNotFoundError: No module named 'CIME'.

Here's what I did so far:
In /glade/work/slevis/git_cesm/cesm3 I checked out the latest cesm3 tag cesm3_0_alpha10c.
./bin/git-fleximod update
In /components/clm I checked out fix/2658-ccs-config-path
conda activate ctsm_pylib
./run_ctsm_py_tests -u

@johnpaulalex have you tested your PR in a CESM checkout?

John Alex added 4 commits September 26, 2026 07:46
If git isn't going to check out a submodule, it still creates the submodule directory (apparently to reserve it, in case you check it out later). So we can't simply check for existence of a subdir to verify submodule, we need to look for files in it.

Added unit test coverage in test_unit_path_utils.py.
- lilac_make_runtime_inputs was missing the add_cime_to_path that all the other scripts already have, to find CIME.
- subset_data: resolve user_nl_clm from CTSM root and user_nl_datm_streams from
  enclosing CESM root (if present) in setup_user_mods(). Added unit tests too.
…CESM layouts

Help two tests work in CESM as well as CTSM:

- test_unit_sspmatrix.py is the sole caller of path_utils' add_ctsm_systests_to_path(), to find cime_config (within CTSM). Fixed that method to find CTSM in either scenario.
- test_sys_lilac_build_ctsm: needs to find CIME, now calls add_cime_lib_to_path
…from any directory

The short config modify_fsurdat_short.cfg points to a checked-in .nc file via a relative path, relative to CTSM/python/.  That relative path only resolves correctly when the script is run from that python/ subdir.  To fix it, we use the same search-and-replace pattern that the other tests do, to replace the relative path with an absolute path.
@johnpaulalex johnpaulalex changed the title fix(path_utils): resolve C(E|T)SM root paths in Python tools (resolves #2658, #3552) fix(python): resolve submodule paths and support nested CESM checkouts (resolves #2658, #3552) Sep 26, 2026
@johnpaulalex

johnpaulalex commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Hey @slevis-lmwg , I did not do manual test runs in a CESM repo. And actually I needed to run the automated tests themselves from both locations because they also had assumptions about where they were running(!). Also TIL that run_ctsm_py_tests exists.

So, my bad - sorry about that. I guess I haven’t worked on CESM in a while, plus haven’t worked in this part of the code before - I had a too-low level of paranoia, in retrospect. I updated the PR description to list all the testing I’ve now done.

Based on the manual runs, I added 3 more (tiny) commits to fix various things.

Various questions:

  1. I also added a fourth commit, which is fixing an already-broken system test. I’ve opened CI for python tests maybe broken/missing? #4230 because I think unit test CI may be broken, and I’m wondering if there’s some way the system test breakage could have been caught automatically? [update: that issue is now addressed, and apparently we don't have CI for system tests yet. No answer needed for this one anymore]

1a. fwiw I just submitted #4231 which fixes one unit test that checks for a /glade path. (so now I can run all the unit tests on my mac, it's a convenient first pass)

  1. should I make that script robust to missing tags?

  2. In retrospect, the description for my original 3rd commit (which is just formatting changes) is plain wrong - should I force push to fix it?

  3. Perhaps specific to me, but I can’t get diffs when I run system tests on derecho because I don’t have unix access to the baseline directories, owned by group ‘cgdtss’. I guess I don't need it for this particular PR but I do in general, is that fixable? [update: I can work around this by doing a baseline run on a clean client, then a second run on my PR, and then diff them; but it'd be nice to not have to]

@wwieder

wwieder commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

What's the status on this PR? I can't really follow what next steps are needed here?

@johnpaulalex

Copy link
Copy Markdown
Contributor Author

Hi @wwieder , my newer commits need a review, and I have a couple of minor questions for the reviewer in my last post. friendly ping to @slevis-lmwg (and apologies for not being as rigorous in the initial testing as I should have been)

@slevis-lmwg

slevis-lmwg commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Testing in ctsm checkout

  • ./run_ctsm_py_tests -u and -s
  • ./run_sys_tests -s clm_pymods -c ctsm5.4.064 --skip-generate

Testing in cesm checkout

  • ./run_ctsm_py_tests -u and -s

@slevis-lmwg slevis-lmwg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @johnpaulalex for this PR!

@slevis-lmwg
slevis-lmwg merged commit 9f19aaa into ESCOMP:b4b-dev Oct 26, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in LMWG: Sprint Planning Board Oct 26, 2026
@slevis-lmwg slevis-lmwg mentioned this pull request Oct 29, 2026
12 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement new capability or improved behavior of existing capability priority: high High priority to fix/merge soon, e.g., because it is a problem in important configurations usability Improve or clarify user-facing options

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants