Skip to content

Commit

Permalink
Merge branch 'main' into revert_chgres_cube
Browse files Browse the repository at this point in the history
  • Loading branch information
WeirAE authored Oct 8, 2024
2 parents cea5ab3 + b7ed02f commit 6300771
Show file tree
Hide file tree
Showing 44 changed files with 471 additions and 236 deletions.
2 changes: 2 additions & 0 deletions docs/sections/user_guide/cli/drivers/filter_topo/help.out
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Optional arguments:

Positional arguments:
TASK
filtered_output_file
The filtered output file staged from raw input
input_grid_file
The input grid file
namelist_file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"config": {
"additionalProperties": false,
"properties": {
"input_grid_file": {
"filtered_orog": {
"type": "string"
...
"rundir"
Expand Down
2 changes: 2 additions & 0 deletions docs/sections/user_guide/cli/drivers/orog_gsl/help.out
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Optional arguments:

Positional arguments:
TASK
input_config_file
The input config file
input_grid_file
The input grid file
provisioned_rundir
Expand Down
2 changes: 2 additions & 0 deletions docs/sections/user_guide/cli/drivers/shave/help.out
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Optional arguments:

Positional arguments:
TASK
input_config_file
The input config file
provisioned_rundir
Run directory provisioned with all required content
run
Expand Down
8 changes: 8 additions & 0 deletions docs/sections/user_guide/yaml/components/filter_topo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@ config:

Configuration parameters for the ``orog_gsl`` component.

**filtered_orog:**

Name of the filtered output file.

**input_grid_file:**

Path to the tiled input grid file.

**input_raw_orog:**

Path to the raw orography file. The output of the ``orog`` driver.

namelist:
^^^^^^^^^

Expand Down
6 changes: 5 additions & 1 deletion docs/sections/user_guide/yaml/components/shave.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Describes the required parameters to run a ``shave`` configuration.

Name of the grid file with extra points to be shaved.

**nh4:**
**nhalo:**

The number of halo rows/columns.

Expand All @@ -39,6 +39,10 @@ Describes the required parameters to run a ``shave`` configuration.

The j/y dimensions of the compute domain (not including halo)

**output_grid_file:**

The path to the output file.

rundir:
^^^^^^^

Expand Down
24 changes: 21 additions & 3 deletions docs/sections/user_guide/yaml/rocoto.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,30 @@ In the example, the resulting log would appear in the XML file as:

.. code-block:: xml
<log>
<cyclestr>/some/path/to/&FOO;</cyclestr>
</log>
<log><cyclestr>/some/path/to/&FOO;</cyclestr></log>
The ``attrs:`` block is optional within the ``cyclestr:`` block and can be used to specify the cycle offset.

Wherever a ``cyclestr:`` block is accepted, a YAML sequence mixing text and ``cyclestr:`` blocks may also be provided. For example,

.. code-block:: yaml
log:
- cyclestr:
value: "%Y%m%d%H"
- -through-
- cyclestr:
attrs:
offset: "06:00:00"
value: "%Y%m%d%H"
- .log
would be rendered as

.. code-block:: xml
<log><cyclestr>%Y%m%d%H</cyclestr>-through-<cyclestr offset="06:00:00">%Y%m%d%H</cyclestr>.log</log>
Tasks Section
-------------

Expand Down
2 changes: 2 additions & 0 deletions docs/shared/filter_topo.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
filter_topo:
config:
filtered_orog: C403_filtered_orog.tile7.nc
input_grid_file: /path/to/C403_grid.tile7.halo6.nc
input_raw_orog: /path/to/out.oro.nc
execution:
batchargs:
cores: 1
Expand Down
12 changes: 6 additions & 6 deletions docs/shared/orog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ orog:
cores: 1
walltime: 00:05:00
executable: /path/to/orog
files_to_link:
fort.15: /path/to/fix/thirty.second.antarctic.new.bin
landcover30.fixed: /path/to/fix/landcover30.fixed
fort.235: /path/to/fix/gmted2010.30sec.int
grid_file: /path/to/netcdf/grid/file
rundir: /path/to/run/dir
files_to_link:
fort.15: /path/to/fix/thirty.second.antarctic.new.bin
landcover30.fixed: /path/to/fix/landcover30.fixed
fort.235: /path/to/fix/gmted2010.30sec.int
grid_file: /path/to/netcdf/grid/file
rundir: /path/to/run/dir
platform:
account: me
scheduler: slurm
3 changes: 2 additions & 1 deletion docs/shared/shave.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
shave:
config:
input_grid_file: /path/to/input/grid/file
nh4: 1
nhalo: 0
nx: 214
ny: 128
output_grid_file: /path/to/C403_oro_data.tile7.halo0.nc
execution:
batchargs:
cores: 1
Expand Down
37 changes: 24 additions & 13 deletions src/uwtools/drivers/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(
dry_run: bool = False,
key_path: Optional[list[str]] = None,
schema_file: Optional[Path] = None,
controller: Optional[str] = None,
controller: Optional[list[str]] = None,
) -> None:
config_input = config if isinstance(config, YAMLConfig) else YAMLConfig(config=config)
config_input.dereference(
Expand All @@ -65,8 +65,7 @@ def __init__(
self._config: dict = self._config_intermediate[self.driver_name()]
except KeyError as e:
raise UWConfigError("Required '%s' block missing in config" % self.driver_name()) from e
if controller:
self._config[STR.rundir] = self._config_intermediate[controller][STR.rundir]
self._delegate(controller, STR.rundir)
self.schema_file = schema_file
self._validate()
dryrun(enable=dry_run)
Expand Down Expand Up @@ -167,6 +166,19 @@ def _create_user_updated_config(
else:
log.debug(f"Failed to validate {path}")

def _delegate(self, controller: Optional[list[str]], config_key: str) -> None:
"""
Selectively delegate config to controller.
:param controller: Key(s) leading to block in config controlling run-time values.
:param config_key: Name of config item to delegate to controller.
"""
if controller:
val = self._config_intermediate[controller[0]]
for key in controller[1:]:
val = val[key]
self._config[config_key] = val[config_key]

# Public helper methods

@classmethod
Expand Down Expand Up @@ -241,7 +253,7 @@ def __init__(
dry_run: bool = False,
key_path: Optional[list[str]] = None,
schema_file: Optional[Path] = None,
controller: Optional[str] = None,
controller: Optional[list[str]] = None,
):
super().__init__(
cycle=cycle,
Expand Down Expand Up @@ -274,7 +286,7 @@ def __init__(
dry_run: bool = False,
key_path: Optional[list[str]] = None,
schema_file: Optional[Path] = None,
controller: Optional[str] = None,
controller: Optional[list[str]] = None,
):
super().__init__(
cycle=cycle,
Expand Down Expand Up @@ -314,7 +326,7 @@ def __init__(
dry_run: bool = False,
key_path: Optional[list[str]] = None,
schema_file: Optional[Path] = None,
controller: Optional[str] = None,
controller: Optional[list[str]] = None,
):
super().__init__(
config=config,
Expand All @@ -339,7 +351,7 @@ def __init__(
key_path: Optional[list[str]] = None,
batch: bool = False,
schema_file: Optional[Path] = None,
controller: Optional[str] = None,
controller: Optional[list[str]] = None,
):
super().__init__(
cycle=cycle,
Expand All @@ -351,8 +363,7 @@ def __init__(
controller=controller,
)
self._batch = batch
if controller:
self._config[STR.execution] = self.config_full[controller][STR.execution]
self._delegate(controller, STR.execution)

# Workflow tasks

Expand Down Expand Up @@ -541,7 +552,7 @@ def __init__(
key_path: Optional[list[str]] = None,
batch: bool = False,
schema_file: Optional[Path] = None,
controller: Optional[str] = None,
controller: Optional[list[str]] = None,
):
super().__init__(
cycle=cycle,
Expand Down Expand Up @@ -576,7 +587,7 @@ def __init__(
key_path: Optional[list[str]] = None,
batch: bool = False,
schema_file: Optional[Path] = None,
controller: Optional[str] = None,
controller: Optional[list[str]] = None,
):
super().__init__(
cycle=cycle,
Expand Down Expand Up @@ -618,7 +629,7 @@ def __init__(
key_path: Optional[list[str]] = None,
batch: bool = False,
schema_file: Optional[Path] = None,
controller: Optional[str] = None,
controller: Optional[list[str]] = None,
):
super().__init__(
config=config,
Expand Down Expand Up @@ -650,7 +661,7 @@ def _add_docstring(class_: type, omit: Optional[list[str]] = None) -> None:
:param key_path: Keys leading through the config to the driver's configuration block.
:param batch: Run component via the batch system?
:param schema_file: Path to schema file to use to validate an external driver.
:param controller: Name of block in config controlling run-time values.
:param controller: Key(s) leading to block in config controlling run-time values.
"""
setattr(
class_,
Expand Down
16 changes: 14 additions & 2 deletions src/uwtools/drivers/filter_topo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from uwtools.drivers.driver import DriverTimeInvariant
from uwtools.drivers.support import set_driver_docstring
from uwtools.strings import STR
from uwtools.utils.tasks import symlink
from uwtools.utils.tasks import filecopy, symlink


class FilterTopo(DriverTimeInvariant):
Expand All @@ -27,10 +27,21 @@ def input_grid_file(self):
"""
src = Path(self.config["config"]["input_grid_file"])
dst = Path(self.config[STR.rundir], src.name)
yield self.taskname("Input grid")
yield self.taskname(f"Input grid {str(src)}")
yield asset(dst, dst.is_file)
yield symlink(target=src, linkname=dst)

@task
def filtered_output_file(self):
"""
The filtered output file staged from raw input.
"""
src = Path(self.config["config"]["input_raw_orog"])
dst = self.rundir / self.config["config"]["filtered_orog"]
yield self.taskname(f"Raw orog input {str(dst)}")
yield asset(dst, dst.is_file)
yield filecopy(src=src, dst=dst)

@task
def namelist_file(self):
"""
Expand All @@ -56,6 +67,7 @@ def provisioned_rundir(self):
yield self.taskname("provisioned run directory")
yield [
self.input_grid_file(),
self.filtered_output_file(),
self.namelist_file(),
self.runscript(),
]
Expand Down
23 changes: 20 additions & 3 deletions src/uwtools/drivers/orog.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def grid_file(self):
The input grid file.
"""
grid_file = Path(self.config["grid_file"])
yield self.taskname("Input grid file")
yield self.taskname(f"Input grid file {grid_file}")
yield asset(grid_file, grid_file.is_file) if str(grid_file) != "none" else None

@task
Expand All @@ -62,8 +62,9 @@ def input_config_file(self):
"blat",
]
inputs = " ".join([str(inputs[i]) for i in ordered_entries])
outgrid = self.config["grid_file"]
orogfile = self.config.get("orog_file")
outgrid = "'{}'".format(self.config["grid_file"])
if orogfile := self.config.get("orog_file"):
orogfile = "'{}'".format(orogfile)
mask_only = ".true." if self.config.get("mask") else ".false."
merge_file = self.config.get("merge", "none") # string none is intentional
content = [i for i in [inputs, outgrid, orogfile, mask_only, merge_file] if i is not None]
Expand All @@ -82,6 +83,22 @@ def provisioned_rundir(self):
self.runscript(),
]

@task
def runscript(self):
"""
The runscript.
"""
path = self._runscript_path
yield self.taskname(path.name)
yield asset(path, path.is_file)
yield None
envvars = {
"KMP_AFFINITY": "disabled",
"OMP_NUM_THREADS": self.config.get(STR.execution, {}).get(STR.threads, 1),
"OMP_STACKSIZE": "2048m",
}
self._write_runscript(path=path, envvars=envvars)

# Public helper methods

@classmethod
Expand Down
Loading

0 comments on commit 6300771

Please sign in to comment.