@@ -29,13 +29,9 @@ def __init__(self, conf):
2929
3030 def clean_shot_lists (self ):
3131 shot_list_dir = self .conf ['paths' ]['shot_list_dir' ]
32- paths = [
33- os .path .join (
34- shot_list_dir ,
35- f ) for f in listdir (shot_list_dir ) if os .path .isfile (
36- os .path .join (
37- shot_list_dir ,
38- f ))]
32+ paths = [os .path .join (shot_list_dir , f ) for f in
33+ listdir (shot_list_dir ) if
34+ os .path .isfile (os .path .join (shot_list_dir , f ))]
3935 for path in paths :
4036 self .clean_shot_list (path )
4137
@@ -87,16 +83,15 @@ def preprocess_from_files(self, shot_files, use_shots):
8783 # empty
8884 used_shots = ShotList ()
8985
90- use_cores = max (1 , mp .cpu_count ()- 2 )
86+ # TODO(KGF): generalize the follwowing line to perform well on
87+ # architecutres other than CPUs, e.g. KNLs
88+ # min( <desired-maximum-process-count>, max(1,mp.cpu_count()-2) )
89+ use_cores = max (1 , mp .cpu_count () - 2 )
9190 pool = mp .Pool (use_cores )
92- print ('running in parallel on {} processes' .format (pool ._processes ))
91+ print ('Running in parallel on {} processes' .format (pool ._processes ))
9392 start_time = time .time ()
94- for (
95- i ,
96- shot ) in enumerate (
97- pool .imap_unordered (
98- self .preprocess_single_file ,
99- shot_list_picked )):
93+ for (i , shot ) in enumerate (pool .imap_unordered (
94+ self .preprocess_single_file , shot_list_picked )):
10095 # for (i,shot) in
10196 # enumerate(map(self.preprocess_single_file,shot_list_picked)):
10297 sys .stdout .write ('\r {}/{}' .format (i , len (shot_list_picked )))
@@ -105,19 +100,15 @@ def preprocess_from_files(self, shot_files, use_shots):
105100 pool .close ()
106101 pool .join ()
107102 print ('Finished Preprocessing {} files in {} seconds' .format (
108- len (shot_list_picked ), time .time ()- start_time ))
109- print (
110- 'Omitted {} shots of {} total.' .format (
111- len (shot_list_picked )
112- - len (used_shots ),
113- len (shot_list_picked )))
103+ len (shot_list_picked ), time .time () - start_time ))
104+ print ('Omitted {} shots of {} total.' .format (
105+ len (shot_list_picked ) - len (used_shots ), len (shot_list_picked )))
114106 print ('{}/{} disruptive shots' .format (used_shots .num_disruptive (),
115107 len (used_shots )))
116108 if len (used_shots ) == 0 :
117- print (
118- "WARNING: All shots were omitted, please ensure raw data "
119- " is complete and available at {}." .format (
120- self .conf ['paths' ]['signal_prepath' ]))
109+ print ("WARNING: All shots were omitted, please ensure raw data "
110+ " is complete and available at {}." .format (
111+ self .conf ['paths' ]['signal_prepath' ]))
121112 return used_shots
122113
123114 def preprocess_single_file (self , shot ):
@@ -127,17 +118,15 @@ def preprocess_single_file(self, shot):
127118 if recompute or not shot .previously_saved (processed_prepath ):
128119 shot .preprocess (self .conf )
129120 shot .save (processed_prepath )
130-
131121 else :
132122 try :
133123 shot .restore (processed_prepath , light = True )
134124 sys .stdout .write ('\r {} exists.' .format (shot .number ))
135125 except BaseException :
136126 shot .preprocess (self .conf )
137127 shot .save (processed_prepath )
138- sys .stdout .write (
139- '\r {} exists but corrupted, resaved.' .format (
140- shot .number ))
128+ sys .stdout .write ('\r {} exists but corrupted, resaved.' .format (
129+ shot .number ))
141130 shot .make_light ()
142131 return shot
143132
@@ -262,14 +251,10 @@ def guarantee_preprocessed(conf):
262251 pp .save_shotlists (shot_list_train , shot_list_validate , shot_list_test )
263252 shot_list_train , shot_list_validate , shot_list_test = apply_bleed_in (
264253 conf , shot_list_train , shot_list_validate , shot_list_test )
265- print (
266- 'validate: {} shots, {} disruptive' .format (
267- len (shot_list_validate ),
268- shot_list_validate .num_disruptive ()))
269- print (
270- 'training: {} shots, {} disruptive' .format (
271- len (shot_list_train ),
272- shot_list_train .num_disruptive ()))
254+ print ('validate: {} shots, {} disruptive' .format (
255+ len (shot_list_validate ), shot_list_validate .num_disruptive ()))
256+ print ('training: {} shots, {} disruptive' .format (
257+ len (shot_list_train ), shot_list_train .num_disruptive ()))
273258 print ('testing: {} shots, {} disruptive' .format (
274259 len (shot_list_test ), shot_list_test .num_disruptive ()))
275260 print ("...done" )
0 commit comments