-
Notifications
You must be signed in to change notification settings - Fork 0
/
qsbatch
170 lines (141 loc) · 4.33 KB
/
qsbatch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/bash
#echo "in function interactive"
inital_command="$@"
cpus=""
mem=""
exanode=""
sbatch_options=""
sbatch_body=""
execute=true
conda_env=""
#echo "starting to parse args $@"
OPTIND=
OPTARG=
opt=
sbatch_body="#!/bin/bash
### -------- SLURM ----------- ###"
while getopts ":m:c:n:t:e:Edvh" opt; do
#echo "parsing arg $opt"
case "$opt" in
h)
echo "\
usage:
------
qsbatch [ -h ] [ -c CUPS ] [ -m MEMORY ] [ -t TIME ] [ -n NODE ] [ -e CONDAENV ]
[ -E ] [ -d ] [ -v ]
description:
------------
Submits the command as a batch job by creating a dummy batch file with the specified
options. This allows you to have error and log files using slurm environment variables.
An added feature is being able to activate a conda environment to run the command in.
To Do:
- Creating work directory and log files directories.
- Better at capturing provenance.
optional arguments:
-------------------
-h Print this help message and exit.
-c CPUS Request CPUS number of cores.
-m MEMORY Request MEMORY amount of RAM. The
default units are megabyts. However
The following suffixes can be used:
[K|M|G|T]
-t TIME Request connection time. Acceptable time formats:
minutes
minutes:seconds
hours:minutes:seconds
days-hours
days-hours:minutes
days-hours:minutes:seconds
-n NODE Request a particular child exanode, e.g. 2-5
-E Run the job in the users login environment
-e CONDAENV Activate the conda environment CONDAENV
-d Don't execute. Just display command.
-v Print command. Use with dry run to verify command.
"
execute=false
#exit 2
;;
c)
cpus="$OPTARG"
sbatch_options="$sbatch_options --mincpus $cpus"
sbatch_body="$sbatch_body
#SBATCH --mincpus=$cpus"
#echo "cpus=$cpus"
;;
m)
mem="$OPTARG"
sbatch_options="$sbatch_options --mem ${mem}"
sbatch_body="$sbatch_body
#SBATCH --mem=${mem}"
#echo "mem=$mem"
;;
n)
exanode="$OPTARG"
sbatch_options="$sbatch_options --exanodelist \"exaexanode-${exanode}\""
sbatch_body="$sbatch_body
#SBATCH --exanodelist \"exaexanode-${exanode}\""
#echo "exanode=$exanode"
;;
t)
time="$OPTARG"
sbatch_options="$sbatch_options --time ${time}"
sbatch_body="$sbatch_body
#SBATCH --time=${time}"
#echo "time=$time"
;;
e)
conda_env="$OPTARG"
;;
E)
sbatch_body="$sbatch_body
#SBATCH --get-user-env"
;;
d)
execute=false
;;
v)
verbose=true
;;
?)
echo "Error: did not recognize option, ${OPTARG}."
echo "Please try -h for help."
execute=false
#exit 1
;;
esac
done
shift $(($OPTIND - 1))
executable=$1
actual_command=$@
#echo "actual command: $actual_command"
out="${executable}_%A_%a_%j.out"
sbatch_options="$sbatch_options --output=$out"
sbatch_body="$sbatch_body
#SBATCH --output=$out"
err="${executable}_%A_%a_%j.err"
sbatch_body="$sbatch_body
#SBATCH --error=$err"
sbatch_options="$sbatch_options --error=$err"
sbatch_body="$sbatch_body
### -------------------------- ###
echo "$initial_command"
"
if [[ $conda_env != "" ]]; then
sbatch_body="$sbatch_body
source /home/exacloud/tempwork/teamMicrobiome/conda/etc/profile.d/conda.sh
conda activate $conda_env"
fi
if [[ $verbose ]]; then
echo "batch file:"
cat<<sbatch_file
$sbatch_body
srun $actual_command
sbatch_file
fi
if [[ $execute == true ]]; then
sbatch<<sbatch_file
$sbatch_body
srun $actual_command
sbatch_file
fi
exit 0