Coverage for yaptide/batch/string_templates.py: 100%
3 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-22 07:31 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-22 07: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}
34INPUT_WILDCARD=$ROOT_DIR/workspaces/task_*/*.bdo
35OUTPUT_DIRECTORY=$ROOT_DIR/output
37mkdir -p $OUTPUT_DIRECTORY
39cd $OUTPUT_DIRECTORY
41convertmc json --many "$INPUT_WILDCARD"
43CLEAR_BDOS={clear_bdos}
45if $CLEAR_BDOS; then
46 rm $INPUT_WILDCARD
47fi
49python3 $ROOT_DIR/result_sender.py --output_dir=$OUTPUT_DIRECTORY\\
50 --sim_id={sim_id} --update_key={update_key} --backend_url={backend_url}
51""" # skipcq: FLK-E501
53ARRAY_SHIELDHIT_BASH: str = """#!/bin/bash
54{array_header}
55ROOT_DIR={root_dir}
56WORK_DIR=$ROOT_DIR/workspaces/task_`printf %04d $SLURM_ARRAY_TASK_ID`
58# seed of RNG
59RNG_SEED=$SLURM_ARRAY_TASK_ID
61# main SHIELD-HIT12A input files
62INPUT_DIR=$ROOT_DIR/input
64# go to working directory
65cd $WORK_DIR
67# make symbolic links to all files from input folder
68ln -s $INPUT_DIR/* .
70sig_handler()
71{{
72 echo "BATCH interrupted"
73 wait # wait for all children, this is important!
74}}
76FILE_TO_WATCH=$WORK_DIR/shieldhit_`printf %04d $SLURM_ARRAY_TASK_ID`.log
77python3 $ROOT_DIR/watcher.py \\
78 --filepath=$FILE_TO_WATCH\\
79 --sim_id={sim_id}\\
80 --task_id=$SLURM_ARRAY_TASK_ID\\
81 --update_key={update_key}\\
82 --backend_url={backend_url}\\
83 --verbose 1>watcher_$SLURM_ARRAY_TASK_ID.stdout 2>watcher_$SLURM_ARRAY_TASK_ID.stderr &
85trap 'sig_handler' SIGUSR1
87# execute simulation
88srun shieldhit -N $RNG_SEED $WORK_DIR &
90wait
91""" # skipcq: FLK-E501