Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support numpy.uint8 in some classes (#455)
- Support numpy.uint8 in some classes - Grayscale should only work on np.uint8. - garage.spaces.Box should have dtype np.float32 by default. - Use dummyEnv for unit test.
- Loading branch information
Showing
19 changed files
with
319 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
from tests.fixtures.envs.dummy.base import DummyEnv | ||
from tests.fixtures.envs.dummy.dummy_box_env import DummyBoxEnv | ||
from tests.fixtures.envs.dummy.dummy_dict_env import DummyDictEnv | ||
from tests.fixtures.envs.dummy.dummy_discrete_2d_env import DummyDiscrete2DEnv | ||
from tests.fixtures.envs.dummy.dummy_discrete_env import DummyDiscreteEnv | ||
from tests.fixtures.envs.dummy.dummy_discrete_pixel_env import ( | ||
DummyDiscretePixelEnv) | ||
|
||
__all__ = ["DummyBoxEnv", "DummyDictEnv", "DummyDiscreteEnv"] | ||
__all__ = [ | ||
"DummyEnv", "DummyBoxEnv", "DummyDictEnv", "DummyDiscrete2DEnv", | ||
"DummyDiscreteEnv", "DummyDiscretePixelEnv" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import gym | ||
|
||
|
||
class DummyEnv(gym.Env): | ||
"""Base dummy environment.""" | ||
|
||
def __init__(self, random): | ||
self.random = random | ||
self.state = None | ||
|
||
@property | ||
def observation_space(self): | ||
"""Return an observation space.""" | ||
raise NotImplementedError | ||
|
||
@property | ||
def action_space(self): | ||
"""Return an action space.""" | ||
raise NotImplementedError | ||
|
||
def reset(self): | ||
"""Reset the environment.""" | ||
raise NotImplementedError | ||
|
||
def step(self, action): | ||
"""Step the environment.""" | ||
raise NotImplementedError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import gym | ||
import numpy as np | ||
|
||
from tests.fixtures.envs.dummy import DummyEnv | ||
|
||
|
||
class DummyDiscrete2DEnv(DummyEnv): | ||
"""A dummy discrete environment.""" | ||
|
||
def __init__(self, random=True): | ||
super().__init__(random) | ||
|
||
@property | ||
def observation_space(self): | ||
"""Return an observation space.""" | ||
self.shape = (2, 2) | ||
return gym.spaces.Box( | ||
low=-1, high=1, shape=self.shape, dtype=np.float32) | ||
|
||
@property | ||
def action_space(self): | ||
"""Return an action space.""" | ||
return gym.spaces.Discrete(2) | ||
|
||
def reset(self): | ||
"""Reset the environment.""" | ||
self.state = np.zeros(self.shape) | ||
return self.state | ||
|
||
def step(self, action): | ||
"""Step the environment.""" | ||
if self.state is not None: | ||
if self.random: | ||
obs = self.observation_space.sample() | ||
else: | ||
obs = self.state + action / 10. | ||
else: | ||
raise RuntimeError( | ||
"DummyEnv: reset() must be called before step()!") | ||
return obs, 0, True, dict() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.