Skip to main content

coupled model configuration generation

Project description

CoupledModelDriver

tests codecov build version license style

coupledmodeldriver generates an overlying job submission framework and configuration directories for NEMS-coupled coastal ocean model ensembles.

It utilizes nemspy to generate NEMS configuration files, shares common configurations between runs, and organizes spinup and mesh partition into separate jobs for dependant submission.

Supported models and platforms

  • models
    • circulation models
    • forcings
      • ATMESH
      • WW3DATA
  • platforms
    • local
    • Slurm
      • Hera
      • Stampede2

Usage

Example scripts can be found at examples/<platform>

1. generate JSON configuration files

The following code (examples/nems_adcirc/hera_shinnecock_ike_spinup_tidal_atmesh_ww3data.py) creates a configuration for coupling (ATMESH + WW3DATA) -> ADCIRC on Hera, over a small Shinnecock Inlet mesh:

#! /usr/bin/env python

from datetime import datetime, timedelta
from pathlib import Path

from adcircpy.forcing.tides import Tides
from adcircpy.forcing.tides.tides import TidalSource
from adcircpy.forcing.waves.ww3 import WaveWatch3DataForcing
from adcircpy.forcing.winds.atmesh import AtmosphericMeshForcing

from coupledmodeldriver import Platform
from coupledmodeldriver.generate import NEMSADCIRCGenerationScript, NEMSADCIRCRunConfiguration

# paths to compiled `NEMS.x` and `adcprep`
NEMS_EXECUTABLE = '/scratch2/COASTAL/coastal/save/shared/repositories/ADC-WW3-NWM-NEMS/NEMS/exe/NEMS.x'
ADCPREP_EXECUTABLE = '/scratch2/COASTAL/coastal/save/shared/repositories/ADC-WW3-NWM-NEMS/ADCIRC/work/adcprep'

MODULES_FILENAME = '/scratch2/COASTAL/coastal/save/shared/repositories/ADC-WW3-NWM-NEMS/modulefiles/envmodules_intel.hera'

# directory containing input ADCIRC mesh nodes (`fort.14`) and (optionally) mesh values (`fort.13`)
MESH_DIRECTORY = Path('/scratch2/COASTAL/coastal/save/shared/models') / 'meshes' / 'shinnecock' / 'v1.0'

# directory containing input atmospheric mesh forcings (`wind_atm_fin_ch_time_vec.nc`) and WaveWatch III forcings (`ww3.Constant.20151214_sxy_ike_date.nc`)
FORCINGS_DIRECTORY = Path('/scratch2/COASTAL/coastal/save/shared/models') / 'forcings' / 'shinnecock' / 'ike'

# directory to which to write configuration
OUTPUT_DIRECTORY = Path(__file__).parent / Path(__file__).stem

HAMTIDE_DIRECTORY = '/scratch2/COASTAL/coastal/save/shared/models/forcings/tides/hamtide'
TPXO_FILENAME = '/scratch2/COASTAL/coastal/save/shared/models/forcings/tides/h_tpxo9.v1.nc'

platform = Platform.HERA
adcirc_processors = 11
modeled_start_time = datetime(2008, 8, 23)
modeled_duration = timedelta(days=14.5)
modeled_timestep = timedelta(seconds=2)
tidal_spinup_duration = timedelta(days=12.5)
nems_interval = timedelta(hours=1)
job_duration = timedelta(hours=6)

# dictionary defining runs with ADCIRC value perturbations - in this case, a single run with no perturbation
runs = {f'test_case_1': None}

# describe connections between coupled components
nems_connections = ['ATM -> OCN', 'WAV -> OCN']
nems_mediations = None
nems_sequence = [
    'ATM -> OCN',
    'WAV -> OCN',
    'ATM',
    'WAV',
    'OCN',
]

slurm_email_address = 'example@email.gov'

# initialize `adcircpy` forcing objects
tidal_forcing = Tides(tidal_source=TidalSource.TPXO, resource=TPXO_FILENAME)
tidal_forcing.use_all()
wind_forcing = AtmosphericMeshForcing(
    filename=FORCINGS_DIRECTORY / 'wind_atm_fin_ch_time_vec.nc',
    nws=17,
    interval_seconds=3600,
)
wave_forcing = WaveWatch3DataForcing(
    filename=FORCINGS_DIRECTORY / 'ww3.Constant.20151214_sxy_ike_date.nc',
    nrs=5,
    interval_seconds=3600,
)
forcings = [tidal_forcing, wind_forcing, wave_forcing]

