Skip to content

Commit

Permalink
Merge branch 'precompute-workflow.247' of github.com:NOAA-GFDL/fre-cl…
Browse files Browse the repository at this point in the history
…i into checkout_edits
  • Loading branch information
Avery Kiihne authored and Avery Kiihne committed Nov 4, 2024
2 parents 8a67e19 + 564be4a commit 438492c
Show file tree
Hide file tree
Showing 13 changed files with 496 additions and 166 deletions.
45 changes: 33 additions & 12 deletions fre/cmor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,39 @@ this subtool's help, and command-specific `run` help:
# subtool command-specific help, e.g. for run
> fre cmor run --help
Usage: fre cmor run [OPTIONS]
Rewrite climate model output
Options:
-d, --indir TEXT Input directory [required]
-l, --varlist TEXT Variable list [required]
-r, --table_config TEXT Table configuration [required]
-p, --exp_config TEXT Experiment configuration [required]
-o, --outdir TEXT Output directory [required]
--help Show this message and exit.
> fre cmor run --help
Usage: fre cmor run [OPTIONS]
Rewrite climate model output files with CMIP-compliant metadata for down-
stream publishing
Options:
-d, --indir TEXT directory containing netCDF files. keys specified
in json_var_list are local variable names used for
targeting specific files in this directory
[required]
-l, --varlist TEXT path pointing to a json file containing directory
of key/value pairs. the keys are the 'local' names
used in the filename, and the values pointed to by
those keys are strings representing the name of the
variable contained in targeted files. the key and
value are often the same, but it is not required.
[required]
-r, --table_config TEXT json file containing CMIP-compliant per-
variable/metadata for specific MIP table. The MIP
table can generally be identified by the specific
filename (e.g. 'Omon') [required]
-p, --exp_config TEXT json file containing metadata dictionary for
CMORization. this metadata is effectively appended
to the final output file's header [required]
-o, --outdir TEXT directory root that will contain the full output
and output directory structure generated by the
cmor module upon request. [required]
-v, --opt_var_name TEXT optional, specify a variable name to specifically
process only filenames matching that variable name.
I.e., this string help target local_vars, not
target_vars.
--help Show this message and exit.
```


Expand Down
289 changes: 172 additions & 117 deletions fre/cmor/cmor_mixer.py

Large diffs are not rendered by default.

34 changes: 26 additions & 8 deletions fre/cmor/frecmor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,53 @@ def cmor_cli():
@cmor_cli.command()
@click.option("-d", "--indir",
type=str,
help="Input directory",
help="directory containing netCDF files. keys specified in json_var_list are local " + \
"variable names used for targeting specific files in this directory",
required=True)
@click.option("-l", "--varlist",
type=str,
help="Variable list",
help="path pointing to a json file containing directory of key/value pairs. " + \
"the keys are the \'local\' names used in the filename, and the values " + \
"pointed to by those keys are strings representing the name of the variable " + \
"contained in targeted files. the key and value are often the same, " + \
"but it is not required.",
required=True)
@click.option("-r", "--table_config",
type=str,
help="Table configuration",
help="json file containing CMIP-compliant per-variable/metadata for specific " + \
"MIP table. The MIP table can generally be identified by the specific " + \
"filename (e.g. \'Omon\')",
required=True)
@click.option("-p", "--exp_config",
type=str,
help="Experiment configuration",
help="json file containing metadata dictionary for CMORization. this metadata is " + \
"effectively appended to the final output file's header",
required=True)
@click.option("-o", "--outdir",
type=str,
help="Output directory",
help="directory root that will contain the full output and output directory " + \
"structure generated by the cmor module upon request.",
required=True)
@click.option('-v', "--opt_var_name",
type = str,
help="optional, specify a variable name to specifically process only filenames " + \
"matching that variable name. I.e., this string help target local_vars, not " + \
"target_vars.",
required=False)
@click.pass_context
def run(context, indir, varlist, table_config, exp_config, outdir):
def run(context, indir, varlist, table_config, exp_config, outdir, opt_var_name):
# pylint: disable=unused-argument
"""Rewrite climate model output"""
"""
Rewrite climate model output files with CMIP-compliant metadata for down-stream publishing
"""
context.invoke(
_cmor_run_subtool,
indir = indir,
json_var_list = varlist,
json_table_config = table_config,
json_exp_config = exp_config,
outdir = outdir
outdir = outdir,
opt_var_name = opt_var_name
)
# context.forward(
# _cmor_run_subtool() )
Expand Down
14 changes: 10 additions & 4 deletions fre/make/createCheckout.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import logging
import sys
import click
from .gfdlfremake import varsfre, yamlfre, checkout, targetfre
import fre.yamltools.combine_yamls as cy
from .gfdlfremake import varsfre, yamlfre, checkout, targetfre

@click.command()
def checkout_create(yamlfile,platform,target,no_parallel_checkout,jobs,execute,verbose):
# Define variables
yml = yamlfile
Expand Down Expand Up @@ -65,7 +64,7 @@ def checkout_create(yamlfile,platform,target,no_parallel_checkout,jobs,execute,v
RUNenv ) = modelYaml.platforms.getPlatformFromName(platformName)

## Create the source directory for the platform
if iscontainer == False:
if iscontainer is False:
srcDir = modelRoot + "/" + fremakeYaml["experiment"] + "/src"
# if the source directory does not exist, it is created
if not os.path.exists(srcDir):
Expand All @@ -80,7 +79,7 @@ def checkout_create(yamlfile,platform,target,no_parallel_checkout,jobs,execute,v
print("\nCheckout script created in "+ srcDir + "/checkout.sh \n")

# Run the checkout script
if run == True:
if run is True:
freCheckout.run()
else:
sys.exit()
Expand All @@ -105,6 +104,13 @@ def checkout_create(yamlfile,platform,target,no_parallel_checkout,jobs,execute,v
freCheckout.finish(pc)
print("\nCheckout script created at " + tmpDir + "/checkout.sh" + "\n")

@click.command()
def _checkout_create(yamlfile,platform,target,no_parallel_checkout,jobs,execute,verbose):
'''
Decorator for calling checkout_create - allows the decorated version
of the function to be separate from the undecorated version
'''
return checkout_create(yamlfile,platform,target,no_parallel_checkout,jobs,execute,verbose)

if __name__ == "__main__":
checkout_create()
16 changes: 10 additions & 6 deletions fre/make/createCompile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from .gfdlfremake import varsfre, yamlfre, targetfre, buildBaremetal
import fre.yamltools.combine_yamls as cy

@click.command()
def compile_create(yamlfile,platform,target,jobs,parallel,execute,verbose):
# Define variables
yml = yamlfile
Expand Down Expand Up @@ -60,10 +59,10 @@ def compile_create(yamlfile,platform,target,jobs,parallel,execute,verbose):
raise ValueError (platformName + " does not exist in " + modelYaml.combined.get("compile").get("platformYaml"))

(compiler,modules,modulesInit,fc,cc,modelRoot,iscontainer,mkTemplate,containerBuild,ContainerRun,RUNenv)=modelYaml.platforms.getPlatformFromName(platformName)
## Make the bldDir based on the modelRoot, the platform, and the target
## Make the bldDir based on the modelRoot, the platform, and the target
srcDir = modelRoot + "/" + fremakeYaml["experiment"] + "/src"
## Check for type of build
if iscontainer == False:
if iscontainer is False:
baremetalRun = True
bldDir = modelRoot + "/" + fremakeYaml["experiment"] + "/" + platformName + "-" + target.gettargetName() + "/exec"
os.system("mkdir -p " + bldDir)
Expand All @@ -82,14 +81,19 @@ def compile_create(yamlfile,platform,target,jobs,parallel,execute,verbose):
fremakeBuildList.append(fremakeBuild)
click.echo("\nCompile script created at " + bldDir + "/compile.sh" + "\n")
if run:
#print("ITS GONNA RUN")
if baremetalRun:
pool = Pool(processes=nparallel) # Create a multiprocessing Pool
pool.map(buildBaremetal.fremake_parallel,fremakeBuildList) # process data_inputs iterable with pool
# else:
# fremakeBuild.run()
else:
sys.exit()

@click.command()
def _compile_create(yamlfile,platform,target,jobs,parallel,execute,verbose):
'''
Decorator for calling compile_create - allows the decorated version
of the function to be separate from the undecorated version
'''
return compile_create(yamlfile,platform,target,jobs,parallel,execute,verbose)

if __name__ == "__main__":
compile_create()
11 changes: 9 additions & 2 deletions fre/make/createDocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from .gfdlfremake import varsfre, targetfre, yamlfre, buildDocker
import fre.yamltools.combine_yamls as cy

@click.command()
def dockerfile_create(yamlfile,platform,target,execute):
srcDir="src"
checkoutScriptName = "checkout.sh"
Expand Down Expand Up @@ -52,7 +51,7 @@ def dockerfile_create(yamlfile,platform,target,execute):
## Make the bldDir based on the modelRoot, the platform, and the target
srcDir = modelRoot + "/" + fremakeYaml["experiment"] + "/src"
## Check for type of build
if iscontainer == True:
if iscontainer is True:
image="ecpe4s/noaa-intel-prototype:2023.09.25"
bldDir = modelRoot + "/" + fremakeYaml["experiment"] + "/exec"
tmpDir = "tmp/"+platformName
Expand All @@ -78,5 +77,13 @@ def dockerfile_create(yamlfile,platform,target,execute):
else:
sys.exit()

@click.command()
def _dockerfile_create(yamlfile,platform,target,execute):
'''
Decorator for calling dockerfile_create - allows the decorated version
of the function to be separate from the undecorated version
'''
return dockerfile_create(yamlfile,platform,target,execute)

if __name__ == "__main__":
dockerfile_create()
11 changes: 9 additions & 2 deletions fre/make/createMakefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from .gfdlfremake import makefilefre, varsfre, targetfre, yamlfre
import fre.yamltools.combine_yamls as cy

@click.command()
def makefile_create(yamlfile,platform,target):
srcDir="src"
checkoutScriptName = "checkout.sh"
Expand Down Expand Up @@ -46,7 +45,7 @@ def makefile_create(yamlfile,platform,target):
## Make the bldDir based on the modelRoot, the platform, and the target
srcDir = modelRoot + "/" + fremakeYaml["experiment"] + "/src"
## Check for type of build
if iscontainer == False:
if iscontainer is False:
baremetalRun = True
bldDir = modelRoot + "/" + fremakeYaml["experiment"] + "/" + platformName + "-" + targetObject.gettargetName() + "/exec"
os.system("mkdir -p " + bldDir)
Expand Down Expand Up @@ -78,5 +77,13 @@ def makefile_create(yamlfile,platform,target):
freMakefile.writeMakefile()
click.echo("\nMakefile created at " + bldDir + "/Makefile" + "\n")

@click.command()
def _makefile_create(yamlfile,platform,target):
'''
Decorator for calling makefile_create - allows the decorated version
of the function to be separate from the undecorated version
'''
return makefile_create(yamlfile,platform,target)

if __name__ == "__main__":
makefile_create()
21 changes: 10 additions & 11 deletions fre/make/fremake.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import click
from .createCheckout import checkout_create
from .createCompile import compile_create
from .createDocker import dockerfile_create
from .createMakefile import makefile_create
from .runFremake import fremake_run
from fre.make import createCheckout
from fre.make import createMakefile
from fre.make import createCompile
from fre.make import createDocker
from fre.make import runFremake

yamlfile_opt_help = """Experiment yaml compile FILE
"""
Expand Down Expand Up @@ -73,7 +73,7 @@ def make_cli():
@click.pass_context
def run_fremake(context, yamlfile, platform, target, parallel, jobs, no_parallel_checkout, verbose):
""" - Perform all fremake functions to run checkout and compile model"""
context.forward(fremake_run)
context.forward(runFremake._fremake_run)

####
@make_cli.command()
Expand Down Expand Up @@ -114,7 +114,7 @@ def run_fremake(context, yamlfile, platform, target, parallel, jobs, no_parallel
@click.pass_context
def create_checkout(context,yamlfile,platform,target,no_parallel_checkout,jobs,execute,verbose):
""" - Write the checkout script """
context.forward(checkout_create)
context.forward(createCheckout._checkout_create)

#####
@make_cli.command
Expand All @@ -136,7 +136,7 @@ def create_checkout(context,yamlfile,platform,target,no_parallel_checkout,jobs,e
@click.pass_context
def create_makefile(context,yamlfile,platform,target):
""" - Write the makefile """
context.forward(makefile_create)
context.forward(createMakefile._makefile_create)

#####

Expand Down Expand Up @@ -178,7 +178,7 @@ def create_makefile(context,yamlfile,platform,target):
@click.pass_context
def create_compile(context,yamlfile,platform,target,jobs,parallel,execute,verbose):
""" - Write the compile script """
context.forward(compile_create)
context.forward(createCompile._compile_create)

@make_cli.command
@click.option("-y",
Expand All @@ -202,8 +202,7 @@ def create_compile(context,yamlfile,platform,target,jobs,parallel,execute,verbos
@click.pass_context
def create_dockerfile(context,yamlfile,platform,target,execute):
""" - Write the dockerfile """
context.forward(dockerfile_create)

context.forward(createDocker._dockerfile_create)

if __name__ == "__main__":
make_cli()
2 changes: 1 addition & 1 deletion fre/make/gfdlfremake/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def finish (self,pc):
## TODO: batch script building
def run (self):
"""
Brief: Changes the permission on the checkout script and runs it
Brief: Runs the checkout script
Param:
- self The checkout script object
"""
Expand Down
11 changes: 8 additions & 3 deletions fre/make/runFremake.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@
import logging
from multiprocessing.dummy import Pool
from pathlib import Path

import click

import fre.yamltools.combine_yamls as cy
from .gfdlfremake import (
targetfre, varsfre, yamlfre, checkout,
makefilefre, buildDocker, buildBaremetal )

@click.command()
def fremake_run(yamlfile,platform,target,parallel,jobs,no_parallel_checkout,verbose):
''' run fremake via click'''
yml = yamlfile
Expand Down Expand Up @@ -89,6 +86,7 @@ def fremake_run(yamlfile,platform,target,parallel,jobs,no_parallel_checkout,verb
freCheckout = checkout.checkout("checkout.sh",srcDir)
freCheckout.writeCheckout(modelYaml.compile.getCompileYaml(),jobs,pc)
freCheckout.finish(pc)
os.chmod(srcDir+"/checkout.sh", 0o744)
## TODO: Options for running on login cluster?
freCheckout.run()

Expand Down Expand Up @@ -202,6 +200,13 @@ def fremake_run(yamlfile,platform,target,parallel,jobs,no_parallel_checkout,verb
# process data_inputs iterable with pool
pool.map(buildBaremetal.fremake_parallel,fremakeBuildList)

@click.command()
def _fremake_run(yamlfile,platform,target,parallel,jobs,no_parallel_checkout,verbose):
'''
Decorator for calling _fremake_run - allows the decorated version
of the function to be separate from the undecorated version
'''
return fremake_run(yamlfile,platform,target,parallel,jobs,no_parallel_checkout,verbose)

if __name__ == "__main__":
fremake_run()
11 changes: 11 additions & 0 deletions fre/tests/test_files/CMORbite_var_list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"lai": "lai",
"t_ref": "t_ref",
"cl": "cl",
"mc": "mc",
"ta": "ta",
"sos": "sos",
"so": "so",
"ch4global": "ch4global",
"gppLut": "gppLut"
}
1 change: 1 addition & 0 deletions fre/tests/test_fre_app_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" test "fre app" calls """

import os
import subprocess
from pathlib import Path

import click
Expand Down
Loading

0 comments on commit 438492c

Please sign in to comment.