Exemplo n.º 1
0
    def test_modif_max_step_increase(self):
        """test that i can modify the max step (and that if I increase it it does trigger a recomputation)"""
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore")
            with make("rte_case5_example", test=True) as env:
                scores = ScoreL2RPN2020(env, nb_scenario=2, verbose=0, max_step=5)

                # the statistics have been properly computed
                assert os.path.exists(os.path.join(env.get_path_env(),
                                                   EpisodeStatistics.get_name_dir(ScoreL2RPN2020.NAME_DN)))
                assert os.path.exists(os.path.join(env.get_path_env(),
                                                   EpisodeStatistics.get_name_dir(ScoreL2RPN2020.NAME_DN_NO_OVERWLOW)))

                my_agent = DoNothingAgent(env.action_space)
                my_scores, *_ = scores.get(my_agent)
                assert np.max(np.abs(my_scores)) <= self.tol_one, "error for the first do nothing"

                scores2 = ScoreL2RPN2020(env, nb_scenario=2, verbose=0, max_step=10)
                assert scores2._recomputed_dn
                assert scores2._recomputed_no_ov

            # delete them
            stats_0 = EpisodeStatistics(env, ScoreL2RPN2020.NAME_DN)
            stats_1 = EpisodeStatistics(env, ScoreL2RPN2020.NAME_DN_NO_OVERWLOW)
            stats_2 = EpisodeStatistics(env, ScoreL2RPN2020.NAME_RP_NO_OVERWLOW)
            stats_0.clear_all()
            stats_1.clear_all()
            stats_2.clear_all()
            assert not os.path.exists(os.path.join(env.get_path_env(),
                                                   EpisodeStatistics.get_name_dir(ScoreL2RPN2020.NAME_DN)))
            assert not os.path.exists(os.path.join(env.get_path_env(),
                                                   EpisodeStatistics.get_name_dir(ScoreL2RPN2020.NAME_DN_NO_OVERWLOW)))
            assert not os.path.exists(os.path.join(env.get_path_env(),
                                                   EpisodeStatistics.get_name_dir(ScoreL2RPN2020.NAME_RP_NO_OVERWLOW)))
Exemplo n.º 2
0
    def test_donothing_noov_80(self):
        """test that do nothing has a score of 80.0 if it is run with "no overflow disconnection" """
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore")
            with make("rte_case5_example", test=True) as env:
                # I cannot decrease the max step: it must be above the number of steps the do nothing does
                scores = ScoreL2RPN2020(env,
                                        nb_scenario=2,
                                        verbose=0,
                                        max_step=130)
                assert scores._recomputed_dn
                assert scores._recomputed_no_ov

                # the statistics have been properly computed
                assert os.path.exists(
                    os.path.join(
                        env.get_path_env(),
                        EpisodeStatistics.get_name_dir(
                            ScoreL2RPN2020.NAME_DN)))
                assert os.path.exists(
                    os.path.join(
                        env.get_path_env(),
                        EpisodeStatistics.get_name_dir(
                            ScoreL2RPN2020.NAME_DN_NO_OVERWLOW)))

                my_agent = DoNothingAgent(env.action_space)
                my_scores, *_ = scores.get(my_agent)
                assert np.max(
                    np.abs(my_scores
                           )) <= self.tol_one, "error for the first do nothing"

            param = Parameters()
            param.NO_OVERFLOW_DISCONNECTION = True
            with make("rte_case5_example", test=True, param=param) as env:
                scores2 = ScoreL2RPN2020(env,
                                         nb_scenario=2,
                                         verbose=0,
                                         max_step=130)
                assert not scores2._recomputed_dn
                assert not scores2._recomputed_no_ov
                my_agent = DoNothingAgent(env.action_space)
                my_scores, *_ = scores2.get(my_agent)
                assert np.max(
                    np.abs(np.array(my_scores) - 80.0)) <= self.tol_one

            # delete them
            stats_0 = EpisodeStatistics(env, ScoreL2RPN2020.NAME_DN)
            stats_1 = EpisodeStatistics(env,
                                        ScoreL2RPN2020.NAME_DN_NO_OVERWLOW)
            stats_0.clear_all()
            stats_1.clear_all()
            assert not os.path.exists(
                os.path.join(
                    env.get_path_env(),
                    EpisodeStatistics.get_name_dir(ScoreL2RPN2020.NAME_DN)))
            assert not os.path.exists(
                os.path.join(
                    env.get_path_env(),
                    EpisodeStatistics.get_name_dir(
                        ScoreL2RPN2020.NAME_DN_NO_OVERWLOW)))
