Skip to content

Commit

Permalink
Merge pull request ESCOMP#858 from PUMASDevelopment/katetc/machlrn_ca…
Browse files Browse the repository at this point in the history
…mdev_pr2_cac

cam6_3_144: New PUMAS external with machine learning support
  • Loading branch information
cacraigucar authored Jan 2, 2024
2 parents 536045c + 2bb62a4 commit 0ac715b
Show file tree
Hide file tree
Showing 22 changed files with 761 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Externals_CAM.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ required = True
local_path = src/physics/pumas
protocol = git
repo_url = https://github.com/ESCOMP/PUMAS
tag = pumas_cam-release_v1.29
tag = pumas_cam-release_v1.34
required = True

[pumas-frozen]
Expand Down
18 changes: 16 additions & 2 deletions bld/build-namelist
Original file line number Diff line number Diff line change
Expand Up @@ -3092,14 +3092,28 @@ if ($cfg->get('microphys') =~ /^mg/) {
add_default($nl, 'micro_mg_iaccr_factor');
add_default($nl, 'micro_mg_max_nicons');

# For CESM2, the decision was made to set micro_do_sb_physics to false
add_default($nl, 'micro_do_sb_physics', 'val'=>'.false.');

# namelist options for pumas tag release_v1.22 or later
# (currently only in the cam_dev physics package)
if ($phys =~ /cam_dev/) {
add_default($nl, 'micro_mg_warm_rain');
add_default($nl, 'micro_mg_accre_sees_auto');
add_default($nl, 'micro_mg_vtrms_factor');
add_default($nl, 'micro_mg_implicit_fall');
add_default($nl, 'pumas_stochastic_tau_kernel_filename', 'val'=>"$cfgdir/../src/physics/pumas/KBARF_tau_kernel.dat");

#set path for stochastic_tau_kernel_filename
my $cam_dir = $cfg->get('cam_dir');
add_default($nl, 'pumas_stochastic_tau_kernel_filename');
my $rel_path = $nl->get_value('pumas_stochastic_tau_kernel_filename');
my $abs_path = quote_string(set_abs_filepath($rel_path, $cam_dir));
#overwrite the relative pathname with the absolute pathname
$nl->set_variable_value('pumas_stochastic_tau_nl', 'pumas_stochastic_tau_kernel_filename', $abs_path);

}else {
# For CESM2, the decision was made to set micro_do_sb_physics to false
# This variable is replaced with micro_mg_warm_rain in cam_dev runs
add_default($nl, 'micro_do_sb_physics', 'val'=>'.false.');
}

# tunings for micro_mg_dcs
Expand Down
4 changes: 2 additions & 2 deletions bld/config_files/definition.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ Physics package: cam3, cam4, cam5, cam6, cam_dev, held_suarez, adiabatic, kessle
<entry id="hemco" valid_values="0,1" value="0">
Switch to turn on Harmonized Emissions Component (HEMCO) for chemistry: 0 => no, 1 => yes.
</entry>
<entry id="microphys" valid_values="rk,mg1,mg2,mg3,spcam_m2005,spcam_sam1mom,none" value="">
<entry id="microphys" valid_values="rk,mg1,mg2,mg3,pumas,spcam_m2005,spcam_sam1mom,none" value="">
Microphysics package: rk (Rasch and Kristjansson), mg1 (Morrison and
Gettelman two moment scheme CAM5.1), mg2 (Morrison and Gettelman second
version CAM6), mg3 (MG scheme 3rd version, graupel), SPCAM_m2005, SPCAM_sam1mom.
version CAM6), mg3 (MG scheme 3rd version, graupel), PUMAS, SPCAM_m2005, SPCAM_sam1mom.
</entry>
<entry id="macrophys" valid_values="rk,park,clubb_sgs,spcam_sam1mom,spcam_m2005,none" value="">
Macrophysics package: RK, Park, CLUBB_SGS, SPCAM_sam1mom, SPCAM_m2005.
Expand Down
12 changes: 8 additions & 4 deletions bld/configure
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ OPTIONS
-macrophys <name> Specify the macrophysics option [rk | park | clubb_sgs].
-max_n_rad_cnst <n> Maximum number of constituents that are either radiatively
active, or in any single diagnostic list for the radiation.
-microphys <name> Specify the microphysics option [mg1 | mg2 | mg3| rk].
-microphys <name> Specify the microphysics option [mg1 | mg2 | mg3| rk | pumas].
-model_top <name> Specify the model_top option [ lt | mt ].
-nadv <n> Set total number of advected species to <n>.
-nadv_tt <n> Set number of advected test tracers <n>.
Expand Down Expand Up @@ -839,6 +839,10 @@ if (defined $opts{'microphys'}) {
$microphys_pkg = lc($opts{'microphys'});
}

