From 298baedce0075bbff497ecd0ae56bd951c585e17 Mon Sep 17 00:00:00 2001 From: peverwhee Date: Sun, 10 Aug 2025 18:43:25 -0600 Subject: [PATCH 1/5] skip variable parse checkers during fortran parsing --- scripts/metavar.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/scripts/metavar.py b/scripts/metavar.py index 8f283df6..e0293ae0 100755 --- a/scripts/metavar.py +++ b/scripts/metavar.py @@ -262,7 +262,7 @@ class Var: # All constituent props are optional so no check def __init__(self, prop_dict, source, run_env, context=None, - clone_source=None): + clone_source=None, skip_checks=False): """Initialize a new Var object. If is really a Var object, use that object's prop_dict. If this Var object is a clone, record the original Var object @@ -360,19 +360,21 @@ def __init__(self, prop_dict, source, run_env, context=None, # # end if # # end for # XXgoldyXX: ^ don't fill in default properties? - # Make sure all the variable values are valid - try: - for prop_name, prop_val in self.var_properties(): - prop = Var.get_prop(prop_name) - _ = prop.valid_value(prop_val, - prop_dict=self._prop_dict, error=True) - # end for - except CCPPError as cperr: - lname = self._prop_dict['local_name'] - emsg = "{}: {}" - raise ParseSyntaxError(emsg.format(lname, cperr), - context=self.context) from cperr - # end try + # Make sure all the variable values are validi + if not skip_checks: + try: + for prop_name, prop_val in self.var_properties(): + prop = Var.get_prop(prop_name) + _ = prop.valid_value(prop_val, + prop_dict=self._prop_dict, error=True) + # end for + except CCPPError as cperr: + lname = self._prop_dict['local_name'] + emsg = "{}: {}" + raise ParseSyntaxError(emsg.format(lname, cperr), + context=self.context) from cperr + # end try + # end if def compatible(self, other, run_env, is_tend=False): """Return a VarCompatObj object which describes the equivalence, @@ -1209,9 +1211,10 @@ def __init__(self, prop_dict, source, run_env, context=None, del prop_dict[prop.name] # end if # end for - # Initialize Var + # Initialize Var; skip the parse checkers on the Fortran side since the + # checks are already done during metadata parsing super().__init__(prop_dict, source, run_env, context=context, - clone_source=clone_source) + clone_source=clone_source, skip_checks=True) # Now, restore the saved properties for prop in save_dict: self._prop_dict[prop] = save_dict[prop] From 1ba5a3e687d23e4f2b3b7245bb833bc4e87b1e2f Mon Sep 17 00:00:00 2001 From: peverwhee Date: Mon, 11 Aug 2025 13:52:25 -0600 Subject: [PATCH 2/5] address review comments; add additional ddt testing --- scripts/metavar.py | 4 ++-- test/ddthost_test/CMakeLists.txt | 14 ++++++++++++-- test/ddthost_test/README.md | 2 ++ test/ddthost_test/external_module.F90 | 7 +++++++ test/ddthost_test/temp_adjust.F90 | 6 +++++- test/ddthost_test/temp_adjust.meta | 6 ++++++ test/ddthost_test/wrapped_ddt.F90 | 11 +++++++++++ test/ddthost_test/wrapped_ddt.meta | 7 +++++++ 8 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 test/ddthost_test/external_module.F90 create mode 100644 test/ddthost_test/wrapped_ddt.F90 create mode 100644 test/ddthost_test/wrapped_ddt.meta diff --git a/scripts/metavar.py b/scripts/metavar.py index e0293ae0..a589429b 100755 --- a/scripts/metavar.py +++ b/scripts/metavar.py @@ -360,7 +360,7 @@ def __init__(self, prop_dict, source, run_env, context=None, # # end if # # end for # XXgoldyXX: ^ don't fill in default properties? - # Make sure all the variable values are validi + # Make sure all the variable values are valid if not skip_checks: try: for prop_name, prop_val in self.var_properties(): @@ -1212,7 +1212,7 @@ def __init__(self, prop_dict, source, run_env, context=None, # end if # end for # Initialize Var; skip the parse checkers on the Fortran side since the - # checks are already done during metadata parsing + # checks are already done during metadata parsing super().__init__(prop_dict, source, run_env, context=context, clone_source=clone_source, skip_checks=True) # Now, restore the saved properties diff --git a/test/ddthost_test/CMakeLists.txt b/test/ddthost_test/CMakeLists.txt index cc257619..c7d88ffb 100644 --- a/test/ddthost_test/CMakeLists.txt +++ b/test/ddthost_test/CMakeLists.txt @@ -7,7 +7,7 @@ #------------------------------------------------------------------------------ set(SCHEME_FILES "setup_coeffs" "temp_set" "temp_adjust" "temp_calc_adjust") set(SUITE_SCHEME_FILES "make_ddt" "environ_conditions") -set(HOST_FILES "test_host_data" "test_host_mod" "host_ccpp_ddt") +set(HOST_FILES "test_host_data" "test_host_mod" "host_ccpp_ddt" "wrapped_ddt") set(SUITE_FILES "ddt_suite.xml" "temp_suite.xml") # HOST is the name of the executable we will build. # We assume there are files ${HOST}.meta and ${HOST}.F90 in CMAKE_SOURCE_DIR @@ -46,8 +46,18 @@ add_library(DDT_TESTLIB OBJECT ${SCHEME_FORTRAN_FILES} ${CCPP_CAPS_LIST}) # Setup test executable with needed dependencies +# Dependencies for this test are the test_utils directory and the external_module.F90 file +set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/fortran_modules) add_executable(ddt_host_integration test_ddt_host_integration.F90 ${HOST}.F90) -target_link_libraries(ddt_host_integration PRIVATE DDT_TESTLIB test_utils) +add_library(external_module STATIC external_module.F90) +set_target_properties(external_module PROPERTIES + Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/fortran_modules) +target_compile_options(external_module PRIVATE "-J${CMAKE_BINARY_DIR}/fortran_modules") +target_include_directories(external_module PRIVATE ${CMAKE_BINARY_DIR}/fortran_modules) +target_link_libraries(ddt_host_integration PRIVATE DDT_TESTLIB test_utils external_module) +target_include_directories(ddt_host_integration PRIVATE ${CMAKE_BINARY_DIR}/fortran_modules) +target_link_libraries(DDT_TESTLIB PRIVATE external_module) +target_include_directories(DDT_TESTLIB PRIVATE ${CMAKE_BINARY_DIR}/fortran_modules) target_include_directories(ddt_host_integration PRIVATE "$") # Add executable to be called with ctest diff --git a/test/ddthost_test/README.md b/test/ddthost_test/README.md index 292722dc..8a102e48 100644 --- a/test/ddthost_test/README.md +++ b/test/ddthost_test/README.md @@ -3,6 +3,8 @@ Contains tests to exercise more DDT functionality: - Passing around and modifying a DDT - Making DDT in host model & using it in CCPP-ized physics code +- Providiing metadata for only the top-level DDT + - Ensures framework allows unknown DDT in Fortran as long as there's no metadata for it ## Building/Running diff --git a/test/ddthost_test/external_module.F90 b/test/ddthost_test/external_module.F90 new file mode 100644 index 00000000..a52c4a9f --- /dev/null +++ b/test/ddthost_test/external_module.F90 @@ -0,0 +1,7 @@ +module external_module + + type, public :: unknown_external_ddt + integer :: var + end type + +end module external_module diff --git a/test/ddthost_test/temp_adjust.F90 b/test/ddthost_test/temp_adjust.F90 index 0458292c..daf96893 100644 --- a/test/ddthost_test/temp_adjust.F90 +++ b/test/ddthost_test/temp_adjust.F90 @@ -17,11 +17,13 @@ module temp_adjust !> \section arg_table_temp_adjust_run Argument Table !! \htmlinclude arg_table_temp_adjust_run.html !! - subroutine temp_adjust_run(foo, timestep, temp_prev, temp_layer, qv, ps, & + subroutine temp_adjust_run(foo, timestep, wrapped_ext_ddt, temp_prev, temp_layer, qv, ps, & to_promote, promote_pcnst, errmsg, errflg, innie, outie, optsie) + use wrapped_ddt, only: wrapped_ddt_t integer, intent(in) :: foo real(kind_phys), intent(in) :: timestep + type(wrapped_ddt_t), intent(out) :: wrapped_ext_ddt real(kind_phys), intent(inout),optional :: qv(:) real(kind_phys), intent(inout) :: ps(:) real(kind_phys), intent(in) :: temp_prev(:) @@ -40,6 +42,8 @@ subroutine temp_adjust_run(foo, timestep, temp_prev, temp_layer, qv, ps, & errmsg = '' errflg = 0 + wrapped_ext_ddt%ext_ddt%var = 1 + do col_index = 1, foo temp_layer(col_index) = temp_layer(col_index) + temp_prev(col_index) if (present(qv)) qv(col_index) = qv(col_index) + 1.0_kind_phys diff --git a/test/ddthost_test/temp_adjust.meta b/test/ddthost_test/temp_adjust.meta index 420e9112..209dd6f1 100644 --- a/test/ddthost_test/temp_adjust.meta +++ b/test/ddthost_test/temp_adjust.meta @@ -20,6 +20,12 @@ type = real kind = kind_phys intent = in +[ wrapped_ext_ddt ] + standard_name = wrapped_ddt_for_physics + units = none + dimensions = () + type = wrapped_ddt_t + intent = out [ temp_prev ] standard_name = potential_temperature_at_previous_timestep units = K diff --git a/test/ddthost_test/wrapped_ddt.F90 b/test/ddthost_test/wrapped_ddt.F90 new file mode 100644 index 00000000..8fe2dd68 --- /dev/null +++ b/test/ddthost_test/wrapped_ddt.F90 @@ -0,0 +1,11 @@ +module wrapped_ddt + ! CCPP wrapper for external ddt + use external_module, only: unknown_external_ddt + + !> \section arg_table_wrapped_ddt_t Argument Table + !! \htmlinclude wrapped_ddt_t.html + type, public :: wrapped_ddt_t + type(unknown_external_ddt) :: ext_ddt + end type + +end module wrapped_ddt diff --git a/test/ddthost_test/wrapped_ddt.meta b/test/ddthost_test/wrapped_ddt.meta new file mode 100644 index 00000000..3b89de46 --- /dev/null +++ b/test/ddthost_test/wrapped_ddt.meta @@ -0,0 +1,7 @@ +[ccpp-table-properties] + name = wrapped_ddt_t + type = ddt + +[ccpp-arg-table] + name = wrapped_ddt_t + type = ddt From 33e97e4ee14d5036da59aca40d54f4be56ff5668 Mon Sep 17 00:00:00 2001 From: peverwhee Date: Mon, 11 Aug 2025 14:01:18 -0600 Subject: [PATCH 3/5] fix CMakeLists to satisfy gnu compiler --- test/ddthost_test/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/test/ddthost_test/CMakeLists.txt b/test/ddthost_test/CMakeLists.txt index c7d88ffb..5114df31 100644 --- a/test/ddthost_test/CMakeLists.txt +++ b/test/ddthost_test/CMakeLists.txt @@ -52,7 +52,6 @@ add_executable(ddt_host_integration test_ddt_host_integration.F90 ${HOST}.F90) add_library(external_module STATIC external_module.F90) set_target_properties(external_module PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/fortran_modules) -target_compile_options(external_module PRIVATE "-J${CMAKE_BINARY_DIR}/fortran_modules") target_include_directories(external_module PRIVATE ${CMAKE_BINARY_DIR}/fortran_modules) target_link_libraries(ddt_host_integration PRIVATE DDT_TESTLIB test_utils external_module) target_include_directories(ddt_host_integration PRIVATE ${CMAKE_BINARY_DIR}/fortran_modules) From 31676983fd072062a5a4bd03fd86c1d934756b12 Mon Sep 17 00:00:00 2001 From: Michael Waxmonsky Date: Mon, 11 Aug 2025 18:24:59 -0600 Subject: [PATCH 4/5] Adding mock external library for DDT test. --- test/ddthost_test/CMakeLists.txt | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/test/ddthost_test/CMakeLists.txt b/test/ddthost_test/CMakeLists.txt index 5114df31..57b00faf 100644 --- a/test/ddthost_test/CMakeLists.txt +++ b/test/ddthost_test/CMakeLists.txt @@ -39,24 +39,21 @@ ccpp_capgen(CAPGEN_DEBUG ON ccpp_datafile(DATATABLE "${CCPP_CAP_FILES}/datatable.xml" REPORT_NAME "--ccpp-files") +# Create dependenct libraries to mimic possibly pre-built external dependencies +add_library(external_module STATIC external_module.F90) + # Create test host library add_library(DDT_TESTLIB OBJECT ${SCHEME_FORTRAN_FILES} ${SUITE_SCHEME_FORTRAN_FILES} ${DDT_HOST_FORTRAN_FILES} ${CCPP_CAPS_LIST}) +# Add the external as a dependency of the DDT library. +add_dependencies(DDT_TESTLIB external_module) + # Setup test executable with needed dependencies -# Dependencies for this test are the test_utils directory and the external_module.F90 file -set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/fortran_modules) add_executable(ddt_host_integration test_ddt_host_integration.F90 ${HOST}.F90) -add_library(external_module STATIC external_module.F90) -set_target_properties(external_module PROPERTIES - Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/fortran_modules) -target_include_directories(external_module PRIVATE ${CMAKE_BINARY_DIR}/fortran_modules) -target_link_libraries(ddt_host_integration PRIVATE DDT_TESTLIB test_utils external_module) -target_include_directories(ddt_host_integration PRIVATE ${CMAKE_BINARY_DIR}/fortran_modules) -target_link_libraries(DDT_TESTLIB PRIVATE external_module) -target_include_directories(DDT_TESTLIB PRIVATE ${CMAKE_BINARY_DIR}/fortran_modules) +target_link_libraries(ddt_host_integration PRIVATE DDT_TESTLIB test_utils) target_include_directories(ddt_host_integration PRIVATE "$") # Add executable to be called with ctest From 449216e588d642b6bc282a1f2685c637fb4896b5 Mon Sep 17 00:00:00 2001 From: Michael Waxmonsky Date: Mon, 11 Aug 2025 18:29:44 -0600 Subject: [PATCH 5/5] Fixing typo. --- test/ddthost_test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ddthost_test/CMakeLists.txt b/test/ddthost_test/CMakeLists.txt index 57b00faf..3626979b 100644 --- a/test/ddthost_test/CMakeLists.txt +++ b/test/ddthost_test/CMakeLists.txt @@ -39,7 +39,7 @@ ccpp_capgen(CAPGEN_DEBUG ON ccpp_datafile(DATATABLE "${CCPP_CAP_FILES}/datatable.xml" REPORT_NAME "--ccpp-files") -# Create dependenct libraries to mimic possibly pre-built external dependencies +# Create dependent library to mimic possibly pre-built external dependencies add_library(external_module STATIC external_module.F90) # Create test host library