-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update gym/pettingzoo dependencies * update gym and pettingzoo versions * update unit tests * remove custom gym env due to broken duplicate functionality * update torch etc to latest * address PettingZoo deprecation warnings * update github workflow * Update python-package.yml * Update python-package.yml * Update python-package.yml * Update python-package.yml * remove python 3.6 * support python versions 3.8 and 3.9 * make sure torch versions match * linting Co-authored-by: Nota, Christopher <cnota@irobot.com>
- Loading branch information
Showing
16 changed files
with
141 additions
and
120 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,91 @@ | ||
import gym | ||
from .gym import GymEnvironment | ||
import torch | ||
from all.core import State | ||
from .duplicate_env import DuplicateEnvironment | ||
from .atari_wrappers import ( | ||
NoopResetEnv, | ||
MaxAndSkipEnv, | ||
FireResetEnv, | ||
WarpFrame, | ||
LifeLostEnv, | ||
) | ||
from all.core import State | ||
from .duplicate_env import DuplicateEnvironment | ||
from ._environment import Environment | ||
|
||
|
||
class AtariEnvironment(GymEnvironment): | ||
def __init__(self, name, *args, **kwargs): | ||
# need these for duplication | ||
self._args = args | ||
self._kwargs = kwargs | ||
class AtariEnvironment(Environment): | ||
def __init__(self, name, device='cpu'): | ||
|
||
# construct the environment | ||
env = gym.make(name + "NoFrameskip-v4") | ||
|
||
# apply a subset of wrappers | ||
env = NoopResetEnv(env, noop_max=30) | ||
env = MaxAndSkipEnv(env) | ||
if "FIRE" in env.unwrapped.get_action_meanings(): | ||
env = FireResetEnv(env) | ||
env = WarpFrame(env) | ||
env = LifeLostEnv(env) | ||
# initialize | ||
super().__init__(env, *args, **kwargs) | ||
|
||
# initialize member variables | ||
self._env = env | ||
self._name = name | ||
self._state = None | ||
self._action = None | ||
self._reward = None | ||
self._done = True | ||
self._info = None | ||
self._device = device | ||
|
||
def reset(self): | ||
state = self._env.reset(), 0., False, None | ||
self._state = State.from_gym(state, dtype=self._env.observation_space.dtype, device=self._device) | ||
return self._state | ||
|
||
def step(self, action): | ||
self._state = State.from_gym( | ||
self._env.step(self._convert(action)), | ||
dtype=self._env.observation_space.dtype, | ||
device=self._device | ||
) | ||
return self._state | ||
|
||
def render(self, **kwargs): | ||
return self._env.render(**kwargs) | ||
|
||
def close(self): | ||
return self._env.close() | ||
|
||
def seed(self, seed): | ||
self._env.seed(seed) | ||
|
||
def duplicate(self, n): | ||
return DuplicateEnvironment([AtariEnvironment(self._name, device=self._device) for _ in range(n)]) | ||
|
||
@property | ||
def name(self): | ||
return self._name | ||
|
||
def reset(self): | ||
state = self._env.reset(), 0., False, {'life_lost': False} | ||
self._state = State.from_gym(state, dtype=self._env.observation_space.dtype, device=self._device) | ||
@property | ||
def state_space(self): | ||
return self._env.observation_space | ||
|
||
@property | ||
def action_space(self): | ||
return self._env.action_space | ||
|
||
@property | ||
def state(self): | ||
return self._state | ||
|
||
def duplicate(self, n): | ||
return DuplicateEnvironment([ | ||
AtariEnvironment(self._name, *self._args, **self._kwargs) for _ in range(n) | ||
]) | ||
@property | ||
def env(self): | ||
return self._env | ||
|
||
@property | ||
def device(self): | ||
return self._device | ||
|
||
def _convert(self, action): | ||
if torch.is_tensor(action): | ||
return action.item() | ||
return action |
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
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.