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

[BugFix] RewardSum key check #1718

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Changes from 1 commit
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
Next Next commit
amend
  • Loading branch information
matteobettini committed Nov 28, 2023
commit b935c893acdabe2202f85b50d63195a732367794
13 changes: 10 additions & 3 deletions torchrl/envs/transforms/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4692,6 +4692,7 @@ def __init__(
"""Initialises the transform. Filters out non-reward input keys and defines output keys."""
super().__init__(in_keys=in_keys, out_keys=out_keys)
self._reset_keys = reset_keys
self._keys_checked = False

@property
def in_keys(self):
Expand Down Expand Up @@ -4770,9 +4771,7 @@ def _check_match(reset_keys, in_keys):
return False
return True

if len(reset_keys) != len(self.in_keys) or not _check_match(
reset_keys, self.in_keys
):
if not _check_match(reset_keys, self.in_keys):
raise ValueError(
f"Could not match the env reset_keys {reset_keys} with the {type(self)} in_keys {self.in_keys}. "
f"Please provide the reset_keys manually. Reset entries can be "
Expand All @@ -4781,6 +4780,14 @@ def _check_match(reset_keys, in_keys):
)
reset_keys = copy(reset_keys)
self._reset_keys = reset_keys

if not self._keys_checked and len(reset_keys) != len(self.in_keys):
raise ValueError(
f"Could not match the env reset_keys {reset_keys} with the {type(self)} in_keys {self.in_keys}. "
"Please make sure that these have the same length."
)
self._keys_checked = True

return reset_keys

@reset_keys.setter
Expand Down
Loading