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

[develop] Refactor setup.py to remove use of global variables. #505

Merged
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6b46fa3
Move config load out into function.
christinaholtNOAA Oct 21, 2022
b8fe83d
WIP
christinaholtNOAA Nov 7, 2022
abd00c4
Merge remote-tracking branch 'ufs-community/develop' into refactor_setup
christinaholtNOAA Nov 7, 2022
3a017e1
Run black.
christinaholtNOAA Nov 7, 2022
1779051
A tiny attempt at linting.
christinaholtNOAA Nov 8, 2022
75f1a27
WIP
christinaholtNOAA Nov 22, 2022
de3bef4
Merge remote-tracking branch 'ufs-community/develop' into refactor_setup
christinaholtNOAA Nov 22, 2022
e045a6b
Finishing up tests.
christinaholtNOAA Dec 2, 2022
1bb963f
Merge remote-tracking branch 'ufs-community/develop' into refactor_setup
christinaholtNOAA Dec 2, 2022
4cec6f0
Cleanup mods found during self review.
christinaholtNOAA Dec 2, 2022
29272d5
Fix ozone test failure.
christinaholtNOAA Dec 2, 2022
db4e7eb
Pass unit tests
christinaholtNOAA Dec 2, 2022
24bf06e
Fix NCO test
christinaholtNOAA Dec 5, 2022
bb540cc
Merge remote-tracking branch 'ufs-community/develop' into refactor_setup
christinaholtNOAA Dec 5, 2022
884e0b1
Minor changes from review comments.
christinaholtNOAA Dec 8, 2022
a3ae539
Run black on files I modified.
christinaholtNOAA Dec 8, 2022
946df71
LOGDIR can't be in var_defns.sh to avoid namespace collision.
christinaholtNOAA Dec 8, 2022
4469643
Spell check.
christinaholtNOAA Dec 8, 2022
5a7b6d8
Fix failures on machines with no data streams.
christinaholtNOAA Dec 8, 2022
139ec9e
Make directory before linking files there.
christinaholtNOAA Dec 12, 2022
487b812
Perhaps better error catching.
christinaholtNOAA Dec 12, 2022
1afaaa7
Removing relics.
christinaholtNOAA Dec 13, 2022
3b82d28
Better logging.
christinaholtNOAA Dec 16, 2022
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
11 changes: 4 additions & 7 deletions parm/FV3LAM_wflow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ Directories and files.
{%- endif %}

{%- if run_envir == "nco" %}
<!ENTITY LOGDIR "{{ logdir }}/<cyclestr>@Y@m@d</cyclestr>">
<!ENTITY LOGDIR "{{ logbasedir }}/<cyclestr>@Y@m@d</cyclestr>">
<!ENTITY LOGEXT ".{{ workflow_id }}.log" >
{%- else %}
<!ENTITY LOGDIR "{{ logdir }}">
<!ENTITY LOGDIR "{{ logbasedir }}">
<!ENTITY LOGEXT ".log" >
{%- endif %}
<!ENTITY CMPEXT "_task_complete.txt">
Expand Down Expand Up @@ -362,11 +362,8 @@ MODULES_RUN_TASK_FP script.
{%- if do_ensemble %}
<metatask name="run_ensemble">

<var name="{{ ensmem_indx_name }}">
{%- for m in range(1, num_ens_members+1) -%}
{%- set fmtstr=" %0"~ndigits_ensmem_names~"d" -%}
{{- fmtstr%m -}}
{%- endfor %} </var>
<var name="{{ ensmem_indx_name }}">{% for m in range(1, num_ens_members+1) %}{{ "%03d " % m }}{% endfor %}</var>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Members should be named with a consistent set of zeros so it's predictable from experiment to experiment. I set it to 3 here so that we can support the vast majority of use cases.


{%- endif %}

{%- if run_task_make_ics %}
Expand Down
2 changes: 1 addition & 1 deletion scripts/exregional_run_vx_ensgrid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export fhr_last
fhr_list=`echo ${FHR} | $SED "s/ /,/g"`
export fhr_list

NUM_PAD=${NDIGITS_ENSMEM_NAMES}
NUM_PAD=3

#
#-----------------------------------------------------------------------
Expand Down
12 changes: 10 additions & 2 deletions tests/WE2E/run_WE2E_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,12 @@ Please correct and rerun."
#
#-----------------------------------------------------------------------
#

# Save the environment variable since a default will override when
# sourced.
save_USHdir=${USHdir}
source_config ${USHdir}/config_defaults.yaml
USHdir=${save_USHdir}
MACHINE_FILE=${machine_file:-"${USHdir}/machine/${machine,,}.yaml"}
source_config ${MACHINE_FILE}
source_config ${test_config_fp}
Expand Down Expand Up @@ -1026,7 +1031,7 @@ model_ver="we2e""
#
# Set NCO mode OPSROOT
#
OPSROOT=\"${opsroot}\""
OPSROOT=\"${opsroot:-$OPSROOT}\""
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why not use the default when the user does not provide a value?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not related to this particular change, but have you tested that specifying OPSROOT from the command line still works. That and 5 other root directories are passed through the environment on WCOSS2

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@danielabdi-noaa Thanks for bringing that to my attention. I did not notice that was a thing, and have most definitely messed it up.

