@@ -28,39 +28,13 @@ def __init__(self, optional_log_type=None):
2828 if optional_log_type is not None :
2929 self .log_types .extend (optional_log_type )
3030
31- class DownloadLogTool (BasicLogTool ):
32- def __init__ (self , rla_config_path , proj_root , task , regex , * args , ** kwargs ):
33- fs = open (rla_config_path , encoding = "UTF-8" )
34- self .private_config = yaml .load (fs )
35- self .proj_root = proj_root
36- self .task_table_name = task
37- self .regex = regex
38-
39- def _download_log (self , show = False ):
40- for log_type in self .log_types :
41- root_dir_regex = osp .join (self .proj_root , log_type , self .task_table_name , self .regex )
42- empty = True
43- for root_dir in glob .glob (root_dir_regex ):
44-
45- pass
46-
47- class DeleteLogTool (BasicLogTool ):
48- def __init__ (self , proj_root , task_table_name , regex , filter , * args , ** kwargs ):
49- self .proj_root = proj_root
50- self .task_table_name = task_table_name
51- self .regex = regex
52- assert isinstance (filter , Filter )
53- self .filter = filter
54- self .small_timestep_regs = []
55- super (DeleteLogTool , self ).__init__ (* args , ** kwargs )
56-
57- def _find_small_timestep_log (self ):
58- root_dir_regex = osp .join (self .proj_root , LOG , self .task_table_name , self .regex )
31+ def _find_small_timestep_log (self , proj_root , task_table_name , regex , timstep_upper_bound = np .inf , timestep_lower_bound = 0 ):
32+ small_timestep_regs = []
33+ root_dir_regex = osp .join (proj_root , LOG , task_table_name , regex )
5934 for root_dir in glob .glob (root_dir_regex ):
6035 print ("searching dirs" , root_dir )
6136 if os .path .exists (root_dir ):
6237 for file_list in os .walk (root_dir ):
63-
6438 if re .search (r'\d{4}/\d{2}/\d{2}/\d{2}-\d{2}-\d{2}-\d{6}' , file_list [0 ]):
6539 target_reg = re .search (r'\d{4}/\d{2}/\d{2}/\d{2}-\d{2}-\d{2}-\d{6}' , file_list [0 ]).group (0 )
6640 else :
@@ -77,7 +51,8 @@ def _find_small_timestep_log(self):
7751 if file_list [1 ] == ['tb' ] or os .path .exists (progress_csv_file ): # in root of logdir
7852 if not os .path .exists (progress_csv_file ) or os .path .getsize (progress_csv_file ) == 0 :
7953 print ("[delete] find an experiment without progress.csv." , file_list [0 ])
80- self .small_timestep_regs .append (target_reg )
54+ if timestep_lower_bound <= 0 :
55+ small_timestep_regs .append ([target_reg , file_list [0 ]])
8156 else :
8257 try :
8358 reader = pd .read_csv (progress_csv_file , chunksize = 100000 , quoting = csv .QUOTE_NONE ,
@@ -88,9 +63,9 @@ def _find_small_timestep_log(self):
8863 raw_df = pd .concat ([raw_df , slim_chunk ], ignore_index = True )
8964 last_timestep = raw_df [DEFAULT_X_NAME ].max ()
9065 print ("[found a log] time_step " , last_timestep , target_reg )
91- if last_timestep < self . filter . timstep_bound :
92- self . small_timestep_regs .append (target_reg )
93- print ("[delete] find an experiment with too small number of logs . " , file_list [0 ])
66+ if timestep_lower_bound <= last_timestep <= timstep_upper_bound :
67+ small_timestep_regs .append ([ target_reg , file_list [ 0 ]] )
68+ print ("[delete] find an experiment satisfied timestep range . " , file_list [0 ])
9469 else :
9570 print ("[valid]" )
9671 except Exception as e :
@@ -101,8 +76,35 @@ def _find_small_timestep_log(self):
10176 elif 'events' in file_list [0 ]: # in event dir
10277 pass
10378 else : # empty dir
104- self .small_timestep_regs .append (target_reg )
79+ if timestep_lower_bound <= 0 :
80+ small_timestep_regs .append ([target_reg , file_list [0 ]])
10581 print ("[delete] find an experiment without any files. " , file_list [0 ])
82+ return small_timestep_regs
83+
84+ class DownloadLogTool (BasicLogTool ):
85+ def __init__ (self , rla_config_path , proj_root , task , regex , * args , ** kwargs ):
86+ fs = open (rla_config_path , encoding = "UTF-8" )
87+ self .private_config = yaml .load (fs )
88+ self .proj_root = proj_root
89+ self .task_table_name = task
90+ self .regex = regex
91+
92+ def _download_log (self , show = False ):
93+ for log_type in self .log_types :
94+ root_dir_regex = osp .join (self .proj_root , log_type , self .task_table_name , self .regex )
95+ empty = True
96+ for root_dir in glob .glob (root_dir_regex ):
97+ pass
98+
99+ class DeleteLogTool (BasicLogTool ):
100+ def __init__ (self , proj_root , task_table_name , regex , filter , * args , ** kwargs ):
101+ self .proj_root = proj_root
102+ self .task_table_name = task_table_name
103+ self .regex = regex
104+ assert isinstance (filter , Filter )
105+ self .filter = filter
106+ self .small_timestep_regs = []
107+ super (DeleteLogTool , self ).__init__ (* args , ** kwargs )
106108
107109 def _delete_related_log (self , regex , show = False ):
108110 log_found = 0
@@ -155,7 +157,7 @@ def delete_related_log(self, skip_ask=False):
155157 return 0
156158
157159 def delete_small_timestep_log (self , skip_ask = False ):
158- self ._find_small_timestep_log ()
160+ self .small_timestep_regs = self . _find_small_timestep_log (self . proj_root , self . task_table_name , self . regex , timstep_upper_bound = self . filter . timstep_bound )
159161 print ("complete searching." )
160162 if skip_ask :
161163 s = 'y'
@@ -164,17 +166,17 @@ def delete_small_timestep_log(self, skip_ask=False):
164166 log_found = 0
165167
166168 if s == 'y' or skip_ask :
167- for reg in self .small_timestep_regs :
168- print ("[delete small-timestep log] reg: " , reg )
169- self ._delete_related_log (show = True , regex = reg + '*' )
169+ for res in self .small_timestep_regs :
170+ print ("[delete small-timestep log] reg: " , res [ 1 ] )
171+ self ._delete_related_log (show = True , regex = res [ 0 ] + '*' )
170172 if skip_ask :
171173 s = 'y'
172174 else :
173175 s = input ("delete these files? (y/n)" )
174176 if s == 'y' or skip_ask :
175- for reg in self .small_timestep_regs :
176- print ("do delete: " , reg )
177- log_found += self ._delete_related_log (show = False , regex = reg + '*' )
177+ for res in self .small_timestep_regs :
178+ print ("do delete: " , res [ 1 ] )
179+ log_found += self ._delete_related_log (show = False , regex = res [ 0 ] + '*' )
178180 return log_found
179181
180182class ArchiveLogTool (BasicLogTool ):
@@ -231,6 +233,44 @@ def archive_log(self, skip_ask=False):
231233 print ("do archive ..." )
232234 self ._archive_log (show = False )
233235
236+ class ViewLogTool (BasicLogTool ):
237+ def __init__ (self , proj_root , task_table_name , regex , * args , ** kwargs ):
238+ self .proj_root = proj_root
239+ self .task_table_name = task_table_name
240+ self .regex = regex
241+ super (ViewLogTool , self ).__init__ (* args , ** kwargs )
242+
243+ def _view_log (self , regex ):
244+ root_dir_regex = osp .join (self .proj_root , LOG , self .task_table_name , regex )
245+ for root_dir in glob .glob (root_dir_regex ):
246+ if os .path .exists (root_dir ):
247+ for file_list in os .walk (root_dir ):
248+ if re .search (r'\d{4}/\d{2}/\d{2}/\d{2}-\d{2}-\d{2}-\d{6}' , file_list [0 ]):
249+ target_reg = re .search (r'\d{4}/\d{2}/\d{2}/\d{2}-\d{2}-\d{2}-\d{6}' , file_list [0 ]).group (0 )
250+ else :
251+ target_reg = None
252+ if target_reg is not None :
253+ backup_file = file_list [0 ] + '/backup.txt'
254+ if file_list [1 ] == ['tb' ] or os .path .exists (backup_file ): # in root of logdir
255+ with open (backup_file ) as f :
256+ print (f .read ())
257+
258+ def view_log (self , skip_ask = False ):
259+ found_regs = self ._find_small_timestep_log (self .proj_root , self .task_table_name , self .regex , timestep_lower_bound = 1 )
260+ for res in found_regs :
261+ print ("view experiments:" , res [1 ])
262+ if skip_ask :
263+ s = 'y'
264+ else :
265+ s = input ("press y to view \n " )
266+ if s == 'y' :
267+ self ._view_log (regex = res [0 ] + '*' )
268+
269+
270+
271+
272+
273+
234274# if __name__ == '__main__':
235275# dlt = DeleteLogTool("../", "var_seq_imitation", "self-transfer", "2019/11/29/01-11*")
236276# dlt.delete_related_log()
0 commit comments