Пример #1
0
 def test_creation_ControlVoltage(self):
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         with make("rte_case5_example", test=True) as env:
             volt_cont = ControlVoltageFromFile(
                 controler_backend=env.backend, gridobj=env.backend)
Пример #2
0
 def test_case5_redispatch_available(self):
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         with make("rte_case5_example", test=True) as env:
             obs = env.reset()
             assert env.redispatching_unit_commitment_availble == True
Пример #3
0
        msg_tmp = "chronics at: {}".format(chron_name)
        msg_tmp += "\ttotal reward: {:.6f}".format(cum_reward)
        msg_tmp += "\ttime steps: {:.0f}/{:.0f}".format(nb_time_step, max_ts)
        print(msg_tmp)

    if save_gif:
        save_log_gif(logs_path, res)


if __name__ == "__main__":
    # Parse command line
    args = cli()
    # Create dataset env
    env = make(args.data_dir,
               reward_class=RedispReward,
               action_class=TopologyAction,
               other_rewards={
                   "bridge": BridgeReward,
                   "overflow": CloseToOverflowReward,
                   "distance": DistanceReward
               })
    # Call evaluation interface
    evaluate(env,
             load_path=args.load_file,
             logs_path=args.logs_dir,
             nb_episode=args.nb_episode,
             nb_process=args.nb_process,
             max_steps=args.max_steps,
             verbose=args.verbose,
             save_gif=args.gif)
Пример #4
0
 def test_create_dev(self):
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         env = make("l2rpn_neurips_2020_track2", test=True)
     assert env != None
     assert isinstance(env, MultiMixEnvironment)
Пример #5
0
 def test_case14_fromfile(self):
     self.skipTest("deprecated test")
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         env = make("rte_case14_fromfile", test=True)
         obs = env.reset()
Пример #6
0
 def test_voltagecontroler_class(self):
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         with make("rte_case5_example", test=True, voltagecontroler_class=ControlVoltageFromFile) as env:
             obs = env.reset()
Пример #7
0
 def test_opponent_class(self):
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         with make("rte_case5_example", test=True, opponent_class=BaseOpponent) as env:
             obs = env.reset()
Пример #8
0
 def test_case14test_thermals(self):
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         with make("rte_case14_test", test=True) as env:
             obs = env.reset()
             assert np.all(env._thermal_limit_a == case14_test_TH_LIM)
Пример #9
0
 def test_param(self):
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         with make("rte_case5_example", test=True, param=Parameters()) as env:
             obs = env.reset()
Пример #10
0
 def setUp(self):
     self.max_iter = 10
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         self.env = make("rte_case14_realistic", test=True)
         self.env.chronics_handler.set_max_iter(self.max_iter)
Пример #11
0
 def test_load_error(self):
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         with self.assertRaises(EnvError):
             with make("rte_case14_realistic", test=True, chronics_path="/answer/life/42"):
                 pass
Пример #12
0
 def setUp(self):
     # powergrid
     self.tolvect = 1e-2
     self.tol_one = 1e-4
     self.env = make("case5_example")
Пример #13
0
 def setUp(self):
     # Create env with custom params
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         self.params = Parameters()
         self.env = make("rte_case5_example", test=True, param=self.params)
Пример #14
0
    def test_sub_dont_change(self):
        """test that i cannot reconect a powerline by acting on the substation"""
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore")
            params = Parameters()
            params.MAX_SUB_CHANGED = 1
            params.MAX_LINE_STATUS_CHANGED = 1
            params.NB_TIMESTEP_COOLDOWN_LINE = 3
            params.NB_TIMESTEP_COOLDOWN_SUB = 3
            params.NO_OVERFLOW_DISCONNECTION = True
            env = make("rte_case5_example", test=True, param=params)
        l_id = 2
        # prepare the actions
        disco_act = env.action_space.disconnect_powerline(line_id=l_id)
        reco_act = env.action_space.reconnect_powerline(line_id=l_id,
                                                        bus_or=1,
                                                        bus_ex=1)
        set_or_1_act = env.action_space(
            {"set_bus": {
                "lines_or_id": [(l_id, 1)]
            }})
        set_ex_1_act = env.action_space(
            {"set_bus": {
                "lines_ex_id": [(l_id, 1)]
            }})

        obs, reward, done, info = env.step(disco_act)
        assert obs.rho[l_id] == 0.
        assert obs.time_before_cooldown_line[l_id] == 3
        assert env.backend._grid.line.iloc[l_id]["in_service"] == False

        # i have a cooldown to 2 so i cannot reconnect it
        assert obs.time_before_cooldown_line[l_id] == 3
        obs, reward, done, info = env.step(reco_act)
        assert obs.rho[l_id] == 0.
        assert info["is_illegal"]
        assert obs.time_before_cooldown_line[l_id] == 2
        assert env.backend._grid.line.iloc[l_id]["in_service"] == False

        # this is not supposed to reconnect it either (cooldown)
        assert obs.time_before_cooldown_line[l_id] == 2
        obs, reward, done, info = env.step(set_or_1_act)
        # pdb.set_trace()
        # assert info["is_illegal"]
        assert env.backend._grid.line.iloc[l_id]["in_service"] == False
        assert obs.rho[l_id] == 0.
        assert obs.time_before_cooldown_line[l_id] == 1
        assert env.backend._grid.line.iloc[l_id]["in_service"] == False

        # and neither is that (cooldown)
        assert obs.time_before_cooldown_line[l_id] == 1
        obs, reward, done, info = env.step(set_ex_1_act)
        assert obs.rho[l_id] == 0.
        assert obs.time_before_cooldown_line[l_id] == 0
        assert env.backend._grid.line.iloc[l_id]["in_service"] == False

        # and now i can reconnect
        obs, reward, done, info = env.step(reco_act)
        assert obs.rho[l_id] != 0.
        assert obs.time_before_cooldown_line[l_id] == 3
        assert env.backend._grid.line.iloc[l_id]["in_service"] == True
