def test_json(self): with warnings.catch_warnings(): warnings.filterwarnings("ignore") with make("l2rpn_wcci_2020", test=True) as env: # test i can create obs_space = GymObservationSpace(env) act_space = GymActionSpace(env) obs_space.seed(0) act_space.seed(0) self._aux_test_json(obs_space) self._aux_test_json(act_space)
def test_to_from_gym_obs(self): with warnings.catch_warnings(): warnings.filterwarnings("ignore") with make(self.get_env_name(), test=True) as env: obs_space = GymObservationSpace(env) obs = env.reset() gym_obs = obs_space.to_gym(obs) self._aux_test_json(obs_space, gym_obs) assert obs_space.contains(gym_obs) obs2 = obs_space.from_gym(gym_obs) # TODO there is not reason that these 2 are equal: reset, will erase everything # TODO whereas creating the observation # assert obs == obs2 obs_diff, attr_diff = obs.where_different(obs2) for el in attr_diff: assert el in obs.attr_list_json, f"{el} should be equal in obs and obs2" for i in range(10): obs, *_ = env.step(env.action_space()) gym_obs = obs_space.to_gym(obs) self._aux_test_json(obs_space, gym_obs) assert obs_space.contains(gym_obs), "gym space does not contain the observation for ts {}".format(i) obs2 = obs_space.from_gym(gym_obs) # TODO there is not reason that these 2 are equal: reset, will erase everything # TODO whereas creating the observation # assert obs == obs2, "obs and converted obs are not equal for ts {}".format(i) obs_diff, attr_diff = obs.where_different(obs2) for el in attr_diff: assert el in obs.attr_list_json, f"{el} should be equal in obs and obs2 for ts {i}"
def test_creation(self): with warnings.catch_warnings(): warnings.filterwarnings("ignore") with make(self.get_env_name(), test=True) as env: # test i can create obs_space = GymObservationSpace(env) act_space = GymActionSpace(env)
def test_creation(self): with warnings.catch_warnings(): warnings.filterwarnings("ignore") if self.get_env_path() is not None: env_path_or_name = os.path.join(self.get_env_path(), self.get_env_name()) else: env_path_or_name = self.get_env_name() with make(env_path_or_name, test=True) as env: # test i can create obs_space = GymObservationSpace(env) act_space = GymActionSpace(env)
def test_to_from_gym_obs(self): with warnings.catch_warnings(): warnings.filterwarnings("ignore") with make("l2rpn_wcci_2020", test=True) as env: obs_space = GymObservationSpace(env) obs = env.reset() gym_obs = obs_space.to_gym(obs) self._aux_test_json(obs_space, gym_obs) assert obs_space.contains(gym_obs) obs2 = obs_space.from_gym(gym_obs) assert obs == obs2 for i in range(10): obs, *_ = env.step(env.action_space()) gym_obs = obs_space.to_gym(obs) self._aux_test_json(obs_space, gym_obs) assert obs_space.contains( gym_obs ), "gym space does not contain the observation for ts {}".format( i) obs2 = obs_space.from_gym(gym_obs) assert obs == obs2, "obs and converted obs are not equal for ts {}".format( i)