Skip to content

Commit

Permalink
Don't do deepcopies in open ai api
Browse files Browse the repository at this point in the history
  • Loading branch information
hsahovic committed Apr 6, 2024
1 parent a4a3785 commit ad7536d
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/poke_env/player/openai_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,8 @@ def reset(
while self.current_battle == self.agent.current_battle:
time.sleep(0.01)
self.current_battle = self.agent.current_battle
battle = copy.copy(self.current_battle)
battle.logger = None
self.last_battle = copy.deepcopy(battle)
self.current_battle.logger = None
self.last_battle = self.current_battle
return self._observations.get(), self.get_additional_info()

def get_additional_info(self) -> Dict[str, Any]:
Expand Down Expand Up @@ -362,7 +361,7 @@ def step(
raise RuntimeError("Battle is already finished, call reset")
battle = copy.copy(self.current_battle)
battle.logger = None
self.last_battle = copy.deepcopy(battle)
self.last_battle = battle
self._actions.put(action)
observation = self._observations.get()
reward = self.calc_reward(self.last_battle, self.current_battle)
Expand Down Expand Up @@ -526,12 +525,12 @@ async def _ladder_loop(
for _ in range(n_challenges):
await self.agent.ladder(1)
if callback and self.current_battle is not None:
callback(copy.deepcopy(self.current_battle))
callback(self.current_battle)
else:
while self._keep_challenging:
await self.agent.ladder(1)
if callback and self.current_battle is not None:
callback(copy.deepcopy(self.current_battle))
callback(self.current_battle)

def start_laddering(
self,
Expand Down

0 comments on commit ad7536d

Please sign in to comment.