def test_get_commit_hash(save_path): '''Test get_commit_hash function.''' with pytest.raises(RuntimeError): utils_file.get_commit_hash(save_path) subprocess.run(["git", "init"], cwd=save_path) commit_no = utils_file.get_commit_hash(save_path) assert commit_no
def run_experiment(parameters): '''Set up and run an experiment.''' repository_path = Path(__file__).parent save_to = parameters['path'] task_name = '{alg}-{learning_rate:.4f}-{gamma:.4f}-{seed:d}' task_name = task_name.format(**parameters) save_to = Path(save_to, task_name) with utils_file.create_directory(save_to, False, False) as log_dir: parameters['commit'] = utils_file.get_commit_hash(repository_path) utils_file.save_json(parameters, log_dir / 'hyperparams.json') parameters['model_path'] = str(log_dir / 'model.pkl') log_path = str(log_dir / 'monitor_{:d}') env_name = parameters['env_name'] kwargs = parameters.setdefault('kwargs', {}) env_callable = [ partial(Monitor, gym.make(env_name, **kwargs), log_path.format(i), allow_early_resets=True, info_keywords=('loss', 'accuracy', 'actions_mean', 'weights_mean', 'actions_std', 'states_mean', 'grads_mean'), chunk_size=parameters.setdefault('chunk_size', 5)) for i in range(1) ] try: run_agent(env_callable, parameters) except RuntimeError as error: LOGGER.error('%s, %s', error, parameters) return parameters
def run_experiment(parameters, trial): '''Set up and run an experiment.''' parameters = parameters.copy() batch_size = [2**i for i in range(5, 12)] batch_size = int(trial.suggest_categorical('batch_size', batch_size)) obs_version = int(trial.suggest_int('observation_version', 0, 3)) max_history = int(trial.suggest_discrete_uniform('max_history', 5, 50, 5)) learning_rate = float(trial.suggest_loguniform('learning_rate', 1e-5, 1e0)) buffer_size = int(trial.suggest_int('replay_buffer_size', 1e3, 1e5)) parameters.update({ 'gamma': float(trial.suggest_uniform('gamma', 0.1, 1.0)), 'replay_buffer_size': buffer_size }) parameters.setdefault('agent_parameters', {}).update({ 'policy': { 'learning_rate': learning_rate }, 'critic': { 'learning_rate': learning_rate } }) parameters.setdefault('kwargs', {}).update({ 'batch_size': batch_size, 'version': int(trial.suggest_int('version', 0, 5)), 'observation_version': obs_version, 'max_history': max_history, 'reward_version': int(trial.suggest_int('reward_version', 0, 1)), 'action_version': int(trial.suggest_int('action_version', 0, 1)) }) path = Path(parameters['path']) / str(trial.number) path.mkdir() parameters['path'] = str(path) parameters['commit'] = utils_file.get_commit_hash(Path(__file__).parent) utils_file.save_json(parameters, path / 'parameters.json') return run_agents(parameters, trial)
def run_experiment(parameters, trial): '''Set up and run an experiment.''' parameters = parameters.copy() parameters.update(get_parameters(trial)) trial_path = Path(parameters['path'], str(trial.number)) trial_path.mkdir() parameters['path'] = str(trial_path) parameters['commit'] = utils_file.get_commit_hash(Path(__file__).parent) log_path = str(trial_path / 'monitor_{:d}') kwargs = parameters.setdefault('kwargs', {}) utils_file.save_json(parameters, trial_path / 'parameters.json') wrapped_envs = [ partial(Monitor, partial(gym.make, parameters['env_name'], **kwargs), log_path.format(i), info_keywords=('loss', 'actions_mean', 'weights_mean', 'actions_std', 'states_mean', 'grads_mean'), chunk_size=parameters.setdefault('chunk_size', 5)) for i in range(1) ] return -run_agent(wrapped_envs, parameters, trial)
def run_experiment(parameters, trial): '''Set up and run an experiment.''' parameters = parameters.copy() learning_rate = float(trial.suggest_loguniform('learning_rate', 1e-5, 1e0)) buffer_size = int(trial.suggest_int('replay_buffer_size', 1e3, 1e5)) parameters.update({ 'gamma': float(trial.suggest_uniform('gamma', 0.1, 1.0)), 'replay_buffer_size': buffer_size }) parameters.setdefault('agent_parameters', {}).update({ 'policy': { 'learning_rate': learning_rate }, 'critic': { 'learning_rate': learning_rate } }) path = Path(parameters['path']) / str(trial.number) path.mkdir() parameters['path'] = str(path) parameters['commit'] = utils_file.get_commit_hash(Path(__file__).parent) utils_file.save_json(parameters, path / 'parameters.json') return run_agents(parameters, trial)