-
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
Replaced rllab.envs.Env with gym.Env #129
base: integration
Are you sure you want to change the base?
Conversation
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)]) |
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 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.
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)]) |
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.
Same as unflatten. Please check the unflatten_n of rllab.spaces.product
rllab/envs/gym_env_util.py
Outdated
] | ||
|
||
|
||
def action_dim(env): |
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 can be rename to action_flat_dim. With flat_dim() of spaces, I don't think this function is necessary.
rllab/envs/gym_env_util.py
Outdated
|
||
|
||
def log_diagnostics(env, paths): | ||
pass |
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 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.
rllab/envs/gym_env_util.py
Outdated
from rllab.misc import ext | ||
from rllab.misc import special | ||
from rllab.misc.overrides import overrides | ||
|
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 remove imports that is not used.
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 also remove files that used GymEnv in examples since GymEnv would not be used anymore.
rllab/envs/gym_util/space_util.py
Outdated
|
||
|
||
def log_diagnostics(space, paths): | ||
pass |
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 remove useless function.
rllab/envs/gym_util/space_util.py
Outdated
|
||
def components(space): | ||
if isinstance(space, gym.spaces.Tuple): | ||
return self.spaces |
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 is actually only for Tuple. Using space.spaces looks cleaner than me.
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 double check your codes when copying from other files.
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]) |
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 do not just copy paste codes.. Variable x is not declared at all.
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) |
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.
Same as unflatten(space, obs).. also line 107, there is not self here because is not an object.
rllab/envs/gym_util/space_util.py
Outdated
def sample(space): | ||
if isinstance(space, gym.spaces.Tuple): | ||
return tuple(x.sample() for x in self.spaces) | ||
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.
There is not self in this method.
@@ -1,38 +0,0 @@ | |||
from rllab.algos import TRPO |
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 remove this file?
@@ -1,38 +0,0 @@ | |||
from rllab.algos import TRPO |
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 remove this file?
@@ -1,38 +0,0 @@ | |||
from rllab.algos import TRPO |
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 remove this file?
@@ -1,40 +0,0 @@ | |||
# This doesn't work. After 150 iterations still didn't learn anything. |
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 remove this file?
@@ -1,38 +0,0 @@ | |||
from rllab.algos import TRPO |
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 remove this file?
examples/trpo_gym_pendulum.py
Outdated
@@ -1,48 +0,0 @@ | |||
from rllab.algos import TRPO |
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 remove this file?
examples/trpo_gym_tf_cartpole.py
Outdated
@@ -1,42 +0,0 @@ | |||
from rllab.baselines import LinearFeatureBaseline |
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 remove this file?
rllab/envs/gym_util/env_util.py
Outdated
@@ -0,0 +1,37 @@ | |||
import gym |
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 can be located in rllab.envs.util / rllab/envs/util.py
No need for the long import path.
rllab/envs/gym_util/space_util.py
Outdated
@@ -0,0 +1,141 @@ | |||
import gym |
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.
these probably also belong in rllab/envs/util.py
rllab/envs/normalized_env.py
Outdated
@@ -1,3 +1,4 @@ | |||
import gym |
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.
what is the relationship between this file and #125 ?
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.
rllab/envs/base.py
Outdated
@@ -88,7 +87,8 @@ def set_param_values(self, params): | |||
pass | |||
|
|||
|
|||
_Step = collections.namedtuple("Step", ["observation", "reward", "done", "info"]) | |||
_Step = collections.namedtuple("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.
there don't appear to be any meaningful changes in this file?
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 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.
Please reopen this PR against https://github.com/rlworkgroup/garage |
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