configuration = NEMSADCIRCRunConfiguration(
    fort13=MESH_DIRECTORY / 'fort.13',
    fort14=MESH_DIRECTORY / 'fort.14',
    modeled_start_time=modeled_start_time,
    modeled_end_time=modeled_start_time + modeled_duration,
    modeled_timestep=modeled_timestep,
    nems_interval=nems_interval,
    nems_connections=nems_connections,
    nems_mediations=nems_mediations,
    nems_sequence=nems_sequence,
    tidal_spinup_duration=tidal_spinup_duration,
    platform=platform,
    runs=runs,
    forcings=forcings,
    adcirc_processors=adcirc_processors,
    slurm_partition=None,
    slurm_job_duration=job_duration,
    slurm_email_address=slurm_email_address,
    nems_executable=NEMS_EXECUTABLE,
    adcprep_executable=ADCPREP_EXECUTABLE,
    source_filename=MODULES_FILENAME,
)

configuration.write_directory(OUTPUT_DIRECTORY, overwrite=False)

generation_script = NEMSADCIRCGenerationScript()
generation_script.write(OUTPUT_DIRECTORY / 'generate_nems_adcirc.py', overwrite=True)

Alternatively, you may use the command-line interface:

initialize_adcirc \
    --platform HERA \
    --mesh-directory ../../../../models/meshes/hsofs/250m/v1.0 \
    --output-directory hera_shinnecock_ike_spinup_tidal_atmesh_ww3data \
    --modeled-start-time 20080823 \
    --modeled-duration 14:06:00:00 \
    --modeled-timestep 00:00:02 \
    --nems-interval 01:00:00 \
    --tidal-spinup-duration 12:06:00:00 \
    --adcirc-executable /scratch2/COASTAL/coastal/save/shared/repositories/ADC-WW3-NWM-NEMS/NEMS/exe/NEMS.x \
    --adcprep-executable /scratch2/COASTAL/coastal/save/shared/repositories/ADC-WW3-NWM-NEMS/ADCIRC/work/adcprep \
    --modulefile /scratch2/COASTAL/coastal/save/shared/repositories/ADC-WW3-NWM-NEMS/modulefiles/envmodules_intel.hera \
    --generate-script \
    --forcings tidal,atmesh,ww3data \
    --tidal-source TPXO \
    --tidal-path /scratch2/COASTAL/coastal/save/shared/models/forcings/tides/h_tpxo9.v1.nc \
    --atmesh-path /scratch2/COASTAL/coastal/save/shared/models/forcings/shinnecock/ike/wind_atm_fin_ch_time_vec.nc \
    --ww3data-path /scratch2/COASTAL/coastal/save/shared/models/forcings/shinnecock/ike/ww3.Constant.20151214_sxy_ike_date.nc

Either method will create the directory hera_shinnecock_ike_spinup_tidal_atmesh_ww3data/ and generate the following JSON configuration files:

๐Ÿ“ฆ hera_shinnecock_ike_spinup_tidal_atmesh_ww3data/
โ”ฃ โœŽ configure_modeldriver.json
โ”ฃ โœŽ configure_adcirc.json
โ”ฃ โœŽ configure_nems.json
โ”ฃ โœŽ configure_slurm.json
โ”ฃ โœŽ configure_tidal_forcing.json
โ”ฃ โœŽ configure_atmesh.json
โ”ฃ โœŽ configure_ww3data.json
โ”—  โ–ถ generate_nems_adcirc.py

These files contain relevant configuration values for an ADCIRC run. You will likely wish to change these values to alter the resulting run, before generating the actual model configuration.

2. generate model configuration files

Run the following command to read the JSON configuration and generate the ADCIRC run configuration:

generate_adcirc

The resulting configuration will have the following structure:

