def __init__(self, render, sim_config, exp_config, checkpoint_path):

        import ray
        from ray.tune import run_experiments
        from ray.tune.registry import register_env
        from ray import tune
        import yaml
        from SingleLaneIDM.SimulatorCode.main_env import Wrapper

        from ray.rllib.agents.ppo.ppo import PPOAgent
        import os
        import pickle

        if render == 1:
            sim_config["config"]["render"] = True
        else:
            sim_config["config"]["render"] = False

        sim_config["config"]["acc-noise"] = False

        exp_name = list(exp_config.keys())[0]
        exp_config[exp_name]["config"]["num_gpus"] = 0
        exp_config[exp_name]["config"]["num_workers"] = 1
        exp_config[exp_name]["config"]["num_envs_per_worker"] = 1

        env_creator_name = "tsim-v0"
        register_env(env_creator_name, lambda config: Wrapper(sim_config))

        ray.init()
        self.agent = PPOAgent(env="tsim-v0",
                              config=exp_config[exp_name]["config"])
        self.agent.restore(checkpoint_path)
    def __init__(self, render, sim_config, exp_config, checkpoint_path):

        import ray
        from ray.tune import run_experiments
        from ray.tune.registry import register_env
        from ray import tune
        import yaml
        from SingleLaneIDM.SimulatorCode.main_env import Wrapper

        from ray.rllib.agents.dqn.apex import ApexAgent
        import ray.rllib.agents.dqn as apex

        import os
        import pickle

        if render == 1:
            sim_config["config"]["render"] = True
        else:
            sim_config["config"]["render"] = False

        sim_config["config"]["acc-noise"] = False

        exp_name = list(exp_config.keys())[0]

        exp_config[exp_name]["config"]["num_gpus"] = 0
        exp_config[exp_name]["config"]["num_workers"] = 2
        exp_config[exp_name]["config"]["num_envs_per_worker"] = 1

        env_creator_name = "tsim-v0"
        register_env(env_creator_name, lambda config: Wrapper(sim_config))

        ray.init()
        self.agent = ApexAgent(env="tsim-v0",
                               config=exp_config[exp_name]["config"])
        self.agent.restore(checkpoint_path)
        self.agent.optimizer.foreach_evaluator(lambda ev: ev.for_policy(
            lambda pi: pi.set_epsilon(0.0), policy_id="default"))
    if args.render == 1:
        sim_config["config"]["render"] = True
    else:
        sim_config["config"]["render"] = False

    sim_config["config"]["trajec-file-path"] = os.getcwd() + trajec_path
    sim_config["config"]["external-controller"] = True
    sim_config["config"]["test-mode"] = True
    sim_config["config"]["test-file-path"] = os.getcwd() + test_trajec_path
    sim_config["config"]["enable-traffic-light"] = False

    exp_name = list(exp_config.keys())[0]
    exp_config[exp_name]["config"]["horizon"] = int(
        sim_config["config"]["horizon"])

    env = Wrapper(sim_config)
    controller = PPORLController(False, sim_config, exp_config,
                                 args.checkpoint_file)
    print(env.observation_space)
    print(env.action_space)

    episodes = args.num_episodes
    horizon = args.episode_length
    print(horizon)

    for episode in range(0, episodes):

        prev_state = env.reset(args.density)
        episode_reward = 0.0
        #lstm_state = [np.zeros(256), np.zeros(256)]
                    type=str,
                    help="ppo experiment configuration file")

if __name__ == "__main__":

    args = parser.parse_args()
    trajec_path = "/SingleLaneIDM/SimulatorCode/micro.pkl"

    with open(args.sim_config_file, "r") as handle:
        sim_config = yaml.load(handle)

    with open(args.apex_config_file, "r") as handle:
        exp_config = yaml.load(handle)

    sim_config["config"]["render"] = False
    sim_config["config"]["render-grid"] = False
    sim_config["config"]["trajec-file-path"] = os.getcwd() + trajec_path
    sim_config["config"]["external-controller"] = True

    exp_name = list(exp_config.keys())[0]

    exp_config[exp_name]["config"]["callbacks"]["on_episode_end"] = None
    exp_config[exp_name]["config"]["horizon"] = int(
        sim_config["config"]["horizon"])

    env_creator_name = "tsim-v0"
    register_env(env_creator_name, lambda config: Wrapper(sim_config))

    #print(exp_config)
    ray.init()
    run_experiments(exp_config)
Beispiel #5
0
        exp_config = yaml.load(handle)

    sim_config["config"]["render"] = False

    sim_config["config"]["trajec-file-path"] = os.getcwd() + trajec_path
    sim_config["config"]["external-controller"] = True
    sim_config["config"]["enable-traffic-light"] = True

    num_episodes = args.num_episodes
    episode_length = args.episode_length

    exp_name = list(exp_config.keys())[0]
    exp_config[exp_name]["config"]["horizon"] == int(
        sim_config["config"]["horizon"])

    env = Wrapper(sim_config)
    controller = PPORLController(False, sim_config, exp_config,
                                 args.checkpoint_file)

    global_data_dict["num_episodes"] = num_episodes
    global_data_dict["episode-length"] = episode_length
    global_data_dict["time-period"] = sim_config["config"]["time-period"]
    global_data_dict["data"] = {}

    for density in densities:

        density_data = {}

        completed_episodes = 0
        while completed_episodes < num_episodes: