# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import pickle
import re
import numpy as np
import ast

from os import listdir
import glob


file_names = glob.glob('../../iclr_result_dirs/keras-resnet/out*')

len(file_names)

file_name='../../iclr_result_dirs/teacher_student/out_traject.831800'


def vanilla_out_parser(file_name, result_string = 'comitee accuracy:',result_string2 = 'individual accuracy:'):    
    count_test_results = 0
    done_config = False
    accu=-1
    accu2=np.nan
    with open(file_name,'r') as f:
        for line in f:
            if not done_config and line[:6]=='config':
                config_dict_str = line[7:].lstrip()
                done_config = True
            if line[:6] == 'python':
                python_command = line
            if count_test_results > 0:
                accu = line.split(':')[-1]
                accu_list.append(float(accu))
                count_test_results -= 1
            if result_string == line[:len(result_string)]:
                accu = float(line.split(':')[-1])
            if result_string2 == line[:len(result_string2)]:
                accu2 = float(line.split(':')[-1])
            

    # print(accu_list)
    if accu>0:
        config_dict = ast.literal_eval(config_dict_str)
#         print(config_dict)
#         print(np.mean(accu_list))
        config_dict['accuracy'] = np.mean(accu)
        config_dict['accuracy2'] = np.mean(accu2)
#         config_dict['accuracy_std'] = np.std(accu_list)
#         config_dict['accuracy'] = np.mean(accu_list)
        return config_dict
    else:
        return None


records = []
for ii,file_name in enumerate(file_names):
    conf=vanilla_out_parser(file_name)
    if conf is not None:
        conf['file_name']=file_name.split('/')[-1]
        conf['file_name_full']=file_name
#         conf['teacher_short']=conf['teacher_net'][-25:]
#         print(conf['teacher_short'])
        records.append(conf)

import pandas as pd

df = pd.DataFrame(records)

df.columns

df.sort_values(by=['n_classes']).loc[df['style']=='spiral_2dir'].loc[ df['epochs']==100].loc[:,['file_name','style','n_classes','n_samples', 'accuracy', 'accuracy2']]

df.loc[df['style']=='spiral_2dir'].loc[:,['file_name','style','n_classes','n_samples', 'accuracy']]

df.loc[df['style']=='xx1_vonmises_walk']



df.sort_values(by=['n_classes']).loc[df['style']=='spiral_2dir'].loc[:,['file_name','teacher_short','style','resnet_mode',
                                                                        'n_samples','n_classes','epochs', 'accuracy']]

df.sort_values(by=['n_classes']).loc[df['style']=='spiral_2dir2'].loc[df['resnet_mode']].loc[:,['file_name','teacher_short','style','resnet_mode',
                                                                         'student_block_size',
                                                                         'broadcast','n_samples','n_classes','epochs', 'accuracy']]

df.to_pickle('DRC_results_Oct3_21.pkl')

700*100/3600







































































conf['file_name_full']













StarcoderdataJupyterScriptsDedupFiltered