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

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

Open
Soha18 opened this issue Oct 12, 2023 · 7 comments
Open

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

Soha18 opened this issue Oct 12, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@Soha18
Copy link

Soha18 commented Oct 12, 2023

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
Copy link
Contributor

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
Copy link
Author

Soha18 commented Oct 18, 2023

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
Copy link
Contributor

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

@Soha18
Copy link
Author

Soha18 commented Oct 19, 2023

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

@babbatem
Copy link

babbatem commented Oct 19, 2023

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
Copy link

babbatem commented Oct 19, 2023

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
Copy link
Author

Soha18 commented Oct 19, 2023

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

Many thanks , you almost saved my life...

@zhuyifengzju zhuyifengzju added the bug Something isn't working label Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants