Example #1
0
    def test_agents(self):
        params = ParameterServer()
        params["ML"]["BaseAgent"]["NumSteps"] = 2
        params["ML"]["BaseAgent"]["MaxEpisodeSteps"] = 2

        bp = DiscreteHighwayBlueprint(params,
                                      number_of_senarios=10,
                                      random_seed=0)
        env = SingleAgentRuntime(blueprint=bp, render=False)
        env._observer = NearestAgentsObserver(params)
        env._action_wrapper = BehaviorDiscreteMacroActionsML(params)

        fqf_agent = FQFAgent(agent_save_dir="./save_dir",
                             env=env,
                             params=params)
        fqf_agent.train_episode()

        fqf_agent.save(checkpoint_type="best")
        fqf_agent.save(checkpoint_type="last")

        loaded_agent = FQFAgent(agent_save_dir="./save_dir",
                                checkpoint_load="best")
        loaded_agent2 = FQFAgent(agent_save_dir="./save_dir",
                                 checkpoint_load="last")

        loaded_agent_with_env = FQFAgent(env=env,
                                         agent_save_dir="./save_dir",
                                         checkpoint_load="last")
        loaded_agent_with_env.train_episode()

        self.assertEqual(loaded_agent.ml_behavior.action_space.n,
                         fqf_agent.ml_behavior.action_space.n)
        self.assertEqual(loaded_agent.ent_coef, fqf_agent.ent_coef)
        return
Example #2
0
 def test_agent_wrapping(self):
     params = ParameterServer()
     env = gym.make("highway-v1", params=params)
     env.reset()
     # agent = IQNAgent(env=env, test_env=env, params=params)
     params["ML"]["BaseAgent"]["MaxEpisodeSteps"] = 2
     params["ML"]["BaseAgent"]["NumEvalEpisodes"] = 2
     agent = FQFAgent(env=env, params=params)
     agent.train_episode()
     agent.evaluate()
 def test_agent_wrapping(self):
     params = ParameterServer()
     env = gym.make("highway-v1", params=params)
     env.reset()
     params["ML"]["BaseAgent"]["MaxEpisodeSteps"] = 2
     params["ML"]["BaseAgent"]["NumEvalEpisodes"] = 2
     train_bench = TrainingBenchmarkDatabase()
     agent = FQFAgent(env=env,
                      agent_save_dir="./save_dir",
                      params=params,
                      training_benchmark=train_bench)
     agent.train_episode()
     agent.evaluate()