def retro_analyze_trials(predir): '''Retro-analyze all trial level datas.''' logger.info('Retro-analyzing trials from file') from slm_lab.experiment.control import Trial filenames = ps.filter_(os.listdir(predir), lambda filename: filename.endswith('_trial_df.csv')) for idx, filename in enumerate(filenames): filepath = f'{predir}/{filename}' prepath = filepath.replace('_trial_df.csv', '') spec, info_space = util.prepath_to_spec_info_space(prepath) trial_index, _ = util.prepath_to_idxs(prepath) trial = Trial(spec, info_space) trial.session_data_dict = session_data_dict_from_file( predir, trial_index, ps.get(info_space, 'ckpt')) # zip only at the last zip = (idx == len(filenames) - 1) trial_fitness_df = analysis.analyze_trial(trial, zip) # write trial_data that was written from ray search trial_data_filepath = filepath.replace('_trial_df.csv', '_trial_data.json') if os.path.exists(trial_data_filepath): fitness_vec = trial_fitness_df.iloc[0].to_dict() fitness = analysis.calc_fitness(trial_fitness_df) trial_data = util.read(trial_data_filepath) trial_data.update({ **fitness_vec, 'fitness': fitness, 'trial_index': trial_index, }) util.write(trial_data, trial_data_filepath)
def run_trial(experiment, config): trial_index = config.pop('trial_index') spec = spec_from_config(experiment, config) info_space = deepcopy(experiment.info_space) info_space.set('trial', trial_index) trial_fitness_df = experiment.init_trial_and_run(spec, info_space) fitness_vec = trial_fitness_df.iloc[0].to_dict() fitness = analysis.calc_fitness(trial_fitness_df) trial_data = {**config, **fitness_vec, 'fitness': fitness, 'trial_index': trial_index} prepath = util.get_prepath(spec, info_space, unit='trial') util.write(trial_data, f'{prepath}_trial_data.json') return trial_data
def run_trial(experiment, config): trial_index = config.pop('trial_index') spec = spec_from_config(experiment, config) info_space = deepcopy(experiment.info_space) info_space.set('trial', trial_index) trial_fitness_df = experiment.init_trial_and_run(spec, info_space) fitness_vec = trial_fitness_df.iloc[0].to_dict() fitness = analysis.calc_fitness(trial_fitness_df) trial_data = { **config, **fitness_vec, 'fitness': fitness, 'trial_index': trial_index, } prepath = analysis.get_prepath(spec, info_space, unit='trial') util.write(trial_data, f'{prepath}_trial_data.json') return trial_data
def lab_trial(config, reporter): '''Trainable method to run a trial given ray config and reporter''' trial_index = config.pop('trial_index') spec = self.spec_from_config(config) info_space = deepcopy(self.experiment.info_space) info_space.set('trial', trial_index) trial_fitness_df = self.experiment.init_trial_and_run( spec, info_space) fitness_vec = trial_fitness_df.iloc[0].to_dict() fitness = analysis.calc_fitness(trial_fitness_df) trial_index = trial_fitness_df.index[0] trial_data = { **config, **fitness_vec, 'fitness': fitness, 'trial_index': trial_index, } done = True # TODO timesteps = episode len or total_t from space_clock # call reporter from inside trial/session loop reporter(timesteps_total=-1, done=done, info=trial_data)