๐Ÿ“ฆ hera_shinnecock_ike_spinup_tidal_atmesh_ww3data/
โ”ฃ โœŽ configure_modeldriver.json
โ”ฃ โœŽ configure_adcirc.json
โ”ฃ โœŽ configure_nems.json
โ”ฃ โœŽ configure_slurm.json
โ”ฃ โœŽ configure_tidal_forcing.json
โ”ฃ โœŽ configure_atmesh.json
โ”ฃ โœŽ configure_ww3data.json
โ”ฃ  โ–ถ generate_nems_adcirc.py
โ”ฃ ๐Ÿ“‚ coldstart/
โ”ƒ  โ”ฃ ๐Ÿ“œ fort.13
โ”ƒ  โ”ฃ ๐Ÿ”— fort.14 -> ../fort.14
โ”ƒ  โ”ฃ ๐Ÿ“œ fort.15
โ”ƒ  โ”ฃ ๐Ÿ”— nems.configure -> ../nems.configure.coldstart
โ”ƒ  โ”ฃ ๐Ÿ”— config.rc -> ../config.rc.coldstart
โ”ƒ  โ”ฃ ๐Ÿ”— model_configure -> ../model_configure.coldstart
โ”ƒ  โ”ฃ ๐Ÿ”— adcprep.job -> ../job_adcprep_hera.job
โ”ƒ  โ”ฃ ๐Ÿ”— adcirc.job -> ../job_adcirc_hera.job.coldstart
โ”ƒ  โ”— ๐Ÿ”— setup.sh -> ../setup.sh.coldstart
โ”ฃ ๐Ÿ“‚ runs/
โ”ƒ  โ”— ๐Ÿ“‚ test_case_1/
โ”ƒ    โ”ฃ ๐Ÿ“œ fort.13
โ”ƒ    โ”ฃ ๐Ÿ”— fort.14 -> ../../fort.14
โ”ƒ    โ”ฃ ๐Ÿ“œ fort.15
โ”ƒ    โ”ฃ ๐Ÿ”— fort.67.nc -> ../../coldstart/fort.67.nc
โ”ƒ    โ”ฃ ๐Ÿ”— nems.configure -> ../../nems.configure.hotstart
โ”ƒ    โ”ฃ ๐Ÿ”— config.rc -> ../../config.rc.hotstart
โ”ƒ    โ”ฃ ๐Ÿ”— model_configure -> ../../model_configure.hotstart
โ”ƒ    โ”ฃ ๐Ÿ”— adcprep.job -> ../../job_adcprep_hera.job
โ”ƒ    โ”ฃ ๐Ÿ”— adcirc.job -> ../../job_adcirc_hera.job.hotstart
โ”ƒ    โ”— ๐Ÿ”— setup.sh -> ../../setup.sh.hotstart
โ”ฃ ๐Ÿ“œ fort.14
โ”ฃ ๐Ÿ“œ nems.configure.coldstart
โ”ฃ ๐Ÿ“œ nems.configure.hotstart
โ”ฃ ๐Ÿ“œ config.rc.coldstart
โ”ฃ ๐Ÿ“œ config.rc.hotstart
โ”ฃ ๐Ÿ“œ model_configure.coldstart
โ”ฃ ๐Ÿ“œ model_configure.hotstart
โ”ฃ ๐Ÿ“œ job_adcprep_hera.job
โ”ฃ ๐Ÿ“œ job_adcirc_hera.job.coldstart
โ”ฃ ๐Ÿ“œ job_adcirc_hera.job.hotstart
โ”ฃ ๐Ÿ“œ setup.sh.coldstart
โ”ฃ ๐Ÿ“œ setup.sh.hotstart
โ”ฃ ๐Ÿ“œ cleanup.sh
โ”—  โ–ถ run_hera.sh

3. run the model

Run the following to submit the model run to the Slurm job queue:

sh run_hera.sh

The queue will have the following jobs added:

   JOBID                  NAME CPUS NODE                      DEPENDENCY          SUBMIT_TIME           START_TIME             END_TIME
16368044 ADCIRC_MESH_PARTITION    1    1                          (null)  2021-02-18T19:29:17                  N/A                  N/A
16368045      ADCIRC_COLDSTART   11    1  afterany:16368044(unfulfilled)  2021-02-18T19:29:17                  N/A                  N/A
16368046 ADCIRC_MESH_PARTITION    1    1  afterany:16368045(unfulfilled)  2021-02-18T19:29:17                  N/A                  N/A
16368047       ADCIRC_HOTSTART   13    1  afterany:16368046(unfulfilled)  2021-02-18T19:29:17                  N/A                  N/A

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coupledmodeldriver-1.2.10.tar.gz (29.9 kB view hashes)

Uploaded Source

Built Distribution

coupledmodeldriver-1.2.10-py3-none-any.whl (35.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page