def end_training()

in shaDow/logging_base.py [0:0]


    def end_training(self, status):
        assert status in ['crashed', 'finished', 'killed']
        if status == 'finished':        # print plain summary: used by wrapper script of ./script/train_multiple_runs.py
            str_summary = "FINAL SUMMARY: "
            for k, v in self.acc_final.items():
                for kk, vv in v.items():
                    str_summary += f'{MODE2STR[k]} {kk} {vv} '
            print(str_summary)
        if self.no_log:
            from itertools import product
            if os.path.exists(self.dir_log):
                assert os.path.isdir(self.dir_log)
                # assert dir_log only contains one *.yml file and one *.pkl / pt file
                f_ymlpt = os.listdir(self.dir_log)
                if len(f_ymlpt) == 1:
                    assert f_ymlpt[0].split('.')[-1] in ['yml', 'yaml'], \
                        f"DIR {self.dir_log} CONTAINS UNKNOWN TYPE OF FILE. ABORTING!"
                else:
                    assert len(f_ymlpt) <= 3
                    assert all(os.path.isfile(f"{self.dir_log}/{f}") for f in f_ymlpt)
                    ext1 = ['yml', 'yaml']
                    ext2 = ['pkl', 'pt']
                    assert set(f.split('.')[-1] for f in f_ymlpt) in [set(p) for p in product(ext1, ext2)], \
                        f"DIR {self.dir_log} CONTAINS UNKNOWN TYPE OF FILE. ABORTING!"
                shutil.rmtree(self.dir_log)
                self.printf(f"Successfully removed log dir {self.dir_log}!", style='red')
        else:
            # move all files from 'running' to the subdir corresponding to status
            dir_split = self.dir_log.split('/')     
            dir_split = dir_split if dir_split[-1] != '' else dir_split[:-1]
            assert dir_split[-2] == 'running'
            dir_split[-2] = status
            dir_new_parent = '/'.join(dir_split[:-1])
            if not os.path.exists(dir_new_parent):
                os.makedirs(dir_new_parent)
            assert os.path.isdir(self.dir_log) and os.path.isdir(dir_new_parent)
            f_logfiles = os.listdir(self.dir_log)
            assert all(os.path.isfile(f"{self.dir_log}/{f}") for f in f_logfiles)
            shutil.move(self.dir_log, dir_new_parent)
            self.printf(f"Successfully moved {self.dir_log} to {dir_new_parent}", style='red')