Skip to content

Commit

Permalink
Hotfix/fix frame skip random (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottower authored Nov 28, 2023
2 parents dc4dc8a + 1db594d commit 67e47b4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
6 changes: 2 additions & 4 deletions supersuit/generic_wrappers/frame_skip.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, env, num_frames):

def step(self, action):
low, high = self.num_frames
num_skips = int(self.np_random.integers(low, high + 1))
num_skips = int(self.env.unwrapped.np_random.integers(low, high + 1))
total_reward = 0.0

for x in range(num_skips):
Expand Down Expand Up @@ -146,8 +146,7 @@ def __init__(self, env, num_frames, default_action=None):
def step(self, action):
action = {**action}
low, high = self.num_frames
num_skips = int(self.np_random.integers(low, high + 1))
self.agents = self.env.agents[:]
num_skips = int(self.env.unwrapped.np_random.integers(low, high + 1))
orig_agents = set(action.keys())

total_reward = make_defaultdict({agent: 0.0 for agent in self.agents})
Expand Down Expand Up @@ -190,7 +189,6 @@ def step(self, action):
del total_infos[agent]
del total_obs[agent]

self.agents = self.env.agents[:]
return (
total_obs,
total_reward,
Expand Down
4 changes: 2 additions & 2 deletions supersuit/generic_wrappers/utils/shared_wrapper_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import gymnasium
from pettingzoo.utils import BaseParallelWrapper
from pettingzoo.utils.wrappers import OrderEnforcingWrapper as PettingzooWrap
from pettingzoo.utils.wrappers import OrderEnforcingWrapper as BaseWrapper

from supersuit.utils.wrapper_chooser import WrapperChooser


class shared_wrapper_aec(PettingzooWrap):
class shared_wrapper_aec(BaseWrapper):
def __init__(self, env, modifier_class):
super().__init__(env)

Expand Down
6 changes: 3 additions & 3 deletions supersuit/lambda_wrappers/reward_lambda.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import gymnasium
from pettingzoo.utils import BaseWrapper as PettingzooWrap

from supersuit.utils.base_aec_wrapper import PettingzooWrap
from supersuit.utils.make_defaultdict import make_defaultdict
from supersuit.utils.wrapper_chooser import WrapperChooser

Expand All @@ -24,7 +24,7 @@ def reset(self, seed=None, options=None):
super().reset(seed=seed, options=options)
self.rewards = {
agent: self._change_reward_fn(reward)
for agent, reward in self.rewards.items()
for agent, reward in self.env.rewards.items() # you don't want to unwrap here, because another reward wrapper might have been applied
}
self.__cumulative_rewards = make_defaultdict({a: 0 for a in self.agents})
self._accumulate_rewards()
Expand All @@ -34,7 +34,7 @@ def step(self, action):
super().step(action)
self.rewards = {
agent: self._change_reward_fn(reward)
for agent, reward in self.rewards.items()
for agent, reward in self.env.rewards.items() # you don't want to unwrap here, because another reward wrapper might have been applied
}
self.__cumulative_rewards[agent] = 0
self._cumulative_rewards = self.__cumulative_rewards
Expand Down
4 changes: 2 additions & 2 deletions supersuit/utils/base_aec_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pettingzoo.utils.wrappers import OrderEnforcingWrapper as PettingzooWrap
from pettingzoo.utils.wrappers import OrderEnforcingWrapper as PZBaseWrapper


class BaseWrapper(PettingzooWrap):
class BaseWrapper(PZBaseWrapper):
def __init__(self, env):
"""
Creates a wrapper around `env`. Extend this class to create changes to the space.
Expand Down

0 comments on commit 67e47b4

Please sign in to comment.