Replaced rllab.envs.Env with gym.Env#129
Conversation
| 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.
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)]) |
There was a problem hiding this comment.
Same as unflatten. Please check the unflatten_n of rllab.spaces.product
| ] | ||
|
|
||
|
|
||
| def action_dim(env): |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 | ||
|
|
There was a problem hiding this comment.
Please remove imports that is not used.
|
|
||
|
|
||
| def log_diagnostics(space, paths): | ||
| pass |
There was a problem hiding this comment.
Please remove useless function.
|
|
||
| def components(space): | ||
| if isinstance(space, gym.spaces.Tuple): | ||
| return self.spaces |
There was a problem hiding this comment.
This is actually only for Tuple. Using space.spaces looks cleaner than me.
zhanpenghe
left a comment
There was a problem hiding this comment.
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]) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
There is not self in this method.
| @@ -1,38 +0,0 @@ | |||
| from rllab.algos import TRPO | |||
| @@ -1,38 +0,0 @@ | |||
| from rllab.algos import TRPO | |||
| @@ -1,38 +0,0 @@ | |||
| from rllab.algos import TRPO | |||
| @@ -1,40 +0,0 @@ | |||
| # This doesn't work. After 150 iterations still didn't learn anything. | |||
| @@ -1,38 +0,0 @@ | |||
| from rllab.algos import TRPO | |||
| @@ -1,48 +0,0 @@ | |||
| from rllab.algos import TRPO | |||
| @@ -1,42 +0,0 @@ | |||
| from rllab.baselines import LinearFeatureBaseline | |||
| @@ -0,0 +1,37 @@ | |||
| import gym | |||
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
these probably also belong in rllab/envs/util.py
| @@ -1,3 +1,4 @@ | |||
| import gym | |||
There was a problem hiding this comment.
what is the relationship between this file and #125 ?
|
|
||
|
|
||
| _Step = collections.namedtuple("Step", ["observation", "reward", "done", "info"]) | ||
| _Step = collections.namedtuple("Step", |
There was a problem hiding this comment.
there don't appear to be any meaningful changes in this file?
ryanjulian
left a comment
There was a problem hiding this comment.
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