-
Notifications
You must be signed in to change notification settings - Fork 0
/
condor_wrapper.py
86 lines (67 loc) · 2.76 KB
/
condor_wrapper.py
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
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 24 18:33:40 2014
@author: suberlak
A program to create .cfg files, as well as .csh files, each of which
calls javelin_drw_condor.py , in a following fashion:
python program.py LC_name dir_in dir_chains With_Prior?
for example :
program = /astro/users/suberlak/Desktop/SDSS/javelin_drw_condor.py
LC_name = DRWtest_LC210_err1.dat
dir_in = /astro/users/suberlak/Desktop/SDSS/qso_drw_upd/
dir_chains = /astro/users/suberlak/Desktop/SDSS/qso_drw_chains/
With_Prior? = No (or Yes )
Thus - USE FULL ADDRESS !
This is because Condor jobs will be run from Condor directory, and
stored elsewhere
"""
import subprocess
import os
import stat
import numpy as np
root='/astro/users/suberlak/Desktop/SDSS/'
dir_in = ['qso_drw_medium_LC/']
dir_cond = ['qso_drw_medium_condor/']
dir_out = ['qso_drw_medium_LC_chains/']
filelist = dir_in[0] +'drw_err1.list'
names = np.loadtxt(filelist, dtype=str)
with_prior = ['Yes','No']
################################################################
# LOOP OVER NAMES, TO MAKE A SEPARATE CONDOR RUN FOR EACH DRW #
################################################################
for i in range(2,len(names)): #len(names)
cshfile = root+dir_cond[0] + str(i) +'_'+ names[i] + '.csh'
file = open(cshfile,"w")
file.write('#!/bin/csh\n')
file.write('source /astro/users/suberlak/.cshrc\n')
s2 = 'echo python ' +root+'javelin_drw_condor.py'+' '+ \
names[i] + ' ' + root+dir_in[0] +' '+ root+dir_out[0] +' '+ with_prior[0] +'\n'
file.write(s2)
s = 'python ' +root+'javelin_drw_condor.py'+' '+ \
names[i] + ' ' + root+dir_in[0] +' '+ root+dir_out[0] +' '+ with_prior[0] +'\n'
file.write(s)
file.close()
cfgfile = root+dir_cond[0] + str(i) +'_'+names[i] + '.cfg'
file = open(cfgfile,"w")
file.write('Notification = never\n\n')
file.write('getenv = true\n\n')
execs = 'Executable = ' + cshfile+'\n\n'
file.write(execs)
initial = 'Initialdir =' +root+dir_cond[0]+'\n\n'
file.write(initial)
file.write('Universe = vanilla\n\n')
log = 'Log = '+root+dir_cond[0] + 'run_'+str(i)+'_log.txt\n\n'
out = 'Output = ' + root+dir_cond[0] + 'run_'+str(i)+'_out.txt\n\n'
err = 'Error =' + root+dir_cond[0] + 'run_'+str(i)+'_err.txt\n\n'
file.write(log)
file.write(out)
file.write(err)
file.write('Queue\n')
file.close()
# source my cshrc file to enable Javelin run
# subprocess.check_call(['source', ' ~/.cshrc' ])
# Change file permissions of the csh file
st = os.stat(cshfile)
os.chmod(cshfile, st.st_mode | 0111)
# Submit the fitting job to Condor
subprocess.check_call(['condor_submit', cfgfile])