Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for scheme w/o run phase #548

Merged
merged 6 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions scripts/ccpp_datafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,9 @@ def _new_scheme_entry(parent, scheme, group_name, scheme_headers):
emsg = "Scheme entry already exists for {} but name is {}"
raise CCPPDatatableError(emsg.format(sch_name, pname))
# end if
# Special case: Scheme w/o run phase.
if not scheme._has_run_phase:
return
else:
phase_entry = ET.SubElement(sch_entry, sch_tag)
phase_entry.set("name", sch_name)
Expand Down
16 changes: 11 additions & 5 deletions scripts/suite_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,7 @@ def __init__(self, scheme_xml, context, parent, run_env):
self.__var_debug_checks = list()
self.__forward_transforms = list()
self.__reverse_transforms = list()
self._has_run_phase = True
self.__optional_vars = list()
super().__init__(name, context, parent, run_env, active_call_list=True)

Expand Down Expand Up @@ -1143,6 +1144,9 @@ def analyze(self, phase, group, scheme_library, suite_vars, level):
if phase in func:
my_header = func[phase]
Copy link
Collaborator

Choose a reason for hiding this comment

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

This just says phase, is phase always run?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is to catch instances when "func" doesn't contain a run.
But yeah, phase can be init, run, or final, but we don't care if init and final are not present.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I still don't understand the logic. Somewhere, the code calls analyze for a certain phase (which can be anything you said: init, final, ...). Then in line 1144, you check if that phase is in the func dictionary. If it is not, you set has_run_phase to False. That makes sense if phase is run, but not if the argument phase is init?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The way I understand it is, this may be wrong:

Capgen creates group caps for each CCPP phase except for the run phase, and caps for each group's run phase. For example, in the SCM GFS_v16 SDF, we have the following caps created (4 ccpp phase caps, and 3 group caps):
public :: SCM_GFS_v16_initialize
public :: SCM_GFS_v16_timestep_initial
public :: SCM_GFS_v16_time_vary
public :: SCM_GFS_v16_radiation
public :: SCM_GFS_v16_physics

public :: SCM_GFS_v16_timestep_final
public :: SCM_GFS_v16_finalize

So when analyzing/writing the group caps you can only have phase=run.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, that is fundamentally different from prebuild. In prebuild, there is a cap for each phase and each group. I think right now that limitation in capgen isn't a problem, but I would prefer that check in the code just in case the capgen implementation changes in the future and analyze at the group level can get called for other phases, too.

For example:

            if phase in func:
                my_header = func[phase]
            #else:
            elif phase == 'run':
                self._has_run_phase = False
                return set()

Copy link
Collaborator

Choose a reason for hiding this comment

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

There's another option though. We could try to treat the FV3 dycore with the fast physics as its own "host model" for CCPP framework purposes. I thought about this in the past, when I heard discussions about moving more physics into the FV3 dycore ("inline physics"). I think that should be possible with relatively little engineering on the build system side.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We have discussed one way to handle this but I can't find the reference right now. The idea would be that we have two ways to combine sub-suites. Do you recall where that took place or should I add what I recall to #275 ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you could, yes please. I don't remember. Thanks very much!

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have added what I recall to the description section of #275 .

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks! Yes, I think this would give us the desired capability.

