You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The docstring of Transform._call() says it will be called by TransformedEnv.step() and TransformedEnv.reset(). However, resetting the transformed environment does not trigger _call().
To Reproduce
fromtensordictimportTensorDictBasefromtorchrl.envs.transformsimportTransform, TransformedEnvfromtorchrl.envsimportGymEnvclassPrintHiTransform(Transform):
def_call(self, tensordict: TensorDictBase) ->TensorDictBase:
print("Hi")
returntensordictenv=GymEnv("Pendulum-v1")
env=TransformedEnv(env, PrintHiTransform())
print("Calling env.reset()")
initial_state=env.reset() # Does NOT print "Hi"action=env.rand_action(initial_state)
print("Calling env.step()")
env.step(action) # Prints "Hi" as desired
0.6.0 2.0.2 3.9.20 | packaged by conda-forge | (main, Sep 30 2024, 17:49:10)
[GCC 13.3.0] linux
Possible fix
I would fix this by changing Transform._reset().
def_reset(self, tensordict: TensorDictBase, tensordict_reset: TensorDictBase) ->TensorDictBase:
"""Resets a transform if it is stateful."""returnself._call(tensordict_reset) # Was before: return tensordict_reset
Maybe there's a good reason why this is not the case, but to me it seems inconsistent: Why should _step call _call but _reset does not?
The text was updated successfully, but these errors were encountered:
Describe the bug
The docstring of
Transform._call()
says it will be called byTransformedEnv.step()
andTransformedEnv.reset()
. However, resetting the transformed environment does not trigger_call()
.To Reproduce
System info
Describe the characteristic of your environment:
0.6.0 2.0.2 3.9.20 | packaged by conda-forge | (main, Sep 30 2024, 17:49:10)
[GCC 13.3.0] linux
Possible fix
I would fix this by changing
Transform._reset()
.Maybe there's a good reason why this is not the case, but to me it seems inconsistent: Why should
_step
call_call
but_reset
does not?The text was updated successfully, but these errors were encountered: