forked from jade-package/JADE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjobfilter2.py
156 lines (133 loc) · 4.07 KB
/
jobfilter2.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
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
#! /usr/bin/env python
# =====================
# dulikai @qibebt
# @2014.5.10
# =====================
import os
# read the job status reports
# filter the undesired trajectory
# conditions:
# 1. >= n_step or
# 2. >= ratio or
# 3. greedy
# 4. 1 & 2 & 3 is also ok
#
# then,
# generate a file to understand the job status
#
class jobfilter():
def __init__(self):
self.status = {}
self.filter = {}
self.params = {}
return
def get_ststus(self):
"""
read in status.dat
"""
filename = "status.dat"
fp = open(filename, "r")
line = fp.readline()
rec = line.split()
n_traj = int(rec[0]); n_step = int(rec[1])
line = fp.readline()
traj = {}
for i in xrange(n_traj):
line = fp.readline()
rec = line.split()
key = rec[0]
traj[key] = {'complete': int(rec[1]), 'n_step': int(rec[2]),
'ratio': float(rec[3])
}
self.status = {'n_step': n_step, 'n_traj': n_traj,
'traj': traj
}
return
def getcmd(self):
"""
read in control parameters
"""
n_step = self.params['n_step']
self.params['mode'] = "normal"
line = raw_input("the filter mode: <normal/greedy> [default: normal] \n > ")
if line.strip() != "":
self.params['model'] = line.strip()
line = raw_input("conditions (maybe integer or float) [default: 1.0] \n > ")
mystring = line.strip()
if mystring == "":
self.params['ratio0'] = 1.0
self.params['n_step0'] = n_step
elif "." in mystring:
self.params['ratio0'] = float(mystring)
self.params['n_step0'] = int(n_step * float(mystring))
else:
self.params['n_step0'] = int(mystring)
if self.params['n_step0'] > n_step:
print "invalid value..."
exit(1)
return
def select(self):
"""
select ...
"""
n_step0 = self.params['n_step0']
n_traj = self.status['n_traj']
traj = self.status['traj']
traj2 = []
for i in xrange(n_traj):
n_step = traj[i]['n_step']
if n_step >= n_step0:
traj2.append(traj[i])
else:
continue
n_traj2 = len(traj2)
steps = [n_traj2 for i in xrange(n_step0)]
self.filter = {'n_step': n_step0, 'n_step_t': self.params['n_step']
'n_traj': n_traj2, 'traj': traj2, 'steps': steps
}
return
def greedy(self):
"""
sum ... greedy case..
"""
n_step_t = self.filter['n_step_t']
n_traj = self.filter['n_traj']
traj = self.filter['traj']
steps = [0 for i in xrange(n_step_t)]
for i in xrange(n_traj):
n_step = traj[i]['n_step']
for j in xrange(n_step):
steps[j] += 1
self.filter['steps'] = steps
return
def filter(self):
"""
do the main jobs..
"""
self.getcmd()
self.get_status()
self.select()
if self.params['mode'] == 'greedy':
self.greedy()
return
def dump(self):
"""
write the report..
"""
fp = open("prepare.dat", "w")
n_step = self.filter['n_step']
n_traj = len(self.params['mylist'])
print >>fp, "%10d %10d" % (n_traj, n_step)
print >>fp, ""
res = self.results
for sid in res:
val = res[sid]
print >>fp, "%10s %5d %10d %12.6f" % \
(sid, val['complete'], val['n_step'], val['ratio'])
fp.close()
if __name__ == "__main__":
job = jobfilter()
job.filter()
# generate filter.dat to describe each traj
# generate prepare.dat for summary: total number of each step
# traj list, n_step