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

Refactor rllab from rllab.mujoco_py to mujoco_py (v1.5.0) #91

Merged
merged 19 commits into from
May 30, 2018

Conversation

jonashen
Copy link
Collaborator

@jonashen jonashen commented May 25, 2018

When rllab was first developed, the mujoco_py package written by MuJoCo was barebones and sorely lacking in functionality. As such, the original creators of rllab decided to copy in a local folder called rllab.mujoco_py, in which they built upon the mujoco_py package with custom functions they felt were necessary to implement rllab.

As MuJoCo has now upgraded to a new version (i.e. v1.5.0), many of the functions in this folder are now obsolete, and can be replaced. Thus, there is no need to keep this folder; instead, we can utilize the functionality of mujoco_py directly. This PR will replace all usage of rllab.mujoco_py with mujoco_py instead, as well as remove the rllab.mujoco_py folder itself.

P.S. this PR will also update the setup_mujoco.sh script to support installation of MuJoCo v1.5.0 in lieu of v1.3.0.

P.P.S. I have also inadvertently built upon a commit that supports asynchronous support for plot rollout.

See: #1, #4, #55, #90

@ryanjulian ryanjulian mentioned this pull request May 25, 2018
Copy link
Owner

@ryanjulian ryanjulian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but this PR definitely looks like a WIP.

  • Please remove all commented-out code
  • If you're unsure whether an API maps 1:1, test it.

plotter.init_plot(self.env, self.policy)
plotter.init_plot(self.env, self.policy, self.max_path_length)
# Call rollout once to display glfw window
rollout(self.env, self.policy, animated=True, max_path_length=self.max_path_length)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make a TODO/github issue to make this API better. Shouldn't this be part of init_plot()?

@@ -4,6 +4,7 @@
import rllab.misc.logger as logger
import rllab.plotter as plotter
from rllab.policies.base import Policy
from rllab.sampler.utils import rollout
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8: alphabetical imports

Copy link
Collaborator Author

@jonashen jonashen May 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain which part isn't in alphabetical order? I don't see it

import rllab.mujoco_py.mjconstants as C
from rllab.mujoco_py.mjlib import mjlib
from mujoco_py import MjRenderContext, MjSim, functions, const as C
from mujoco_py.generated.const import CAT_ALL
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

@jonashen jonashen May 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • "MuJoCo comes with its own version of GLFW, so it's preferable to use that one. The easy solution is to import mujoco_py before import glfw."

This comment is specified by the creators of mujoco_py; should I make a note of this fact using a comment? If so, should I make a note of this in every file that contains these two import statements?

See: https://github.com/openai/mujoco-py/blob/6ac6ac203a875ef35b1505827264cadccbfd9f05/mujoco_py/builder.py

self.con = mjcore.MJRCONTEXT()
# self.objects = mjcore.MJVOBJECTS()
# self.cam = mjcore.MJVCAMERA()
# self.vopt = mjcore.MJVOPTION()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't commit commented-out code.

@@ -35,52 +39,67 @@ def __init__(self):
def set_model(self, model):
self.model = model
if model:
self.data = model.data
# self.data = model.data
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't commit commented-out code.

@@ -401,9 +410,9 @@ def get_ori(self):
obj = obj.wrapped_env
try:
return obj.get_ori()
except (NotImplementedError, AttributeError) as e:
except (NotImplementedError, AttributeError):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is anything but completely meaningless, can you please at least omit a warning in the logger?

If the program cannot meaningfully continue when this error is raised, then do not suppress it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an implementation of the original contributors. As specified in this function's header,

First it tries to use a get_ori from the wrapped env. If not successful, falls back to the default based on the ORI_IND specified in Maze (not accurate for quaternions)

Thus, the program will continue without fault even if this exception is thrown; it simply falls back to the default implementation.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm

@@ -5,14 +5,17 @@
from rllab import spaces
from rllab.envs.base import Env
from rllab.misc.overrides import overrides
from rllab.mujoco_py import MjModel, MjViewer
import mujoco_py
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8 imports

@@ -1,29 +0,0 @@
GEM
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleted code is best code.

@@ -1,8 +1,10 @@
import atexit
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did this file get accidentally mixed with your other commit for async plotting?

see my slack announcement about rebasing.

@@ -1,14 +1,14 @@
#!/bin/bash

if [ "$(uname)" == "Darwin" ]; then
mujoco_file="libmujoco131.dylib"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove this whole setup and just rely on the system MuJoCo.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will need to update the .rst documentation.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take that back. Let's make that a different issue.

@ryanjulian ryanjulian added this to the Week of May 21 milestone May 25, 2018
@ryanjulian ryanjulian added big big multi-feature projects housecleaning labels May 25, 2018
import mujoco_py
from mujoco_py import const as C
from mujoco_py import functions
from mujoco_py import MjRenderContext
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8: import ordering and grouping

from ctypes import byref
import math
import mujoco_py
from mujoco_py import functions
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8: import ordering and grouping

from cached_property import cached_property
import mako.template
import mako.lookup
import mujoco_py
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8: import ordering and grouping

# frame_skip_id = self.data.numeric_names.index("frame_skip")
# addr = self.sim.numeric_adr.flat[frame_skip_id]
# self.frame_skip = int(self.sim.numeric_data.flat[addr])
# else:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why all the commented code? Remove it or leave a TODO+github issue.


def get_body_xmat(self, body_name):
idx = self.model.body_names.index(body_name)
return self.model.data.xmat[idx].reshape((3, 3))
# idx = self.model.body_names.index(body_name)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented code

idx = self.model.body_names.index(body_name)
return self.model.data.com_subtree[idx]
# idx = self.model.body_names.index(body_name)
# return self.sim.data.subtree_com[idx]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented code

idx = self.model.body_names.index(body_name)
return self.model.body_comvels[idx]
# idx = self.model.body_names.index(body_name)
# return self.model.body_comvels[idx]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented code

from .mujoco_env import MujocoEnv
import numpy as np
from rllab.envs.base import Step
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8: import ordering and grouping

@@ -1,10 +1,10 @@
from rllab.envs.base import Step
import glfw
import math
from .mujoco_env import MujocoEnv
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8: no relative imports

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glfw is an absolute import:

/Library/Frameworks/Pyton.framework/Versions/3.6/lib/python3.6/site-packages/glfw/init.py

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from .mujoco_env import MujocoEnv

Copy link
Owner

@ryanjulian ryanjulian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just make sure to remove the changes to rllab/plotter/plotter.py before merge


import glfw
import numpy as np

from .mujoco_env import MujocoEnv
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8: no relative imports, please.

Copy link
Owner

@ryanjulian ryanjulian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. Please fix my comment about the relative import, rebase your changes, and submit.

Don't forget to set the commit message to the authoritative one when you submit. Wrap the body to 72 chars, please.

@jonashen jonashen merged commit 2e55295 into ryanjulian:integration May 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
big big multi-feature projects housecleaning
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants