11import os
22import lightning as L
3+ import datetime
34
45# PyTorch TensorBoard support
56from torch .utils .tensorboard import SummaryWriter
@@ -10,7 +11,8 @@ def fun_control_init(
1011 _L_in = None ,
1112 _L_out = None ,
1213 enable_progress_bar = False ,
13- spot_tensorboard_path = "runs_spot/" ,
14+ spot_tensorboard_path = None ,
15+ TENSORBOARD_CLEAN = False ,
1416 num_workers = 0 ,
1517 device = None ,
1618 seed = 1234 ,
@@ -82,10 +84,19 @@ def fun_control_init(
8284 os .makedirs (RESULTS_PATH , exist_ok = True )
8385 # Path to the folder where the tensorboard files are saved
8486 TENSORBOARD_PATH = os .environ .get ("PATH_TENSORBOARD" , "runs/" )
87+ if TENSORBOARD_CLEAN :
88+ # if the folder "runs" exists, move it to "runs_Y_M_D_H_M_S" to avoid overwriting old tensorboard files
89+ if os .path .exists (TENSORBOARD_PATH ):
90+ now = datetime .datetime .now ()
91+ # use [:-1] to remove "/" from the end of the path
92+ TENSORBOARD_PATH_OLD = TENSORBOARD_PATH [:- 1 ] + now .strftime ("%Y_%m_%d_%H_%M_%S" )
93+ os .rename (TENSORBOARD_PATH [:- 1 ], TENSORBOARD_PATH_OLD )
8594 os .makedirs (TENSORBOARD_PATH , exist_ok = True )
8695 if spot_tensorboard_path is not None :
8796 os .makedirs (spot_tensorboard_path , exist_ok = True )
8897 spot_writer = SummaryWriter (spot_tensorboard_path )
98+ else :
99+ spot_writer = None
89100
90101 if not os .path .exists ("./figures" ):
91102 os .makedirs ("./figures" )
0 commit comments