# Path: options/options_train.py
# def add_general_arguments(parser):
# def overwrite(opt, opt_f_old, unique_params):
# def parse(add_additional_arguments=None):
# 
# Path: loggers/loggers.py
# class BaseLogger(object):
# class _LogCumulator(BaseLogger):
# class ProgbarLogger(BaseLogger):
# class CsvLogger(BaseLogger):
# class BatchCsvLogger(BaseLogger):
# class ModelSaveLogger(BaseLogger):
# class TerminateOnNaN(BaseLogger):
# class TensorBoardLogger(BaseLogger):
# class HtmlLogger(BaseLogger):
# class ComposeLogger(BaseLogger):
#     def __init__(self):
#     def set_mute(self):
#     def on_train_begin(self):
#     def on_train_end(self):
#     def on_epoch_begin(self, epoch):
#     def on_epoch_end(self, epoch, epoch_log):
#     def on_batch_begin(self, batch):
#     def on_batch_end(self, batch, batch_log):
#     def set_params(self, params):
#     def set_model(self, model):
#     def train(self):
#     def eval(self):
#     def _set_unused_metric_mode(self, mode='none'):
#     def _allow_unused(self):
#     def __init__(self):
#     def on_epoch_begin(self, epoch):
#     def on_batch_end(self, batch, batch_log):
#     def get_epoch_log(self):
#     def __init__(self, count_mode='samples', allow_unused_fields='none', interval=10, no_accum=False):
#     def on_train_begin(self):
#     def on_epoch_begin(self, epoch):
#     def on_batch_begin(self, batch):
#     def on_batch_end(self, batch, batch_log):
#     def on_epoch_end(self, epoch, epoch_log):
#     def __init__(self, filename, allow_unused_fields='none'):
#     def on_train_begin(self):
#     def on_epoch_end(self, epoch, epoch_log):
#     def on_train_end(self):
#     def __init__(self, filename, allow_unused_fields='none'):
#     def on_train_begin(self):
#     def on_batch_end(self, batch, batch_log=None):
#     def on_train_end(self):
#     def __init__(self, filepath, period=1, save_optimizer=False, save_best=False, prev_best=None):
#     def on_train_begin(self):
#     def on_epoch_end(self, epoch, epoch_log):
#     def __init__(self):
#     def on_batch_begin(self, batch):
#     def on_batch_end(self, batch, batch_log):
#     def __init__(self, filepath, use_html_logger=False, allow_unused_fields='none'):
#     def on_train_begin(self):
#     def on_epoch_end(self, epoch, epoch_log):
#     def on_train_end(self):
#     def __init__(self, summary_filepath, allow_unused_fields='none'):
#     def on_train_begin(self):
#     def flush(self):
#     def on_epoch_begin(self, epoch):
#     def on_epoch_end(self, epoch, *args, **kargs):
#     def content_to_html(self):
#     def summary_to_html(self):
#     def __init__(self, loggers):
#     def get_tensorboard(self):
#     def get_html_logger(self):
#     def add_logger(self, logger):
#     def on_train_begin(self):
#     def on_train_end(self):
#     def on_epoch_begin(self, epoch):
#     def on_epoch_end(self, epoch, epoch_log):
#     def on_batch_begin(self, batch):
#     def on_batch_end(self, batch, batch_log):
#     def set_params(self, params):
#     def set_model(self, model):
#     def train(self):
#     def eval(self):
# 
# Path: util/util_print.py
# class bcolors:
#     HEADER = '\033[95m'
#     OKBLUE = '\033[94m'
#     OKGREEN = '\033[92m'
#     WARNING = '\033[93m'
#     FAIL = '\033[91m'
#     ENDC = '\033[0m'
#     BOLD = '\033[1m'
#     UNDERLINE = '\033[4m'
# 
# Path: util/util_loadlib.py
# def set_gpu(gpu, check=True):
# def _check_gpu_setting_in_use(gpu):
# def _check_gpu(gpu):
# def set_manual_seed(seed):


import sys
import os
import time
import torch
import datasets
import models
import pandas as pd
import torch.multiprocessing as mp
import torch.distributed as dist
from options import options_train
from loggers import loggers
from util.util_print import str_error, str_stage, str_verbose, str_warning
from util import util_loadlib as loadlib
        from subprocess import call
                while need_input:
                    response = input().lower()
                    if response in ('y', 'n'):
                        need_input = False
                if response == 'n':
                    print(str_stage, "User decides to quit")
                    sys.exit()
                os.system('rm -rf ' + logdir)
            else:
                raise ValueError(str_error + " Refuse to remove positive expr_id")
        os.system('mkdir -p ' + logdir)
    else:
        if not os.path.isdir(logdir):
            print(str_warning, 'training from scratch...')
            os.system('mkdir -p ' + logdir)
        else:
            opt_f_old = os.path.join(logdir, 'opt.pt')
            opt = options_train.overwrite(opt, opt_f_old, unique_opt_params)

    # Save opt
    if os.path.exists(os.path.join(logdir, 'opt.pt')) and opt.pt_no_overwrite:
        print(str_warning, 'not overwriting previous opt.pt, this should only be set when doing on the fly eval.')
        pass
    else:
        torch.save(vars(opt), os.path.join(logdir, 'opt.pt'))
        with open(os.path.join(logdir, 'opt.txt'), 'w') as fout:
            for k, v in vars(opt).items():
                fout.write('%20s\t%-20s\n' % (k, v))

    opt.full_logdir = logdir

