def test_compute_without_score(self): """test that i can compute and erase the results afterwards""" with warnings.catch_warnings(): warnings.filterwarnings("ignore") with make("rte_case5_example", test=True) as env: stats = EpisodeStatistics(env, "test") stats.compute(nb_scenario=2, max_step=10, pbar=False) # i can access it prods, ids_ = stats.get("prod_p") assert prods.shape == (22, 2), "error on the prods shape" assert ids_.shape == (22, 1), "error on the ids shape" with self.assertRaises(RuntimeError): scores, ids_ = stats.get("scores") # i can clear everything stats.clear_all() assert not os.path.exists(os.path.join(env.get_path_env(), stats.get_name_dir("test")))
def test_compute_with_score(self): """test that i can compute and erase the results afterwards""" with warnings.catch_warnings(): warnings.filterwarnings("ignore") with make("rte_case5_example", test=True) as env: stats = EpisodeStatistics(env, "test") stats.compute(nb_scenario=2, max_step=10, pbar=False, scores_func=L2RPNSandBoxScore) # i can access it scores, ids_ = stats.get(EpisodeStatistics.SCORES) assert scores.shape == (20,), "error on the score shape" assert ids_.shape == (20, 1), "error on the ids shape" scores, ids_ = stats.get("scores") assert scores.shape == (20,), "error on the score shape" assert ids_.shape == (20, 1), "error on the ids shape" # i can clear everything stats.clear_all() assert not os.path.exists(os.path.join(env.get_path_env(), stats.get_name_dir("test")))
def test_read(self): """test that i can read the data stored""" with warnings.catch_warnings(): warnings.filterwarnings("ignore") with make("rte_case5_example", test=True) as env: obs = env.reset() stats = EpisodeStatistics(env) aor_, ids_ = stats.get("a_or") assert aor_.shape == (7930, 8) assert np.max(ids_) == 19 assert ids_.shape == (7930, 1) assert self.compare_vect(np.mean(aor_, axis=0), np.array([351.6208, 153.674, 91.057, 80.47367, 351.93213, 89.18627, 89.18627, 74.77638], dtype=dt_float))
def test_compute_erase(self): """test that i can compute and erase the results afterwards""" with warnings.catch_warnings(): warnings.filterwarnings("ignore") with make("rte_case5_example", test=True) as env: stats = EpisodeStatistics(env, "test") stats.compute(nb_scenario=1, max_step=10, pbar=False) # the file have been created assert os.path.exists(os.path.join(env.get_path_env(), stats.get_name_dir("test"))) # i can access it aor_, ids_ = stats.get("a_or") assert aor_.shape == (11, 8) # i can clear the data of individual episode stats.clear_episode_data() assert not os.path.exists(os.path.join(env.get_path_env(), stats.get_name_dir("test"), "00")) # i can clear everything stats.clear_all() assert not os.path.exists(os.path.join(env.get_path_env(), stats.get_name_dir("test")))