diff --git a/docs/source/_static/img/rename_transform.png b/docs/source/_static/img/rename_transform.png new file mode 100644 index 00000000000..3de518362cd Binary files /dev/null and b/docs/source/_static/img/rename_transform.png differ diff --git a/docs/source/reference/envs.rst b/docs/source/reference/envs.rst index 9527baaf36c..afef09aa312 100644 --- a/docs/source/reference/envs.rst +++ b/docs/source/reference/envs.rst @@ -722,6 +722,9 @@ Since each transform uses a ``"in_keys"``/``"out_keys"`` set of keyword argument also easy to root the transform graph to each component of the observation data (e.g. pixels or states etc). +Forward and inverse transforms +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Transforms also have an ``inv`` method that is called before the action is applied in reverse order over the composed transform chain: this allows to apply transforms to data in the environment before the action is taken @@ -733,6 +736,20 @@ in the environment. The keys to be included in this inverse transform are passed >>> env.append_transform(DoubleToFloat(in_keys_inv=["action"])) # will map the action from float32 to float64 before calling the base_env.step +The way ``in_keys`` relates to ``in_keys_inv`` can be understood by considering the base environment as the "inner" part +of the transform. In constrast, the user inputs and outputs to and from the transform are to be considered as the +outside world. The following figure shows what this means in practice for the :class:`~torchrl.envs.RenameTransform` +class: the input ``TensorDict`` of the ``step`` function must have the ``out_keys_inv`` listed in its entries as they +are part of the outside world. The transform changes these names to make them match the names of the inner, base +environment using the ``in_keys_inv``. The inverse process is executed with the output tensordict, where the ``in_keys`` +are mapped to the corresponding ``out_keys``. + +.. figure:: /_static/img/rename_transform.png + + Rename transform logic + + + Cloning transforms ~~~~~~~~~~~~~~~~~~