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

Broken dm_control.viewer #90

Closed
solismortis opened this issue Jun 11, 2023 · 14 comments · Fixed by #104
Closed

Broken dm_control.viewer #90

solismortis opened this issue Jun 11, 2023 · 14 comments · Fixed by #104

Comments

@solismortis
Copy link

solismortis commented Jun 11, 2023

When I try using shimmy with locomotion (uses composer.Environment) or a custom composer.Environment env, the dm_contorl.viewer starts but is either unresponsive (with default locomotion envs) or has no animation (for my custom env)

But the env is working, as you can see observations and rewards changing. No issues with suite envs (control.Environment).

from shimmy.dm_control_compatibility import DmControlCompatibilityV0
from dm_control.locomotion.walkers.cmu_humanoid import CMUHumanoidPositionControlled
from dm_control.locomotion.arenas.floors import Floor
from dm_control.locomotion import tasks
from dm_control import composer

task = tasks.corridors.RunThroughCorridor(CMUHumanoidPositionControlled(), Floor())
env = DmControlCompatibilityV0(composer.Environment(task), render_mode="human")
observation, info = env.reset(seed=42)
for _ in range(1000):
   action = env.action_space.sample()  # this is where you would insert your policy
   observation, reward, terminated, truncated, info = env.step(action)
   print(reward)

   if terminated or truncated:
      observation, info = env.reset()
env.close()
  • OS: Linux-5.19.0-43-generic-x86_64-with-glibc2.35 # 44~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon May 22 13:39:36 UTC 2
  • Python: 3.10.6
  • PyTorch: 2.0.1+cu117
  • GPU Enabled: True
  • Numpy: 1.24.3
  • Cloudpickle: 2.2.1
  • Gymnasium: 0.28.1
  • OpenAI Gym: 0.26.2
  • Mujoco: 2.3.5
  • dm-control: 1.0.12
  • Shimmy: 0.2.1
@pseudo-rnd-thoughts
Copy link
Member

@elliottower Do you have any time to work on this? We should probably try to fix this and #15

@elliottower
Copy link
Contributor

I’ve been super busy so if you could look into it that would be great

@pseudo-rnd-thoughts
Copy link
Member

@Melanol I have experimented and tested most of the default shimmy environments and haven't found an issue with any of them.
I suspect there is an issue with the custom implementation rather than Shimmy's implementation

Looking at the other composer environment - https://github.com/deepmind/dm_control/blob/330c91f41a21eacadcf8316f0a071327e3f5c017/dm_control/locomotion/examples/basic_cmu_2019.py#L39
They use observable_options but these didn't seem to work

Can you render using just dm-control? If so, could you produce some example code?

@solismortis
Copy link
Author

Can you render using just dm-control? If so, could you produce some example code?

https://github.com/Melanol/dm_control_tripod_mini. Run tripod_mini_env.py to play with the 3D model, run render.py to make a video.

@pseudo-rnd-thoughts
Copy link
Member

Thanks, I have solved the issue, the default camera_id in dm_control render function is -1 while shimmy's is 0
I'm making several updates to the rendering implementation to make it more generic

@solismortis
Copy link
Author

@pseudo-rnd-thoughts Have you tested this? Because nothing has changed on my side. I updated shimmy to 1.1.0, the code on my 1st message still gives me a frozen window, and the following code when executed in my repo (custom composer.Environment) gives dead animation:

from shimmy.dm_control_compatibility import DmControlCompatibilityV0

from tripod_mini_env import env


env = DmControlCompatibilityV0(env, render_mode="human")

env.reset()
observation, info = env.reset(seed=42)
for _ in range(1000):
    action = env.action_space.sample()  # this is where you would insert your policy
    observation, reward, terminated, truncated, info = env.step(action)
    print(reward)

    if terminated or truncated:
        observation, info = env.reset()
env.close()

Tried running tests on test_dm_control.py. I get 9 failed, 181 passed, and 29 ignored out of 219 tests.

@elliottower
Copy link
Contributor

Reopening this until it’s fixed @pseudo-rnd-thoughts

Weird thing is our CI should also catch this issue and all the tests pass so I’m thinking maybe your local environment has a package conflict and couldn’t actually upgrade to the newest version 1.1.0. Can’t think of why else it would happen. But maybe clone the most recent master then install with pip install -e . And then if you can figure out a way to fix things you can make a PR.

@elliottower elliottower reopened this Jun 16, 2023
@pseudo-rnd-thoughts
Copy link
Member

@Melanol This is fixed for rgb_array for recording videos, sorry, I forgot to check on human rendering.
Looking this seems to be a MujocoRendering issue rather a shimmy error.
@rodrigodelazcano Any ideas?

@elliottower
Copy link
Contributor

I'm going to add some tests for human rendering and the other possible rendering modes, for meltingpot for example I do test human rendering but others it is not done

@solismortis
Copy link
Author

I tried cloning main and then pip install -e ".[all,testing]". dm_control tests still fail, but now 15 fail, not 9. Maybe you need to update requirements. Also tried running the code in the 1st message in 15 after reinstalling, and it gives me

Traceback (most recent call last):
  File "/home/mel/PycharmProjects/Shimmy/venv/lib/python3.10/site-packages/gymnasium/wrappers/monitoring/video_recorder.py", line 181, in __del__
    if not self._closed:
AttributeError: 'VideoRecorder' object has no attribute '_closed'

@elliottower
Copy link
Contributor

elliottower commented Jun 16, 2023

I just pulled the most recent master and installed locally (pip install -e .[all,testing]) and ran the pytest for test_dm_control and got 190 passed 29 ignored. Tried the alternative syntax you used (with quotes around it: ".[all,testing]") just to confirm that it isn't an install issue and got the same results

@elliottower
Copy link
Contributor

Also just FWIW, running the code in the original post here I got the same results of a frozen GUI, so I agree with Mark that it's most likely an issue with mujoco rendering.

@solismortis
Copy link
Author

I think we are somehow getting different setups.

@spiglerg
Copy link
Contributor

Hi, I've encountered the same problem and I found the issue.
The problem is due to the fact that dm_control deletes and re-instantiate the "physics" object (including both Model and Data structures). As such, the original MujocoViewer created on init() no longer reads the correct structures. The problem arises after the first call to reset().

I have opened a pull-request with the code to fix the problem: https://github.com/Farama-Foundation/Shimmy/pull/104

It may be possible to simplify the code further by updating 'model' and 'data' alone, instead of creating a new Viewer on each reset:
self.viewer.model = self._env.physics.model.ptr
self.viewer.data = self._env.physics.data.ptr

but, while slightly faster, it may be a bit "hacky".

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 a pull request may close this issue.

4 participants