Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Environment.wraps signature now has correct arguments #67

Merged
merged 2 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion helx/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# file generated by setuptools_scm
# don't change, don't track in version control
__version__ = "1.1.4"
__version__ = "1.1.5"
__version_info__ = tuple(int(i) for i in __version__.split(".") if i.isdigit())
7 changes: 7 additions & 0 deletions helx/base/mdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from jax import Array
import jax.numpy as jnp
import jax.tree_util as jtu
from flax import struct


Expand All @@ -42,3 +43,9 @@ class Timestep(struct.PyTreeNode):
"""The true state of the MDP, $s_t$ before taking action `action`"""
info: Dict[str, Any] = struct.field(default_factory=dict)
"""Additional information about the environment. Useful for accumulations (e.g. returns)"""

def __getitem__(self, key: Any) -> Timestep:
return jtu.tree_map(lambda x: x[key], self)

def __setitem__(self, key: Any, value: Any) -> Timestep:
return jtu.tree_map(lambda x: x.at[key].set(value), self)
4 changes: 2 additions & 2 deletions helx/envs/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def step(
class EnvironmentWrapper(Environment):
env: Any = struct.field(pytree_node=False)

@abc.abstractmethod
def wraps(self, env: Any) -> Timestep:
@abc.abstractclassmethod
def wraps(cls, env: Any) -> EnvironmentWrapper:
raise NotImplementedError()

def unwrapped(self) -> Any:
Expand Down
Loading