Skip to content

Commit 2ef79c2

Browse files
Fix case generation for standard MOM6 grids. (#23)
* add a test that catches the issue with std mom6 grid: Case creator attemps to set NTASKS_OCN for by checking OCN_NX and OCN_NY but those variables are not set for standard MOM6 grids. * fix the issue with standard MOM6 grids: Case creator attemps to set NTASKS_OCN for by checking OCN_NX and OCN_NY but those variables are not set for standard MOM6 grids. While we can retrieve them for standard grids too, we should still not change NTASKS for standard ocn grids, because they have associated, and optimized NTASKS values set in config_pes files.
1 parent 2818e98 commit 2ef79c2

2 files changed

Lines changed: 109 additions & 2 deletions

File tree

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/env python3
2+
3+
import pytest
4+
import shutil
5+
import os
6+
from pathlib import Path
7+
import tempfile
8+
import time
9+
10+
from ProConPy.config_var import ConfigVar, cvars
11+
from ProConPy.stage import Stage
12+
from ProConPy.csp_solver import csp
13+
from visualCaseGen.cime_interface import CIME_interface
14+
from visualCaseGen.initialize_configvars import initialize_configvars
15+
from visualCaseGen.initialize_widgets import initialize_widgets
16+
from visualCaseGen.initialize_stages import initialize_stages
17+
from visualCaseGen.specs.options import set_options
18+
from visualCaseGen.specs.relational_constraints import get_relational_constraints
19+
from visualCaseGen.custom_widget_types.mom6_bathy_launcher import MOM6BathyLauncher
20+
from visualCaseGen.custom_widget_types.case_creator_widget import CaseCreatorWidget
21+
from tests.utils import safe_create_case
22+
23+
24+
# do not show logger output
25+
import logging
26+
27+
logger = logging.getLogger()
28+
logger.setLevel(logging.CRITICAL)
29+
30+
base_temp_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "temp"))
31+
32+
33+
def test_custom_compset_std_grid():
34+
"""Configure a custom compset with a standard grid: 2000_DATM%JRA_SLND_CICE%PRES_MOM6_SROF_SGLC_WW3. Progress through the stages
35+
until the launch stage is reached."""
36+
37+
ConfigVar.reboot()
38+
Stage.reboot()
39+
cime = CIME_interface()
40+
initialize_configvars(cime)
41+
initialize_widgets(cime)
42+
initialize_stages(cime)
43+
set_options(cime)
44+
csp.initialize(cvars, get_relational_constraints(cvars), Stage.first())
45+
46+
# At initialization, the first stage should be enabled
47+
assert Stage.first().enabled
48+
cvars['COMPSET_MODE'].value = 'Custom'
49+
50+
# CCOMPSET_MODE is the only variable in the first stage, so assigning a value to it should disable the first stage
51+
assert not Stage.first().enabled
52+
53+
# The next stge is Custom Component Set, whose first child is Model Time Period
54+
assert Stage.active().title.startswith('Time Period')
55+
cvars['INITTIME'].value = '1850'
56+
57+
cvars['COMP_OCN'].value = "mom"
58+
cvars['COMP_ICE'].value = "sice"
59+
cvars['COMP_ATM'].value = "cam"
60+
cvars['COMP_ROF'].value = "mosart"
61+
cvars['COMP_LND'].value = "clm"
62+
cvars['COMP_WAV'].value = "swav"
63+
cvars['COMP_GLC'].value = "sglc"
64+
65+
66+
assert Stage.active().title.startswith('Component Physics')
67+
68+
cvars['COMP_ATM_PHYS'].value = "CAM60"
69+
cvars['COMP_LND_PHYS'].value = "CLM60"
70+
71+
assert Stage.active().title.startswith('Component Options')
72+
73+
cvars['COMP_ATM_OPTION'].value = "1PCT"
74+
cvars['COMP_LND_OPTION'].value = "BGC"
75+
cvars['COMP_OCN_OPTION'].value = "(none)"
76+
cvars['COMP_ICE_OPTION'].value = "(none)"
77+
cvars['COMP_ROF_OPTION'].value = "(none)"
78+
79+
assert Stage.active().title.startswith('2. Grid')
80+
81+
cvars['GRID_MODE'].value = 'Standard'
82+
cvars['GRID'].value = 'f09_t232'
83+
84+
assert Stage.active().title.startswith('3. Launch')
85+
launch_stage = Stage.active()
86+
87+
with tempfile.TemporaryDirectory(dir=base_temp_dir) as temp_case_path:
88+
pass # immediately remove the random temporary directory,
89+
# which will become the caseroot directory below
90+
91+
cvars["CASEROOT"].value = temp_case_path
92+
93+
case_creator = launch_stage._widget._main_body.children[-1]
94+
assert isinstance(case_creator, CaseCreatorWidget)
95+
96+
cvars["PROJECT"].value = "12345"
97+
98+
# *Click* the create_case button
99+
safe_create_case(cime.srcroot, case_creator)
100+
101+
# sleep for a bit to allow the case to be created
102+
time.sleep(5)
103+
104+
# remove the caseroot directory
105+
shutil.rmtree(temp_case_path)
106+
107+

visualCaseGen/custom_widget_types/case_creator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,8 @@ def _apply_all_xmlchanges(self, do_exec):
508508
else:
509509
assert lnd_grid_mode in [None, "", "Standard"], f"Unknown land grid mode: {lnd_grid_mode}"
510510

511-
# Set NTASKS based on grid size. e.g. NX * NY < max_pts_per_core
512-
if cvars["COMP_OCN"].value == "mom":
511+
# Set NTASKS based on grid size if custom ocn grid. e.g. NX * NY < max_pts_per_core
512+
if cvars["COMP_OCN"].value == "mom" and cvars["OCN_GRID_MODE"].value == "Custom":
513513
num_points = int(cvars["OCN_NX"].value) * int(cvars["OCN_NY"].value)
514514
cores = CaseCreator._calc_cores_based_on_grid(num_points)
515515
with self._out:

0 commit comments

Comments
 (0)