#!/usr/bin/env bash
##
## provide this information together with a link to this website in Helpdesk tickets at: http://support.vbc.ac.at"
## ===========================================
## Cryosparc project: P159 J657
## Cryosparc user: matthias.vorlaender@imp.ac.at
## Cryosparc job dir: /groups/plaschka/shared/data/em/Krios/20220317_CD2_IMP/P14_restored/J657
## Cryosparc project dir: /groups/plaschka/shared/data/em/Krios/20220317_CD2_IMP/P14_restored/
## Cryosparc job log: /groups/plaschka/shared/data/em/Krios/20220317_CD2_IMP/P14_restored/J657/job.log
## ===========================================
##
#### cryoSPARC cluster submission script template for SLURM
## variables via: https://guide.cryosparc.com/setup-configuration-and-management/how-to-download-install-and-configure/downloading-and-installing-cryosparc#connect-a-managed-worker-to-cryosparc
## Available variables:
## run_cmd: ~/cryosparc_worker/bin/cryosparcw run --project P159 --job J657 --master_hostname imp-cryosparc-1.vbc.ac.at --master_command_core_port 39002 > /groups/plaschka/shared/data/em/Krios/20220317_CD2_IMP/P14_restored/J657/job.log 2>&1             - the complete command string to run the job
## num_cpu: 2            - the number of CPUs needed
## num_gpu: 0            - the number of GPUs needed.
##                            Note: the code will use this many GPUs starting from dev id 0
##                                  the cluster scheduler or this script have the responsibility
##                                  of setting CUDA_VISIBLE_DEVICES so that the job code ends up
##                                  using the correct cluster-allocated GPUs.
## ram_gb: 16.0             - the amount of RAM needed in GB
## job_dir_abs: /groups/plaschka/shared/data/em/Krios/20220317_CD2_IMP/P14_restored/J657        - absolute path to the job directory
## project_dir_abs: /groups/plaschka/shared/data/em/Krios/20220317_CD2_IMP/P14_restored/    - absolute path to the project dir
## job_log_path_abs: /groups/plaschka/shared/data/em/Krios/20220317_CD2_IMP/P14_restored/J657/job.log   - absolute path to the log file for the job
## worker_bin_path: ~/cryosparc_worker/bin/cryosparcw    - absolute path to the cryosparc worker command
## run_args: --project P159 --job J657 --master_hostname imp-cryosparc-1.vbc.ac.at --master_command_core_port 39002           - arguments to be passed to cryosparcw run
## project_uid: P159        - uid of the project
## job_uid: J657            - uid of the job
## job_creator: matthias.vorlaender@plc        - name of the user that created the job (may contain spaces)
## cryosparc_username: matthias.vorlaender@imp.ac.at - cryosparc username of the user that created the job (usually an email)
## job_type: restack_particles           - cryosparc job type
##                                    defined in /cryosparc_master/cryosparc_compute/jobs/jobregister.py
##
## ====== parameters ======
## 'cbe_time': 
##   - 'auto': select based on job_type(TBD), currently: 8h
##   - 'short', 'medium', 'long' - to select max run duration for that QOS (8h, 48h, 168h)
##   - max runtime in MINUTES
## 'cbe_ram_multiplier': 
##   - default = 1.0
##
## inputs:
##   cbe_time=auto
##   cbe_ram_multiplier=1.0

## configured qos_limit: {'short': 480, 'medium': 2880, 'long': 20160}

## cbe_time auto select -> short, or based on job type: restack_particles


## auto time select: qos=short for job_type: restack_particles

## cbe_time: 480
## qos: short
##
## What follows is a simple SLURM script:
#SBATCH --job-name cs_matthias.vorlaender_P159_J657_restack_particles
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=2
#SBATCH --gres=gpu:0
#SBATCH --partition c
#SBATCH --qos short
#SBATCH --time 480
#SBATCH --mem=16000MB
#SBATCH -o /groups/plaschka/shared/data/em/Krios/20220317_CD2_IMP/P14_restored/J657/P159_J657.out
#SBATCH -e /groups/plaschka/shared/data/em/Krios/20220317_CD2_IMP/P14_restored/J657/P159_J657.err
#SBATCH -A plc
#SBATCH --comment 'cbe_time=auto;cbe_ram_multiplier=1.0;qos=short;job_type=restack_particles;'


echo "starting Cryosparc work ..."

~/cryosparc_worker/bin/cryosparcw run --project P159 --job J657 --master_hostname imp-cryosparc-1.vbc.ac.at --master_command_core_port 39002 > /groups/plaschka/shared/data/em/Krios/20220317_CD2_IMP/P14_restored/J657/job.log 2>&1 

#
# provide the output below for servicedesk requests: http://support.vbc.ac.at
#
cat << EOF | tee "/groups/plaschka/shared/data/em/Krios/20220317_CD2_IMP/P14_restored/J657/jobinfo.txt"
Cryosparc job resource consumption summary:

cryosparc project/job: P159 J657
slurm jobid: $SLURM_JOBID
cryosparc user: matthias.vorlaender@imp.ac.at
job_dir: /groups/plaschka/shared/data/em/Krios/20220317_CD2_IMP/P14_restored/J657
project_dir: /groups/plaschka/shared/data/em/Krios/20220317_CD2_IMP/P14_restored/
job_log: /groups/plaschka/shared/data/em/Krios/20220317_CD2_IMP/P14_restored/J657/job.log

job_type: restack_particles
cbe_time: auto
cbe_ram_multiplier: 1.0
cryosparc ram_gb: 16.0
time_limit: 480
qos: short

# =========================================== 

$(jobinfo $SLURM_JOBID)

# =========================================== 

$(scontrol show job $SLURM_JOBID)

# =========================================== 

EOF

