-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathlibra_htclean_condor.sh
More file actions
executable file
·616 lines (542 loc) · 17.9 KB
/
libra_htclean_condor.sh
File metadata and controls
executable file
·616 lines (542 loc) · 17.9 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
#!/bin/bash
# Copyright (C) 2024
# Associated Universities, Inc. Washington DC, USA.
#
# This library is free software; you can redistribute it and/or modify it
# under the terms of the GNU Library General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
# License for more details.is
#
# You should have received a copy of the GNU Library General Public License
# along with this library; if not, write to the Free Software Foundation,
# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
#
# Correspondence concerning this should be addressed as follows:
# Postal address: National Radio Astronomy Observatory
# 1003 Lopezville Road,
# Socorro, NM - 87801, USA
#
# $Id$
# For easier debugging
#set -e # fail at first error
set -v # echo commands
lsdir()
{
path=$1
echo ""
echo "Listing contents of ${path}:"
echo "`ls -l ${path}`"$'\n\n'
}
setupLibra()
{
# Add casa-data to .casarc
tar xzf casa-data.tgz; rm -rf casa-data.tgz
echo "measures.directory:${PWD}/casa-data" > ~/.casarc
libra_bundle=`find . -name 'libra.*.sh'`
sh ${libra_bundle} libra;# rm -rf ${libra_bundle}
libra_install=$?
if [ ${libsetup} -ne "0" ]
then
return 5 # Error code to indicate failure to install libra
else
libraBIN=${PWD}/libra/bin
return 0
fi
}
setupRoadRunner()
{
echo "Setting up roadrunner on `hostname`. Output of nvidia-smi is:"
echo "`nvidia-smi`"
echo "`nvidia-smi --query-gpu=name,compute_cap --format=csv --id=${NVIDIA_VISIBLE_DEVICES}`"
echo ""
nvidia-smi --query-gpu=timestamp,name,utilization.memory,memory.used --format=csv -l 5 --id=${NVIDIA_VISIBLE_DEVICES} > working/logs/nvidia.${jobmode}.${partId}.out &
bundles_dir=`ls libra/bundles`
echo "bundles_dir: $bundles_dir"
if [ -e /.singularity.d/libs/libcuda.so.1 ]
then
cp -f /.singularity.d/libs/libcuda.so.1 libra/bundles/${bundles_dir}/lib64
else
if [ -e /lib64/libcuda.so.1 ]
then
cp -f /lib64/libcuda.so.1 libra/bundles/${bundles_dir}/lib64
else
echo "libcuda.so.1: File not found on knwon paths. Trying with packaged version"
fi
fi
echo "LD_LIBRARY_PATH: ${LD_LIBRARY_PATH}"
echo ""
# OMP_PROC_BIND should always be set to false. Setting it to true limits the data rate when
# more than one instance of roadrunner runs on the same execute host
export OMP_PROC_BIND=false
export NPROCS=0
mkdir -p working/${imagename}.workdirectory
}
checkInputMSName()
{
lsdir ${PWD}
if [ ! -e ${msname} ]
then
_msname=`find . -maxdepth 1 -name *.ms`
if [ "${_msname}" != "" ]
then
echo "Found ${_msname}, renaming to ${msname}"
mv ${_msname} ${msname}
else # workaround for transfer plugin not renaming expanded tarball
if [ -d ${msname}.tar ]
then
mv ${msname}.tar ${msname}
mv ${cfcache}.tar ${cfcache}
else
if [ -f ${msname}.tar ]
then
echo "Expanding tarballs: ${msname}.tar, ${cfcache}.tar"
tar xf ${msname}.tar; rm -rf ${msname}.tar
tar xf ${cfcache}.tar; rm -rf ${cfcache}.tar
fi
fi
fi
fi
}
expandInputImageTarballs()
{
if [ $# -gt 0 ]
then
imglist="$@"
for img in ${imglist}
do
echo "Expanding tarball: ${img}"
tar xf ${img}; rm -rf ${img}
done
else
echo "Didn't find any image tarballs to expand."
lsdir ${PWD}
fi
}
createTar()
{
if [ $# -gt 0 ]
then
imglist="$@"
for img in ${imglist}
do
name=${imagename}.${img}
echo "Making tarball: ${name}.tar"
if [ -e ${name} ]
then
tar cf ${name}.tar ${name}
else
echo "${name}: file not found."
return 1
fi
done
return 0
else
echo "$0 expects at least one argument, none given."
return 2
fi
}
checkLog()
{
logfile=$1
grep SEVERE ${logfile}
if [ $? != 0 ]
then
return 0
else
return 1
fi
}
makeInputImageList()
{
ext=$1
unset partimagenames
eval "`grep msnamelist.*\= ${input_file} | sed 's/ //g'`"
msnamelist=`echo ${msnamelist} | sed 's/,/ /g'`
partimagenames=${imagename}.n1.${ext}
i=2
for msname in `echo $msnamelist | awk '{$1=""}{print substr($0, 2)}'`
do
partimagenames=${partimagenames},${imagename}.n${i}.${ext}
i=$((i+1))
done
}
readStartImageFlags()
{
eval "`grep useStartModel.*\= ${input_file} | sed 's/ //g'`"
useStartModel=`echo ${useStartModel} | sed 's/,/ /g'`
eval "`grep useStartMask.*\= ${input_file} | sed 's/ //g'`"
useStartMask=`echo ${useStartMask} | sed 's/,/ /g'`
}
runGather()
{
extlist=$@
gatherApp=${libraBIN}/chip
excode=0
for ext in ${extlist}
do
makeInputImageList ${ext}
logname=logs/gather_${ext}-$(date +%Y%m%d-%H%M%S)
cp ${input_file} ${logname}.def
# Change input parameters
echo "imagename = ${partimagenames}" >> ${logname}.def
echo "outputimage = ${imagename}.${ext}" >> ${logname}.def
if [ ${useStartMask} = "True" ] || [ ${useStartModel} = "True" ] && [ "${ext}" != "sumwt" ]
then
echo "overwrite = 1" >> ${logname}.def
fi
echo "resetoutput = 1" >> ${logname}.def
echo "stats = all" >> ${logname}.def
${gatherApp} help=def,${logname}.def &> ${logname}.log
checkLog ${logname}.log
ex=$?
logname=${logname}.checkAmp
cp ${input_file} ${logname}.def
# Change input parameters
echo "imagename = ${imagename}.${ext}" >> ${logname}.def
${libraBIN}/acme help=def,${logname}.def &> ${logname}.log
checkAmp=$?
if [ ${checkAmp} -gt ${ex} ]
then
ex=${checkAmp}
fi
[ ${ex} -gt ${excode} ] && excode=${ex}
done
return ${excode}
}
runNormalize()
{
f_imtype=$1
norm_app=${libraBIN}/dale
#Change input parameters
echo "imtype = ${f_imtype}" >> ${input_file}
if [ ${f_imtype} = "psf" ]
then
echo "computepb = 1" >> ${input_file}
# Workaround for NOOP in dale
elif [ ${f_imtype} = "model" ]
then
sed -i 's/SubType.*=.*//g' ${imagename}.model/table.info
fi
# Normalize psf and weight and compute pb
logname=logs/norm_${f_imtype}-$(date +%Y%m%d-%H%M%S)
cp ${input_file} ${logname}.def
${norm_app} help=def,${input_file} &> ${logname}.log
checkLog ${logname}.log
return $?
}
makeStartImageCopies()
{
cpext=$1
extlist="weight psf residual"
for ext in ${extlist}
do
cp -r ${imagename}.${cpext} ${imagename}.${ext}
done
tar cf ${imagename}.residual.start.tar ${imagename}.residual
}
htclean_finalize()
{
#create tgz file containing casalogs directory
cd $_CONDOR_SCRATCH_DIR
mv working/logs $_CONDOR_SCRATCH_DIR
tar czf logs.${jobmode}.tgz logs
lsdir ${PWD}
}
[ -n "${1}" ] && jobmode=${1}
[ -n "${2}" ] && input_file=${2}
[ -n "${3}" ] && partId=${3}
[ -n "${4}" ] && msname=${4}
[ -n "${5}" ] && imagename=${5}
[ -n "${6}" ] && cfcache=${6}
echo "jobmode is (${1})"
echo "input_file is (${2})"
echo "partId is (${3})"
echo "msname is (${4})"
echo "imagename is (${5})"
echo "cfcache is (${6})"
echo "OS version: `cat /etc/redhat-release`"
echo "Hostname: `hostname -f`"
echo "Physical Host Name: `cat $_CONDOR_MACHINE_AD | grep -i k8sphysicalhostname | awk '{print $3}'`"
mkdir -p working/logs
export HOME=${HOME:=$TMPDIR}
export OMP_NUM_THREADS=1
setupLibra
libra_install=$?
if [ ${libra_install} -ne "0" ]
then
exit ${libra_install}
fi
case ${jobmode} in
makePSF)
checkInputMSName
setupRoadRunner
mv ${cfcache} working
cd working
# Change parameter values by writing to the end of ${input_file}
# Make .weight image
echo "vis = ../${msname}" >> ${input_file}
echo "imagename = ${imagename}.workdirectory/${imagename}.${partId}.weight" >> ${input_file}
echo "mode = weight" >> ${input_file}
echo "cfcache = ${cfcache}" >> ${input_file}
logname=logs/weight-$(date +%Y%m%d-%H%M%S).${partId}
cp ${input_file} ${logname}.def
cp ${logname}.def roadrunner.def
${libraBIN}/roadrunner help=def,${input_file} &> ${logname}.log
weight=$?
logname=${logname}.checkAmp
${libraBIN}/acme help=def,${input_file} &> ${logname}.log
checkAmp=$?
if [ ${checkAmp} -gt ${weight} ]
then
weight=${checkAmp}
fi
# Make .psf image
echo "imagename = ${imagename}.workdirectory/${imagename}.${partId}.psf" >> ${input_file}
echo "mode = psf" >> ${input_file}
logname=logs/psf-$(date +%Y%m%d-%H%M%S).${partId}
cp ${input_file} ${logname}.def
${libraBIN}/roadrunner help=def,${input_file} &> ${logname}.log
psf=$?
logname=${logname}.checkAmp
${libraBIN}/acme help=def,${input_file} &> ${logname}.log
checkAmp=$?
if [ ${checkAmp} -gt ${psf} ]
then
psf=${checkAmp}
fi
# create tar files from image directories
if [ $weight -eq 0 ] && [ $psf -eq 0 ] && [ -e ${imagename}.workdirectory/${imagename}.${partId}.weight ] && [ -e ${imagename}.workdirectory/${imagename}.${partId}.psf ]
then
echo "Adding images to tarballs:"
cd ${imagename}.workdirectory
echo "Contents of ${PWD}:"
echo "`ls`"$'\n\n'
createTar ${partId}.weight ${partId}.sumwt ${partId}.psf
makePSF=$?
mv ${imagename}.${partId}.*.tar $_CONDOR_SCRATCH_DIR
else
echo "Failed to make images, check inputs carefully. Exit-codes are weight: ${weight} and psf: ${psf}."
if [ $weight -gt $psf ]
then
makePSF=$weight
else
makePSF=$psf
if [ $psf -eq 0 ]
then
makePSF=1
fi
fi
fi
htclean_finalize
exit ${makePSF}
;;
runResidualCycle)
checkInputMSName
imagelist=`find . -maxdepth 1 -name "${imagename}.*.tar"`
expandInputImageTarballs ${imagelist}
setupRoadRunner
mv ${cfcache} working
mv ${imagename}.* working
cd working
mv ${imagename}.${partId}.* ${imagename}.workdirectory
# Change parameters by writing to the end of ${input_file}
echo "vis = ../${msname}" >> ${input_file}
echo "imagename = ${imagename}.workdirectory/${imagename}.${partId}.residual" >> ${input_file}
echo "mode = residual" >> ${input_file}
echo "cfcache = ${cfcache}" >> ${input_file}
# If model image exists, also update modelimagename
# Attention to the name of the model image, modify workflow accordingly
if [ -e ${imagename}.divmodel ]
then
echo "modelimagename = ${imagename}.divmodel" >> ${input_file}
fi
# Compute .residual
logname=logs/residual-$(date +%Y%m%d-%H%M%S).${partId}
cp ${input_file} ${logname}.def
${libraBIN}/roadrunner help=def,${input_file} &> ${logname}.log
residual=$?
logname=${logname}.checkAmp
${libraBIN}/acme help=def,${input_file} &> ${logname}.log
checkAmp=$?
if [ ${checkAmp} -gt ${residual} ]
then
residual=${checkAmp}
fi
if [ $residual -eq 0 ] && [ -e ${imagename}.workdirectory/${imagename}.${partId}.residual ]
then
echo "Adding images to tarballs:"
cd ${imagename}.workdirectory
createTar ${partId}.residual
mv ${imagename}.${partId}.residual.tar $_CONDOR_SCRATCH_DIR
else
echo "Failed to make images, check inputs carefully."
if [ $residual -eq 0 ]
then
residual=1
fi
fi
htclean_finalize
exit ${residual}
;;
# Gather and normalize PSF and weight; compute pb
gatherPSF)
imagelist=`find . -maxdepth 1 -name "${imagename}.*.tar"`
expandInputImageTarballs ${imagelist}
mv ${imagename}.* working
cd working
readStartImageFlags
if [ ${useStartModel} = "True" ]
then
makeStartImageCopies model
else
if [ ${useStartMask} = "True" ]
then
makeStartImageCopies mask
fi
fi
runGather psf weight sumwt
gatherPSF=$?
runNormalize psf
normPSF=$?
if [ "${useStartModel}" = "True" ] && [ ${normPSF} -eq 0 ] && [ -e ${imagename}.model ]
then
runNormalize model
divModel=$?
if [ ${divModel} -ne 0 ]
then
normPSF=${divModel}
else
createTar divmodel
fi
fi
if [ ${gatherPSF} -eq 0 ] && [ -e ${imagename}.psf ] && [ ${normPSF} -eq 0 ]
then
createTar weight sumwt psf pb
mv ${imagename}.*.tar $_CONDOR_SCRATCH_DIR
gathernormPSF=0
else
echo "Failed in gather/normalize, check inputs carefully. Exit-codes are gather: ${gatherPSF} and normalize: ${normPSF}."
if [ $gatherPSF -gt $normPSF ]
then
gathernormPSF=$gatherPSF
else
gathernormPSF=$normPSF
if [ $normPSF -eq 0 ]
then
gathernormPSF=1
fi
fi
fi
htclean_finalize
exit ${gathernormPSF}
;;
gather)
imagelist=`find . -maxdepth 1 -name "${imagename}.*.tar"`
expandInputImageTarballs ${imagelist}
mv ${imagename}.* working
cd working
readStartImageFlags
runGather residual
gather=$?
runNormalize residual
norm=$?
if [ ${gather} -eq 0 ] && [ -e ${imagename}.residual ] && [ ${norm} -eq 0 ]
then
createTar residual
mv ${imagename}.residual.tar $_CONDOR_SCRATCH_DIR
else
echo "Failed in gather/normalize, check inputs carefully. Exit-codes are gather: ${gather} and normalize: ${norm}."
if [ $gather -gt $norm ]
then
gathernorm=$gather
else
gathernorm=$norm
if [ $norm -eq 0 ]
then
gathernorm=1
fi
fi
fi
htclean_finalize
exit ${gathernorm}
;;
runModelCycle)
imagelist=`find . -maxdepth 1 -name "${imagename}.*.tar"`
expandInputImageTarballs ${imagelist}
mv ${imagename}.* working
cd working
lsdir ${PWD}
# workaround for rest frequency mismatch when using external model/mask
mv ${imagename}.sumwt ${imagename}.sumwt.noop
logname=logs/modelUpdate-$(date +%Y%m%d-%H%M%S)
cp ${input_file} ${logname}.def
${libraBIN}/hummbee help=def,${input_file} &> ${logname}.log
checkLog ${logname}.log
updateModel=$?
# Test convergence
grep "Reached n-sigma threshold\|Reached global stopping criteria" ${logname}.log
[ "$?" -eq "0" ] && touch $_CONDOR_SCRATCH_DIR/stopIMCycles
# Undo rename sumwt so that acme gets required inputs
mv ${imagename}.sumwt.noop ${imagename}.sumwt
# Change parameters and run acme to divide model by weight
runNormalize model
divModel=$?
if [ ${updateModel} -eq 0 ] && [ ${divModel} -eq 0 ] && [ -e ${imagename}.divmodel ]
then
createTar model divmodel residual mask
mv ${imagename}.*.tar $_CONDOR_SCRATCH_DIR
model=0
else
echo "Failed to update model, check inputs carefully. Exit-codes are updateModel: ${updateModel} and normalize: ${divModel}."
if [ $updateModel -gt $divModel ]
then
model=$updateModel
else
model=$divModel
if [ $divModel -eq 0 ]
then
model=1
fi
fi
fi
htclean_finalize
exit ${model}
;;
makeFinalImages)
imagelist=`find . -maxdepth 1 -name "${imagename}.*.tar"`
expandInputImageTarballs ${imagelist}
mv ${imagename}.* working
cd working
lsdir ${PWD}
# workaround for rest frequency mismatch when using external model/mask
mv ${imagename}.sumwt ${imagename}.sumwt.noop
echo "mode = restore" >> ${input_file}
logname=logs/makeFinalImages-$(date +%Y%m%d-%H%M%S)
cp ${input_file} ${logname}.def
${libraBIN}/hummbee help=def,${input_file} &> ${logname}.log
checkLog ${logname}.log
makeFinalImages=$?
if [ ${makeFinalImages} -eq 0 ] && [ -e ${imagename}.image ]
then
createTar image image.pbcor
mv ${imagename}.image*.tar $_CONDOR_SCRATCH_DIR
else
echo "Failed to make images, check inputs carefully."
if [ ${makeFinalImages} -eq 0 ]
then
makeFinalImages=1
fi
fi
htclean_finalize
exit ${makeFinalImages}
;;
*)
echo "${jobmode}: unknown jobmode. Exiting."
exit 1
;;
esac