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

Replaced rllab.envs.Env with gym.Env #129

Open
wants to merge 13 commits into
base: integration
Choose a base branch
from
Open

Replaced rllab.envs.Env with gym.Env #129

wants to merge 13 commits into from

Conversation

jonashen
Copy link
Collaborator

@jonashen jonashen commented Jun 8, 2018

Using Zhanpeng's refactoring of normalized_env as a baseline, this PR creates two utility files (i.e. gym_env_util and gym_space_util) to convert gym spaces for use in rllab algorithms.

Ref: #85

return special.from_onehot(obs)
elif isinstance(space, gym.spaces.Tuple):
return np.concatenate(
[gym_space_unflatten(xi, c) for c, xi in zip(space.spaces, obs)])
Copy link
Collaborator

@zhanpenghe zhanpenghe Jun 8, 2018

Choose a reason for hiding this comment

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

Did you test the unflatten of Tuple? It should take account of the dims of components of the tuples and reshape the flatten obs. Unflatten is a bit more complicated than flatten.

return special.from_onehot_n(obs)
elif isinstance(space, gym.spaces.Tuple):
return np.concatenate(
[gym_space_unflatten_n(xi, c) for c, xi in zip(space.spaces, obs)])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as unflatten. Please check the unflatten_n of rllab.spaces.product

]


def action_dim(env):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be rename to action_flat_dim. With flat_dim() of spaces, I don't think this function is necessary.



def log_diagnostics(env, paths):
pass
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function is different for different environments. It's not a good practice to implement one function for all envs because there could be too many of them.

from rllab.misc import ext
from rllab.misc import special
from rllab.misc.overrides import overrides

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove imports that is not used.

@jonashen jonashen requested a review from zhanpenghe June 8, 2018 20:56
Copy link
Collaborator

@zhanpenghe zhanpenghe left a comment

Choose a reason for hiding this comment

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

Please also remove files that used GymEnv in examples since GymEnv would not be used anymore.



def log_diagnostics(space, paths):
pass
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove useless function.


def components(space):
if isinstance(space, gym.spaces.Tuple):
return self.spaces
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is actually only for Tuple. Using space.spaces looks cleaner than me.

Copy link
Collaborator

@zhanpenghe zhanpenghe left a comment

Choose a reason for hiding this comment

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

Please double check your codes when copying from other files.

return special.from_onehot(obs)
elif isinstance(space, gym.spaces.Tuple):
dims = [flat_dim(c) for c in space.spaces]
flat_xs = np.split(x, np.cumsum(dims)[:-1])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please do not just copy paste codes.. Variable x is not declared at all.

return special.from_onehot_n(obs)
elif isinstance(space, gym.spaces.Tuple):
dims = [flat_dim(c) for c in self.spaces]
flat_xs = np.split(xs, np.cumsum(dims)[:-1], axis=-1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as unflatten(space, obs).. also line 107, there is not self here because is not an object.

def sample(space):
if isinstance(space, gym.spaces.Tuple):
return tuple(x.sample() for x in self.spaces)
else:
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is not self in this method.

@zhanpenghe zhanpenghe mentioned this pull request Jun 9, 2018
@@ -1,38 +0,0 @@
from rllab.algos import TRPO
Copy link
Owner

Choose a reason for hiding this comment

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

why remove this file?

@@ -1,38 +0,0 @@
from rllab.algos import TRPO
Copy link
Owner

Choose a reason for hiding this comment

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

why remove this file?

@@ -1,38 +0,0 @@
from rllab.algos import TRPO
Copy link
Owner

Choose a reason for hiding this comment

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

why remove this file?

@@ -1,40 +0,0 @@
# This doesn't work. After 150 iterations still didn't learn anything.
Copy link
Owner

Choose a reason for hiding this comment

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

why remove this file?

@@ -1,38 +0,0 @@
from rllab.algos import TRPO
Copy link
Owner

Choose a reason for hiding this comment

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

why remove this file?

@@ -1,48 +0,0 @@
from rllab.algos import TRPO
Copy link
Owner

Choose a reason for hiding this comment

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

why remove this file?

@@ -1,42 +0,0 @@
from rllab.baselines import LinearFeatureBaseline
Copy link
Owner

Choose a reason for hiding this comment

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

why remove this file?

@@ -0,0 +1,37 @@
import gym
Copy link
Owner

Choose a reason for hiding this comment

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

this can be located in rllab.envs.util / rllab/envs/util.py

No need for the long import path.

@@ -0,0 +1,141 @@
import gym
Copy link
Owner

Choose a reason for hiding this comment

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

these probably also belong in rllab/envs/util.py

@@ -1,3 +1,4 @@
import gym
Copy link
Owner

Choose a reason for hiding this comment

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

what is the relationship between this file and #125 ?

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 file will be replaced by #125, but the utility functions located in #125 are relocated here in rllab.envs.util. I will remove edits to this file.

@@ -88,7 +87,8 @@ def set_param_values(self, params):
pass


_Step = collections.namedtuple("Step", ["observation", "reward", "done", "info"])
_Step = collections.namedtuple("Step",
Copy link
Owner

Choose a reason for hiding this comment

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

there don't appear to be any meaningful changes in this file?

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.

I know it's painful, but can you please remove all YAPF reformatting for non-new files?

YAPF formatting makes it difficult to figure out what changed in large changes like this.

@ryanjulian
Copy link
Owner

Please reopen this PR against https://github.com/rlworkgroup/garage

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.

3 participants