ec-jrc / pyPoseidon

Framework for Hydrodynamic simulations
https://pyposeidon.readthedocs.io/
European Union Public License 1.2
20 stars 7 forks source link

launchSchism.sh only runs if you execute it from the same directory #148

Closed pmav99 closed 1 year ago

pmav99 commented 1 year ago
./launchSchism.sh   # <- works
cd ../
20181001.00/launchSchism.sh  # <- fails
pmav99 commented 1 year ago

Fixing this is easy enough. For example:

#!/usr/bin/env bash
#
# launchschism.sh
#
# Launch schism using MPI

set -euo pipefail

root_dir="$(dirname "$(realpath "$0")")"
cd "${root_dir}"

rm -rf outputs
mkdir -p outputs

exec mpirun {mpirun_flags} -N {ncores} {cmd} {scribes}

Nevertheless, I think that it would be useful to add some extra functionality to the script. E.g. to log the progress of the execution to stdout and to store the logs to the model directory. The "problem" is that in order to do so we need to make use of bash variables which conflict with the syntax python uses for variable interpolation in strings:

"${bash_var}"  # <- bash
This is my {python_var}. # <- python

To circumvent this we need to use an actual template engine (i.e. jinja) instead of plain string formatting. BTW we are already pulling jinja as a secondary dependency. I will think about it.

pmav99 commented 1 year ago

For now, I decided to:

  1. Fix the issue at hand
  2. Reimplement the scripts using jinja

The transition to jinja will make it easier to implement more elaborate logic in the launch scripts in the future.