-
Notifications
You must be signed in to change notification settings - Fork 15
/
run.py
70 lines (57 loc) · 1.93 KB
/
run.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
import os,sys
sys.path.append(os.popen("pwd").read().replace("\n","")+"/Model")
def getInput(input,key):
try:
txt = [i for i in input if i.find(key)!=-1][0].split("=")[1].split("#", 1)[0].replace("\n","")
except:
txt = ""
return txt.replace(" ","")
try:
inputfile = sys.argv[1]
input = open(inputfile, 'r').readlines()
except:
inputfile = "input.txt"
input = open(inputfile, 'r').readlines()
print(f"Reading {inputfile}")
fold = 'output'
try :
fold = sys.argv[2]
except:
pass
# System
system = getInput(input,"System")
os.system(f"rm -rf {fold}")
os.system(f"mkdir -p {fold}")
# SLURM
if system == "slurm" or system == "htcondor":
print (f"Running jobs in a {system}")
model = getInput(input,"Model")
exec(f"from {model} import parameters")
ntraj = parameters.NTraj
ncpus = int(getInput(input,"Cpus"))
totalTraj = ntraj * ncpus
print(f"Using {ncpus} CPUs")
print("-"*20, "Default Parameters", "-"*20)
print(f"Total Number of Trajectories = {totalTraj}")
print(f"Trajectories per CPU = {ntraj}")
print("-"*50)
parameters = [i for i in input if i.split("#")[0].split("=")[0].find("$") !=- 1]
for p in parameters:
print(f"Overriding parameters: {p.split('=')[0].split('$')[1]} = {p.split('=')[1].split('#')[0]}")
print("-"*50)
if system == "slurm":
for i in range(ncpus):
os.system(f"sbatch serial.py {inputfile} {fold} {i}")
if system == "htcondor":
os.system(f"condor_submit condor.sub input={inputfile} outFold={fold} -queue {ncpus}")
# PC
else:
print ("Running jobs in your local machine (like a PC)")
# Some messages
model = getInput(input,"Model")
exec(f"from {model} import parameters")
ntraj = parameters.NTraj
print("-"*50)
print(f"Total Number of Trajectories = {ntraj}")
print("-"*50)
os.system(f"python3 serial.py {inputfile} {fold}")