rl
rl copied to clipboard
[BUG] VecNorm.to_observation_norm broken for multiple keys
Describe the bug
The VecNorm transform produces a bug when calling the to_observation_norm method with multiple keys
To Reproduce
gym_env = GymEnv("MountainCarContinuous-v0", device='cpu')
transformed_env = TransformedEnv(gym_env, VecNorm(in_keys=["observation", "reward"]))
transformed_env.rollout(100)
transformed_env.transform[0].to_observation_norm()
Expected behavior
Should return ObservationNorm but gives following error:
...
out += ObservationNorm
TypeError: 'type' object is not iterable
Reason and Possible fixes
Using the VecNorm transform with only one key works - so to do it for multiple keys one can just use it repeatedly with single keys.
Checklist
- [x] I have checked that there is no similar issue in the repo (required)
- [x] I have read the documentation (required)
- [x] I have provided a minimal working example to reproduce the bug (required)
Another bug here:
When using the VecNorm transform with only one in_key, but a key that isn't a pure string, to_observation_norm also fails. There is an easy fix for this: the to_observation_norm method is missing a call to key = self._key_str(key)
. I will create a pull request to add this if that's okay with you.
An example of this situation might occur for instance in the multiagent setting, where the observations might be stored under the key ("agents", "observation")
.