def train_agent(config, agent): torch.manual_seed(config.SEED) env = NeodroidGymWrapper( BinaryActionEncodingWrapper( environment_name=config.ENVIRONMENT_NAME, connect_to_running=config.CONNECT_TO_RUNNING, )) env.seed(config.SEED) agent.build(env) listener = add_early_stopping_key_combination(agent.stop_procedure) if listener: listener.start() try: ( trained_model, running_signals, running_lengths, *training_statistics, ) = agent.train(env, env, rollouts=config.ROLLOUTS, render=config.RENDER_ENVIRONMENT) except ValueError as e: running_signals = None running_lengths = None trained_model = None raise e finally: if listener: listener.stop() draugr.save_statistic( running_signals, stat_name="running_signals", config_name=C.CONFIG_NAME, project_name=C.PROJECT_NAME, directory=C.LOG_DIRECTORY, ) draugr.save_statistic( running_lengths, stat_name="running_lengths", directory=C.LOG_DIRECTORY, config_name=C.CONFIG_NAME, project_name=C.PROJECT_NAME, ) U.save_model(trained_model, **config) env.close()
def train_agent(config, agent): neo.seed(config.SEED) torch.manual_seed(config.SEED) env = neo( environment_name=config.ENVIRONMENT_NAME, connect_to_running=config.CONNECT_TO_RUNNING, ) env.seed(config.SEED) agent.build(env) listener = add_early_stopping_key_combination(agent.stop_procedure) if listener: listener.start() try: ( trained_model, running_signals, running_lengths, *training_statistics, ) = agent.train(env, config.ROLLOUTS, render=config.RENDER_ENVIRONMENT) finally: if listener: listener.stop() draugr.save_statistic( running_signals, stat_name="running_signals", config_name=C.CONFIG_NAME, project_name=C.PROJECT_NAME, directory=C.LOG_DIRECTORY, ) draugr.save_statistic( running_lengths, stat_name="running_lengths", directory=C.LOG_DIRECTORY, config_name=C.CONFIG_NAME, project_name=C.PROJECT_NAME, ) U.save_model(trained_model, **config) env.close()