-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_jobs.sh
executable file
·180 lines (155 loc) · 4.28 KB
/
setup_jobs.sh
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
171
172
173
174
175
176
177
178
179
180
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
function dirs() {
data_dir="/scidatasm/$USER/"
if [[ -e "$data_dir" ]]; then
echo "using existing $data_dir"
else
echo "creating $data_dir"
mkdir "$data_dir"
fi
results_dir="/results/$USER"
if [[ -e "$results_dir" ]]; then
echo "using existing $results_dir"
else
echo "creating $results_dir"
mkdir "$results_dir"
fi
}
function sync() {
echo "copying directories to /scidatasm/$USER/"
rsync -avr "$(pwd)" "/scidatasm/$USER"
echo "sync complete at $(date)"
echo "waiting for the data to be syncrhonized..."
sleep 600
echo "data is syncrhonized at $(date)"
}
function clean_users() {
# we use single quotes on purpose, as we want to change usernames to $USER
# (not to evaluate $USER variable as expression)
echo 'changing all usernames in clean_users/*.sh to $USER'
sed -i -e 's/kk385830/$USER/' jobs/*.sh
sed -i -e 's/mo382777/$USER/' jobs/*.sh
sed -i -e 's/tm385898/$USER/' jobs/*.sh
}
function check() {
active_python=$(which python)
if [[ "$active_python" == "/scidatasm/"* ]]; then
echo "python location ok"
else
echo ""
echo "ERROR"
echo "active python expected to be under /scidatasm/ partition, yours is at $active_python"
echo "possibly, your virtual environment has not been activated"
return 1
fi
python_version=$(python --version)
if [[ "$python_version" == *"3.8"* ]]; then
echo "python version ok"
else
echo ""
echo "ERROR"
echo "active python version expected to be 3.8, yours is $python_version"
echo "possibly, your virtual environment has not been activated"
return 1
fi
usernames=$(grep -e kk385830 -e mo382777 -e tm385898 -e "$USER" -- jobs/*.sh || true)
if [[ -z "$usernames" ]]; then
echo "usernames ok"
else
echo ""
echo "ERROR"
echo "found usernames for users:"
echo "$usernames"
echo ""
echo "change them to a generic \$USER before proceeding:"
echo "$0 clean_users"
return 1
fi
results_dir="/results/$USER"
data_dir="/scidatasm/$USER"
if [[ -d "$results_dir" ]] && [[ -d "$data_dir" ]]; then
echo "directories ok"
else
echo "ERROR"
echo "missing data or results directory"
echo ""
echo "to create them & synchronize with current directory:"
echo "$0 all"
return 1
fi
# setting +e to preserve output, but only display it in case pip fails
set +e
pip_out=$(pip install -r requirements.txt)
if [[ $? -eq 0 ]]; then
echo "python packages ok"
else
echo "error installing requirements"
echo "$pip_out"
return 1
fi
set -e
echo "all checks complete"
}
function run() {
echo "starting job $1..."
# create output file based on job name
job_filename=$(basename -- "$1")
job_name="${job_filename%.*}"
out_filename="/results/$USER/${job_name}_$(date +"%Y-%m-%d_%H-%M-%S").out"
# start the job
sbatch -o "$out_filename" "$1"
echo "results will be saved to:"
echo "$out_filename"
}
function help() {
echo "Setup tasks:"
echo "$0 dirs - make directories necessary to run the jobs"
echo "$0 sync - sync all necessary data to /scidatasm/$USER/ partiion"
echo "$0 clean_users - change usernames in job files to a generic \$USER"
echo "$0 all - perform all of the setup tasks in sequence"
echo ""
echo "Running jobs:"
echo "$0 check - checks scripts for common errors"
echo "$0 run [job_file] performs checks and runs the job using sbatch"
}
# argument checks
if [[ $# -eq 0 ]]; then
help
exit 2
fi
# additional check for run command
if [[ "$1" == "run" ]] && [[ $# -ne 2 ]]; then
echo "Usage:"
echo "$0 run [job_file]"
exit 2
fi
# call function based on 1st argument or display help message
case "$1" in
dirs)
dirs
;;
sync)
sync
;;
clean_users)
clean_users
;;
check)
check
;;
run)
check
run "$2"
;;
all)
dirs
sync
clean_users
;;
*)
help
exit 2
;;
esac