self.__subroutine_name = my_header.title
else:
self._has_run_phase = False
return set()
# end if
else:
estr = 'No schemes found for {}'
Expand Down Expand Up @@ -1727,11 +1731,13 @@ def write(self, outfile, errcode, errmsg, indent):
#
# Write the scheme call.
#
stmt = 'call {}({})'
outfile.write('',indent+1)
outfile.write('! Call scheme', indent+1)
outfile.write(stmt.format(self.subroutine_name, my_args), indent+1)
outfile.write('',indent+1)
if self._has_run_phase:
stmt = 'call {}({})'
outfile.write('',indent+1)
outfile.write('! Call scheme', indent+1)
outfile.write(stmt.format(self.subroutine_name, my_args), indent+1)
outfile.write('',indent+1)
# end if
#
# Copy any local pointers.
#
Expand Down
13 changes: 9 additions & 4 deletions test/capgen_test/run_test
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ ccpp_files="${ccpp_files},${build_dir}/ccpp/test_host_ccpp_cap.F90"
ccpp_files="${ccpp_files},${build_dir}/ccpp/ccpp_ddt_suite_cap.F90"
ccpp_files="${ccpp_files},${build_dir}/ccpp/ccpp_temp_suite_cap.F90"
process_list="setter=temp_set,adjusting=temp_calc_adjust"
module_list="environ_conditions,make_ddt,temp_adjust,temp_calc_adjust,temp_set"
module_list="environ_conditions,make_ddt,setup_coeffs,temp_adjust,temp_calc_adjust,temp_set"
dependencies="bar.F90,foo.F90,qux.F90"
suite_list="ddt_suite;temp_suite"
required_vars_ddt="ccpp_error_code,ccpp_error_message,horizontal_dimension"
Expand All @@ -145,7 +145,9 @@ input_vars_ddt="${input_vars_ddt},model_times,number_of_model_times"
input_vars_ddt="${input_vars_ddt},surface_air_pressure"
output_vars_ddt="ccpp_error_code,ccpp_error_message"
output_vars_ddt="${output_vars_ddt},model_times,number_of_model_times"
required_vars_temp="ccpp_error_code,ccpp_error_message,horizontal_dimension"
required_vars_temp="ccpp_error_code,ccpp_error_message"
required_vars_temp="${required_vars_temp},coefficients_for_interpolation"
required_vars_temp="${required_vars_temp},horizontal_dimension"
required_vars_temp="${required_vars_temp},horizontal_loop_begin"
required_vars_temp="${required_vars_temp},horizontal_loop_end"
required_vars_temp="${required_vars_temp},index_of_water_vapor_specific_humidity"
Expand All @@ -157,7 +159,8 @@ required_vars_temp="${required_vars_temp},time_step_for_physics"
required_vars_temp="${required_vars_temp},vertical_interface_dimension"
required_vars_temp="${required_vars_temp},vertical_layer_dimension"
required_vars_temp="${required_vars_temp},water_vapor_specific_humidity"
input_vars_temp="horizontal_dimension"
input_vars_temp="coefficients_for_interpolation"
input_vars_temp="${input_vars_temp},horizontal_dimension"
input_vars_temp="${input_vars_temp},horizontal_loop_begin"
input_vars_temp="${input_vars_temp},horizontal_loop_end"
input_vars_temp="${input_vars_temp},index_of_water_vapor_specific_humidity"
Expand All @@ -168,7 +171,9 @@ input_vars_temp="${input_vars_temp},surface_air_pressure,time_step_for_physics"
input_vars_temp="${input_vars_temp},vertical_interface_dimension"
input_vars_temp="${input_vars_temp},vertical_layer_dimension"
input_vars_temp="${input_vars_temp},water_vapor_specific_humidity"
output_vars_temp="ccpp_error_code,ccpp_error_message,potential_temperature"
output_vars_temp="ccpp_error_code,ccpp_error_message"
output_vars_temp="${output_vars_temp},coefficients_for_interpolation"
output_vars_temp="${output_vars_temp},potential_temperature"
output_vars_temp="${output_vars_temp},potential_temperature_at_interface"
output_vars_temp="${output_vars_temp},surface_air_pressure"
output_vars_temp="${output_vars_temp},water_vapor_specific_humidity"
Expand Down
24 changes: 24 additions & 0 deletions test/capgen_test/setup_coeffs.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module setup_coeffs
use ccpp_kinds, ONLY: kind_phys
implicit none

public :: setup_coeffs_timestep_init

contains
!> \section arg_table_setup_coeffs_timestep_init Argument Table
!! \htmlinclude arg_table_setup_coeffs_timestep_init.html
!!
subroutine setup_coeffs_timestep_init(coeffs, errmsg, errflg)

real(kind_phys), intent(inout) :: coeffs(:)
character(len=512), intent(out) :: errmsg
integer, intent(out) :: errflg

errmsg = ''
errflg = 0

coeffs(:) = 1._kind_phys

end subroutine setup_coeffs_timestep_init

