Exemplo n.º 1
0
def make_agent(env, submission_dir):
    """
    This function will be used by codalab to create your agent. It should accept exactly an environment and a path
    to your submission directory and return a valid agent.
    """
    agent = RandomAgent(env.action_space)
    return agent
Exemplo n.º 2
0
 def test_2random(self):
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         env = grid2op.make("rte_case5_example", test=True)
         env2 = grid2op.make("rte_case14_realistic", test=True)
     agent = RandomAgent(env.action_space)
     agent2 = RandomAgent(env2.action_space)
     # test i can reset the env
     obs = env.reset()
     obs2 = env2.reset()
     # test the agent can act
     act = agent.act(obs, 0., False)
     act2 = agent2.act(obs2, 0., False)
     # test the env can step
     _ = env.step(act)
     _ = env2.step(act2)
Exemplo n.º 3
0
    def test_random(self):
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore")
            with grid2op.make("rte_case5_example", test=True) as env:
                obs = env.reset()
                my_agent = RandomAgent(env.action_space)
                my_agent.seed(0)
                nb_test = 100
                res = np.zeros(nb_test, dtype=np.int)
                res2 = np.zeros(nb_test, dtype=np.int)
                res3 = np.zeros(nb_test, dtype=np.int)
                for i in range(nb_test):
                    res[i] = my_agent.my_act(obs, 0., False)
                my_agent.seed(0)
                for i in range(nb_test):
                    res2[i] = my_agent.my_act(obs, 0., False)
                my_agent.seed(1)
                for i in range(nb_test):
                    res3[i] = my_agent.my_act(obs, 0., False)

                # the same seeds should produce the same sequence
                assert np.all(res == res2)
                # different seeds should produce different sequence
                assert np.any(res != res3)
Exemplo n.º 4
0
 def __init__(self, action_space):
     RandomAgent.__init__(self, action_space)
     self.i = 0
Exemplo n.º 5
0
 def __init__(self, *args, **kwargs):
     RandomAgent.__init__(self, *args, **kwargs)
     self.seeds = []
Exemplo n.º 6
0
                this_epi_scores = json.load(f)
            score_this_ep, nb_ts_survived, total_ts_tmp = \
                self._compute_episode_score(ep_id,
                                            meta=this_epi_meta,
                                            other_rewards=this_epi_scores,
                                            dn_metadata=meta_data_dn,
                                            no_ov_metadata=no_ov_metadata)
            all_scores.append(score_this_ep)
            ts_survived.append(nb_ts_survived)
            total_ts.append(total_ts_tmp)

        if need_delete:
            dir_tmp.cleanup()
        return all_scores, ts_survived, total_ts


if __name__ == "__main__":
    import grid2op
    from lightsim2grid import LightSimBackend
    from grid2op.Agent import RandomAgent, DoNothingAgent
    env = grid2op.make("l2rpn_case14_sandbox", backend=LightSimBackend())
    nb_scenario = 16
    my_score = ScoreL2RPN2020(env,
                              nb_scenario=nb_scenario,
                              env_seeds=[0 for _ in range(nb_scenario)],
                              agent_seeds=[0 for _ in range(nb_scenario)])

    my_agent = RandomAgent(env.action_space)
    my_agent = DoNothingAgent(env.action_space)
    print(my_score.get(my_agent))
Exemplo n.º 7
0
    stats_dn.clear_episode_data()

    # you can also change the parameters
    param = Parameters()
    param.NO_OVERFLOW_DISCONNECTION = True
    stats_no_overflow = EpisodeStatistics(env, name_stats="no_overflow")
    stats_no_overflow.compute(
        nb_scenario=nb_scenario,
        parameters=param,
        pbar=True,
        scores_func=L2RPNSandBoxScore
    )  # this will take a while to compute in most cases
    stats_no_overflow.clear_episode_data()

    # or use a different agent
    my_agent = RandomAgent(
        env.action_space)  # use any grid2op agent you want here
    stats_custom_agent = EpisodeStatistics(env, name_stats="custom_agent")
    stats_custom_agent.compute(
        nb_scenario=nb_scenario,
        agent=my_agent,
        pbar=True,
        scores_func=L2RPNSandBoxScore
    )  # this will take a while to compute in most cases
    stats_custom_agent.clear_episode_data()

    # and then you can retrieve the statistics
    rho_dn, ids = stats_dn.get("rho")
    rho_dn_all, ids = stats_no_overflow.get("rho")
    rho_custom_agent, ids = stats_custom_agent.get("rho")