Skip to content

Commit

Permalink
script naming
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharyburnett committed Feb 18, 2021
1 parent 5c0cf20 commit 114d7dc
Show file tree
Hide file tree
Showing 39 changed files with 119 additions and 1,366 deletions.
111 changes: 58 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,70 +102,75 @@ write_adcirc_configurations(
This code will generate a directory `hera_shinnecock_ike/` with the following structure:

```
hera_shinnecock_ike/
├── coldstart/
│ ├── fort.13
│ ├── fort.14
│ └── fort.15
├── runs/
│ └── test_case_1/
├── fort.13
├── fort.14
└── fort.15
├── config.rc.coldstart
├── config.rc.hotstart
├── model_configure.coldstart
├── model_configure.hotstart
├── nems.configure.coldstart
├── nems.configure.hotstart
├── hera_adcprep.job
├── hera_nems_adcirc.job.coldstart
├── hera_nems_adcirc.job.hotstart
└── run_hera.sh
📦 hera_shinnecock_ike/
┣ 📂 coldstart/
┃ ┣ 📜 fort.13
┃ ┣ 📜 fort.14
┃ ┗ 📜 fort.15
┣ 📂 runs/
┃ ┗ 📂 test_case_1/
┣ 📜 fort.13
┣ 📜 fort.14
┗ 📜 fort.15
┣ 📜 config.rc.coldstart
┣ 📜 config.rc.hotstart
┣ 📜 model_configure.coldstart
┣ 📜 model_configure.hotstart
┣ 📜 nems.configure.coldstart
┣ 📜 nems.configure.hotstart
┣ 📜 job_adcprep_hera.job
┣ 📜 job_nems_adcirc_hera.job.coldstart
┣ 📜 job_nems_adcirc_hera.job.hotstart
┗ 📜 run_hera.sh
```

_**Note:** the required NEMS configuration files (`nems.configure`, `model_configure`) do not yet exist in the run
directories (`coldstart/`, `runs/test_case_1/`). These will be populated in the next step._

### 2. run job submission script `run_<platform>.sh`

Run `sh run_hera.sh` to submit the jobs as a batch. This will create symbolic links to populate configuration directories
within the structure, as so:
Run `run_hera.sh`:

```bash
sh run_hera.sh
```

This will first create symbolic links to populate configuration directories,

```
hera_shinnecock_ike/
├── coldstart/
│ ├── fort.13
│ ├── fort.14
│ ├── fort.15
│ ├── config.rc -> ../config.rc.coldstart
│ ├── model_configure -> ../model_configure.coldstart
│ ├── nems.configure -> ../nems.configure.coldstart
│ ├── hera_adcprep.job -> ../hera_adcprep.job
│ └── hera_nems_adcirc.job -> ../hera_nems_adcirc.job.coldstart
├── runs/
│ └── test_case_1/
├── fort.13
├── fort.14
├── fort.15
├── config.rc -> ../../config.rc.hotstart
├── model_configure -> ../../model_configure.hotstart
├── nems.configure -> ../../nems.configure.hotstart
├── hera_adcprep.job -> ../../hera_adcprep.job
└── hera_nems_adcirc.job -> ../../hera_nems_adcirc.job.hotstart
├── config.rc.coldstart
├── config.rc.hotstart
├── model_configure.coldstart
├── model_configure.hotstart
├── nems.configure.coldstart
├── nems.configure.hotstart
├── hera_adcprep.job
├── hera_nems_adcirc.job.coldstart
├── hera_nems_adcirc.job.hotstart
└── run_hera.sh
📦 hera_shinnecock_ike/
┣ 📂 coldstart/
┃ ┣ 📜 fort.13
┃ ┣ 📜 fort.14
┃ ┣ 📜 fort.15
┃ ┣ 🔗 config.rc -> ../config.rc.coldstart
┃ ┣ 🔗 model_configure -> ../model_configure.hotstart
┃ ┣ 🔗 nems.configure -> ../nems.configure.coldstart
┃ ┣ 🔗 hera_adcprep.job -> ../job_adcprep_hera.job
┃ ┗ 🔗 hera_nems_adcirc.job -> ../job_nems_adcirc_hera.job.coldstart
┣ 📂 runs/
┃ ┗ 📂 test_case_1/
┣ 📜 fort.13
┣ 📜 fort.14
┣ 📜 fort.15
┣ 🔗 config.rc -> ../../config.rc.hotstart
┣ 🔗 model_configure -> ../../model_configure.hotstart
┣ 🔗 nems.configure -> ../../nems.configure.hotstart
┣ 🔗 hera_adcprep.job -> ../../job_adcprep_hera.job
┗ 🔗 hera_nems_adcirc.job -> ../../job_nems_adcirc_hera.job.hotstart
┣ 📜 config.rc.coldstart
┣ 📜 config.rc.hotstart
┣ 📜 model_configure.coldstart
┣ 📜 model_configure.hotstart
┣ 📜 nems.configure.coldstart
┣ 📜 nems.configure.hotstart
┣ 📜 job_adcprep_hera.job
┣ 📜 job_nems_adcirc_hera.job.coldstart
┣ 📜 job_nems_adcirc_hera.job.hotstart
┗ 📜 run_hera.sh
```

The script then submits the requested jobs to the queue:
and then submit the requested jobs to the queue:

```bash
JOBID NAME CPUS NODE DEPENDENCY ACCOUNT PARTITION SUBMIT_TIME START_TIME END_TIME
Expand Down
27 changes: 4 additions & 23 deletions coupledmodeldriver/adcirc.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import copy
from datetime import timedelta
from glob import glob
import os
from os import PathLike
from pathlib import Path
import re

from adcircpy import AdcircMesh, AdcircRun
from adcircpy.forcing.base import Forcing
Expand Down Expand Up @@ -147,7 +145,7 @@ def write_adcirc_configurations(
slurm_log_filename=f'{adcprep_run_name}.out.log',
)
adcprep_script.write(
output_directory / f'{adcprep_script.platform.value}_adcprep.job', overwrite=True
output_directory / f'job_adcprep_{adcprep_script.platform.value}.job', overwrite=True
)

if spinup is not None:
Expand Down Expand Up @@ -190,7 +188,7 @@ def write_adcirc_configurations(
)

coldstart_run_script.write(
output_directory / f'{coldstart_run_script.platform.value}_nems_adcirc.job.coldstart',
output_directory / f'job_nems_adcirc_{coldstart_run_script.platform.value}.job.coldstart',
overwrite=True,
)

Expand All @@ -215,11 +213,8 @@ def write_adcirc_configurations(
slurm_log_filename=f'{adcirc_hotstart_run_name}.out.log',
)

hotstart_run_script.write(
output_directory
/ f'{hotstart_run_script.platform.value}_nems_adcirc.job.hotstart',
overwrite=True,
)
hotstart_run_script.write(output_directory / f'job_nems_adcirc_{hotstart_run_script.platform.value}.job.hotstart',
overwrite=True)

slurm = SlurmConfig(
account=slurm_account,
Expand Down Expand Up @@ -275,19 +270,5 @@ def write_adcirc_configurations(
driver.mesh.set_attribute(attribute_name, value)
driver.write(run_directory, overwrite=True, coldstart=None, hotstart='fort.15', driver=None)

pattern = re.compile(' p*adcirc')
replacement = ' NEMS.x'
for job_filename in glob(str(output_directory / '**' / 'slurm.job'), recursive=True):
with open(job_filename) as job_file:
text = job_file.read()
matched = pattern.search(text)
if matched:
LOGGER.debug(
f'replacing `{matched.group(0)}` with `{replacement}`' f' in "{job_filename}"'
)
text = re.sub(pattern, replacement, text)
with open(job_filename, 'w') as job_file:
job_file.write(text)

run_script = RunScript(platform)
run_script.write(output_directory / f'run_{platform.value}.sh', overwrite=True)
17 changes: 10 additions & 7 deletions coupledmodeldriver/job_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def __str__(self) -> str:

if self.platform != Platform.LOCAL:
lines.extend(
[self.slurm_header, '', 'set -e', '', ]
[self.slurm_header, '', 'set -e', '']
)

if self.modules is not None:
Expand Down Expand Up @@ -384,21 +384,24 @@ def __init__(self, platform: Platform):

def __str__(self) -> str:
lines = [
'DIRECTORY="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"',
'DIRECTORY="$(',
' cd "$(dirname "$0")" >/dev/null 2>&1',
' pwd -P',
')"',
'',
'# prepare single coldstart directory',
f'cd $DIRECTORY/coldstart',
f'ln -sf ../{self.platform.value}_adcprep.job adcprep.job',
f'ln -sf ../{self.platform.value}_nems_adcirc.job.coldstart nems_adcirc.job',
f'ln -sf ../job_adcprep_{self.platform.value}.job adcprep.job',
f'ln -sf ../job_nems_adcirc_{self.platform.value}.job.coldstart nems_adcirc.job',
'cd $DIRECTORY',
'',
'# prepare every hotstart directory',
bash_for_loop(
'for hotstart in $DIRECTORY//runs/*/',
[
'cd "$hotstart"',
f'ln -sf ../../{self.platform.value}_adcprep.job adcprep.job',
f'ln -sf ../../{self.platform.value}_nems_adcirc.job.hotstart nems_adcirc.job',
f'ln -sf ../../job_adcprep_{self.platform.value}.job adcprep.job',
f'ln -sf ../../job_nems_adcirc_{self.platform.value}.job.hotstart nems_adcirc.job',
'cd $DIRECTORY/',
]
),
Expand Down Expand Up @@ -475,7 +478,7 @@ def write(self, filename: PathLike, overwrite: bool = False):
filename = Path(filename)

if filename.is_dir():
filename = filename / f'run.sh'
filename = filename / f'run_{self.platform.value}.sh'

output = f'{self}\n'
if overwrite or not filename.exists():
Expand Down
2 changes: 1 addition & 1 deletion tests/data/reference/hera_shinnecock_ike/coldstart/fort.15
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
created on 2021-02-18 14:49 ! RUNDES
created on 2021-02-18 15:59 ! RUNDES
Shinacock Inlet Coarse Grid ! RUNID
1 ! NFOVER
1 ! NABOUT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# `config.rc` generated with NEMSpy 0.3.1.post8.dev0+91de88b
# `config.rc` generated with NEMSpy 0.3.1.post9.dev0+5c0cf20

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `config.rc` generated with NEMSpy 0.3.1.post8.dev0+91de88b
# `config.rc` generated with NEMSpy 0.3.1.post9.dev0+5c0cf20
atm_dir: input/shinnecock_ike/forcings
atm_nam: wind_atm_fin_ch_time_vec.nc
wav_dir: input/shinnecock_ike/forcings
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `model_configure` generated with NEMSpy 0.3.1.post8.dev0+91de88b
# `model_configure` generated with NEMSpy 0.3.1.post9.dev0+5c0cf20
total_member: 1
print_esmf: .true.
namelist: atm_namelist
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `model_configure` generated with NEMSpy 0.3.1.post8.dev0+91de88b
# `model_configure` generated with NEMSpy 0.3.1.post9.dev0+5c0cf20
total_member: 1
print_esmf: .true.
namelist: atm_namelist
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `nems.configure` generated with NEMSpy 0.3.1.post8.dev0+91de88b
# `nems.configure` generated with NEMSpy 0.3.1.post9.dev0+5c0cf20
# EARTH #
EARTH_component_list: OCN
EARTH_attributes::
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `nems.configure` generated with NEMSpy 0.3.1.post8.dev0+91de88b
# `nems.configure` generated with NEMSpy 0.3.1.post9.dev0+5c0cf20
# EARTH #
EARTH_component_list: ATM WAV OCN
EARTH_attributes::
Expand Down
13 changes: 8 additions & 5 deletions tests/data/reference/hera_shinnecock_ike/run_hera.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
DIRECTORY="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
DIRECTORY="$(
cd "$(dirname "$0")" >/dev/null 2>&1
pwd -P
)"

# prepare single coldstart directory
cd $DIRECTORY/coldstart
ln -sf ../hera_adcprep.job adcprep.job
ln -sf ../hera_nems_adcirc.job.coldstart nems_adcirc.job
ln -sf ../job_adcprep_hera.job adcprep.job
ln -sf ../job_nems_adcirc_hera.job.coldstart nems_adcirc.job
cd $DIRECTORY

# prepare every hotstart directory
for hotstart in $DIRECTORY//runs/*/; do
cd "$hotstart"
ln -sf ../../hera_adcprep.job adcprep.job
ln -sf ../../hera_nems_adcirc.job.hotstart nems_adcirc.job
ln -sf ../../job_adcprep_hera.job adcprep.job
ln -sf ../../job_nems_adcirc_hera.job.hotstart nems_adcirc.job
cd $DIRECTORY/
done

Expand Down
Loading

0 comments on commit 114d7dc

Please sign in to comment.