def backup_pickle(experiment, stats):
    "'\n    Back up handling function.\n\n    Arguments:\n    experiment -- Experiment object, contains the initial sorn parameters\n    stats -- bunch of stats stored during the simulation\n    "
    params = experiment.init_params
    results_dir = experiment.results_dir
    files_tosave = experiment.files_tosave
    directory = 'backup/{}'.format(results_dir)
    time.sleep(np.random.rand())
    for n_sim in range(1, 1000):
        final_dir = '{}_{}/'.format(directory, str(n_sim))
        if (not os.path.exists(final_dir)):
            try:
                os.makedirs(final_dir)
                break
            except:
                pass
    if ('params' in files_tosave):
        with open((final_dir + 'init_params.p'), 'wb') as f:
            pickle.dump(params, f)
    if ('stats' in files_tosave):
        if hasattr(stats, 'track'):
            stats.track.write((final_dir + 'sample.mid'))
        if hasattr(stats, 'input_index_readout'):
            del stats.input_index_readout
        if hasattr(stats, 'input_readout'):
            del stats.input_readout
        if hasattr(stats, 'raster_readout'):
            del stats.raster_readout
        if hasattr(stats, 't_past'):
            del stats.t_past
        with open((final_dir + 'stats.p'), 'wb') as f:
            pickle.dump(stats, f)
    if ('scripts' in files_tosave):
        for f in ['utils', 'common', results_dir.split('_')[0]]:
            shutil.copytree(f, (final_dir + f), ignore=ignore_patterns('*.pyc', '*.git'))
'
Back up handling function.

Arguments:
experiment -- Experiment object, contains the initial sorn parameters
stats -- bunch of stats stored during the simulation
def backup_pickle(experiment, stats):
    "'\n    Back up handling function.\n\n    Arguments:\n    experiment -- Experiment object, contains the initial sorn parameters\n    stats -- bunch of stats stored during the simulation\n    "
    params = experiment.init_params
    results_dir = experiment.results_dir
    files_tosave = experiment.files_tosave
    directory = 'backup/{}'.format(results_dir)
    time.sleep(np.random.rand())
    for n_sim in range(1, 1000):
        final_dir = '{}_{}/'.format(directory, str(n_sim))
        if (not os.path.exists(final_dir)):
            try:
                os.makedirs(final_dir)
                break
            except:
                pass
    if ('params' in files_tosave):
        with open((final_dir + 'init_params.p'), 'wb') as f:
            pickle.dump(params, f)
    if ('stats' in files_tosave):
        if hasattr(stats, 'track'):
            stats.track.write((final_dir + 'sample.mid'))
        if hasattr(stats, 'input_index_readout'):
            del stats.input_index_readout
        if hasattr(stats, 'input_readout'):
            del stats.input_readout
        if hasattr(stats, 'raster_readout'):
            del stats.raster_readout
        if hasattr(stats, 't_past'):
            del stats.t_past
        with open((final_dir + 'stats.p'), 'wb') as f:
            pickle.dump(stats, f)
    if ('scripts' in files_tosave):
        for f in ['utils', 'common', results_dir.split('_')[0]]:
            shutil.copytree(f, (final_dir + f), ignore=ignore_patterns('*.pyc', '*.git'))