ARISE-Initiative / robosuite

robosuite: A Modular Simulation Framework and Benchmark for Robot Learning
https://robosuite.ai
Other
1.23k stars 394 forks source link

'MjSim' object has no attribute 'model' #426

Open Soha18 opened 10 months ago

Soha18 commented 10 months ago

Hi,

I'm trying to use domain_randomization_wrapper with lift environment, but it through this error: modder.save_defaults() File "~/lib/python3.10/site-packages/robosuite/utils/mjmod.py", line 867, in save_defaults self.textures = [Texture(self.model, i) for i in range(self.model.ntex)] File "~/lib/python3.10/site-packages/robosuite/utils/mjmod.py", line 60, in model return self.sim.model AttributeError: 'MjSim' object has no attribute 'model'

would you please advice to solve it.

Thanks

zhuyifengzju commented 10 months ago

Hi, can you give more context regarding your usage? Depending on the order of how you initialize the environment, the MjSim object might not have been created before querying the model attribute.

Soha18 commented 10 months ago

Hi, Thanks for your response.. this is the part of code when the randomization_wrapper is used: controller_config = load_controller_config(default_controller="OSC_POSE") env = suite.make( env_name="Lift", robots="Panda", reward_shaping=True, has_renderer=True, render_camera = 'robot0_eye_in_hand', has_offscreen_renderer=True, controller_configs=controller_config, use_camera_obs=True, horizon = 100, use_object_obs= True, camera_names = 'robot0_eye_in_hand', camera_heights = 84, camera_widths = 84 ) env = MultiModalEnv(env) env = DomainRandomizationWrapper(env) obs = env.reset()

here MultiModalEnv wrapper is a custom wrapper to initialize environment with dict observations, even without applying this wrapper I got the same error:

Traceback (most recent call last): File "~/multimodal_env_test.py", line 173, in main() File "~/multimodal_env_test.py", line 150, in main obs = env.reset() File "~/domain_randomization.py", line 205, in reset self.save_default_domain() File "~/domain_randomization.py", line 261, in save_default_domain modder.save_defaults() File "~/lib/python3.9/site-packages/robosuite/utils/mjmod.py", line 866, in save_defaults self.textures = [Texture(self.model, i) for i in range(self.model.ntex)] File "~/lib/python3.9/site-packages/robosuite/utils/mjmod.py", line 59, in model return self.sim.model AttributeError: 'MjSim' object has no attribute 'model'

Thanks in advance

zhuyifengzju commented 10 months ago

I see that you have your own implementation of MultiModalEnv. Have you tried not using it?

Soha18 commented 10 months ago

yes I mentioned that ,, even without applying my own wrapper the same error comes out..

babbatem commented 10 months ago

I'm experiencing this error as well, with mujoco==2.3.7 and robosuite==1.4.0 from pip or source. The following script reproduces the error above:

import numpy as np
import robosuite as suite
from robosuite.wrappers import DomainRandomizationWrapper

env = suite.make(
    env_name="Door", # try with other tasks like "Stack" and "Door"
    robots="Panda",  # try with other robots like "Sawyer" and "Jaco"
    has_renderer=True,
    has_offscreen_renderer=False,
    use_camera_obs=False,
)
env = DomainRandomizationWrapper(env)

env.reset()
Traceback (most recent call last):
  File "/Users/abba/projects/rma/test_free_space.py", line 16, in <module>
    env.reset()
  File "/Users/abba/miniconda3/envs/debugdomainrandom/lib/python3.11/site-packages/robosuite/wrappers/domain_randomization_wrapper.py", line 202, in reset
    self.save_default_domain()
  File "/Users/abba/miniconda3/envs/debugdomainrandom/lib/python3.11/site-packages/robosuite/wrappers/domain_randomization_wrapper.py", line 258, in save_default_domain
    modder.save_defaults()
  File "/Users/abba/miniconda3/envs/debugdomainrandom/lib/python3.11/site-packages/robosuite/utils/mjmod.py", line 866, in save_defaults
    self.textures = [Texture(self.model, i) for i in range(self.model.ntex)]
                                                           ^^^^^^^^^^
  File "/Users/abba/miniconda3/envs/debugdomainrandom/lib/python3.11/site-packages/robosuite/utils/mjmod.py", line 59, in model
    return self.sim.model
           ^^^^^^^^^^^^^^
AttributeError: 'MjSim' object has no attribute 'model'
babbatem commented 10 months ago

Specifying hard_reset=False when creating the environment fixes the issue.

(conversely, changing hard_reset to True in demo_domain_randomization.py yields the error)

Soha18 commented 10 months ago

Hi, Yes, initializing environment with hard_reset =False solved the problem.

Many thanks , you almost saved my life...