Exemplo n.º 3
0
    def test_modif_nb_scenario(self):
        """
        test that i can modify the nb_scenario and it properly recomputes it when it increased and not
        when it decreases
        """
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore")
            with make("rte_case5_example", test=True) as env:
                scores = ScoreL2RPN2020(env,
                                        nb_scenario=2,
                                        verbose=0,
                                        max_step=5)

                # the statistics have been properly computed
                assert os.path.exists(
                    os.path.join(
                        env.get_path_env(),
                        EpisodeStatistics.get_name_dir(
                            ScoreL2RPN2020.NAME_DN)))
                assert os.path.exists(
                    os.path.join(
                        env.get_path_env(),
                        EpisodeStatistics.get_name_dir(
                            ScoreL2RPN2020.NAME_RP_NO_OVERFLOW)))

                my_agent = DoNothingAgent(env.action_space)
                my_scores, *_ = scores.get(my_agent)
                assert np.max(
                    np.abs(my_scores
                           )) <= self.tol_one, "error for the first do nothing"

                scores2 = ScoreL2RPN2020(env,
                                         nb_scenario=4,
                                         verbose=0,
                                         max_step=5)
                assert scores2._recomputed_dn
                assert scores2._recomputed_no_ov_rp

                scores2 = ScoreL2RPN2020(env,
                                         nb_scenario=3,
                                         verbose=0,
                                         max_step=5)
                assert not scores2._recomputed_dn
                assert not scores2._recomputed_no_ov_rp

            # delete them
            # delete them
            scores.clear_all()
            assert not os.path.exists(
                os.path.join(
                    env.get_path_env(),
                    EpisodeStatistics.get_name_dir(ScoreL2RPN2020.NAME_DN)))
            # assert not os.path.exists(os.path.join(env.get_path_env(),
            #                                        EpisodeStatistics.get_name_dir(ScoreL2RPN2020.NAME_DN_NO_OVERWLOW)))
            assert not os.path.exists(
                os.path.join(
                    env.get_path_env(),
                    EpisodeStatistics.get_name_dir(
                        ScoreL2RPN2020.NAME_RP_NO_OVERFLOW)))
Exemplo n.º 4
0
    def test_can_compute(self):
        """test that i can initialize the score and then delete the statistics"""
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore")
            with make("rte_case5_example", test=True) as env:
                scores = ScoreL2RPN2020(env,
                                        nb_scenario=4,
                                        verbose=0,
                                        max_step=50)

            # the statistics have been properly computed
            assert os.path.exists(
                os.path.join(
                    env.get_path_env(),
                    EpisodeStatistics.get_name_dir(ScoreL2RPN2020.NAME_DN)))
            assert os.path.exists(
                os.path.join(
                    env.get_path_env(),
                    EpisodeStatistics.get_name_dir(
                        ScoreL2RPN2020.NAME_RP_NO_OVERFLOW)))

            # delete them
            scores.clear_all()
            assert not os.path.exists(
                os.path.join(
                    env.get_path_env(),
                    EpisodeStatistics.get_name_dir(ScoreL2RPN2020.NAME_DN)))
            # assert not os.path.exists(os.path.join(env.get_path_env(),
            #                                       EpisodeStatistics.get_name_dir(ScoreL2RPN2020.NAME_DN_NO_OVERWLOW)))
            assert not os.path.exists(
                os.path.join(
                    env.get_path_env(),
                    EpisodeStatistics.get_name_dir(
                        ScoreL2RPN2020.NAME_RP_NO_OVERFLOW)))
Exemplo n.º 5
0
    def test_donothing_0(self):
        """test that do nothing has a score of 0.00"""
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore")
            with make("rte_case5_example", test=True) as env:
                scores = ScoreL2RPN2020(env, nb_scenario=4, verbose=0, max_step=20)

                # the statistics have been properly computed
                assert os.path.exists(os.path.join(env.get_path_env(),
                                                   EpisodeStatistics.get_name_dir(ScoreL2RPN2020.NAME_DN)))
                assert os.path.exists(os.path.join(env.get_path_env(),
                                                   EpisodeStatistics.get_name_dir(ScoreL2RPN2020.NAME_DN_NO_OVERWLOW)))

                my_agent = DoNothingAgent(env.action_space)
                my_scores, *_ = scores.get(my_agent)
                assert np.max(np.abs(my_scores)) <= self.tol_one

            # delete them
            stats_0 = EpisodeStatistics(env, ScoreL2RPN2020.NAME_DN)
            stats_1 = EpisodeStatistics(env, ScoreL2RPN2020.NAME_DN_NO_OVERWLOW)
            stats_2 = EpisodeStatistics(env, ScoreL2RPN2020.NAME_RP_NO_OVERWLOW)
            stats_0.clear_all()
            stats_1.clear_all()
            stats_2.clear_all()
            assert not os.path.exists(os.path.join(env.get_path_env(),
                                                   EpisodeStatistics.get_name_dir(ScoreL2RPN2020.NAME_DN)))
            assert not os.path.exists(os.path.join(env.get_path_env(),
                                                   EpisodeStatistics.get_name_dir(ScoreL2RPN2020.NAME_DN_NO_OVERWLOW)))
            assert not os.path.exists(os.path.join(env.get_path_env(),
                                                   EpisodeStatistics.get_name_dir(ScoreL2RPN2020.NAME_RP_NO_OVERWLOW)))