if($microphys_pkg eq 'pumas') {
$microphys_pkg = 'mg3';
}

$cfg_ref->set('microphys', $microphys_pkg);

if ($print>=2) { print "Microphysics package: $microphys_pkg$eol"; }
Expand All @@ -857,7 +861,7 @@ if ($carma_pkg =~ m/cirrus/i) {
unless ($microphys_pkg =~ /^mg/) {
die <<"EOF";
** ERROR: microphysics package set to: $microphys_pkg
** The CARMA cirrus model only works with MG microphysics.
** The CARMA cirrus model only works with MG or PUMAS microphysics.
EOF
}
}
Expand All @@ -884,7 +888,7 @@ if (defined $opts{'clubb_sgs'}) {
if ($clubb_sgs and not ($microphys_pkg =~ m/^mg/ )) {
die <<"EOF";
** ERROR: microphysics package set to: $microphys_pkg
** CLUBB_SGS only works with MG microphysics.
** CLUBB_SGS only works with MG or PUMAS microphysics.
EOF
}

Expand Down Expand Up @@ -1024,7 +1028,7 @@ if ($pbl_pkg =~ m/uw/i) {
unless ($microphys_pkg =~ /^mg/) {
die <<"EOF";
** ERROR: microphysics package set to: $microphys_pkg
** The UW PBL scheme only works with MG microphysics.
** The UW PBL scheme only works with MG or PUMAS microphysics.
EOF
}
}
Expand Down
3 changes: 3 additions & 0 deletions bld/namelist_files/namelist_defaults_cam.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2195,6 +2195,7 @@
<microp_scheme microphys="spcam_m2005" >SPCAM_m2005 </microp_scheme>
<microp_scheme microphys="spcam_sam1mom">SPCAM_sam1mom</microp_scheme>
<microp_scheme microphys="mg3">MG</microp_scheme>
<microp_scheme microphys="pumas">MG</microp_scheme>

<micro_mg_version microphys="mg1"> 1 </micro_mg_version>
<micro_mg_sub_version microphys="mg1"> 0 </micro_mg_sub_version>
Expand Down Expand Up @@ -2251,6 +2252,7 @@
<micro_mg_homog_size microphys="mg2" > 25.D-6 </micro_mg_homog_size>

<micro_mg_vtrmi_factor > 1.D0 </micro_mg_vtrmi_factor>
<micro_mg_vtrms_factor > 1.D0 </micro_mg_vtrms_factor>

<micro_mg_effi_factor > 1.D0 </micro_mg_effi_factor>
<micro_mg_effi_factor microphys="mg2" > 1.D0 </micro_mg_effi_factor>
Expand All @@ -2263,6 +2265,7 @@

<micro_mg_implicit_fall phys="cam_dev" > .true. </micro_mg_implicit_fall>
<micro_mg_accre_sees_auto phys="cam_dev" > .true. </micro_mg_accre_sees_auto>
<micro_mg_warm_rain phys="cam_dev" > kk2000 </micro_mg_warm_rain>
<micro_mg_precip_fall_corr phys="cam_dev" > .true. </micro_mg_precip_fall_corr>

<cld_macmic_num_steps> 1 </cld_macmic_num_steps>
Expand Down
38 changes: 37 additions & 1 deletion bld/namelist_files/namelist_definition.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2740,6 +2740,12 @@ Unitless scaling factor for ice fall speed to account for sub-grid scale ice cry
Default: 1.0
</entry>

<entry id="micro_mg_vtrms_factor" type="real" category="microphys"
group="micro_mg_nl" valid_values="" >
Unitless scaling factor for snow fall speed to account for sub-grid scale ice crystal shape variability.
Default: 1.0
</entry>

<entry id="micro_mg_effi_factor" type="real" category="microphys"
group="micro_mg_nl" valid_values="" >
Unitless scaling factor for ice effective radius as seen by radiation. This scaling factor adjusts for sub-grid scale ice crystal shape variability.
Expand All @@ -2757,13 +2763,43 @@ Default: 1
Maximum allowed ice number concentration
Default: 1.0e8
</entry>
x

<entry id="micro_do_sb_physics" type="logical" category="microphys"
group="micro_mg_nl" valid_values="" >
Do Seifert and Behang (2001) autoconversion and accretion physics when set to true.
Default: .false.
</entry>

<entry id="micro_mg_warm_rain" type="char*16" category="microphys"
group="micro_mg_nl" valid_values="kk2000,sb2001,tau,emulated" >
Warm rain process
sb2001 turns on alternative autoconversion and accretion scheme for liquid in microphysics (Seifert and Behang 2001)
kk2000 uses original autoconversion and accretion scheme for liquid in microphysics
tau replaces autoconversion and accretion with a faster emulator to generate machine learning training data
emulated turns on use of machine learning for warm rain
Default: set in namelist_defaults
</entry>

<entry id="stochastic_emulated_filename_quantile" type="char*256" input_pathname="abs" category="microphys"
group="stochastic_emulated_nl" >
Neural net file for warm_rain machine learning
</entry>

<entry id="stochastic_emulated_filename_input_scale" type="char*256" input_pathname="abs" category="microphys"
group="stochastic_emulated_nl" >
Neural net input scaling values file for warm_rain machine learning
</entry>

<entry id="stochastic_emulated_filename_output_scale" type="char*256" input_pathname="abs" category="microphys"
group="stochastic_emulated_nl" >
Neural net output scaling values file for warm_rain machine learning
</entry>

<entry id="pumas_stochastic_tau_kernel_filename" type="char*256" input_pathname="abs" category="microphys"
group="pumas_stochastic_tau_nl" >
Coefficients for the stochastic collection kernel used by the TAU stochastic collection code, invoked in PUMAS with micro_pumas_warm_rain = 'tau'
</entry>

<entry id="micro_do_massless_droplet_destroyer" type="logical" category="microphys"
group="micro_mg_nl" valid_values="" >
Do destruction of massless droplets
Expand Down
47 changes: 47 additions & 0 deletions cime_config/SystemTests/mgp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""
CIME MGP test. This class inherits from SystemTestsCompareTwo
This is a changing config options test to compare between MG3 and
PUMAS in camdev. The use of MG3 or PUMAS should be bfb.
This is just like an ERC test and it's meant for CAM only
as it only does a single build.
(1) Do an initial run with microphys setup as MG3 (suffix MG3)
(2) Do an initial run with microphys setup as PUMAS (suffix PUMAS)
"""

import sys
from CIME.XML.standard_module_setup import *
from CIME.SystemTests.system_tests_compare_two import SystemTestsCompareTwo

logger = logging.getLogger(__name__)

class MGP(SystemTestsCompareTwo):

def __init__(self, case,
separate_builds=True,
run_one_suffix="mg3",
run_two_suffix="pumas",
run_one_description="MG3 microphysics",
run_two_description="PUMAS microphysics",
multisubmit=False,
**kwargs
):
SystemTestsCompareTwo.__init__(self, case,
separate_builds=separate_builds,
run_one_suffix=run_one_suffix,
run_two_suffix=run_two_suffix,
run_one_description=run_one_description,
run_two_description=run_two_description,
multisubmit=multisubmit,
**kwargs
)
def _case_one_setup(self):
stop_n = self._case1.get_value("STOP_N")
expect(stop_n >= 3, "STOP_N must be at least 3, STOP_N = {}".format(stop_n))
self._case.set_value("CAM_CONFIG_OPTS","-phys cam_dev -microphys mg3")

def _case_two_setup(self):
self._case.set_value("CAM_CONFIG_OPTS","-phys cam_dev -microphys pumas")


10 changes: 10 additions & 0 deletions cime_config/config_tests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,15 @@ TMC CAM mass conservation test
<HIST_N>$STOP_N</HIST_N>
</test>

<test NAME="MGP">
<DESC>CAM test: Verify mg3 and pumas give identical answers</DESC>
<INFO_DBUG>1</INFO_DBUG>
<DOUT_S>FALSE</DOUT_S>
<CONTINUE_RUN>FALSE</CONTINUE_RUN>
<STOP_OPTION>nsteps</STOP_OPTION>
<STOP_N>7</STOP_N>
<HIST_OPTION>$STOP_OPTION</HIST_OPTION>
<HIST_N>$STOP_N</HIST_N>
</test>

</config_test>
39 changes: 39 additions & 0 deletions cime_config/testdefs/testlist_cam.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,16 @@
</options>
</test>

<test compset="F2000dev" grid="ne30pg3_ne30pg3_mg17" name="MGP_D_Ln9" testmods="cam/outfrq3s">
<machines>
<machine name="cheyenne" compiler="intel" category="aux_pumas"/>
</machines>
<options>
<option name="wallclock">01:00:00</option>
<option name="comment"> Ensuring PUMAS and MG3 config options give the same answers.</option>
</options>
</test>

<!-- CAM Simple Models -->

<test compset="FDABIP04" grid="T42z30_T42_mg17" name="ERP_D_Ln9_Vnuopc" testmods="cam/outfrq9s">
Expand Down Expand Up @@ -1467,15 +1477,44 @@
<test compset="F2000dev" grid="ne30pg3_ne30pg3_mg17" name="ERP_D_Ln9_Vnuopc" testmods="cam/outfrq9s" supported="false">
<machines>
<machine name="cheyenne" compiler="intel" category="aux_cam"/>
<machine name="cheyenne" compiler="intel" category="aux_pumas"/>
<machine name="cheyenne" compiler="intel" category="prealpha"/>
</machines>
<options>
<option name="wallclock">01:00:00</option>
</options>
</test>
<test compset="F2000dev" grid="ne30pg3_ne30pg3_mg17" name="SMS_D_Ln9_Vnuopc" testmods="cam/outfrq9s_pumas_tau" supported="false">
<machines>
<machine name="cheyenne" compiler="intel" category="aux_pumas"/>
</machines>
<options>
<option name="wallclock">01:00:00</option>
<option name="comment">Test PUMAS tau warm rain ML option</option>
</options>
</test>
<test compset="F2000dev" grid="ne30pg3_ne30pg3_mg17" name="ERP_D_Ln9_Vnuopc" testmods="cam/outfrq9s_pumas_sb2001" supported="false">
<machines>
<machine name="cheyenne" compiler="intel" category="aux_pumas"/>
</machines>
<options>
<option name="wallclock">01:00:00</option>
<option name="comment">Test PUMAS sb2001 warm rain option</option>
</options>
</test>
<test compset="F2000dev" grid="ne30pg3_ne30pg3_mg17" name="SMS_D_Ln9_Vnuopc" testmods="cam/outfrq9s_pumas_emulated" supported="false">
<machines>
<machine name="cheyenne" compiler="intel" category="aux_pumas"/>
</machines>
<options>
<option name="wallclock">01:00:00</option>
<option name="comment">Test PUMAS ML emulated warm rain option</option>
</options>
</test>
<test compset="F2000dev" grid="f09_f09_mg17" name="ERP_Ln9_Vnuopc" testmods="cam/outfrq9s_mg3" supported="false">
<machines>
<machine name="cheyenne" compiler="intel" category="aux_cam"/>
<machine name="cheyenne" compiler="intel" category="aux_pumas"/>
<machine name="cheyenne" compiler="intel" category="prealpha"/>
</machines>
<options>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
./xmlchange ROF_NCPL=\$ATM_NCPL
./xmlchange GLC_NCPL=\$ATM_NCPL
./xmlchange CAM_CONFIG_OPTS=' -microphys pumas' --append
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mfilt=1,1,1,1,1,1
ndens=1,1,1,1,1,1
nhtfrq=9,9,9,9,9,9
inithist='ENDOFRUN'
micro_mg_warm_rain='emulated'
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
!----------------------------------------------------------------------------------
! Users should add all user specific namelist changes below in the form of
! namelist_var = new_namelist_value
!
! Include namelist variables for drv_flds_in ONLY if -megan and/or -drydep options
! are set in the CLM_NAMELIST_OPTS env variable.
!
! EXCEPTIONS:
! Set use_cndv by the compset you use and the CLM_BLDNML_OPTS -dynamic_vegetation setting
! Set use_vichydro by the compset you use and the CLM_BLDNML_OPTS -vichydro setting
! Set use_cn by the compset you use and CLM_BLDNML_OPTS -bgc setting
! Set use_crop by the compset you use and CLM_BLDNML_OPTS -crop setting
! Set spinup_state by the CLM_BLDNML_OPTS -bgc_spinup setting
! Set irrigate by the CLM_BLDNML_OPTS -irrig setting
! Set dtime with L_NCPL option
! Set fatmlndfrc with LND_DOMAIN_PATH/LND_DOMAIN_FILE options
! Set finidat with RUN_REFCASE/RUN_REFDATE/RUN_REFTOD options for hybrid or branch cases
! (includes $inst_string for multi-ensemble cases)
! Set glc_grid with CISM_GRID option
! Set glc_smb with GLC_SMB option
! Set maxpatch_glcmec with GLC_NEC option
! Set glc_do_dynglacier with GLC_TWO_WAY_COUPLING env variable
!----------------------------------------------------------------------------------
hist_nhtfrq = 9
hist_mfilt = 1
hist_ndens = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
./xmlchange ROF_NCPL=\$ATM_NCPL
./xmlchange GLC_NCPL=\$ATM_NCPL
./xmlchange CAM_CONFIG_OPTS=' -microphys pumas' --append
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mfilt=1,1,1,1,1,1
ndens=1,1,1,1,1,1
nhtfrq=9,9,9,9,9,9
inithist='ENDOFRUN'
micro_mg_warm_rain='sb2001'
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
!----------------------------------------------------------------------------------
! Users should add all user specific namelist changes below in the form of
! namelist_var = new_namelist_value
!
! Include namelist variables for drv_flds_in ONLY if -megan and/or -drydep options
! are set in the CLM_NAMELIST_OPTS env variable.
!
! EXCEPTIONS:
! Set use_cndv by the compset you use and the CLM_BLDNML_OPTS -dynamic_vegetation setting
! Set use_vichydro by the compset you use and the CLM_BLDNML_OPTS -vichydro setting
! Set use_cn by the compset you use and CLM_BLDNML_OPTS -bgc setting
! Set use_crop by the compset you use and CLM_BLDNML_OPTS -crop setting
! Set spinup_state by the CLM_BLDNML_OPTS -bgc_spinup setting
! Set irrigate by the CLM_BLDNML_OPTS -irrig setting
! Set dtime with L_NCPL option
! Set fatmlndfrc with LND_DOMAIN_PATH/LND_DOMAIN_FILE options
! Set finidat with RUN_REFCASE/RUN_REFDATE/RUN_REFTOD options for hybrid or branch cases
! (includes $inst_string for multi-ensemble cases)
! Set glc_grid with CISM_GRID option
! Set glc_smb with GLC_SMB option
! Set maxpatch_glcmec with GLC_NEC option
! Set glc_do_dynglacier with GLC_TWO_WAY_COUPLING env variable
!----------------------------------------------------------------------------------
hist_nhtfrq = 9
hist_mfilt = 1
hist_ndens = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
./xmlchange ROF_NCPL=\$ATM_NCPL
./xmlchange GLC_NCPL=\$ATM_NCPL
./xmlchange CAM_CONFIG_OPTS=' -microphys pumas' --append
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mfilt=1,1,1,1,1,1
ndens=1,1,1,1,1,1
nhtfrq=9,9,9,9,9,9
inithist='ENDOFRUN'
micro_mg_warm_rain='tau'
Loading

0 comments on commit 0ac715b

Please sign in to comment.