Toni-SM / skrl

Modular reinforcement learning library (on PyTorch and JAX) with support for NVIDIA Isaac Gym, Omniverse Isaac Gym and Isaac Lab
https://skrl.readthedocs.io/
MIT License
439 stars 43 forks source link

dm_control wrapper #165

Open elle-miller opened 5 days ago

elle-miller commented 5 days ago

Description

Hi there,

I have been using skrl with OIGE, but when I try the "Getting Started" code for dm_control :

# import the environment wrapper and the deepmind suite
from skrl.envs.wrappers.torch import wrap_env
from dm_control import suite

# load the environment
env = suite.load(domain_name="cartpole", task_name="swingup")

# wrap the environment
env = wrap_env(env)  # or 'env = wrap_env(env, wrapper="dm")'

I get the following error:

[skrl:INFO] Environment class: dm_env._environment.Environment
INFO:skrl:Environment class: dm_env._environment.Environment
[skrl:INFO] Environment wrapper: DeepMind
INFO:skrl:Environment wrapper: DeepMind
Traceback (most recent call last):
  File "/home/elle/code/envs/sk_test/lib/python3.10/site-packages/skrl/envs/wrappers/torch/base.py", line 24, in __init__
    self._action_space = self._env.single_action_space
AttributeError: 'Environment' object has no attribute 'single_action_space'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/elle/code/devel/skrl_play/test123.py", line 9, in <module>
    env = wrap_env(env)  # or 'env = wrap_env(env, wrapper="dm")'
  File "/home/elle/code/envs/sk_test/lib/python3.10/site-packages/skrl/envs/wrappers/torch/__init__.py", line 103, in wrap_env
    return DeepMindWrapper(env)
  File "/home/elle/code/envs/sk_test/lib/python3.10/site-packages/skrl/envs/wrappers/torch/deepmind_envs.py", line 19, in __init__
    super().__init__(env)
  File "/home/elle/code/envs/sk_test/lib/python3.10/site-packages/skrl/envs/wrappers/torch/base.py", line 27, in __init__
    self._action_space = self._env.action_space
AttributeError: 'Environment' object has no attribute 'action_space'. Did you mean: 'action_spec'?

This is with Python 3.10.14, dm_control==1.0.20 and skrl==1.1.0. It seems that in the inheritance of DeepMindWrapper from in the base Wrapper class, self._env.action_space is being called before self._spec_to_space can happen.

Also just as a heads up, when I try with skrl==1.2.0, I now get this:

Traceback (most recent call last):
  File "/home/elle/code/devel/skrl_play/test123.py", line 9, in <module>
    env = wrap_env(env)  # or 'env = wrap_env(env, wrapper="dm")'
  File "/home/elle/code/envs/sk_test/lib/python3.10/site-packages/skrl/envs/wrappers/torch/__init__.py", line 154, in wrap_env
    raise ValueError(f"Unknown wrapper type: {wrapper}")
ValueError: Unknown wrapper type: ['dm_env._environment.Environment']

Thank you!

What skrl version are you using?

1.1.0

What ML framework/library version are you using?

torch==2.3.1

Additional system information

Python 3.10.14

Toni-SM commented 2 days ago

Hi @elle-miller

Yes, in latest release (version 1.2.0) the automatic detection of the environment to be wrapped was updated and it didn't include DeepMind envs.

Regarding the AttributeError error when wrapping the DeepMind environment, the DeepMind wrapper is not maintained anymore and will be removed in next version in favor of Shimmy. See skrl's Shimmy examples for training using a DeepMind environment.