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

Move file stageing #10

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
52 changes: 1 addition & 51 deletions cime_config/buildlib
Original file line number Diff line number Diff line change
Expand Up @@ -75,57 +75,7 @@ def buildlib(bldroot, libroot, case, compname=None):
s,o,e = run_cmd("make install VERBOSE=1 DESTDIR={}".format(destdir), from_dir=bldroot, verbose=True)
expect(not s,"ERROR from make output={}, error={}".format(o,e))

#----------------------------------------------------
# Prestage necessary files to rundir
#----------------------------------------------------
rundir = case.get_value("RUNDIR")

# Create rundir/ww3_moddef_create
filename = "ww3_grid"
item = os.path.join(bldroot, filename)
if os.path.isfile(item):
ww3_moddef_dir = os.path.join(rundir, "ww3_moddef_create")
if not os.path.exists(ww3_moddef_dir):
os.makedirs(ww3_moddef_dir)
safe_copy(item, ww3_moddef_dir)

if case.get_value("WW3_MODDEF") == 'unset':
# Create output dir ww3_moddef_create if appropriate
output_dir = os.path.join(rundir, "ww3_moddef_create")
if not os.path.exists(output_dir):
os.makedirs(output_dir)

# Copy ww3_inp and other needed info to ww3_moddef_create directory
input_dir = case.get_value("WW3_GRID_INP_DIR")
files = os.listdir(input_dir)
for filename in files:
if not os.path.isfile(os.path.join(output_dir, filename)):
shutil.copy(os.path.join(input_dir, filename), os.path.join(output_dir, filename))

# Create mod_def file using ww3_grid and the grid_input files
os.chdir(output_dir)
os.scandir()
os.system("./ww3_grid > mod_def.ww3.log")

# Copy mod_def.ww3 to $RUNDIR
shutil.move("mod_def.ww3", os.path.join(rundir, "mod_def.ww3"))
shutil.move("mod_def.ww3.log", os.path.join(rundir, "mod_def.ww3.log"))

else:
# Use mod_def already created
mod_def_in = case.get_value("WW3_MODDEF")
if os.path.isfile(mod_def_in):
import filecmp
copy_file = False
if not os.path.isfile(os.path.join(rundir, "mod_def.ww3")):
copy_file = True
elif not filecmp.cmp(mod_def_in, os.path.join(rundir, "mod_def.ww3")):
copy_file = True
if copy_file:
shutil.copy(mod_def_in, os.path.join(rundir, "mod_def.ww3"))
else:
raise RuntimeError("mod_def_in {} does not exist on disk".format(mod_def_in))


def _main_func(args):
caseroot, libroot, bldroot = parse_input(args)
with Case(caseroot) as case:
Expand Down
59 changes: 58 additions & 1 deletion cime_config/buildnml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,64 @@ def buildnml(case, caseroot, compname):
logger.debug("WW3 namelist copy: file1 %s file2 %s ", file1, file2)
shutil.copy2(file1, file2)

_prestage_inputs(case)

###############################################################################
def _prestage_inputs(case):
###############################################################################
#----------------------------------------------------
# Prestage necessary files to rundir
#----------------------------------------------------
rundir = case.get_value("RUNDIR")

# Create rundir/ww3_moddef_create
filename = "ww3_grid"
bldroot = os.path.join(case.get_value("EXEROOT"),"wav","obj")
item = os.path.join(bldroot, filename)
if os.path.isfile(item):
ww3_moddef_dir = os.path.join(rundir, "ww3_moddef_create")
if not os.path.exists(ww3_moddef_dir):
os.makedirs(ww3_moddef_dir)
safe_copy(item, ww3_moddef_dir)

if case.get_value("WW3_MODDEF") == 'unset':
# Create output dir ww3_moddef_create if appropriate
output_dir = os.path.join(rundir, "ww3_moddef_create")
if not os.path.exists(output_dir):
os.makedirs(output_dir)

# Copy ww3_inp and other needed info to ww3_moddef_create directory
input_dir = case.get_value("WW3_GRID_INP_DIR")
files = os.listdir(input_dir)
for filename in files:
if not os.path.isfile(os.path.join(output_dir, filename)):
safe_copy(os.path.join(input_dir, filename), os.path.join(output_dir, filename))

# Create mod_def file using ww3_grid and the grid_input files
run_cmd("ww3_grid", from_dir=output_dir)
Copy link
Member

Choose a reason for hiding this comment

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

Modifying this line as follows should fix this PR:

run_cmd("./ww3_grid > mod_def.ww3.log", from_dir=output_dir)

Copy link
Member

Choose a reason for hiding this comment

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

Better yet, I suggest replacing lines 218-223 with the following:

        if os.path.isfile(os.path.join(output_dir,"ww3_grid")): 
            run_cmd("./ww3_grid > mod_def.ww3.log", from_dir=output_dir)
            if not os.path.isfile(os.path.join(output_dir,"mod_def.ww3")):
                raise RuntimeError("mod_def.ww3 was not created, check mod_def.ww3.log for errors.")
            shutil.move(os.path.join(output_dir,"mod_def.ww3"), os.path.join(rundir, "mod_def.ww3"))
        else:
            logger.warning("ww3_grid file not found. The mod_def.ww3 file will be created after the build phase.")

Copy link
Member

Choose a reason for hiding this comment

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

Actually, even these changes don't fix the issue with TEST runs. It appears like, when you run a TEST case, the buildnml script doesn't get called in between build and run phases. And so the mod_def file never gets created in a TEST run.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have found the toggle to skip the pnl in tests and am testing a change to unset this when ww3 is in the compset.


# Move mod_def.ww3 to $RUNDIR

shutil.move(os.path.join(output_dir,"mod_def.ww3"), os.path.join(rundir, "mod_def.ww3"))

else:
# Use mod_def already created
mod_def_in = case.get_value("WW3_MODDEF")
if os.path.isfile(mod_def_in):
import filecmp
copy_file = False
if not os.path.isfile(os.path.join(rundir, "mod_def.ww3")):
copy_file = True
elif not filecmp.cmp(mod_def_in, os.path.join(rundir, "mod_def.ww3")):
copy_file = True
if copy_file:
shutil.copy(mod_def_in, os.path.join(rundir, "mod_def.ww3"))
else:
raise RuntimeError("mod_def_in {} does not exist on disk".format(mod_def_in))




###############################################################################
def _main_func():
###############################################################################
Expand All @@ -190,6 +248,5 @@ def _main_func():
buildnml(case, caseroot, "ww")

###############################################################################

if __name__ == "__main__":
_main_func()