Skip to content

Commit

Permalink
add back achievement logging that was accidentally deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTMatthews committed May 29, 2024
1 parent fbe4b50 commit e1f21bc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
11 changes: 11 additions & 0 deletions craftax/craftax/envs/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from craftax.craftax.craftax_state import EnvState
from craftax.craftax.constants import *


def log_achievements_to_info(state: EnvState, done: bool):
achievements = state.achievements * done * 100.0
info = {}
for achievement in Achievement:
name = f"Achievements/{achievement.name.lower()}"
info[name] = achievements[achievement.value]
return info
7 changes: 5 additions & 2 deletions craftax/craftax/envs/craftax_pixels_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import chex

from craftax.craftax.constants import *
from craftax.craftax.envs.common import log_achievements_to_info
from craftax.craftax.game_logic import craftax_step, is_game_over
from craftax.craftax.craftax_state import EnvState, EnvParams, StaticEnvParams
from craftax.craftax.renderer import render_craftax_pixels
Expand Down Expand Up @@ -34,7 +35,8 @@ def step_env(
state, reward = craftax_step(key, state, action, params, self.static_env_params)

done = self.is_terminal(state, params)
info = {"discount": self.discount(state, params)}
info = log_achievements_to_info(state, done)
info["discount"] = self.discount(state, params)

return (
lax.stop_gradient(self.get_obs(state)),
Expand Down Expand Up @@ -105,7 +107,8 @@ def step_env(
state, reward = craftax_step(key, state, action, params, self.static_env_params)

done = self.is_terminal(state, params)
info = {"discount": self.discount(state, params)}
info = log_achievements_to_info(state, done)
info["discount"] = self.discount(state, params)

return (
lax.stop_gradient(self.get_obs(state)),
Expand Down
7 changes: 5 additions & 2 deletions craftax/craftax/envs/craftax_symbolic_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Tuple, Optional
import chex

from craftax.craftax.envs.common import log_achievements_to_info
from craftax.environment_base.environment_bases import EnvironmentNoAutoReset
from craftax.craftax.constants import *
from craftax.craftax.game_logic import craftax_step, is_game_over
Expand Down Expand Up @@ -56,7 +57,8 @@ def step_env(
state, reward = craftax_step(rng, state, action, params, self.static_env_params)

done = self.is_terminal(state, params)
info = {"discount": self.discount(state, params)}
info = log_achievements_to_info(state, done)
info["discount"] = self.discount(state, params)

return (
lax.stop_gradient(self.get_obs(state)),
Expand Down Expand Up @@ -128,7 +130,8 @@ def step_env(
state, reward = craftax_step(rng, state, action, params, self.static_env_params)

done = self.is_terminal(state, params)
info = {"discount": self.discount(state, params)}
info = log_achievements_to_info(state, done)
info["discount"] = self.discount(state, params)

return (
lax.stop_gradient(self.get_obs(state)),
Expand Down

0 comments on commit e1f21bc

Please sign in to comment.