def main(): args = parser.parse_args() run_experiment(json_to_dict(args.experiment), monitor_path=args.monitor_path, only_last=args.only_last, description=args.description, seed=args.seed)
def run_experiment(spec, monitor_path=None, only_last=False): """Run an experiment using a specification dictionary.""" args = spec["agent"]["args"] if monitor_path: args["monitor_path"] = monitor_path else: monitor_path = args["monitor_path"] if not os.path.exists(monitor_path): os.makedirs(monitor_path) envs_type = spec["environments"]["type"] if envs_type == "single": envs = [make_environment(spec["environments"]["source"])] elif envs_type == "json": envs = make_environments(json_to_dict(spec["environments"]["source"])) args["envs"] = envs if len(envs) == 1 or only_last: args["env"] = envs[-1] action_space_type = "discrete" if isinstance(envs[0].action_space, Discrete) else "continuous" state_dimensions = "single" if len( envs[0].observation_space.shape) == 1 else "multi" agent = make_agent(spec["agent"]["name"], state_dimensions, action_space_type, **args) save_config(monitor_path, agent.config, [env.to_dict() for env in envs]) agent.learn()
def main(): args = parser.parse_args() spec = cluster_spec(args.n_tasks, 1) cluster = tf.train.ClusterSpec(spec).as_cluster_def() cls = load("agents.actorcritic.a3c_worker:" + args.cls) config = json_to_dict(args.config) task = cls(args.env_id, args.task_id, cluster, args.monitor_path, config, video=args.video) task.learn()
def main(): comm = MPI.Comm.Get_parent() task_id = comm.Get_rank() args = parser.parse_args() cls = load("agents.ppo.dppo_worker:" + args.cls) config = json_to_dict(args.config) task = cls(args.env_id, task_id, comm, args.monitor_path, config, args.seed) task.run()
def run_experiment(spec, monitor_path=None, only_last=False, description=None, seed=None): """Run an experiment using a specification dictionary.""" import os if seed is not None: set_seed(seed) import datetime import gym gym.logger.set_level(gym.logger.ERROR) from gym.spaces import Discrete from environment.registration import make, make_environments from agents.registration import make_agent args = spec["agent"]["args"] args["config_path"] = os.path.join(monitor_path, "config.json") if monitor_path: args["monitor_path"] = monitor_path else: monitor_path = args["monitor_path"] if not os.path.exists(monitor_path): os.makedirs(monitor_path) envs_type = spec["environments"]["type"] if envs_type == "single": envs = [make(spec["environments"]["source"])] elif envs_type == "json": envs = make_environments(json_to_dict(spec["environments"]["source"])) if seed is not None: for env in envs: env.seed(seed) args["seed"] = seed args["envs"] = envs if len(envs) == 1 or only_last: args["env"] = envs[-1] action_space_type = "discrete" if isinstance(envs[0].action_space, Discrete) else "continuous" state_dimensions = "single" if len( envs[0].observation_space.shape) == 1 else "multi" agent = make_agent(spec["agent"]["name"], state_dimensions, action_space_type, **args) config = agent.config.copy() if description is not None: config["description"] = description config["seed"] = str(seed) config["start_time"] = datetime.datetime.now().astimezone().isoformat() save_config(monitor_path, config, [env.metadata["parameters"] for env in envs]) agent.learn()
def main(): args = parser.parse_args() run_experiment(json_to_dict(args.experiment), monitor_path=args.monitor_path, only_last=args.only_last)