Skip to content

fix: rebind domain randomization modders after a hard reset#818

Open
VihaanAgarwal wants to merge 1 commit into
ARISE-Initiative:masterfrom
VihaanAgarwal:fix/domain-randomization-hard-reset
Open

fix: rebind domain randomization modders after a hard reset#818
VihaanAgarwal wants to merge 1 commit into
ARISE-Initiative:masterfrom
VihaanAgarwal:fix/domain-randomization-hard-reset

Conversation

@VihaanAgarwal

Copy link
Copy Markdown

What this does

Fixes #426 (🐛 Bug)

When an environment uses the mujoco renderer, a hard reset frees the old MjSim and builds a new one (_destroy_sim then _initialize_sim in MujocoEnv.reset). DomainRandomizationWrapper.reset called save_default_domain() before rebinding its modders to the new sim, so the modders still pointed at the freed sim. Reading a model parameter from it then raised:

AttributeError: 'MjSim' object has no attribute 'model'

Reproducer from the issue:

import robosuite as suite
from robosuite.wrappers import DomainRandomizationWrapper

env = suite.make("Door", robots="Panda", has_renderer=True, has_offscreen_renderer=False, use_camera_obs=False)
env = DomainRandomizationWrapper(env)
env.reset()

The update_sim loop that rebinds the modders already existed, it just ran after save_default_domain(). Moving it ahead of the save so the modders read from the live sim is enough to fix it. This is also what was suggested in the issue thread.

How it was tested

Added test_domain_randomization_hard_reset in tests/test_environments/test_domain_randomization.py. It wraps a Lift env with the mujoco renderer and resets it across several hard resets. The test fails on master with the AttributeError above and passes with this change. randomize_color is left off in the test because TextureModder requires mujoco==3.1.1.

black, isort and flake8 are clean on the changed files.

How to checkout & try? (for the reviewer)

python -m pytest tests/test_environments/test_domain_randomization.py

A hard reset frees the old MjSim and builds a new one, but the wrapper
saved the default domain before pointing its modders at the new sim. On
the "mujoco" renderer the modders still referenced the freed sim, so the
next reset raised "'MjSim' object has no attribute 'model'".

Move the update_sim call ahead of save_default_domain so the modders read
from the live sim, and add a regression test that resets a wrapped env
across several hard resets.

Fixes ARISE-Initiative#426
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 this pull request may close these issues.

'MjSim' object has no attribute 'model'

1 participant