-
Notifications
You must be signed in to change notification settings - Fork 21
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
Conversation
There was a problem hiding this 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.
rllab/algos/batch_polopt.py
Outdated
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) |
There was a problem hiding this comment.
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()?
rllab/algos/batch_polopt.py
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8: alphabetical imports
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8 imports
There was a problem hiding this comment.
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
beforeimport 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?
self.con = mjcore.MJRCONTEXT() | ||
# self.objects = mjcore.MJVOBJECTS() | ||
# self.cam = mjcore.MJVCAMERA() | ||
# self.vopt = mjcore.MJVOPTION() |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sgtm
rllab/envs/mujoco/mujoco_env.py
Outdated
@@ -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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
rllab/plotter/plotter.py
Outdated
@@ -1,8 +1,10 @@ | |||
import atexit |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
import mujoco_py | ||
from mujoco_py import const as C | ||
from mujoco_py import functions | ||
from mujoco_py import MjRenderContext |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
rllab/envs/mujoco/mujoco_env.py
Outdated
from cached_property import cached_property | ||
import mako.template | ||
import mako.lookup | ||
import mujoco_py |
There was a problem hiding this comment.
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
rllab/envs/mujoco/mujoco_env.py
Outdated
# 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: |
There was a problem hiding this comment.
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.
rllab/envs/mujoco/mujoco_env.py
Outdated
|
||
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commented code
rllab/envs/mujoco/mujoco_env.py
Outdated
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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commented code
rllab/envs/mujoco/mujoco_env.py
Outdated
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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commented code
rllab/envs/mujoco/point_env.py
Outdated
from .mujoco_env import MujocoEnv | ||
import numpy as np | ||
from rllab.envs.base import Step |
There was a problem hiding this comment.
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
rllab/envs/mujoco/point_env.py
Outdated
@@ -1,10 +1,10 @@ | |||
from rllab.envs.base import Step | |||
import glfw | |||
import math | |||
from .mujoco_env import MujocoEnv |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8: no relative imports
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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
rllab/envs/mujoco/point_env.py
Outdated
|
||
import glfw | ||
import numpy as np | ||
|
||
from .mujoco_env import MujocoEnv |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
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