# Path: options/options_train.py
# def add_general_arguments(parser):
# def overwrite(opt, opt_f_old, unique_params):
# def parse(add_additional_arguments=None):
# 
# Path: loggers/loggers.py
# class BaseLogger(object):
# class _LogCumulator(BaseLogger):
# class ProgbarLogger(BaseLogger):
# class CsvLogger(BaseLogger):
# class BatchCsvLogger(BaseLogger):
# class ModelSaveLogger(BaseLogger):
# class TerminateOnNaN(BaseLogger):
# class TensorBoardLogger(BaseLogger):
# class HtmlLogger(BaseLogger):
# class ComposeLogger(BaseLogger):
#     def __init__(self):
#     def set_mute(self):
#     def on_train_begin(self):
#     def on_train_end(self):
#     def on_epoch_begin(self, epoch):
#     def on_epoch_end(self, epoch, epoch_log):
#     def on_batch_begin(self, batch):
#     def on_batch_end(self, batch, batch_log):
#     def set_params(self, params):
#     def set_model(self, model):
#     def train(self):
#     def eval(self):
#     def _set_unused_metric_mode(self, mode='none'):
#     def _allow_unused(self):
#     def __init__(self):
#     def on_epoch_begin(self, epoch):
#     def on_batch_end(self, batch, batch_log):
#     def get_epoch_log(self):
#     def __init__(self, count_mode='samples', allow_unused_fields='none', interval=10, no_accum=False):
#     def on_train_begin(self):
#     def on_epoch_begin(self, epoch):
#     def on_batch_begin(self, batch):
#     def on_batch_end(self, batch, batch_log):
#     def on_epoch_end(self, epoch, epoch_log):
#     def __init__(self, filename, allow_unused_fields='none'):
#     def on_train_begin(self):
#     def on_epoch_end(self, epoch, epoch_log):
#     def on_train_end(self):
#     def __init__(self, filename, allow_unused_fields='none'):
#     def on_train_begin(self):
#     def on_batch_end(self, batch, batch_log=None):
#     def on_train_end(self):
#     def __init__(self, filepath, period=1, save_optimizer=False, save_best=False, prev_best=None):
#     def on_train_begin(self):
#     def on_epoch_end(self, epoch, epoch_log):
#     def __init__(self):
#     def on_batch_begin(self, batch):
#     def on_batch_end(self, batch, batch_log):
#     def __init__(self, filepath, use_html_logger=False, allow_unused_fields='none'):
#     def on_train_begin(self):
#     def on_epoch_end(self, epoch, epoch_log):
#     def on_train_end(self):
#     def __init__(self, summary_filepath, allow_unused_fields='none'):
#     def on_train_begin(self):
#     def flush(self):
#     def on_epoch_begin(self, epoch):
#     def on_epoch_end(self, epoch, *args, **kargs):
#     def content_to_html(self):
#     def summary_to_html(self):
#     def __init__(self, loggers):
#     def get_tensorboard(self):
#     def get_html_logger(self):
#     def add_logger(self, logger):
#     def on_train_begin(self):
#     def on_train_end(self):
#     def on_epoch_begin(self, epoch):
#     def on_epoch_end(self, epoch, epoch_log):
#     def on_batch_begin(self, batch):
#     def on_batch_end(self, batch, batch_log):
#     def set_params(self, params):
#     def set_model(self, model):
#     def train(self):
#     def eval(self):
# 
# Path: util/util_print.py
# class bcolors:
#     HEADER = '\033[95m'
#     OKBLUE = '\033[94m'
#     OKGREEN = '\033[92m'
#     WARNING = '\033[93m'
#     FAIL = '\033[91m'
#     ENDC = '\033[0m'
#     BOLD = '\033[1m'
#     UNDERLINE = '\033[4m'
# 
# Path: util/util_loadlib.py
# def set_gpu(gpu, check=True):
# def _check_gpu_setting_in_use(gpu):
# def _check_gpu(gpu):
# def set_manual_seed(seed):


# Path: train.py
import sys
import os
import time
import torch
import datasets
import models
import pandas as pd
import torch.multiprocessing as mp
import torch.distributed as dist
from options import options_train
from loggers import loggers
from util.util_print import str_error, str_stage, str_verbose, str_warning
from util import util_loadlib as loadlib
        from subprocess import call

                while need_input:
                    response = input().lower()
                    if response in ('y', 'n'):
                        need_input = False
                if response == 'n':
                    print(str_stage, "User decides to quit")
                    sys.exit()
                os.system('rm -rf ' + logdir)
            else:
                raise ValueError(str_error + " Refuse to remove positive expr_id")
        os.system('mkdir -p ' + logdir)
    else:
        if not os.path.isdir(logdir):
            print(str_warning, 'training from scratch...')
            os.system('mkdir -p ' + logdir)
        else:
            opt_f_old = os.path.join(logdir, 'opt.pt')
            opt = options_train.overwrite(opt, opt_f_old, unique_opt_params)

    # Save opt
    if os.path.exists(os.path.join(logdir, 'opt.pt')) and opt.pt_no_overwrite:
        print(str_warning, 'not overwriting previous opt.pt, this should only be set when doing on the fly eval.')
        pass
    else:
        torch.save(vars(opt), os.path.join(logdir, 'opt.pt'))
        with open(os.path.join(logdir, 'opt.txt'), 'w') as fout:
            for k, v in vars(opt).items():
                fout.write('%20s\t%-20s\n' % (k, v))

    opt.full_logdir = logdir

    print(str_verbose, "Logging directory set to: %s" % logdir)