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

[Bug Report] MuJoCo Ant & Humanoid have wrong "x_position" & "y_position" info #521

Closed
1 task done
Kallinteris-Andreas opened this issue May 24, 2023 · 4 comments
Closed
1 task done
Labels
bug Something isn't working

Comments

@Kallinteris-Andreas
Copy link
Collaborator

Kallinteris-Andreas commented May 24, 2023

Describe the bug

For the Humanoid and Ant the info['x_position'] and info['y_position'] are not the same as the observations when exclude_current_positions_from_observation=False is passed. (which is what the documentation suggests)

In general, I see no unit tests for MuJoCo info

Humanoid

The humanoid returns the center of mass instead of qpos[0:2]

xy_position_after = mass_center(self.model, self.data)

"x_position": xy_position_after[0],
"y_position": xy_position_after[1],

Ant

The humanoid returns the get_body_com('torso')[0:2] instead of qpos[0:2]

xy_position_after = self.get_body_com("torso")[:2].copy()

"x_position": xy_position_after[0],
"y_position": xy_position_after[1],

Code example

import gymnasium as gym
import pytest


# Note: "HumnanoidStandup-v4" does not have `info`
@pytest.mark.parametrize("env_id", ['Ant-v4', 'Ant-v3', 'HalfCheetah-v4', 'HalfCheetah-v3', 'Hopper-v4', 'Hopper-v3', 'Humanoid-v4', 'Humanoid-v3', 'Swimmer-v4', 'Swimmer-v3', 'Walker2d-v4', 'Walker2d-v3'])
def test_verify_info_x_position(env_id):
    """Asserts that the environment has position[0] == info['x_position']"""
    env = gym.make(env_id, exclude_current_positions_from_observation=False)

    _, _ = env.reset()
    obs, _,  _, _, info = env.step(env.action_space.sample())

    assert(obs[0] == info['x_position'])


# Note: "HumnanoidStandup-v4" does not have `info`
@pytest.mark.parametrize("env_id", ['Ant-v4', 'Ant-v3', 'Humanoid-v4', 'Humanoid-v3', 'Swimmer-v4', 'Swimmer-v3'])
def test_verify_info_y_position(env_id):
    """Asserts that the environment has position[0] == info['y_position']"""
    env = gym.make(env_id, exclude_current_positions_from_observation=False)

    _, _ = env.reset()
    obs, _,  _, _, info = env.step(env.action_space.sample())

    assert(obs[1] == info['y_position'])

System info

$ pip list | grep gym  
gym                           0.26.2
gym-notices                   0.0.8
gymnasium                     0.28.1
gymnasium-notices             0.0.1
gymnasium-robotics            1.2.2

Additional context

['HalfCheetah-v5', 'Hopper-v5', 'HumanoidStandup-v5', 'Swimmer-v5', 'Walker2d-v5'] are not affected

Checklist

  • I have checked that there is no similar issue in the repo
@Kallinteris-Andreas Kallinteris-Andreas added the bug Something isn't working label May 24, 2023
@pseudo-rnd-thoughts
Copy link
Member

@Kallinteris-Andreas could you make tests and update the code. I think we can make the changes in the v4 environments without a version change due to how infrequently exclude_current_positions_from_observation and info are used

@Kallinteris-Andreas
Copy link
Collaborator Author

I would rather not (by that logic, we should fix v3 too), we should keep v4 as is and fix it in v5.

@Kallinteris-Andreas
Copy link
Collaborator Author

@rodrigodelazcano is there a reason the info was implemented this way, or simply an oversight?

@Kallinteris-Andreas
Copy link
Collaborator Author

The info was giving xpos instead of qpos observations, it will be fixed in v5

if anyone is interested as to why it could have been implemented this way you can read
google-deepmind/mujoco#889

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants