def __init__(self, settings, log): """constructor""" self.space = self.define_search_space(settings) # Read inputs self.log = log self._split_timeline(0.8, settings['read_options']['one_timestamp']) self.org_log = copy.deepcopy(log) self.org_log_train = copy.deepcopy(self.log_train) self.org_log_valdn = copy.deepcopy(self.log_valdn) # Load settings self.settings = settings self.temp_output = os.path.join('output_files', sup.folder_id()) if not os.path.exists(self.temp_output): os.makedirs(self.temp_output) self.file_name = os.path.join(self.temp_output, sup.file_id(prefix='OP_')) # Results file if not os.path.exists(self.file_name): open(self.file_name, 'w').close() # Trials object to track progress self.bayes_trials = Trials() self.best_output = None self.best_parms = dict() self.best_similarity = 0
def __init__(self, parms, log, ac_index, rl_index): """constructor""" self.space = self.define_search_space(parms) self.log = copy.deepcopy(log) self.ac_index = ac_index self.rl_index = rl_index # Load settings self.parms = parms self.temp_output = parms['output'] if not os.path.exists(self.temp_output): os.makedirs(self.temp_output) os.makedirs(os.path.join(self.temp_output, 'opt_parms')) self.file_name = sup.file_id(prefix='OP_') # Results file if not os.path.exists(os.path.join(self.temp_output, self.file_name)): open(os.path.join(self.temp_output, self.file_name), 'w').close() self.conn = { 'partition': 'main', 'mem': str(32000), 'cpus': str(10), 'env': 'deep_generator_pip', 'script': os.path.join('model_training', 'slurm_trainer.py') } self.slurm_workers = 50 self.best_output = None self.best_parms = dict() self.best_loss = 1
def __init__(self, parms, log_train, log_valdn, ac_index, ac_weights): """constructor""" self.space = self.define_search_space(parms) self.log_train = copy.deepcopy(log_train) self.log_valdn = copy.deepcopy(log_valdn) self.ac_index = ac_index self.ac_weights = ac_weights # Load settings self.parms = parms self.temp_output = parms['output'] if not os.path.exists(self.temp_output): os.makedirs(self.temp_output) os.makedirs(os.path.join(self.temp_output, 'opt_parms')) self.file_name = os.path.join(self.temp_output, sup.file_id(prefix='OP_')) # Results file if not os.path.exists(self.file_name): open(self.file_name, 'w').close() self.conn = {'partition': 'main', 'mem': str(32000), 'cpus': str(10), 'env': 'deep_sim3', 'script': os.path.join('core_modules', 'times_allocator', 'slurm_trainer.py')} self.slurm_workers = 50 self.best_output = None self.best_parms = dict() self.best_loss = 1
def _execute_simulator(bimp_path, temp_path, model): """Executes BIMP Simulations. Args: settings (dict): Path to jar and file names rep (int): repetition number """ sim_log = os.path.join(temp_path, sup.file_id('SIM_')) args = ['java', '-jar', bimp_path, model, '-csv', sim_log] subprocess.run(args, check=True, stdout=subprocess.PIPE) return sim_log
def _export_results(self, output_path) -> None: # Save results pd.DataFrame(self.sim_values).to_csv(os.path.join( output_path, sup.file_id(prefix='SE_')), index=False) # Save logs log_test = self.log_test[~self.log_test.task.isin(['Start', 'End'])] log_test.to_csv(os.path.join( output_path, 'tst_' + self.parms['gl']['file'].split('.')[0] + '.csv'), index=False) if self.parms['gl']['save_models']: paths = [ 'bpmn_models', 'embedded_path', 'ia_gen_path', 'seq_flow_gen_path', 'times_gen_path' ] sources = list() for path in paths: for root, dirs, files in os.walk(self.parms['gl'][path]): for file in files: if self.parms['gl']['file'].split('.')[0] in file: sources.append(os.path.join(root, file)) for source in sources: base_folder = os.path.join( output_path, os.path.basename(os.path.dirname(source))) if not os.path.exists(base_folder): os.makedirs(base_folder) destination = os.path.join(base_folder, os.path.basename(source)) # Copy dl models allowed_ext = self._define_model_path({ **self.parms['gl'], **self.parms['t_gen'] }) is_dual = self.parms['t_gen']['model_type'] == 'dual_inter' if is_dual and ('times_gen_models' in source) and any( [x in source for x in allowed_ext]): shutil.copyfile(source, destination) elif not is_dual and ('times_gen_models' in source) and any([ self.parms['gl']['file'].split('.')[0] + x in source for x in allowed_ext ]): shutil.copyfile(source, destination) # copy other models folders = ['bpmn_models', 'embedded_matix', 'ia_gen_models'] allowed_ext = [ '.emb', '.bpmn', '_mpdf.json', '_prf.json', '_prf_meta.json', '_mpdf_meta.json', '_meta.json' ] if any([x in source for x in folders]) and any([ self.parms['gl']['file'].split('.')[0] + x in source for x in allowed_ext ]): shutil.copyfile(source, destination)
def _export_results(self, output_path) -> None: # Save results pd.DataFrame(self.sim_values).to_csv( os.path.join(self.output_route, sup.file_id(prefix='SE_')), index=False) # Save logs log_test = self.log[~self.log.task.isin(['Start', 'End'])] log_test.to_csv( os.path.join(self.output_route, 'tst_'+ self.parms['model_file'].split('.')[0]+'.csv'), index=False)
def export_params(self): configs_files = list() for config in self.space: config['ac_index'] = self.ac_index config['rl_index'] = self.rl_index conf_file = sup.file_id(prefix='CNF_', extension='.json') sup.create_json( config, os.path.join(self.temp_output, 'opt_parms', conf_file)) configs_files.append(conf_file) self.log.to_csv(os.path.join(self.temp_output, 'opt_parms', 'train.csv'), index=False, encoding='utf-8') return configs_files
def __init__(self, parms, log_train, log_valdn, ac_index, ac_weights): """constructor""" self.space = self.define_search_space(parms) self.log_train = copy.deepcopy(log_train) self.log_valdn = copy.deepcopy(log_valdn) self.ac_index = ac_index self.ac_weights = ac_weights # Load settings self.parms = parms self.temp_output = parms['output'] if not os.path.exists(self.temp_output): os.makedirs(self.temp_output) self.file_name = os.path.join(self.temp_output, sup.file_id(prefix='OP_')) # Results file if not os.path.exists(self.file_name): open(self.file_name, 'w').close() # Trials object to track progress self.bayes_trials = Trials() self.best_output = None self.best_parms = dict() self.best_loss = 1