Skip to content

Commit

Permalink
update changelog description and fix test_envs.py formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
wjxgeorge committed Dec 13, 2024
1 parent 35baa79 commit 83b4a5f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 30 deletions.
2 changes: 1 addition & 1 deletion gymnasium_robotics/envs/fetch/pick_and_place.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class MujocoFetchPickAndPlaceEnv(MujocoFetchEnv, EzPickle):
## Version History
* v4: Fixed bug: the initial state not matching the initial state description in the documentation. Fetch environments' initial states after reset now align with the documentation.(related [GitHub issue](https://github.com/Farama-Foundation/Gymnasium-Robotics/issues/251))
* v4: Fixed bug where initial state did not match initial state description in documentation. Fetch environments' initial states after reset now match the documentation (related [GitHub issue](https://github.com/Farama-Foundation/Gymnasium-Robotics/issues/251)).
* v3: Fixed bug: `env.reset()` not properly resetting the internal state. Fetch environments now properly reset their state (related [GitHub issue](https://github.com/Farama-Foundation/Gymnasium-Robotics/issues/207)).
* v2: the environment depends on the newest [mujoco python bindings](https://mujoco.readthedocs.io/en/latest/python.html) maintained by the MuJoCo team in Deepmind.
* v1: the environment depends on `mujoco_py` which is no longer maintained.
Expand Down
4 changes: 2 additions & 2 deletions gymnasium_robotics/envs/fetch/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ class MujocoFetchPushEnv(MujocoFetchEnv, EzPickle):
```
## Version History
* v4: Fixed bug: the initial state not matching the initial state description in the documentation. Fetch environments' initial states after reset now align with the documentation.(related [GitHub issue](https://github.com/Farama-Foundation/Gymnasium-Robotics/issues/251))
* v4: Fixed bug where initial state did not match initial state description in documentation. Fetch environments' initial states after reset now match the documentation (related [GitHub issue](https://github.com/Farama-Foundation/Gymnasium-Robotics/issues/251)).
* v3: Fixed bug: `env.reset()` not properly resetting the internal state. Fetch environments now properly reset their state (related [GitHub issue](https://github.com/Farama-Foundation/Gymnasium-Robotics/issues/207)).
* v2: the environment depends on the newest [mujoco python bindings](https://mujoco.readthedocs.io/en/latest/python.html) maintained by the MuJoCo team in Deepmind.
* v1: the environment depends on `mujoco_py` which is no longer maintained.
Expand Down
4 changes: 2 additions & 2 deletions gymnasium_robotics/envs/fetch/reach.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ class MujocoFetchReachEnv(MujocoFetchEnv, EzPickle):
```
## Version History
* v4: Fixed bug: the initial state not matching the initial state description in the documentation. Fetch environments' initial states after reset now align with the documentation.(related [GitHub issue](https://github.com/Farama-Foundation/Gymnasium-Robotics/issues/251))
* v4: Fixed bug where initial state did not match initial state description in documentation. Fetch environments' initial states after reset now match the documentation (related [GitHub issue](https://github.com/Farama-Foundation/Gymnasium-Robotics/issues/251)).
* v3: Fixed bug: `env.reset()` not properly resetting the internal state. Fetch environments now properly reset their state (related [GitHub issue](https://github.com/Farama-Foundation/Gymnasium-Robotics/issues/207)).
* v2: the environment depends on the newest [mujoco python bindings](https://mujoco.readthedocs.io/en/latest/python.html) maintained by the MuJoCo team in Deepmind.
* v1: the environment depends on `mujoco_py` which is no longer maintained.
Expand Down
4 changes: 2 additions & 2 deletions gymnasium_robotics/envs/fetch/slide.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ class MujocoFetchSlideEnv(MujocoFetchEnv, EzPickle):
```
## Version History
* v4: Fixed bug: the initial state not matching the initial state description in the documentation. Fetch environments' initial states after reset now align with the documentation.(related [GitHub issue](https://github.com/Farama-Foundation/Gymnasium-Robotics/issues/251))
* v4: Fixed bug where initial state did not match initial state description in documentation. Fetch environments' initial states after reset now match the documentation (related [GitHub issue](https://github.com/Farama-Foundation/Gymnasium-Robotics/issues/251)).
* v3: Fixed bug: `env.reset()` not properly resetting the internal state. Fetch environments now properly reset their state (related [GitHub issue](https://github.com/Farama-Foundation/Gymnasium-Robotics/issues/207)).
* v2: the environment depends on the newest [mujoco python bindings](https://mujoco.readthedocs.io/en/latest/python.html) maintained by the MuJoCo team in Deepmind.
* v1: the environment depends on `mujoco_py` which is no longer maintained.
Expand Down
3 changes: 2 additions & 1 deletion gymnasium_robotics/envs/shadow_dexterous_hand/reach.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ class MujocoHandReachEnv(get_base_hand_reanch_env(MujocoHandEnv)):
```
## Version History
* v3: Fixed bug: the initial state not matching the initial state description in the documentation. Hand Reach environments' initial states after reset now align with the documentation.(related [GitHub issue](https://github.com/Farama-Foundation/Gymnasium-Robotics/issues/251))
* v3: Fixed bug where initial state did not match initial state description in documentation. Hand Reach environments' initial states after reset now match the documentation (related [GitHub issue](https://github.com/Farama-Foundation/Gymnasium-Robotics/issues/251)).
* v2: Fixed bug: `env.reset()` not properly resetting the internal state. Fetch environments now properly reset their state (related [GitHub issue](https://github.com/Farama-Foundation/Gymnasium-Robotics/issues/207)).
* v1: the environment depends on the newest [mujoco python bindings](https://mujoco.readthedocs.io/en/latest/python.html) maintained by the MuJoCo team in Deepmind.
* v0: the environment depends on `mujoco_py` which is no longer maintained.
Expand Down
64 changes: 42 additions & 22 deletions tests/test_envs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import pickle
import warnings

import numpy as np

import gymnasium as gym
import numpy as np
import pytest
from gymnasium.envs.mujoco.utils import check_mujoco_reset_state
from gymnasium.envs.registration import EnvSpec
Expand Down Expand Up @@ -166,43 +165,64 @@ def test_pickle_env(env_spec):
env.close()
pickled_env.close()

_test_robot_env_reset_list = ['Fetch', 'HandReach']

_test_robot_env_reset_list = ["Fetch", "HandReach"]


@pytest.mark.parametrize(
"spec",
[spec for spec in non_mujoco_py_env_specs if np.any([tar in spec.id for tar in _test_robot_env_reset_list])],
ids=[spec.id for spec in non_mujoco_py_env_specs if np.any([tar in spec.id for tar in _test_robot_env_reset_list])]
"spec",
[
spec
for spec in non_mujoco_py_env_specs
if np.any([tar in spec.id for tar in _test_robot_env_reset_list])
],
ids=[
spec.id
for spec in non_mujoco_py_env_specs
if np.any([tar in spec.id for tar in _test_robot_env_reset_list])
],
)
def test_robot_env_reset(spec):
"""Checks initial state of robotic environment, i.e. Fetch and Shadow Dexterous Hand Reach,
whether their initial states align with the document."""
"""Check initial state of robotic environment, i.e. Fetch and Shadow Dexterous Hand Reach,
whether their initial states match the description in the documentation."""

def _test_initial_states(env, seed=None):
diag_dict = {}

init_obs = env.reset(seed = seed)
init_obs = env.reset(seed=seed)

if isinstance(init_obs[0], dict):
diag_dict.update(**init_obs[0])
elif isinstance(init_obs[0], np.ndarray):
diag_dict.update({'observation': init_obs[0]})
diag_dict.update({
'qpos': env.unwrapped.data.qpos,
'qvel': env.unwrapped.data.qvel,
'init_qpos': env.unwrapped.initial_qpos,
'init_qvel': env.unwrapped.initial_qvel
})
diag_dict.update({"observation": init_obs[0]})
diag_dict.update(
{
"qpos": env.unwrapped.data.qpos,
"qvel": env.unwrapped.data.qvel,
"init_qpos": env.unwrapped.initial_qpos,
"init_qvel": env.unwrapped.initial_qvel,
}
)

# exclude object location from environments
if np.any([tar in spec.id for tar in ['FetchPush', 'FetchPickAndPlace', 'FetchSlide',]]):
diag_dict['qpos'] = np.delete(diag_dict['qpos'], np.s_[-7:-5])
diag_dict['init_qpos'] = np.delete(diag_dict['init_qpos'], np.s_[-7:-5])
if np.any(
[
tar in spec.id
for tar in [
"FetchPush",
"FetchPickAndPlace",
"FetchSlide",
]
]
):
diag_dict["qpos"] = np.delete(diag_dict["qpos"], np.s_[-7:-5])
diag_dict["init_qpos"] = np.delete(diag_dict["init_qpos"], np.s_[-7:-5])

# testing
assert np.allclose(diag_dict['qpos'], diag_dict['init_qpos'])
assert np.allclose(diag_dict['qvel'], diag_dict['init_qvel'])
assert np.allclose(diag_dict["qpos"], diag_dict["init_qpos"])
assert np.allclose(diag_dict["qvel"], diag_dict["init_qvel"])
return diag_dict

cur_env: gym.Env = spec.make()

_test_initial_states(cur_env, seed=24)
Expand Down

0 comments on commit 83b4a5f

Please sign in to comment.