Skip to content

Commit

Permalink
Return to single thread, add default values and fix imports
Browse files Browse the repository at this point in the history
There is a bottleneck at function load_model_from_xml from mujoco-py
when using multi threading. In a single thread, a call to this function
takes units of milliseconds, while in multi threading it takes tens of
milliseconds. Maybe this is due to internal data structures that are
required for both loading the model in the worker thread and performing
the simulations in the main thread, causing the delay in
load_model_from_xml and other functions that can be perceived in the
cumulative time obtained by the profiler by running
test_dynamics_rand.py.
Due to this poor performance, the file mujoco_model_gen.py was removed
since it serves no purpose now that the variations.py file contains
methods to process the XML file, and the calls to obtain the randomized
model are done directly in the class RandomizedEnv.
  • Loading branch information
Angel Gonzalez committed Jun 8, 2018
1 parent f154042 commit a1b9f2a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 91 deletions.
86 changes: 0 additions & 86 deletions rllab/envs/mujoco/dynamics_randomization/mujoco_model_generator.py

This file was deleted.

9 changes: 4 additions & 5 deletions rllab/envs/mujoco/dynamics_randomization/randomized_env.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os.path as osp

from mujoco_py import MjSim
from mujoco_py import load_model_from_xml

from rllab.core import Serializable
from rllab.envs import Env
from rllab.envs.mujoco.dynamics_randomization import MujocoModelGenerator
from rllab.envs.mujoco.mujoco_env import MODEL_DIR


Expand All @@ -25,16 +25,16 @@ def __init__(self, mujoco_env, variations):
self._wrapped_env = mujoco_env
self._variations = variations
self._file_path = osp.join(MODEL_DIR, mujoco_env.FILE)
self._model_generator = MujocoModelGenerator(self._file_path,
variations)
self._variations.initialize_variations(self._file_path)

def reset(self):
"""
The new model with randomized parameters is requested and the
corresponding parameters in the MuJoCo environment class are
set.
"""
self._wrapped_env.model = self._model_generator.get_model()
self._wrapped_env.model = load_model_from_xml(
self._variations.get_randomized_xml_model())
if hasattr(self._wrapped_env, 'action_space'):
del self._wrapped_env.__dict__['action_space']
self._wrapped_env.sim = MjSim(self._wrapped_env.model)
Expand Down Expand Up @@ -65,7 +65,6 @@ def terminate(self):
Besides regular termination, the MuJoCo model generator is
stopped.
"""
self._model_generator.stop()
self._wrapped_env.terminate()

@property
Expand Down

0 comments on commit a1b9f2a

Please sign in to comment.