Skip to content

Commit aaac187

Browse files
larsrpeMayankm96
andcommitted
Fixes onpolicy runner to handle intrnsic rewards (#71)
This commit fixes two potential bugs in the Runner: 1: Accessing a dictionary that is None if either alg_cfg["rnd_cfg"] or alg_cfg["symmetry_cfg"] are None. 2: Accessing alg.intrinsic_rewards before it is created in alg.process_env_step(...). Co-authored-by: Mayank Mittal <[email protected]>
1 parent e9b5b12 commit aaac187

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

rsl_rl/runners/on_policy_runner.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self, env: VecEnv, train_cfg: dict, log_dir: str | None = None, dev
4141
).to(self.device)
4242

4343
# resolve dimension of rnd gated state
44-
if "rnd_cfg" in self.alg_cfg and self.alg_cfg["rnd_cfg"] is not None:
44+
if self.alg_cfg.get("rnd_cfg") is not None:
4545
# check if rnd gated state is present
4646
rnd_state = extras["observations"].get("rnd_state")
4747
if rnd_state is None:
@@ -54,7 +54,7 @@ def __init__(self, env: VecEnv, train_cfg: dict, log_dir: str | None = None, dev
5454
self.alg_cfg["rnd_cfg"]["weight"] *= env.dt
5555

5656
# if using symmetry then pass the environment config object
57-
if "symmetry_cfg" in self.alg_cfg and self.alg_cfg["symmetry_cfg"] is not None:
57+
if self.alg_cfg.get("symmetry_cfg") is not None:
5858
# this is used by the symmetry function for handling different observation terms
5959
self.alg_cfg["symmetry_cfg"]["_env"] = env
6060

@@ -161,12 +161,12 @@ def learn(self, num_learning_iterations: int, init_at_random_ep_len: bool = Fals
161161
else:
162162
critic_obs = obs
163163

164-
# Intrinsic rewards (extracted here only for logging)!
165-
intrinsic_rewards = self.alg.intrinsic_rewards if self.alg.rnd else None
166-
167164
# Process env step and store in buffer
168165
self.alg.process_env_step(rewards, dones, infos)
169166

167+
# Intrinsic rewards (extracted here only for logging)!
168+
intrinsic_rewards = self.alg.intrinsic_rewards if self.alg.rnd else None
169+
170170
if self.log_dir is not None:
171171
# Book keeping
172172
if "episode" in infos:

0 commit comments

Comments
 (0)