Пример #15
0
 def test_names_chronics_to_backend(self):
     self.skipTest("deprecated test for now")
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         with make("rte_case5_example", test=True, names_chronics_to_backend={}) as env:
             obs = env.reset()
Пример #16
0
 def test_backend(self):
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         with make("rte_case5_example", test=True, backend=PandaPowerBackend()) as env:
             obs = env.reset()
Пример #17
0
 def test_chronics_class(self):
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         with make("rte_case5_example", test=True, chronics_class=Multifolder) as env:
             pass
Пример #18
0
 def test_obsclass(self):
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         with make("rte_case5_example", test=True, observation_class=CompleteObservation) as env:
             obs = env.reset()
Пример #19
0
 def test_other_rewards(self):
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         with make("rte_case5_example", test=True, other_rewards={"test": L2RPNReward}) as env:
             obs = env.reset()
Пример #20
0
 def test_gamerules(self):
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         with make("rte_case5_example", test=True, gamerules_class=AlwaysLegal) as env:
             obs = env.reset()
Пример #21
0
 def test_opponent_init_budget(self):
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         with make("rte_case5_example", test=True, opponent_init_budget=10) as env:
             obs = env.reset()
Пример #22
0
 def test_chronics_path(self):
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         with make("rte_case5_example", test=True, chronics_path=EXAMPLE_CHRONICSPATH) as env:
             obs = env.reset()
Пример #23
0
 def test_create_from_path(self):
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         env = make(PATH_DATA_MULTIMIX)
     assert env != None
     assert isinstance(env, MultiMixEnvironment)
Пример #24
0
 def test_reward_class(self):
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         with make("rte_case5_example", test=True, reward_class=FlatReward) as env:
             obs = env.reset()
Пример #25
0
 def test_case5_example(self):
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         env = make("rte_case5_example", test=True)
         obs = env.reset()
Пример #26
0
 def test_action_class(self):
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         with make("rte_case5_example", test=True, action_class=BaseAction) as env:
             obs = env.reset()
Пример #27
0
 def test_case14_redisp(self):
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         env = make("rte_case14_redisp", test=True)
         obs = env.reset()
Пример #28
0
 def test_grid_path(self):
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         with make("rte_case5_example", test=True, grid_path=EXAMPLE_CASEFILE) as env:
             obs = env.reset()
Пример #29
0
    if save_gif:
        if verbose:
            print("Saving the gif of the episodes")
        save_log_gif(logs_path, res)

    return agent, res


if __name__ == "__main__":
    from grid2op.Reward import L2RPNSandBoxScore, L2RPNReward
    from l2rpn_baselines.utils import cli_eval

    # Parse command line
    args = cli_eval().parse_args()

    # Create dataset env
    env = make(args.env_name,
               reward_class=L2RPNSandBoxScore,
               other_rewards={"reward": L2RPNReward})

    # Call evaluation interface
    evaluate(env,
             name=args.name,
             load_path=os.path.abspath(args.load_path),
             logs_path=args.logs_dir,
             nb_episode=args.nb_episode,
             nb_process=args.nb_process,
             max_steps=args.max_steps,
             verbose=args.verbose,
             save_gif=args.save_gif)
Пример #30
0
 def setUp(self) -> None:
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         self.env1 = make("rte_case14_test", test=True)
         self.env2 = make("rte_case5_example", test=True)