I will look into that mechanism a bit more. Just to clarify, those env variables are passed at configuration time?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, they are available during worklfow generation and will override any config settings for OPSROOT, COMROOT etc.


fi
#
Expand Down Expand Up @@ -1314,10 +1319,13 @@ exist or is not a directory:
#
#-----------------------------------------------------------------------
#
$USHdir/generate_FV3LAM_wflow.py || \
$USHdir/generate_FV3LAM_wflow.py

if [ $? != 0 ] ; then
print_err_msg_exit "\
Could not generate an experiment for the test specified by test_name:
test_name = \"${test_name}\""
fi

done

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ user:
RUN_ENVIR: community
workflow:
DATA_TABLE_TMPL_FN: data_table
DIAG_TABLE_TMPL_FN: diag_table
FIELD_TABLE_TMPL_FN: field_table
DIAG_TABLE_TMPL_FN: diag_table.FV3_GFS_v15p2
FIELD_TABLE_TMPL_FN: field_table.FV3_GFS_v15p2
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 setup.py script no longer does this for us, so we need to specify it here in full.

MODEL_CONFIG_TMPL_FN: model_configure
NEMS_CONFIG_TMPL_FN: nems.configure
CCPP_PHYS_SUITE: FV3_GFS_v15p2
Expand Down
33 changes: 19 additions & 14 deletions ush/calculate_cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@ def calculate_cost(config_fn):
]
import_vars(env_vars=IMPORTS)

ushdir = os.path.dirname(os.path.abspath(__file__))

# get grid config parameters (predefined or custom)
if PREDEF_GRID_NAME:
QUILTING = False
params_dict = set_predef_grid_params(
PREDEF_GRID_NAME,
QUILTING,
DT_ATMOS,
LAYOUT_X,
LAYOUT_Y,
BLOCKSIZE,
USHdir=ushdir,
grid_name=PREDEF_GRID_NAME,
quilting=QUILTING,
)
for param, value in params_dict.items():
if param in IMPORTS and globals()[param] is not None:
params_dict[param] = globals()[param]
import_vars(dictionary=params_dict)
else:
cfg_u = load_config_file(config_fn)
Expand All @@ -60,11 +62,13 @@ def calculate_cost(config_fn):
iend_of_t7_on_t6g=GFDLgrid_IEND_OF_RGNL_DOM_ON_T6G,
jstart_of_t7_on_t6g=GFDLgrid_JSTART_OF_RGNL_DOM_ON_T6G,
jend_of_t7_on_t6g=GFDLgrid_JEND_OF_RGNL_DOM_ON_T6G,
RUN_ENVIR="community",
VERBOSE=False,
run_envir="community",
verbose=False,
nh4=4,
)

elif GRID_GEN_METHOD == "ESGgrid":
constants = load_config_file(os.path.join(ushdir, "constants.yaml"))
grid_params = set_gridparams_ESGgrid(
lon_ctr=ESGgrid_LON_CTR,
lat_ctr=ESGgrid_LAT_CTR,
Expand All @@ -74,6 +78,7 @@ def calculate_cost(config_fn):
halo_width=ESGgrid_WIDE_HALO_WIDTH,
delx=ESGgrid_DELX,
dely=ESGgrid_DELY,
constants=constants["constants"],
)

NX = grid_params["NX"]
Expand All @@ -84,13 +89,13 @@ def calculate_cost(config_fn):
PREDEF_GRID_NAME = "RRFS_CONUS_25km"

params_dict = set_predef_grid_params(
PREDEF_GRID_NAME,
QUILTING,
DT_ATMOS,
LAYOUT_X,
LAYOUT_Y,
BLOCKSIZE,
USHdir=os.path.dirname(os.path.abspath(__file__)),
grid_name=PREDEF_GRID_NAME,
quilting=QUILTING,
)
for param, value in params_dict.items():
if param in IMPORTS and globals()[param] is not None:
params_dict[param] = globals()[param]
import_vars(dictionary=params_dict)

cost.extend([DT_ATMOS, ESGgrid_NX * ESGgrid_NY])
Expand Down
1 change: 0 additions & 1 deletion ush/config.nco.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ nco:
NET: rrfs
model_ver: v1.0
RUN: rrfs_test
OPSROOT: ""
task_get_extrn_ics:
EXTRN_MDL_NAME_ICS: FV3GFS
FV3GFS_FILE_FMT_ICS: grib2
Expand Down
Loading