Skip to content

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

Open
jonashen wants to merge 13 commits intointegrationfrom
gym_env
Open

Replaced rllab.envs.Env with gym.Env#129
jonashen wants to merge 13 commits intointegrationfrom
gym_env

Conversation

@jonashen
Copy link
Copy Markdown
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

Comment thread rllab/envs/gym_space_util.py Outdated
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
Copy Markdown
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.

Comment thread rllab/envs/gym_space_util.py Outdated
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
Copy Markdown
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

Comment thread rllab/envs/gym_env_util.py Outdated
]


def action_dim(env):
Copy link
Copy Markdown
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.

Comment thread rllab/envs/gym_env_util.py Outdated


def log_diagnostics(env, paths):
pass
Copy link
Copy Markdown
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.

Comment thread rllab/envs/gym_env_util.py Outdated
from rllab.misc import ext
from rllab.misc import special
from rllab.misc.overrides import overrides

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread rllab/envs/gym_util/space_util.py Outdated


def log_diagnostics(space, paths):
pass
Copy link
Copy Markdown
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.

Comment thread rllab/envs/gym_util/space_util.py Outdated

def components(space):
if isinstance(space, gym.spaces.Tuple):
return self.spaces
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread rllab/envs/gym_util/space_util.py Outdated
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
Copy Markdown
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.

Comment thread rllab/envs/gym_util/space_util.py Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?

Comment thread rllab/envs/gym_util/env_util.py Outdated
@@ -0,0 +1,37 @@
import gym
Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread rllab/envs/normalized_env.py Outdated
@@ -1,3 +1,4 @@
import gym
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread rllab/envs/base.py Outdated


_Step = collections.namedtuple("Step", ["observation", "reward", "done", "info"])
_Step = collections.namedtuple("Step",
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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