Using transformations and custom environment with own rand_action? #2828
-
I have a custom environment based on torchrl.env.EnvBase. In the corresponding sublasss of EnvBase I have defined a specific rand_action method, which does some masking in the action_space. Now I want to use torchrl.envs.ObservationNorm which supports the initialization of stats (loc, scale) based on a roll-out with a given number of steps. The roll-out in turn calls rand_action. I now do observe that when applying the transformation to my environment, the transformations always has the type torchrl.envs.TransformedEnv and thus the init_stats method calls the generic rand_action method - this is not what I want. Subclassing TransformedEnv does not seem a feasible path because when applying a transformation, then the parent environment always results in a vanilla TransformedEnv (_EEvPostInit). Question: how can I achieve that the specific rand_action method of my custom_environment is called when doing init_stats for ObservationNorm attached to my base environment? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Thanks for raising this!
I guess this is the line where the dummy rollout is gathered: rl/torchrl/envs/transforms/transforms.py Line 3130 in f4713f9 In theory the rand_action of your env should be called unless you have a transform that affects the action: rl/torchrl/envs/transforms/transforms.py Lines 1059 to 1081 in f4713f9 Do you have such transform?
Ah never thought about that. This kind of things is a bit hard to handle, because you could have a |
Beta Was this translation helpful? Give feedback.
Thanks for raising this!
I guess this is the line where the dummy rollout is gathered:
rl/torchrl/envs/transforms/transforms.py
Line 3130 in f4713f9
In theory the rand_action of your env should be called unless you have a transform that affects the action:
rl/torchrl/envs/transforms/transforms.py
Lines 1059 to 1081 in f4713f9