Coverage for yaptide/batch/string_templates.py: 100%
3 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-04 00:31 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-04 00:31 +0000
1SUBMIT_SHIELDHIT: str = """#!/bin/bash
2OUT=`mktemp`
3module load shieldhit
5ROOT_DIR={root_dir}
6cd $ROOT_DIR
7mkdir -p $ROOT_DIR/workspaces/task_{{0001..{n_tasks}}}
8mkdir -p $ROOT_DIR/input
11INPUT_DIR=$ROOT_DIR/input
12ARRAY_SCRIPT=$ROOT_DIR/array_script.sh
13COLLECT_SCRIPT=$ROOT_DIR/collect_script.sh
15unzip -d $INPUT_DIR $ROOT_DIR/input.zip
16rm $ROOT_DIR/input.zip
18SHIELDHIT_CMD="sbatch --array=1-{n_tasks} {array_options} --parsable $ARRAY_SCRIPT > $OUT"
19eval $SHIELDHIT_CMD
20JOB_ID=`cat $OUT | cut -d ";" -f 1`
21echo "Job id: $JOB_ID"
23if [ -n "$JOB_ID" ] ; then
24 COLLECT_CMD="sbatch --dependency=afterany:$JOB_ID {collect_options} --parsable $COLLECT_SCRIPT > $OUT"
25 eval $COLLECT_CMD
26 COLLECT_ID=`cat $OUT | cut -d ";" -f 1`
27 echo "Collect id: $COLLECT_ID"
28fi
29""" # skipcq: FLK-E501
31COLLECT_BASH: str = """#!/bin/bash
32{collect_header}
33ROOT_DIR={root_dir}
34python3 $ROOT_DIR/simulation_data_sender.py --sim_id={sim_id} --update_key={update_key} \\
35 --backend_url={backend_url} --simulation_state=MERGING_RUNNING
37INPUT_WILDCARD=$ROOT_DIR/workspaces/task_*/*.bdo
38OUTPUT_DIRECTORY=$ROOT_DIR/output
40mkdir -p $OUTPUT_DIRECTORY
42cd $OUTPUT_DIRECTORY
44convertmc json --many "$INPUT_WILDCARD"
46CLEAR_BDOS={clear_bdos}
48if $CLEAR_BDOS; then
49 rm $INPUT_WILDCARD
50fi
52python3 $ROOT_DIR/simulation_data_sender.py --output_dir=$OUTPUT_DIRECTORY \\
53 --sim_id={sim_id} --update_key={update_key} --backend_url={backend_url}
54""" # skipcq: FLK-E501
56ARRAY_SHIELDHIT_BASH: str = """#!/bin/bash
57{array_header}
58ROOT_DIR={root_dir}
59WORK_DIR=$ROOT_DIR/workspaces/task_`printf %04d $SLURM_ARRAY_TASK_ID`
61# seed of RNG
62RNG_SEED=$SLURM_ARRAY_TASK_ID
64# main SHIELD-HIT12A input files
65INPUT_DIR=$ROOT_DIR/input
67# go to working directory
68cd $WORK_DIR
70# make symbolic links to all files from input folder
71ln -s $INPUT_DIR/* .
73sig_handler()
74{{
75 echo "BATCH interrupted"
76 wait # wait for all children, this is important!
77}}
79FILE_TO_WATCH=$WORK_DIR/shieldhit_`printf %04d $SLURM_ARRAY_TASK_ID`.log
80python3 $ROOT_DIR/watcher.py \\
81 --filepath=$FILE_TO_WATCH\\
82 --sim_id={sim_id}\\
83 --task_id=$SLURM_ARRAY_TASK_ID\\
84 --update_key={update_key}\\
85 --backend_url={backend_url}\\
86 --verbose 1>watcher_$SLURM_ARRAY_TASK_ID.stdout 2>watcher_$SLURM_ARRAY_TASK_ID.stderr &
88trap 'sig_handler' SIGUSR1
90# execute simulation
91srun shieldhit -N $RNG_SEED $WORK_DIR &
93wait
94""" # skipcq: FLK-E501