robfiras / loco-mujoco

Imitation learning benchmark focusing on complex locomotion tasks using MuJoCo.
MIT License
539 stars 46 forks source link

'dict' object has no attribute 'env_specs' #20

Closed nikisim closed 6 months ago

nikisim commented 6 months ago

Hi!

I am trying to run: python3 examples/simple_mushroom_env/example_unitree_a1.py Also I get the same error when I run loco-mujoco-download

But I get an error:

File /loco-mujoco/loco_mujoco/environments/base.py:12
    if id in registry.env_specs:
AttributeError: 'dict' object has no attribute 'env_specs'

I guess it's something about package versions...

I would appreciate any help.

Ubuntu: 22.04 Python: 3.10.12

robfiras commented 6 months ago

Hi! Is this something specific to the A1 environment or does it happen for all environments? Did you install the package from pip or did you do an editable installation from github?

nikisim commented 6 months ago

Is this something specific to the A1 environment or does it happen for all environments?

No, this error occurs with all environments.

Did you install the package from pip or did you do an editable installation from github?

I've tried both ways. Still getting the same error.

robfiras commented 6 months ago

Could you send the whole traceback of the error?

nikisim commented 6 months ago

Yeah, sure!

Traceback (most recent call last):
  File "/home/nikisim/user_folder/loco-mujoco/examples/simple_mushroom_env/example_humanoid_muscle.py", line 2, in <module>
    from loco_mujoco import LocoEnv
  File "/home/nikisim/user_folder/loco-mujoco/loco_mujoco/__init__.py", line 5, in <module>
    from .environments import LocoEnv
  File "/home/nikisim/user_folder/loco-mujoco/loco_mujoco/environments/__init__.py", line 1, in <module>
    from .base import LocoEnv, ValidTaskConf
  File "/home/nikisim/user_folder/loco-mujoco/loco_mujoco/environments/base.py", line 12, in <module>
    from mushroom_rl.core import Environment
  File "/home/nikisim/.local/lib/python3.10/site-packages/mushroom_rl/core/__init__.py", line 7, in <module>
    import mushroom_rl.environments
  File "/home/nikisim/.local/lib/python3.10/site-packages/mushroom_rl/environments/__init__.py", line 10, in <module>
    from .gym_env import Gym
  File "/home/nikisim/.local/lib/python3.10/site-packages/mushroom_rl/environments/gym_env.py", line 9, in <module>
    import pybullet_envs
  File "/home/nikisim/.local/lib/python3.10/site-packages/pybullet_envs/__init__.py", line 14, in <module>
    register(
  File "/home/nikisim/.local/lib/python3.10/site-packages/pybullet_envs/__init__.py", line 6, in register
    if id in registry.env_specs:
AttributeError: 'dict' object has no attribute 'env_specs'
robfiras commented 6 months ago

The problem seems to be Gym, which is not used within LocoMuJoCo (only Gymnasium). Mushroom-Rl requires a specific version of Gym. Using another version causes this issue. Could you try to uninstall it?

nikisim commented 6 months ago

Yes, it works now. Thanks a lot!

By the way, have you thought about datasets compatibility with Minari? I want to use Offline RL algorithms such as IQL and ReBRAC with dataset from Unitree A1 (using simulation and real robot) in my study.

robfiras commented 6 months ago

Great!

Thanks for pointing this out. This could be an idea for the future, even though this repo focuses on imitation learning rather than offline rl.

But if I am not wrong, you could use Minari's Datacollector to create datasets in their format (if you need it). It is just a wrapper around a Gymnasium environment, which we provide.

nikisim commented 6 months ago

you could use Minari's Datacollector to create datasets in their format

Yep, that's the plan :)

Anyway, thanks again for your super-fast help!

robfiras commented 6 months ago

You're welcome!

Fyi, if you are planning to use custom rewards with Unitree A1 environment, use an editable installation of LocoMuJoCo for now. There was a bug #15, which was recently fixed. A new version will be released in the next few days.

nikisim commented 6 months ago

Hello again... Sorry for bothering you, but I'm encountering difficulties in obtaining a dataset for the Unitree A1 in RL format (such d4rl datasets).

I am expecting to get dataset as dict with 'observations', 'actions', 'rewards' for Unitree A1 env. But i can see that default dataset for Unitree A1 contains only state and next state.

Is it possible for me to acquire a dataset that includes the actions for walking straight? Or perhaps you possess one already?

P.S. To use Minari I still must have actions from some pretrained algorithm, but now I abandoned the idea with Minari

robfiras commented 6 months ago

Hi,

LocoMujoco has different types of datasets, two of which are real and perfect. The real datasets are collected via motion capture*. These datasets come with additional challenges like not having access to the actions or having some correspondence mismatch. The perfect dataset are datasets collected within LocoMujoco using the imitation learning baseline we have for the respective real datasets. These datasets come with actions and have no correspondence mismatch.

It is super easy to change the dataset type.

Real:

mdp = LocoEnv.make("UnitreeA1.simple.real")

Perfect:

mdp = LocoEnv.make("UnitreeA1.simple.perfect")

If do not specify the dataset type, real is chosen by default.

*True for all environments except the UnitreeA1, where we used a MPC controller instead

nikisim commented 6 months ago

:man_facepalming: Yeah, I forgot about different types of datasets.

Okay, so, to get a dict dataset with actions I should use mpd.create_dataset()? But it also returns a dataset only with states and next_states...

robfiras commented 6 months ago

Oh, there seems to be a small bug in the UnitreeA1 environment then. For the other environments, it does return actions. Thanks for pointing this out, I will fix this now.

nikisim commented 6 months ago

Cool! It works now! :fire:

Thank you so much