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

Dynamics randomization for MuJoCo #109

Closed
wants to merge 30 commits into from
Closed

Commits on Jun 8, 2018

  1. First draft to specify variations in dynamics randomization

    A simple data structure consisting of a list of variation objects was
    implemented. Each variation object is an instance of the Variation class
    that works as a container for each of the fields used to randomized a
    dynamic parameter within the simulation environment.
    This list of variations is further tested in script
    test_dynamics_rand.py to verify that fields within each variation can be
    set and get.
    Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    cff37ed View commit details
    Browse the repository at this point in the history
  2. Apply PEP8 format with YEPF

    Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    0986def View commit details
    Browse the repository at this point in the history
  3. Reimplement the fluent interface to create individual setters

    A setter for each field in the Variation class is used now instead of a
    constructor containing all fields as parameters. This allows a modular
    setting of fields for different configuration scenarios for dynamics
    randomization.
    To define the methods and distributions, two enumeration classes were
    created: VariationMethods and VariationDistributions.
    Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    84ca64d View commit details
    Browse the repository at this point in the history
  4. Apply PEP8 format with YEPF

    Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    12c7f36 View commit details
    Browse the repository at this point in the history
  5. Add fisrt draft of randomize environment

    Implement basic feature of a wrappered environment, which choose new
    randomized physics params in mujoco on every reset().
    Chang authored and Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    9104c48 View commit details
    Browse the repository at this point in the history
  6. Rename RandomizeEnv.py to randomized_env.py

    All the python files have file names in lowercase. To keep this
    standard, refactor RandomizeEnv.py to randomized_env.py.
    Chang authored and Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    9eba2da View commit details
    Browse the repository at this point in the history
  7. Add features and remove variables in RandomizedEnv

    Add error handling in constructor and reset().
    Remove variables that doesn't depend on self._wrapped_env.sim in
    reset().
    Reuse MODEL_DIR in mujoco_env.py
    Alphabetize imports.
    Chang authored and Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    6fc661b View commit details
    Browse the repository at this point in the history
  8. Fix bugs in error handling

    Fix wrong AttributeError raising in constructor when there
    is element in xml.
    
    Add error handling towards the Variation.range attribute. When
    the range shape isn't the same as the attribute value shape,
    raise an AttributeError.
    CatherineSue authored and Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    e4ce9b1 View commit details
    Browse the repository at this point in the history
  9. Add thread to generate Mujoco models

    Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    28d73e8 View commit details
    Browse the repository at this point in the history
  10. Add thread terminate in mujoco_model_gen

    CatherineSue authored and Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    21e42ee View commit details
    Browse the repository at this point in the history
  11. Add interrupt handler to mujoco model gen

    Finish the thread when the simulaton is interrupted.
    CatherineSue authored and Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    009ddbf View commit details
    Browse the repository at this point in the history
  12. Add documentation to new classes and sort import headers

    Other miscellaneous changes include:
    - Rename classes VariationsMethods and VariationDistributions to
    VariationsMethod and VariationDistribution respectively.
    - The parsing of the XML string and fetch of the dynamic parameters to
    randomize is now done within the worker thread.
    - The file randomize_env.py was renamed to randomized_env.py
    Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    5485bfb View commit details
    Browse the repository at this point in the history
  13. Fix bug in MujocoModelGenerator

    Before this commit, when there is an error raised when loading the xml
    object, only the worker_thread terminates. This commit fixes this bug by
    terminating all the processes.
    
    Fix some typo in the last commit.
    CatherineSue authored and Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    4442f12 View commit details
    Browse the repository at this point in the history
  14. Change multi-thread MujocoModelGen to n-length queue

    Create an 10-length queue in MujocoModelGenerator to store the
    mujoco_models.
    CatherineSue authored and Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    4a96217 View commit details
    Browse the repository at this point in the history
  15. Miscellaneous changes to improve the code

    - Renamed classes VariationMethod and VariationDistribution to Method
    and
    Distribution.
    - Enforced the use of methods exclusive for uniform or normal
    distributions in the fluent interface pattern provided in class
    Variations by splitting the class into VariationsBase,
    VariationsGaussian and VariationsUniform.
    - Included the module os.path.osp in rllab.envs.mujoco modules.
    - Changed error types and improved messages for two errors in class
    MujocoModelGenerator.
    Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    c1a4a81 View commit details
    Browse the repository at this point in the history
  16. Fix PEP8 formatting in file mujoco_model_gen.py

    Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    cf45d0c View commit details
    Browse the repository at this point in the history
  17. Add miscellaneous changes to improve the code

     - Delete unused threading.Event in MujocoModelGenerator.
     - Correct error types in MujocoModelGenerator.
     - Renamed classes RandomizedEnv to RandomizedDynamicsEnv.
     - Delete wrong try-except in RandomizedDynamicsEnv.
     - Use randomize_dynamics() in the launcher.
     - Format method chains onto multiple lines.
     - Correct wrong param name in Variation.
    CatherineSue authored and Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    735ed80 View commit details
    Browse the repository at this point in the history
  18. Add local cache of elems in MujocoModelGenerator

    Solve the problem with v.elem=e, which calls the setter method in
    Variation. Replace this with a local cache of elements.
    
    Same with v.default in MujocoModelGenerator.
    CatherineSue authored and Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    25db0fe View commit details
    Browse the repository at this point in the history
  19. Add miscellaneous changes to improve the code

     - Remove the setter in Variation
     - Add check of parameter shape in MujocoModelGenerator
     - Fix some typo
    CatherineSue authored and Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    22d69af View commit details
    Browse the repository at this point in the history
  20. Fix PEP formatting with YAPF

    CatherineSue authored and Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    a4c8442 View commit details
    Browse the repository at this point in the history
  21. Add error handling to MujocoModelGenerator

     - Add more detailed information in handling the shape of the sampled
     value with the default value
    
     - Add timeout in the Queue.get() in MujocoModelGenerator so the main
     thread will catch error raised in worker thread
    CatherineSue authored and Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    43594ea View commit details
    Browse the repository at this point in the history
  22. Rename RandomizedDynamicsEnv to RandomizedEnv

    CatherineSue authored and Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    4221002 View commit details
    Browse the repository at this point in the history
  23. Fix mujoco exception caused by cached propery action_space

    The cached property action_space found in mujoco_env.py produces an
    error in Linux for dynamics randomization. The idea behind the cached
    property is to avoid doing an expensive computation several times, so
    for regular execution, action_space is obtained from the model that is
    used for the entire training once, improving the performance.
    However, for dynamics randomization there's a new model for each
    episode, and that requires that the action_space is updated accordingly,
    but that does not happen because it's cached.
    To update action_space and not make an invasive change, the attribute is
    invalidated for each reset in the RandomizedEnv class.
    Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    133e2cb View commit details
    Browse the repository at this point in the history
  24. Add miscellaneous changes to improve the code

     - Move the dynamics_randomization package to rllab.envs.mujoco.
    
     - Delete tosser.xml, use xml in rllab/vendor/mujoco_model for test
    
     - The old test_dynamics_rand.py only tests for the Variations API,
       so rewrite it to test for both Variations API and RandomizedEnv.
    
     - Reorder imports.
    
     - Delete import os.path as osp in rllab/envs/mujoco/__init__.py.
       Previously added by mistake.
    Chang authored and Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    27ec748 View commit details
    Browse the repository at this point in the history
  25. Rename mujoco_model_gen to mujoco_model_generator

    Package names should follow class names.
    Chang authored and Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    f18780e View commit details
    Browse the repository at this point in the history
  26. Delete trpo_swimmer in dynamics_randomization

    test_dynamics_rand.py is enough for testing. Remove trpo_swimmer.py
    Chang authored and Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    62331f2 View commit details
    Browse the repository at this point in the history
  27. Initialize variations and generation of XML string in Variations

    The code to initialize the variations and to generate the randomized
    parameters was moved into the Variations class. This will keep all the
    current code related to variations in the same file to improve the API
    of dynamics randomization, and will enable a more modular code for
    further features in the module.
    Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    f154042 View commit details
    Browse the repository at this point in the history
  28. Return to single thread, add default values and fix imports

    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.
    Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    a1b9f2a View commit details
    Browse the repository at this point in the history
  29. Sort modules in the package, add newline at EOF and defaults

    The changes in this commit include:
    - The modules in the __ini__.py file were sorted alphabetically.
    - The new line at the end of file was added in randomized_env.py.
    - Default values were assigned for VariationSpec, specifically for
    fields method, distribution, mean_std and var_range. Fields xpath,
    attrib, elem and default are specific to the model in the XML file
    provided by the user, so they cannot be default parameters. Further
    more, elem and default are obtained by parsing the XML file, so the user
    won't set them.
    Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    ac0d449 View commit details
    Browse the repository at this point in the history
  30. Fix PEP8 formatting in randomized_env.py

    Angel Gonzalez committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    56d2b60 View commit details
    Browse the repository at this point in the history