@@ -46,7 +46,8 @@ def setup(self):
4646        # Initialise the configuration log 
4747        self .configuration_log  =  {}
4848
49-         if  not  os .path .isfile ('configuration_log.yaml' ):
49+         conf_log_p  =  os .path .join (self .control_path , 'configuration_log.yaml' )
50+         if  not  os .path .isfile (conf_log_p ):
5051            # Build a new configuration log 
5152            self ._build_new_configuration_log ()
5253        else :
@@ -60,18 +61,14 @@ def setup(self):
6061        # Make the logging directory 
6162        mkdir_p (os .path .join (self .work_path , "logs" ))
6263
63-         # Get the additional restarts from older restart dirs 
64-         # self._get_further_restarts() 
65- 
66-         # Make necessary adjustments to the configuration log 
67-         # self._handle_configuration_log_setup() 
68- 
6964        self ._set_current_stage ()
65+ 
7066    def  _build_new_configuration_log (self ):
7167        """Build a new configuration log for the first stage of the run.""" 
7268
69+         stage_conf_p  =  os .path .join (self .control_path , 'stage_config.yaml' )
7370        # Read the stage_config.yaml file 
74-         with  open ('stage_config.yaml' , 'r' ) as  stage_conf_f :
71+         with  open (stage_conf_p , 'r' ) as  stage_conf_f :
7572            self .stage_config  =  yaml .safe_load (stage_conf_f )
7673
7774        # On the first run, we need to read the 'stage_config.yaml' file. 
@@ -86,9 +83,12 @@ def _build_new_configuration_log(self):
8683
8784    def  _read_configuration_log (self ):
8885        """Read the existing configuration log.""" 
89-         with  open ('configuration_log.yaml' ) as  conf_log_file :
86+         conf_log_p  =  os .path .join (self .control_path , 'configuration_log.yaml' )
87+         with  open (conf_log_p , 'r' ) as  conf_log_file :
9088            self .configuration_log  =  yaml .safe_load (conf_log_file )
9189
90+         print (f"After reading configuration_log: { self .configuration_log }  )
91+ 
9292    def  _prepare_configuration (self ):
9393        """Prepare the stages in the CABLE configuration.""" 
9494
@@ -231,7 +231,8 @@ def _set_current_stage(self):
231231                self .configuration_log ['queued_stages' ].pop (0 )
232232
233233        self ._save_configuration_log ()
234-         shutil .copy ('configuration_log.yaml' , self .work_path )
234+         conf_log_p  =  os .path .join (self .control_path , 'configuration_log.yaml' )
235+         shutil .copy (conf_log_p , self .work_path )
235236
236237    def  archive (self ):
237238        """Store model output to laboratory archive and update the 
@@ -250,9 +251,10 @@ def archive(self):
250251              "number of queued stages in the configuration log." )
251252        self .expt .n_runs  =  remaining_stages 
252253
253-         if  len (self .configuration_log ["queued_stages" ]) ==  0 :
254+         conf_log_p  =  os .path .join (self .control_path , 'configuration_log.yaml' )
255+         if  self .expt .n_runs  ==  0 :
254256            # Configuration successfully completed 
255-             os .remove ('configuration_log.yaml' )
257+             os .remove (conf_log_p )
256258
257259        super (StagedCable , self ).archive ()
258260
@@ -261,26 +263,28 @@ def _collect_restarts(self):
261263        merge of the files in work_path/restart and in prior_restart_path, with 
262264        the files in work_path/restart taking precedence.""" 
263265
264-         # Move the files in work_path/restart first 
265-         for  f  in  os .listdir (self .work_restart_path ):
266-             shutil .move (os .path .join (self .work_restart_path , f ),
267-                         self .restart_path )
268-         os .rmdir (self .work_restart_path )
269- 
270-         # Now collect any restarts from prior_restart_path only if said restart 
271-         # doesn't already exist (except on first run) 
266+         # First, collect restarts which do not have a newer version (when the 
267+         # counter is greater than 0) 
272268        if  self .expt .counter  >  0 :
273-             # self.prior_restart_path nor expt.prior_restart_path are defined here 
274-             # build it as in experiment.py 
275269            prior_restart_dir  =  'restart{0:03}' .format (self .expt .counter  -  1 )
276270            prior_restart_path  =  os .path .join (self .expt .archive_path ,
277271                                              prior_restart_dir )
278272
279-             current_restarts  =  os .listdir (self .restart_path )
273+             # For each restart, check if newer version was created. If not, 
274+             # copy into the work restart path. 
275+             generated_restarts  =  os .listdir (self .work_restart_path )
276+ 
280277            for  f  in  os .listdir (prior_restart_path ):
281-                 if  f  not  in current_restarts :
278+                 if  f  not  in generated_restarts :
282279                    shutil .copy (os .path .join (prior_restart_path , f ),
283-                             self .restart_path )
280+                             self .work_restart_path )
281+ 
282+ 
283+         # Move the files in work_path/restart first 
284+         for  f  in  os .listdir (self .work_restart_path ):
285+             shutil .move (os .path .join (self .work_restart_path , f ),
286+                         self .restart_path )
287+         os .rmdir (self .work_restart_path )
284288
285289    def  _archive_current_stage (self ):
286290        """Move the current stage to the list of completed stages.""" 
@@ -291,12 +295,14 @@ def _archive_current_stage(self):
291295        self ._save_configuration_log ()
292296
293297        # Copy the configuration log to the restart directory for shareability 
294-         shutil .copy ('configuration_log.yaml' , self .restart_path )
298+         conf_log_p  =  os .path .join (self .control_path , 'configuration_log.yaml' )
299+         shutil .copy (conf_log_p , self .restart_path )
295300
296301    def  collate (self ):
297302        pass 
298303
299304    def  _save_configuration_log (self ):
300305        """Write the updated configuration log back to the staging area.""" 
301-         with  open ('configuration_log.yaml' , 'w+' ) as  config_log_f :
306+         conf_log_p  =  os .path .join (self .control_path , 'configuration_log.yaml' )
307+         with  open (conf_log_p , 'w+' ) as  config_log_f :
302308            yaml .dump (self .configuration_log , config_log_f )
0 commit comments