Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Gym 'vectorized' envs compatibility #1519

Merged
merged 20 commits into from
Sep 17, 2023
Prev Previous commit
Next Next commit
amend
  • Loading branch information
vmoens committed Sep 17, 2023
commit a329b80c8220b4770446feaa6442e92d9e9e0984
54 changes: 31 additions & 23 deletions test/test_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
get_default_devices,
HALFCHEETAH_VERSIONED,
PENDULUM_VERSIONED,
PONG_VERSIONED,
PONG_VERSIONED, rollout_consistency_assertion,
)
from packaging import version
from tensordict import LazyStackedTensorDict
Expand Down Expand Up @@ -396,34 +396,42 @@ def test_vecenvs_wrapper(self, envname): # noqa: F811
assert env.batch_size == torch.Size([2])
check_env_specs(env)

@implement_for("gym", "0.18", "0.27.0")
@pytest.mark.parametrize(
"envname",
["CartPole-v1", "HalfCheetah-v4"],
)
def test_vecenvs_env(self, envname): # noqa: F811
with set_gym_backend("gym"):
env = GymEnv(envname, num_envs=2, from_pixels=False)
check_env_specs(env)
rollout = env.rollout(100, break_when_any_done=False)
for obs_key in env.observation_spec.keys(True, True):
rollout_consistency_assertion(
rollout, done_key="done", observation_key=obs_key
)

with set_gym_backend("gym"):
env = GymEnv(envname, num_envs=2, from_pixels=True)
check_env_specs(env)
@implement_for("gym", "0.18", "0.27.0")
@pytest.mark.parametrize(
"envname",
["CartPole-v1", "HalfCheetah-v4"],
)
def test_vecenvs_env(self, envname): # noqa: F811
with set_gym_backend("gym"):
env = GymEnv(envname, num_envs=2, from_pixels=False)
check_env_specs(env)
rollout = env.rollout(100, break_when_any_done=False)
for obs_key in env.observation_spec.keys(True, True):
rollout_consistency_assertion(
rollout, done_key="done", observation_key=obs_key
)

with set_gym_backend("gym"):
env = GymEnv(envname, num_envs=2, from_pixels=True)
check_env_specs(env)

@implement_for("gym", None, "0.18")
def test_vecenvs_wrapper(self): # noqa: F811
@pytest.mark.parametrize(
"envname",
["CartPole-v1", "HalfCheetah-v4"],
)
def test_vecenvs_wrapper(self, envname): # noqa: F811
# skipping tests for older versions of gym
return
...

@implement_for("gym", None, "0.18")
def test_vecenvs_env(self): # noqa: F811
@pytest.mark.parametrize(
"envname",
["CartPole-v1", "HalfCheetah-v4"],
)
def test_vecenvs_env(self, envname): # noqa: F811
# skipping tests for older versions of gym
return
...


@implement_for("gym", None, "0.26")
Expand Down