mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-30 01:50:19 +00:00
* removed return_info, made info dict mandatory in reset * tenatively removed deprecated seed api for environments * added more info type checks to wrapper tests * formatting/style compliance * addressed some comments * polish to address review * fixed tests after merge, and added a test of the return_info deprecation assertion if found in reset signature * some organization of env_checker tests, reverted a probably merge error * added deprecation check for seed function in env * updated docstring * removed debug prints, tweaked test_check_seed_deprecation * changed return_info deprecation check from assertion to warning * fixes to vector envs, now should be correctly structured * added some explanation and typehints for mockup depcreated return info reset function * re-removed seed function from vector envs * added explanation to _reset_return_info_type and changed the return statement
59 lines
1.9 KiB
Python
59 lines
1.9 KiB
Python
import pytest
|
|
|
|
import gym
|
|
from gym.wrappers import RecordEpisodeStatistics, VectorListInfo
|
|
|
|
ENV_ID = "CartPole-v1"
|
|
NUM_ENVS = 3
|
|
ENV_STEPS = 50
|
|
SEED = 42
|
|
|
|
|
|
def test_usage_in_vector_env():
|
|
env = gym.make(ENV_ID, disable_env_checker=True)
|
|
vector_env = gym.vector.make(ENV_ID, num_envs=NUM_ENVS, disable_env_checker=True)
|
|
|
|
VectorListInfo(vector_env)
|
|
|
|
with pytest.raises(AssertionError):
|
|
VectorListInfo(env)
|
|
|
|
|
|
def test_info_to_list():
|
|
env_to_wrap = gym.vector.make(ENV_ID, num_envs=NUM_ENVS, disable_env_checker=True)
|
|
wrapped_env = VectorListInfo(env_to_wrap)
|
|
wrapped_env.action_space.seed(SEED)
|
|
_, info = wrapped_env.reset(seed=SEED)
|
|
assert isinstance(info, list)
|
|
assert len(info) == NUM_ENVS
|
|
|
|
for _ in range(ENV_STEPS):
|
|
action = wrapped_env.action_space.sample()
|
|
_, _, dones, list_info = wrapped_env.step(action)
|
|
for i, done in enumerate(dones):
|
|
if done:
|
|
assert "final_observation" in list_info[i]
|
|
else:
|
|
assert "final_observation" not in list_info[i]
|
|
|
|
|
|
def test_info_to_list_statistics():
|
|
env_to_wrap = gym.vector.make(ENV_ID, num_envs=NUM_ENVS, disable_env_checker=True)
|
|
wrapped_env = VectorListInfo(RecordEpisodeStatistics(env_to_wrap))
|
|
_, info = wrapped_env.reset(seed=SEED)
|
|
wrapped_env.action_space.seed(SEED)
|
|
assert isinstance(info, list)
|
|
assert len(info) == NUM_ENVS
|
|
|
|
for _ in range(ENV_STEPS):
|
|
action = wrapped_env.action_space.sample()
|
|
_, _, dones, list_info = wrapped_env.step(action)
|
|
for i, done in enumerate(dones):
|
|
if done:
|
|
assert "episode" in list_info[i]
|
|
for stats in ["r", "l", "t"]:
|
|
assert stats in list_info[i]["episode"]
|
|
assert isinstance(list_info[i]["episode"][stats], float)
|
|
else:
|
|
assert "episode" not in list_info[i]
|