Merge stochastic physics (SPPT only) into GSL's develop branch#239
Merge stochastic physics (SPPT only) into GSL's develop branch#239gsketefian wants to merge 207 commits into
Conversation
…he stochastic_physics submodule itself will be added in a separate commit.
…'t updated during latest merge of gsl/develop.
…he gsl/MPAS_stoch_physics in the stochastic_physics repo.
…teger seed workaround.
… smoke) from "output" to "output_smoke" (and file from "history..." to "history_smoke...". This is necessary because the stream name "output" is already taken by the main output stream, and having the same name for two different output streams apparently causes SMIOL I/O errors during the forecast (and incorrect/corrupted history*.nc files).
…) no stale stream_list.atmosphere files exist in the two default_inputs directories (one under core_atmosphere and the other immediately under the MPAS-Model top-level directory), and (2) for the atmosphere core, all files (stream-related as well as namelist) in the top-level directory are backed up before new such files are copied from the default_inputs directory back up a level into the top-level directory. Previously, existing (and thus possibly outdated) stream_list.atmosphere.* files in the top-level directory were not being replaced by newer ones in default_inputs, and that was causing unexpected (and wrong) behavior. Probably a similar fix is needed for the init_atmsophere core and maybe even other ones.
…ll as its output file) so it doesn't conflict with the default output stream.
…tochastic_physics's master branh will gradually happen.
…/MPAS_stoch_physics_try_merge_stoch_master
…tochastic_physics code know that the dycore being used is MPAS.
…ill instead be defined in the Makefile for stochastic_physics only (in a separate commit into the stochastic_physics repo) since it is only needed by the stochastic_physics submodule.
…e that is now added in the Makefile in stochastic_physics).
…s the TEMPO tables.
Change the fetch URL from dustinswales/stochastic_physics to dtcenter/stochastic_physics, which is the authoritative upstream that contains the required commit (063b1897).
| COMMAND mpas_streams_gen ${CMAKE_CURRENT_BINARY_DIR}/Registry_processed.xml streams.${ARG_CORE} stream_list.${ARG_CORE}. listed | ||
| COMMENT "CORE ${ARG_CORE}: Generate Streams" | ||
| DEPENDS mpas_streams_gen Registry_processed.xml) | ||
| DEPENDS mpas_streams_gen ${CMAKE_CURRENT_BINARY_DIR}/Registry_processed.xml) |
There was a problem hiding this comment.
why we need to add ${CMAKE_CURRENT_BINARY_DIR}?
There was a problem hiding this comment.
@gsketefian or @NingWang325, is this one you can answer?
There was a problem hiding this comment.
I'm working on remembering the details of why I needed this.
There was a problem hiding this comment.
Pull request overview
This PR integrates the NOAA-PSL stochastic_physics package (SPPT scheme only) into MPAS-Model as a git submodule, plumbing the perturbation pattern generation and application into the atmosphere core's init/timestep/RK3 paths and the registry. It also adds a dedicated CI workflow that runs convection_permitting and hrrrv5 winter GFS cases with SPPT enabled, plus build-system support (MKL/LAPACK, NetCDF-Fortran) on several HPC modulefiles and CI images.
Changes:
- Add
stochastic_physicsas a submodule with corresponding Make/CMake/Registry wiring and SPPT call sites inatm_core_init,atm_do_timestep, andatm_srk3. - New CI workflow
run_mpas_stoch.ymland new test case directoriesufscommunity.{convection_permitting,hrrrv5}.gfs.winter.stoch(namelists, streams, stream_lists). - Build environment updates: LAPACK/BLAS/MKL on modulefiles and CI, NetCDF-Fortran setup,
MPAS_USE_MPI_F08always defined, registry-processed-file paths made absolute in CMake.
Reviewed changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| testing_and_setup/ufs-community/cases/ufscommunity.hrrrv5.gfs.winter.stoch/* | New SPPT test case files (namelist, streams, stream lists) for the hrrrv5 suite. |
| testing_and_setup/ufs-community/cases/ufscommunity.convection_permitting.gfs.winter.stoch/* | New SPPT test case files for the convection_permitting suite. |
| src/Makefile | Adds $(LAPACK_LIBS) to the link line; introduces an esmf_time_f91 typo in the -I path. |
| src/core_atmosphere/Registry.xml | Adds Gaussian-grid dims (hard-coded 504/248) and new stoch_pattern_* variables; includes stochastic_physics registry. |
| src/core_atmosphere/mpas_atm_core.F | Wires stochastic_physics_pattern_init and _adv into init and timestep paths. |
| src/core_atmosphere/Makefile | Builds and links the stochastic_physics library; reworks post_build to back up existing default_inputs. |
| src/core_atmosphere/dynamics/mpas_atm_time_integration.F | Calls stochastic_physics_pattern_apply for 'phys' and 'prog' tendencies in atm_srk3. |
| src/core_atmosphere/dynamics/Makefile | Adds -I../stochastic_physics include path. |
| src/core_atmosphere/CMakeLists.txt | Defines a stochastic_physics CMake target with BLAS/NetCDF deps and links it into core_atmosphere. |
| modulefiles/mpas/{derecho,gaeac6,hera,orion,ursa}.intel.lua | Loads Intel MKL and exports NetCDF C/Fortran root env vars. |
| Makefile | Adds LAPACK_LIBS to relevant build targets; adds new intel-mpi-gaeac6 build target. |
| CMakeLists.txt | Always defines MPAS_USE_MPI_F08; adds explicit dependency to serialize init_atmosphere on core_atmosphere builds. |
| cmake/Functions/MPAS_Functions.cmake | Uses absolute ${CMAKE_CURRENT_BINARY_DIR} paths for Registry_processed.xml dependencies. |
| .gitmodules | Adds src/core_atmosphere/stochastic_physics submodule pointing at dtcenter fork. |
| .github/workflows/run_mpas.yml, run_mpas_hrrr.yml, build_mpas.yml, build_mpas_intel.yml | Add LAPACK/BLAS, NetCDF setup, and MKL support; minor commented-out trigger lines. |
| .github/workflows/run_mpas_stoch.yml | New CI workflow that runs baseline vs feature SPPT-enabled MPAS and compares outputs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| mpas: $(AUTOCLEAN_DEPS) externals frame ops dycore drver | ||
| $(LINKER) $(LDFLAGS) -o $(EXE_NAME) driver/*.o -L. -ldycore -lops -lframework $(LIBS) -I./external/esmf_time_f90 -L./external/esmf_time_f90 -lesmf_time | ||
| $(LINKER) $(LDFLAGS) -o $(EXE_NAME) driver/*.o -L. -ldycore -lops -lframework $(LIBS) -I./external/esmf_time_f91 -L./external/esmf_time_f90 -lesmf_time $(LAPACK_LIBS) |
There was a problem hiding this comment.
I noticed this as well but thought it might be intentional by @NingWang325. Kind of surprising that it works! @NingWang325 can you say if it's intentional or a typo?
There was a problem hiding this comment.
Turns out the -I flag is not needed at all in this command, so I removed it. See my comment here.
| <dim name="lon_for" definition="504" | ||
| description="The number of longitude points for the Gaussian grid"/> | ||
| <dim name="lat_leg" definition="248" | ||
| description="The number of latitude points for the Gaussian grid"/> |
There was a problem hiding this comment.
Without full comprehension of what these variables are used for, I think Copilot has some valid points here.
There was a problem hiding this comment.
My browser quit on me so I don't know if this will be a duplicate comments or not... Without fully understanding what these variables are for, it seems Copilot has some good points here.
There was a problem hiding this comment.
From @NingWang325, these arrays are only used for debugging. These fields aren't being used otherwise. They can be removed.
| ! | ||
| ! init stochastic pattern generation | ||
| if (dosppt(domain)) then | ||
| call stochastic_physics_pattern_init (domain, ierr) | ||
| endif |
There was a problem hiding this comment.
From @NingWang325: this code follows procedure from NOAA-PSL/stochastic_physics to ensure initialization is successful. For now, a message is passed to the log saying that stochastic physics could not be initialized.
We need to stop the run in NOAA-PSL/stochastic_physics if initialization of any expect stochastic physics method fails. Check the "ierr" value and issue a stop command.
|
@gsketefian @NingWang325 @JeffBeck-NOAA I turned Copilot loose on a review of this PR. It generated five comments, the first few of which (at minimum) look like things that need to be addressed before merge. |
| &soundings | ||
| config_sounding_interval = 'none' | ||
| / | ||
| &nam_stochy |
There was a problem hiding this comment.
just curious, why "nam_stochy"?
There was a problem hiding this comment.
@joeolson42 I think this is what the stochastic physics namelist in the FV3 is called, so we just kept it. My guess as to its meaning: "nam" = namelist, "stochy" = "stochastic". Not sure about the "y" in "stochy". I can't find any explanation in the inline comments in the stochastic_physics code. It might have French origins, since I think there were some French developers working on the code at some point. I'm curious too, so I'll ask @pjpegion in the companion PR #97 into the NOAA-PSL/stochastic_physics repo.
Here's the link to my question.
There was a problem hiding this comment.
@joeolson42 Sorry, turns out @pjpegion doesn't know the answer regarding the "y" in "stochy".
I’d personally prefer a more straightforward name like stoch_phys or stoch_physics for the namelist, though it isn't a strong preference.
There was a problem hiding this comment.
I'd prefer something like "stoch_physics" too, but since it's just a preference, it can't be considered a mandatory change. Maybe let others weigh in.
There was a problem hiding this comment.
@joeolson42 I'm still curious about the "y" in "stochy", especially since it's used not just in "nam_stochy" but also all throughout the stochastic_physics code. I had claude look at that code to see if it can come up with an explanation for the "y". It said:
"stochy" reads as an adjectival nickname — like "patchy" or "scratchy" — a natural informal shorthand for "stochastic" that is also more distinctive as an identifier prefix than the bare stem "stoch".
I'm content with that.
… launching of CI tests on push.
| ! | ||
| ! init stochastic pattern generation | ||
| if (dosppt(domain)) then | ||
| call stochastic_physics_pattern_init (domain, ierr) |
There was a problem hiding this comment.
@gsketefian Should this die and report error if initialization fails?
There was a problem hiding this comment.
@dustinswales I would think it should at least write out a warning in the log file(s) if not die altogether, but I think @NingWang325 is best suited to answer this one.
| if("atmosphere" IN_LIST MPAS_CORES AND "init_atmosphere" IN_LIST MPAS_CORES) | ||
| add_dependencies(mpas_init_atmosphere core_atmosphere) | ||
| endif() | ||
|
|
There was a problem hiding this comment.
Lines 128-134: Is this a new requirement due to the stochastic physics?
I don't think we need this dependency before.
joeolson42
left a comment
There was a problem hiding this comment.
Conditionally approved, pending any changes needed to address comments.
…multiplication subroutine.
…n building with the stand-alone MPAS-Model, stochastic_physics uses "dgemm" instead of "esmf_dgemm" to perform matrix multiplication.
…mpi-gaeac6" for building the stand-alone MPAS-Model with stochastic_physics on Gaea C6 because it turns out that the existing "ifort_icx" target can be used for this purpose -- as long as a small modification (addition of LAPACK_LIBS) is made to it, which we also do here.
|
@gsketefian Can you sync this branch with the noaa/develop branch? |
| COMMAND mpas_streams_gen ${CMAKE_CURRENT_BINARY_DIR}/Registry_processed.xml streams.${ARG_CORE} stream_list.${ARG_CORE}. listed | ||
| COMMENT "CORE ${ARG_CORE}: Generate Streams" | ||
| DEPENDS mpas_streams_gen Registry_processed.xml) | ||
| DEPENDS mpas_streams_gen ${CMAKE_CURRENT_BINARY_DIR}/Registry_processed.xml) |
There was a problem hiding this comment.
Lines 217-234:
Did we get any troubles without these newly added ${CMAKE_CURRENT_BINARY_DIR} etc?
If not, I would suggest removing all the newly added ${CMAKE_CURRENT_BINARY_DIR} etc to keep sync'ed with the upstream NCAR's MPAS-Dev/MPAS-Model as much as possible.
There was a problem hiding this comment.
@guoqing-noaa It took some time to remember why I made these changes. The short answer to your question is that, yes, we did run into trouble without these explicit path additions.
The error does not show up if you're only doing cmake builds. It shows up when you first do a build with the make system that NCAR has (i.e. using the Makefiles that are part of the repo) and THEN do a build with the cmake system. Although this is not what most people would be doing (they'd use either make or cmake), I for one would prefer having make and cmake builds that don't interfere with each other.
I'll describe what happens when building core_init_atmosphere, but the same applies to core_atmosphere.
Assume you first run a successful make build. This will generate the following file (among many others):
.../MPAS-Model/src/core_init_atmosphere/Registry_processed.xml
The way MPAS_Functions.cmake is currently written (i.e. with relative paths) causes the DEPENDS section of the "Parse Registry" build rule, which is given by
add_custom_command(
OUTPUT ${ARG_INCLUDES}
COMMAND mpas_parse_${ARG_CORE} Registry_processed.xml ${CPP_EXTRA_FLAGS}
COMMENT "CORE ${ARG_CORE}: Parse Registry"
DEPENDS mpas_parse_${ARG_CORE} Registry_processed.xml)
to erroneously detect the Registry_processed.xml file in .../MPAS-Model/src/core_init_atmosphere created by the make build. That's because in the DEPENDS, only a relative path is given (just Registry_processed.xml), and apparently cmake's behavior for DEPENDS is to first try to resolve this with respect to the source directory CMAKE_CURRENT_SOURCE_DIR, given by
CMAKE_CURRENT_SOURCE_DIR = .../MPAS-Model/src/core_init_atmosphere/
and only if that fails to then try to resolve it with respect to the current cmake build (binary) directory CMAKE_CURRENT_BINARY_DIR, given by
CMAKE_CURRENT_BINARY_DIR = .../MPAS-Model/build/src/core_init_atmosphere/
Since the initial successful make build creates the file ${CMAKE_CURRENT_SOURCE_DIR}/Registry_processed.xml, when one then runs the cmake build the DEPENDS in the "Parse Registry" rule is satisfied, which means cmake does not establish a dependency of the "Parse Registry" rule on the "Pre-Process Registry" rule that is given by
add_custom_command(
OUTPUT Registry_processed.xml
COMMAND ${CPP_EXECUTABLE} -E -P ${CPP_EXTRA_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/Registry.xml > Registry_processed.xml
COMMENT "CORE ${ARG_CORE}: Pre-Process Registry"
DEPENDS Registry.xml)
Thus, "Parse Registry" runs immediately without waiting for "Pre-Process Registry" to complete. Since "Pre-Process Registry" hasn't yet completed, its output file .../MPAS-Model/build/src/core_init_atmosphere/Registry_processed.xml doesn't yet exist [note that cmake behavior for the COMMAND (and OUTPUT) sections of add_custom_command() is to resolve relative paths using CMAKE_CURRENT_BINARY_DIR, so the "Pre-Process Registry" rule above will place the Registry_processed.xml file it generates in CMAKE_CURRENT_BINARY_DIR, which in this case is .../MPAS-Model/build/src/core_init_atmosphere/]. Since that's the file that "Parse Registry" is looking for as input and it is missing, "Parse Registry" fails with a segfault.
The fix here is to make sure that the DEPENDS in "Parse Registry" checks for Registry_processed.xml ONLY in CMAKE_CURRENT_BINARY_DIR (and never in CMAKE_CURRENT_SOURCE_DIR). The straightforward way to do that is to specify the absolute path in the DEPENDS by adding CMAKE_CURRENT_BINARY_DIR in front of Registry_processed.xml. That's one of the changes made in this PR.
More generally, to get a more robust build configuration that avoids relying on cmake's internal rules for resolving relative paths (which can be complex and obscure), it is best to just use absolute paths in all parts of these add_custom_command() commands. That's what the changes here are doing.
There was a problem hiding this comment.
@gsketefian Thanks a lot for finding out the original intention and providing the details of this change!
I did get the same errors if I did the "make" build first and then did the "cmake" build without cleaning.
However, if we run make clean CORE=atmosphere and/or make clean CORE=init_atmosphere before doing "cmake", we are good.
Now it goes to different preferences by different views. Usually, we will let cmake find the correct path/file without explicitly specifying ${CMAKE_CURRENT_BINARY_DIR}. This is consistent with the upstream NCAR repo.
If users does "make" first and then gets errors at doing "cmake", we can just suggest these users do clean first, just like we usually do before lauching a new round of make.
…piling, not linking.
I merged |
This PR enables use of the SPPT scheme of stochastic physics into MPAS-Model. This is addressed in Issue #204.
Main changes:
stochastic_physicscode as a submodule.Makefiles, registryxmlfiles, and fortran files, and GitHub workflow files to allow the SPPT stochastic scheme to be used with MPAS.stochastic_physicscode as a submodule. There is a companion PR into the authoritativestochastic_physicsrepo here.This PR adds a new GitHub Actions CI workflow (
run_mpas_stoch.yml) that runs two tests of MPAS-Model on a winter case using GFS ICs/LBCs and with SPPT enabled. The first test is the "convection_permitting" physics suite, and the second is with the "hrrrv5" suite. These two tests use the same grid, static file, ICs, LBCs, etc as the existing CI test(s) for the winter case with GFS ICs/LBCs, etc. These tests require the setup (namelist, streams, etc) files located in the directoriesMandatory Questions
MPAS-Model/testing_and_setup/ufs-community/cases/ufscommunity.[convection_permitting|hrrrv5].gfs.winter.stoch, which are under version control.Priority Reviewers