## This file contains the template of the generic workflow
## It can be used as a reference to create a custom workflow.
# TODO: QUESTION: How to split workflows from mother-run-twin and spinoff ensembles?
JOBS:
  TRANSFER_PROJECT:
    FILE: templates/common/transfer_project.sh
    PLATFORM: LOCAL

  BUILD_ICON:
    FILE: templates/common/build_icon.sh
    DEPENDENCIES: TRANSFER_PROJECT
    WALLCLOCK: 04:00
    PROCESSORS: 16
    RETRIALS: 2 # retry because spack downloads sometimes timeout
    NODES: 1

  BUILD_PYTHON_ENVIRONMENT:
    FILE: templates/common/build_python_environment.sh
    # Right now we rely on spack for building icon and having a python interpreter, so we need this dependency:
    DEPENDENCIES: BUILD_ICON
    WALLCLOCK: 01:00
    PROCESSORS: 16
    NODES: 1

############# parent experiment

  PREPARE_PARENT_EXPERIMENT:
    FILE: templates/spin-off/prepare_parent_experiment.sh
    DEPENDENCIES: BUILD_ICON
    RUNNING: once
    WALLCLOCK: 01:00

  PREPARE_PARENT_DATE:  # TODO: ----> get index of date and select appropriate member
    FILE: templates/spin-off/prepare_parent_date.py
    RUNNING: date
    WALLCLOCK: 01:00
    PLATFORM: LOCAL

#  PREPARE_PARENT_MEMBER:
#    FILE: templates/event-generator/prepare_parent_member.sh  # TODO: In here: get ens member for each date
#    DEPENDENCIES: PREPARE_PARENT_EXPERIMENT PREPARE_PARENT_DATE
#    RUNNING: date
#    WALLCLOCK: 01:00

#  ADAPT_PARENT_MEMBER:  # TODO: no multiple members
#    FILE: templates/event-generator/adapt_parent_member.sh
#    RUNNING: date
#    WALLCLOCK: 00:20
#    DEPENDENCIES: PREPARE_PARENT_MEMBER TRANSFER_PROJECT BUILD_PYTHON_ENVIRONMENT

  PREPARE_PARENT_NAMELIST:
    FILE: templates/spin-off/prepare_parent_namelist.py
    DEPENDENCIES: PREPARE_PARENT_EXPERIMENT PREPARE_PARENT_DATE RUN_PARENT_ICON-1
    WALLCLOCK: 00:05
    RUNNING: chunk
    TYPE: python
    EXECUTABLE: "%HPCROOTDIR%/%python_environment.folder_name%/bin/python3"

  RUN_PARENT_ICON:
    FILE: templates/spin-off/run_parent_icon.sh
    DEPENDENCIES: PREPARE_PARENT_NAMELIST COMPRESS-1  # TODO: remove COMPRESS-1?
    WALLCLOCK: 08:00
    RUNNING: chunk
    PROCESSORS: 64
    MEMORY: 81920
    CUSTOM_DIRECTIVES: [ "#SBATCH --exclusive" ]

############# spin-off experiment

  PREPARE_SPINOFF_EXPERIMENT:
    FILE: templates/spin-off/prepare_spinoff_experiment.sh
    DEPENDENCIES: RUN_PARENT_ICON
    RUNNING: once
    WALLCLOCK: 01:00

  PREPARE_SPINOFF_DATE:
    FILE: templates/spin-off/prepare_spinoff_date.sh
    RUNNING: date
    WALLCLOCK: 01:00
    PLATFORM: LOCAL
    DEPENDENCIES: RUN_PARENT_ICON

  PREPARE_SPINOFF_MEMBER:
    FILE: templates/spin-off/prepare_spinoff_member.sh
    DEPENDENCIES: PREPARE_SPINOFF_EXPERIMENT PREPARE_SPINOFF_DATE
    RUNNING: member
    WALLCLOCK: 01:00

  ADAPT_SPINOFF_MEMBER:
    FILE: templates/spin-off/adapt_spinoff_member.sh
    RUNNING: member
    WALLCLOCK: 00:20
    DEPENDENCIES: PREPARE_SPINOFF_MEMBER TRANSFER_PROJECT BUILD_PYTHON_ENVIRONMENT

  PREPARE_SPINOFF_NAMELIST:
    FILE: templates/spin-off/prepare_spinoff_namelist.py
    DEPENDENCIES: ADAPT_SPINOFF_MEMBER RUN_ICON-1
    WALLCLOCK: 00:05
    RUNNING: chunk
    TYPE: python
    EXECUTABLE: "%HPCROOTDIR%/%python_environment.folder_name%/bin/python3"

  RUN_SPINOFF_ICON:
    FILE: templates/common/run_icon.sh
    DEPENDENCIES: PREPARE_SPINOFF_NAMELIST COMPRESS-1
    WALLCLOCK: 08:00
    RUNNING: chunk
    PROCESSORS: 64
    MEMORY: 81920
    CUSTOM_DIRECTIVES: [ "#SBATCH --exclusive" ]

############# finalize

  COMPRESS:
    FILE: templates/common/compress.py
    DEPENDENCIES: RUN_SPINOFF_ICON
    RUNNING: member
    TYPE: python
    EXECUTABLE: "%HPCROOTDIR%/%python_environment.folder_name%/bin/python3"
    PROCESSORS: 16
    MEMORY: 16384
    WALLCLOCK: 01:00

  TRANSFER:
    FILE: templates/common/transfer.sh
    DEPENDENCIES: COMPRESS
    # Since this is running locally, can simply leave a long wallclock.
    WALLCLOCK: 24:00
    RUNNING: member
    PLATFORM: LOCAL

  CLEAN:
    FILE: templates/common/clean.sh
    DEPENDENCIES: TRANSFER
    WALLCLOCK: 00:10
    RUNNING: member
