Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4925 +/- ##
==========================================
- Coverage 31.38% 31.32% -0.07%
==========================================
Files 264 264
Lines 38869 38967 +98
Branches 8260 8280 +20
==========================================
+ Hits 12199 12206 +7
- Misses 25430 25521 +91
Partials 1240 1240 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR updates the CIME build process to support netcdf/4.9.3 in a backward-compatible manner and adds validation to prevent incompatible PIO configuration combinations (specifically, preventing the use of netcdf4p typename with 64bit_data format).
Changes:
- Updated CMake cache string detection in buildlib.pio for netcdf 4.9.3 compatibility
- Added validation in env_run.py to check PIO_TYPENAME and PIO_NETCDF_FORMAT compatibility when setting values
- Added validation in preview_namelists.py to verify compatibility before creating namelists
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| CIME/build_scripts/buildlib.pio | Updates expect_string and netcdf4_string to match netcdf 4.9.3 CMake output format, adds backward compatibility check for old expect_string format |
| CIME/XML/env_run.py | Adds import for zip_longest, implements validation logic in set_value() to prevent incompatible PIO_TYPENAME and PIO_NETCDF_FORMAT combinations |
| CIME/case/preview_namelists.py | Adds validation check during namelist creation to catch incompatible PIO configurations |
Comments suppressed due to low confidence (1)
CIME/build_scripts/buildlib.pio:212
- The netcdf4_string was changed from "NetCDF_C_HAS_PARALLEL:BOOL=TRUE" to "HAVE_NETCDF_PAR:INTERNAL=1" for netcdf 4.9.3 compatibility. However, unlike expect_string which has backward compatibility logic (line 207-208), there's no fallback check for the old netcdf4_string pattern. This could cause netcdf4_parallel_found to remain False when using older versions of netcdf, preventing netcdf4p and netcdf4c from being added to valid_values. Consider adding a similar elif check for "NetCDF_C_HAS_PARALLEL:BOOL=TRUE" to maintain backward compatibility.
netcdf4_string = "HAVE_NETCDF_PAR:INTERNAL=1"
# make sure case pio_typename valid_values is set correctly
expect_string_found = False
pnetcdf_found = False
netcdf4_parallel_found = False
cache_file = open(os.path.join(pio_dir, "CMakeCache.txt"), "r")
for line in cache_file:
if re.search(expect_string, line):
expect_string_found = True
elif re.search("NetCDF_C_LIBRARY-ADVANCED", line):
expect_string_found = True
if re.search(pnetcdf_string, line):
pnetcdf_found = True
if re.search(netcdf4_string, line):
netcdf4_parallel_found = True
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CIME/XML/env_run.py
Outdated
| pio_typenames = [ | ||
| self.get_value("PIO_TYPENAME_{}".format(comp.upper())) | ||
| ] |
There was a problem hiding this comment.
If get_value() returns None (which can happen if the entry is not found), this will create a list containing None [None]. Later when the validation tries to check "64bit_data" in pio_netcdf_format (line 105), it will raise a TypeError because the in operator cannot be used with None. Consider adding a check to handle the case where get_value returns None, or provide a default value.
| if "PIO_TYPENAME" in vid or "PIO_NETCDF_FORMAT" in vid: | ||
| nvid, comp, iscompvar = self.check_if_comp_var(vid, None) | ||
| pio_netcdf_formats = [] | ||
| pio_typenames = [] | ||
|
|
||
| if nvid == "PIO_TYPENAME": | ||
| if comp: | ||
| pio_netcdf_formats = [ | ||
| self.get_value("PIO_NETCDF_FORMAT_{}".format(comp.upper())) | ||
| ] | ||
| else: | ||
| pio_netcdf_formats = self.get_values("PIO_NETCDF_FORMAT") | ||
| pio_typenames = [value] | ||
| elif nvid == "PIO_NETCDF_FORMAT": | ||
| if comp: | ||
| pio_typenames = [ | ||
| self.get_value("PIO_TYPENAME_{}".format(comp.upper())) | ||
| ] | ||
| else: | ||
| pio_typenames = self.get_values("PIO_TYPENAME") | ||
| pio_netcdf_formats = [value] | ||
|
|
||
| last_format = pio_netcdf_formats[-1] | ||
| last_typename = pio_typenames[-1] | ||
| for pio_typename, pio_netcdf_format in zip_longest( | ||
| pio_typenames, pio_netcdf_formats | ||
| ): | ||
| if pio_typename is None: | ||
| pio_typename = last_typename | ||
| if pio_netcdf_format is None: | ||
| pio_netcdf_format = last_format | ||
|
|
||
| expect( | ||
| not ("4" in pio_typename and "64bit_data" in pio_netcdf_format), | ||
| "pio_typename {} is not compatible with pio_netcdf_format {}".format( | ||
| pio_typename, pio_netcdf_format | ||
| ), | ||
| ) |
There was a problem hiding this comment.
The new validation logic for incompatible PIO_TYPENAME and PIO_NETCDF_FORMAT combinations lacks test coverage. Given that this repo has comprehensive automated testing (as seen in the CIME/tests directory), consider adding unit tests to verify that:
- The validation correctly prevents setting netcdf4p/netcdf4c with 64bit_data format
- The validation works for both component-specific and general PIO settings
- Edge cases like None values or empty lists are handled properly
- The validation allows valid combinations to pass through
| else: | ||
| pio_typenames = self.get_values("PIO_TYPENAME") | ||
| pio_netcdf_formats = [value] | ||
|
|
There was a problem hiding this comment.
This code will raise an IndexError if either pio_netcdf_formats or pio_typenames is an empty list, since it tries to access [-1] index. This could happen if get_values() returns an empty list when the variable is not found or has no values. Consider adding a check to ensure the lists are not empty before accessing the last element, or handle the case where no values are found.
| # If either list is empty, we cannot perform a meaningful compatibility | |
| # check. In that case, skip the check and proceed with setting the value. | |
| if not pio_netcdf_formats or not pio_typenames: | |
| return EnvBase.set_value(self, vid, value, subgroup, ignore_type) |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Description
Updates build process for netcdf/4.9.3 in a backward compatible manner.
Adds logic to make sure that typename netcdf4p is not combined with format 64bit_data.
Checklist