end module setup_coeffs
29 changes: 29 additions & 0 deletions test/capgen_test/setup_coeffs.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[ccpp-table-properties]
name = setup_coeffs
type = scheme
[ccpp-arg-table]
name = setup_coeffs_timestep_init
type = scheme
[ coeffs ]
standard_name = coefficients_for_interpolation
long_name = coefficients for interpolation
units = none
dimensions = (horizontal_dimension)
type = real
kind = kind_phys
intent = inout
[ errmsg ]
standard_name = ccpp_error_message
long_name = Error message for error handling in CCPP
units = none
dimensions = ()
type = character
kind = len=512
intent = out
[ errflg ]
standard_name = ccpp_error_code
long_name = Error flag for error handling in CCPP
units = 1
dimensions = ()
type = integer
intent = out
1 change: 1 addition & 0 deletions test/capgen_test/temp_scheme_files.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
setup_coeffs.meta
temp_set.meta
temp_adjust.meta
temp_calc_adjust.meta
1 change: 1 addition & 0 deletions test/capgen_test/temp_suite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<suite name="temp_suite" version="1.0">
<group name="physics1">
<scheme>setup_coeffs</scheme>
<scheme>temp_set</scheme>
</group>
<group name="physics2">
Expand Down
9 changes: 6 additions & 3 deletions test/capgen_test/test_host.F90
Original file line number Diff line number Diff line change
Expand Up @@ -358,23 +358,26 @@ program test
character(len=cs), target :: test_parts1(2) = (/ 'physics1 ', &
'physics2 ' /)
character(len=cs), target :: test_parts2(1) = (/ 'data_prep ' /)
character(len=cm), target :: test_invars1(6) = (/ &
character(len=cm), target :: test_invars1(7) = (/ &
'potential_temperature ', &
'potential_temperature_at_interface ', &
'coefficients_for_interpolation ', &
'surface_air_pressure ', &
'water_vapor_specific_humidity ', &
'potential_temperature_increment ', &
'time_step_for_physics ' /)
character(len=cm), target :: test_outvars1(6) = (/ &
character(len=cm), target :: test_outvars1(7) = (/ &
'potential_temperature ', &
'potential_temperature_at_interface ', &
'coefficients_for_interpolation ', &
'surface_air_pressure ', &
'water_vapor_specific_humidity ', &
'ccpp_error_code ', &
'ccpp_error_message ' /)
character(len=cm), target :: test_reqvars1(8) = (/ &
character(len=cm), target :: test_reqvars1(9) = (/ &
'potential_temperature ', &
'potential_temperature_at_interface ', &
'coefficients_for_interpolation ', &
'surface_air_pressure ', &
'water_vapor_specific_humidity ', &
'potential_temperature_increment ', &
Expand Down
1 change: 1 addition & 0 deletions test/capgen_test/test_host_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module test_host_mod
integer, parameter :: index_qv = 1
real(kind_phys), allocatable :: temp_midpoints(:,:)
real(kind_phys) :: temp_interfaces(ncols, pverP)
real(kind_phys) :: coeffs(ncols)
real(kind_phys), dimension(DiagDimStart:ncols, DiagDimStart:pver) :: &
diag1, &
diag2
Expand Down
6 changes: 6 additions & 0 deletions test/capgen_test/test_host_mod.meta
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,9 @@
dimensions = (number_of_model_times)
type = integer
allocatable = True
[ coeffs ]
standard_name = coefficients_for_interpolation
long_name = coefficients for interpolation
units = none
dimensions = (horizontal_dimension)
type = real | kind = kind_phys
5 changes: 4 additions & 1 deletion test/capgen_test/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def usage(errmsg=None):
os.path.join(_BUILD_DIR, "ccpp", "ccpp_ddt_suite_cap.F90"),
os.path.join(_BUILD_DIR, "ccpp", "ccpp_temp_suite_cap.F90")]
_PROCESS_LIST = ["setter=temp_set", "adjusting=temp_calc_adjust"]
_MODULE_LIST = ["environ_conditions", "make_ddt", "temp_adjust",
_MODULE_LIST = ["environ_conditions", "make_ddt", "setup_coeffs", "temp_adjust",
"temp_calc_adjust", "temp_set"]
_SUITE_LIST = ["ddt_suite", "temp_suite"]
_INPUT_VARS_DDT = ["model_times", "number_of_model_times",
Expand All @@ -85,17 +85,20 @@ def usage(errmsg=None):
_REQUIRED_VARS_TEMP = ["ccpp_error_code", "ccpp_error_message",
"potential_temperature",
"potential_temperature_at_interface",
"coefficients_for_interpolation",
"potential_temperature_increment",
"surface_air_pressure", "time_step_for_physics",
"water_vapor_specific_humidity"]
_INPUT_VARS_TEMP = ["potential_temperature",
"potential_temperature_at_interface",
"coefficients_for_interpolation",
"potential_temperature_increment",
"surface_air_pressure", "time_step_for_physics",
"water_vapor_specific_humidity"]
_OUTPUT_VARS_TEMP = ["ccpp_error_code", "ccpp_error_message",
"potential_temperature",
"potential_temperature_at_interface",
"coefficients_for_interpolation",
"surface_air_pressure", "water_vapor_specific_humidity"]

def fields_string(field_type, field_list, sep):
Expand Down
Loading