<s> """<STR_LIT>""" <EOL> from abc import abstractmethod <EOL> from kameleon_mcmc . tools . GitTools import GitTools <EOL> from os import makedirs <EOL> from pickle import dump , load <EOL> import os <EOL> import sys <EOL> class Experiment ( object ) : <EOL> dispatcher_filename = os . path . abspath ( __file__ ) <EOL> erperiment_output_filename = "<STR_LIT>" <EOL> experiment_output_folder = "<STR_LIT>" <EOL> gitversion_filename = "<STR_LIT>" <EOL> parameters_filename = "<STR_LIT>" <EOL> def __init__ ( self , experiment_dir = "<STR_LIT>" , name = "<STR_LIT>" ) : <EOL> self . experiment_dir = experiment_dir <EOL> self . name = name <EOL> folder_base = experiment_dir + name + "<STR_LIT:_>" <EOL> num = <NUM_LIT:0> ; <EOL> while os . path . exists ( folder_base + str ( num ) + os . sep ) : <EOL> num += <NUM_LIT:1> <EOL> self . foldername = folder_base + str ( num ) + os . sep <EOL> makedirs ( self . foldername ) <EOL> f = open ( self . foldername + Experiment . gitversion_filename , "<STR_LIT:w>" ) <EOL> f . write ( GitTools . get_hash ( ) + os . linesep ) <EOL> f . write ( GitTools . get_branch ( ) + os . linesep ) <EOL> f . close ( ) <EOL> f = open ( self . foldername + Experiment . parameters_filename , "<STR_LIT:w>" ) <EOL> f . write ( str ( self ) ) <EOL> f . close ( ) <EOL> @ abstractmethod <EOL> def __run_experiment__ ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def run ( self ) : <EOL> print "<STR_LIT>" , self . name <EOL> self . __run_experiment__ ( ) <EOL> print "<STR_LIT>" , self . name <EOL> self . save_results ( ) <EOL> print "<STR_LIT>" , self . name , "<STR_LIT>" <EOL> def save_results ( self ) : <EOL> output_folder = self . foldername + Experiment . experiment_output_folder + os . sep <EOL> makedirs ( output_folder ) <EOL> f = open ( output_folder + Experiment . erperiment_output_filename , "<STR_LIT:w>" ) <EOL> dump ( self , f ) <EOL> f . close ( ) <EOL> def __str__ ( self ) : <EOL> s = self . __class__ . __name__ + "<STR_LIT>" <EOL> s += "<STR_LIT>" + str ( self . experiment_dir ) <EOL> s += "<STR_LIT>" + str ( self . name ) <EOL> s += "<STR_LIT>" + str ( self . foldername ) <EOL> s += "<STR_LIT:]>" <EOL> return s <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> if len ( sys . argv ) != <NUM_LIT:2> : <EOL> print "<STR_LIT>" , str ( sys . argv [ <NUM_LIT:0> ] ) . split ( os . sep ) [ - <NUM_LIT:1> ] , "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" + str ( sys . argv [ <NUM_LIT:0> ] ) . split ( os . sep ) [ - <NUM_LIT:1> ] + "<STR_LIT>" <EOL> exit ( ) <EOL> filename = str ( sys . argv [ <NUM_LIT:1> ] ) <EOL> print "<STR_LIT>" , filename <EOL> try : <EOL> f = open ( filename , '<STR_LIT:r>' ) <EOL> experiment = load ( f ) <EOL> f . close ( ) <EOL> experiment . run ( ) <EOL> except IOError : <EOL> print "<STR_LIT>" </s>
