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

Change mujoco_py bindings for mujoco Deepmind bindings #2762

Merged
merged 1 commit into from
May 24, 2022

Conversation

rodrigodelazcano
Copy link
Contributor

@rodrigodelazcano rodrigodelazcano commented Apr 19, 2022

Description

This PR is the continuation of #2595. The PR updates the python bindings for the mujoco environments. The new v4 versions of the mujoco environments now use the new mujoco python bindings from DeepMind https://pypi.org/project/mujoco/.

Fixes # (issue)
This PR also fixes the contact force issue in the Ant env (only v4) at #1541

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

v2-v4 benchmark by @vwxyzjn

@vwxyzjn provided benchmarks between old mujoco environments (v2) and the newer (v4). Results are provided here #2595 (comment)

Checklist:

  • I have run the pre-commit checks with pre-commit run --all-files (see CONTRIBUTING.md instructions to set it up)
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@@ -14,19 +14,25 @@
"accept-rom-license": ["autorom[accept-rom-license]~=0.4.2"],
"box2d": ["box2d-py==2.3.5", "pygame==2.1.0"],
"classic_control": ["pygame==2.1.0"],
"mujoco": ["mujoco_py>=1.50, <2.0"],
"mujoco_py": ["mujoco_py<2.2,>=2.1"],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have mild concerns around gym declaring a dependency on both mujoco and mujoco-py. In principle, this isn't a problem as long as only one gets imported, but if someone tries to import both it's likely that they'll run into inscrutable errors. Would you consider declaring mujoco-py as an optional dependency (extras_require)?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore me: this is already in extras_require.

Comment on lines +189 to +190
if self._mujoco_bindings.__name__ != "mujoco_py":
self._mujoco_bindings.mj_rnePostConstraint(self.model, self.data)
Copy link
Contributor

@vwxyzjn vwxyzjn Apr 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not commented out as in ab38034, which causes regression in Ant-v4. See https://wandb.ai/costa-huang/cleanRL/reports/-4-19-MuJoCo-v4-vs-v2-CleanRL-s-PPO--VmlldzoxODYzODM0, https://github.com/vwxyzjn/validate-new-gym-mujoco-envs

5AF41CE3-F3EB-4040-99CF-3FC722F30565

Our previous benchmark with ab38034 fixes the performance in Ant-v4 as shown below, but I don’t know how it affects performance in other envs.

A3880A07-319D-462F-B808-3D689A370428

Copy link
Contributor

@duburcqa duburcqa May 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introducing bugs on purpose to avoid regression of performance makes no sense to me. It seems way more appropriate to just remove the contact forces from the observation space and reward, instead of carrying out computations pretending it is doing what it is supposed to do. It is just utterly confusing for actual roboticist willing to use mujoco with gym.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @duburcqa
Doesn't this change make the benchmark compatible with MuJoCo < 2.0? Or do all those three (mujoco-py with MuJoCo < 2.0, mujoco-py with MuJoCo >= 2.0, and mujoco) produce different results?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theoretically, for this change in particular it is the same as mujoco < 2.0, but there are probably other internal changes in mujoco binary so I doubt the result would be exactly the same as before.

else:
for name, import_func in _ALL_RENDERERS.items():
try:
self.opengl_context = _ALL_RENDERERS["osmesa"](width, height)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this use name instead of osmesa?
Or

Suggested change
self.opengl_context = _ALL_RENDERERS["osmesa"](width, height)
self.opengl_context = import_func(width, height)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. Thank you for pointing this out.

@@ -0,0 +1,278 @@
from turtle import distance

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an unused import for walker2d.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove this. Thanks!

This was referenced May 23, 2022
@rfernand2
Copy link

Thanks for all the work on this! Will this be in gym 0.24.0 and is there an ETA for that release?

* update new mujoco bindings

* optional ctc_force ant-v4

* force changes

* contact force weight

* add ctc force range

* mujoco v3 skip test

* doc Ant-v4

* inverted pendulum limit control
@rodrigodelazcano
Copy link
Contributor Author

Thanks for all the work on this! Will this be in gym 0.24.0 and is there an ETA for that release?

:) @jkterry1 can probably address this question better.

@rodrigodelazcano
Copy link
Contributor Author

This PR is ready to be merged. Last additional change:

  • Ant-v4 has an option to use contact forces in its observation space. To use this feature set the use_contact_forces argument to True. Note that this option has been added because an ablation test with PPO was performed (https://github.com/vwxyzjn/validate-new-gym-mujoco-envs) and shows that there is a regression on learning when using contact forces. Results shown on image bellow.
    image

@pseudo-rnd-thoughts
Copy link
Contributor

@rfernand2 Yes, there is one other PR that needs approval and merging then after this PR is merged then v0.24.0 will be released.

@saran-t
Copy link

saran-t commented May 24, 2022

I know that people spent a great deal of effort validating the v4 envs and this may well be a bit late now, but please consider pinning to mujoco==2.2.0 instead of 2.1.5 for your v0.24.0 release, since that's the first open sourced version of MuJoCo. It'll allow people to actually look at source code should any future discrepancies arise.

@pseudo-rnd-thoughts
Copy link
Contributor

@saran-t Has there been any significant changes since 2.1.5 for 2.2.0 that would change the training results you think otherwise we should be able to do that

@Trinkle23897
Copy link

Trinkle23897 commented May 24, 2022

@pseudo-rnd-thoughts No. I ran the alignment test and it seems that 2.2.0 can align with 2.1.5 per step and can have 5% free speedup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants