class ExperimentScheduler: """ The ExperimentSchedule schedules the experiments defined in the given schedule. If a experiment went wrong, the execution goes on for the next experiment and an execution information is printed after each experiment. :Attributes: __schedule: (Dictionary) The schedule containing the experiment order. __successful_experiments: (Array) Contains the names of the successful experiments. __canceled_experiments: (Array) Contains the names of the canceled experiments. __logger: (Logger) The logger for the experiments. __finished_experiments: (Integer) Counts the finished experiments (successful or not). """ def __init__(self, schedule): """ Constructor, initialize member variables. :param schedule: (Dictionary) The schedule containing the experiment order. """ self.__schedule = schedule self.__successful_experiments = [] self.__canceled_experiments = [] self.__logger = SLoggerHandler().getLogger(LoggerNames.EXPERIMENT_C) self.__finished_experiments = 0 def execute(self): """ Executes the experiments defined in the given schedule. If a experiment went wrong, the execution goes on for the next experiment and an execution information is printed after each experiment. """ if self.__schedule["mode"] == "sequential": self.__finished_experiments = 0 for experiment_name in self.__schedule["experimentsToRun"]: self.__finished_experiments = self.__finished_experiments + 1 try: # Dynamically import the experiment class by name. experiment_module = importlib.import_module( "Experiment_Component.Experiments." + experiment_name) # Dynamically load the provider class by name. # Combined with the above import its like: from Experiment_Component.Experiments.CsnMnistExperiment import CsnMnistExperiment experiment = getattr(experiment_module, experiment_name) for config_name in self.__schedule[ "experimentConfigsToRun"][experiment_name]: try: config = ConfigProvider().get_config( "Experiment_Component/ExperimentConfigs/" + config_name) experiment(config).execute() self.__successful_experiments.append( experiment_name) self.__logExecutionInfo() except: self.__logger.error( "Cancled experiment " + experiment_name + " An error accrued:" + str(traceback.format_exc()), "ExperimentScheduler:execute") self.__canceled_experiments.append(experiment_name) self.__logExecutionInfo() except: self.__logger.error( "Cancled experiment " + experiment_name + " An error accrued:" + str(traceback.format_exc()), "ExperimentScheduler:execute") self.__canceled_experiments.append(experiment_name) self.__logExecutionInfo() def __logExecutionInfo(self): """ Logs the execution information (for example the successful or canceled experiments) after each experiment. """ info_text = "\n************ExperimentScheduler************\n" + "Experiment " + str( self.__finished_experiments) + " of " + str( len(self.__schedule["experimentsToRun"]) ) + " finished.\nSuccessful experiments: " + str( self.__successful_experiments ) + "\nCancled experiments: " + str( self.__canceled_experiments ) + "\n*******************************************" self.__logger.info(info_text, "ExperimentScheduler:__logExecutionInfo")
class Controller: """ The controller is the central point of the framework. It takes care of the execution of various programs like the creation of TfRecord datasets or the execution of experiments via a scheduler. :Attributes: __controller_config_file_path: (String) The path to the config for the controller. __config: (Dictionary) The config of the controller. __logger: (Logger) The logger for the controller. __experiment_scheduler: (ExperimentScheduler) The scheduler to handle multiple experiments. __tf_record_handler: (TfRecordHandler) The handler to create the tf records. __config_provider: (ConfigProvider) : The provider to request config input. __experiment_scheduler: (ExperimentScheduler) The scheduler to schedule the experiment execution. """ def __init__(self, controller_config_file_path): """ Constructor, initialize member variables. :param controller_config_file_path: (String) String to controllerConfig File. """ print("Controller: Starting __init__() ...") self.__controller_config_file_path = controller_config_file_path self.__config = None self.__logger = None self.__tf_record_handler = None self.__config_provider = None self.__experiment_scheduler = None print("Controller: Finished __init__()") def init(self): """ Init method, initialize member variables and other program parts. :return: successful: (Boolean) Was the execution successful? """ print("Controller: Starting init() ...") self.__logger = SLoggerHandler().getLogger(LoggerNames.CONTROLLER_C) self.__logger.info("Loading config ...", "Controller:init") successful = True try: self.__config_provider = ConfigProvider() self.__config = self.__config_provider.get_config( self.__controller_config_file_path) self.__logger.info("Finished loading config.", "Controller:init") self.__tf_record_handler = TfRecordHandler( tfrecord_dir="data", dataset_prepreprocessors=self. __config["datasetPrePreProcessors"], num_threads=self.__config["hardware"]["numCPUCores"]) self.__logger.info("Finished init()", "Controller:init") except: successful = False self.__logger.error("Canceled init(). An error accrued!", "Controller:init") print(traceback.format_exc()) return successful def execute(self): """ Executes the execution specified in the controllers config. :return: successful: (Boolean) Was the execution successful?? """ self.__logger.info("Starting execute() ...", "Controller:execute") successful = True if self.__config["executeCreateTfRecordsFromDataset"]: try: self.__logger.info( "Starting executeCreateTfRecordsFromDataset() ...", "Controller:execute") self.__tf_record_handler.createTfRecords( self.__config["datasetsToCreateTfRecords"], self.__config["datasetTfRecordSplits"]) self.__logger.info( "Finished executeCreateTfRecordsFromDataset()", "Controller:execute") except: successful = False self.__logger.error( "Canceled executeCreateTfRecordsFromDataset(). An error accrued!", "Controller:execute") print(traceback.format_exc()) if self.__config["executeExperiments"]: try: self.__logger.info("Starting executeExperiments() ...", "Controller:execute") # load schedule experiment_schedule = self.__config_provider.get_config( "experimentSchedule.json") self.__experiment_scheduler = ExperimentScheduler( experiment_schedule) self.__experiment_scheduler.execute() self.__logger.info("Finished executeExperiments()", "Controller:execute") except: successful = False self.__logger.error( "Canceled executeExperiments(). An error accrued!", "Controller:execute") print(traceback.format_exc()) return successful