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

recorder_log_keys arg: enable logging of arbitrary keys from test rollouts #212

Merged
merged 5 commits into from
Jun 21, 2022
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
Prev Previous commit
Next Next commit
amend
  • Loading branch information
vmoens committed Jun 21, 2022
commit 852b5d9fac8ab08b7caae872f6c5e5afebf13c4a
11 changes: 11 additions & 0 deletions torchrl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# LICENSE file in the root directory of this source tree.

import abc
import collections
import time
from warnings import warn

Expand Down Expand Up @@ -98,3 +99,13 @@ def seed_generator(seed):
rng = np.random.default_rng(seed)
seed = int.from_bytes(rng.bytes(8), "big")
return seed % max_seed_val


class KeyDependentDefaultDict(collections.defaultdict):
def __init__(self, fun=lambda x: x):
self.fun = fun
super().__init__()

def __missing__(self, key):
value = self.fun(key)
return value