Skip to content

Commit d65c4c6

Browse files
authored
[Doc] Minor doc improvements (#907)
1 parent e1620eb commit d65c4c6

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

docs/source/reference/envs.rst

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ Some libraries such as `gym3 <https://github.com/openai/gym3>`_ or `EnvPool <htt
7272
offer interfaces to execute batches of environments simultaneously.
7373
While they often offer a very competitive computational advantage, they do not
7474
necessarily scale to the wide variety of environment libraries supported by TorchRL.
75-
Therefore, TorchRL offers its own, generic :obj:`ParallelEnv` class to run multiple
75+
Therefore, TorchRL offers its own, generic :class:`ParallelEnv` class to run multiple
7676
environments in parallel.
77-
As this class inherits from :obj:`EnvBase`, it enjoys the exact same API as other environment.
78-
Of course, a :obj:`ParallelEnv` will have a batch size that corresponds to its environment count:
77+
As this class inherits from :class:`SerialEnv`, it enjoys the exact same API as other environment.
78+
Of course, a :class:`ParallelEnv` will have a batch size that corresponds to its environment count:
7979

8080
It is important that your environment specs match the input and output that it sends and receives, as
81-
:obj:`ParallelEnv` will create buffers from these specs to communicate with the spawn processes.
82-
Check the :obj:`torchrl.envs.utils.check_env_specs` method for a sanity check.
81+
:class:`ParallelEnv` will create buffers from these specs to communicate with the spawn processes.
82+
Check the :func:`torchrl.envs.utils.check_env_specs` method for a sanity check.
8383

8484
.. code-block::
8585
:caption: Parallel environment
@@ -91,7 +91,7 @@ Check the :obj:`torchrl.envs.utils.check_env_specs` method for a sanity check.
9191
>>> print(env.batch_size)
9292
torch.Size([4])
9393
94-
:obj:`ParallelEnv` allows to retrieve the attributes from its contained environments:
94+
:class:`ParallelEnv` allows to retrieve the attributes from its contained environments:
9595
one can simply call:
9696

9797
.. code-block::
@@ -118,29 +118,29 @@ It is also possible to reset some but not all of the environments:
118118
is_shared=True)
119119
120120
121-
*A note on performance*: launching a :obj:`ParallelEnv` can take quite some time
121+
*A note on performance*: launching a :class:`ParallelEnv` can take quite some time
122122
as it requires to launch as many python instances as there are processes. Due to
123-
the time that it takes to run :obj:`import torch` (and other imports), starting the
123+
the time that it takes to run ``import torch`` (and other imports), starting the
124124
parallel env can be a bottleneck. This is why, for instance, TorchRL tests are so slow.
125125
Once the environment is launched, a great speedup should be observed.
126126

127-
Another thing to take in consideration is that :obj:`ParallelEnv`s (as well as data collectors)
127+
Another thing to take in consideration is that :class:`ParallelEnv`s (as well as data collectors)
128128
will create data buffers based on the environment specs to pass data from one process
129129
to another. This means that a misspecified spec (input, observation or reward) will
130130
cause a breakage at runtime as the data can't be written on the preallocated buffer.
131131
In general, an environment should be tested using the :obj:`check_env_specs`
132-
test function before being used in a :obj:`ParallelEnv`. This function will raise
132+
test function before being used in a :class:`ParallelEnv`. This function will raise
133133
an assertion error whenever the preallocated buffer and the collected data mismatch.
134134

135-
We also offer the :obj:`SerialEnv` class that enjoys the exact same API but is executed
135+
We also offer the :class:`SerialEnv` class that enjoys the exact same API but is executed
136136
serially. This is mostly useful for testing purposes, when one wants to assess the
137-
behaviour of a :obj:`ParallelEnv` without launching the subprocesses.
137+
behaviour of a :class:`ParallelEnv` without launching the subprocesses.
138138

139-
In addition to :obj:`ParallelEnv`, which offers process-based parallelism, we also provide a way to create
139+
In addition to :class:`ParallelEnv`, which offers process-based parallelism, we also provide a way to create
140140
multithreaded environments with :obj:`MultiThreadedEnv`. This class uses `EnvPool <https://github.com/sail-sg/envpool>`_
141141
library underneath, which allows for higher performance, but at the same time restricts flexibility - one can only
142142
create environments implemented in `EnvPool`. This covers many popular RL environments types (Atari, Classic Control,
143-
etc.), but one can not use an arbitrary TorchRL environment, as it is possible with :obj:`ParallelEnv`. Run
143+
etc.), but one can not use an arbitrary TorchRL environment, as it is possible with :class:`ParallelEnv`. Run
144144
`benchmarks/benchmark_batched_envs.py` to compare performance of different ways to parallelize batched environments.
145145

146146
.. autosummary::
@@ -161,8 +161,8 @@ In most cases, the raw output of an environment must be treated before being pas
161161
policy or a value operator). To do this, TorchRL provides a set of transforms that aim at reproducing the transform
162162
logic of `torch.distributions.Transform` and `torchvision.transforms`.
163163

164-
Transformed environments are build using the :doc:`TransformedEnv` primitive.
165-
Composed transforms are built using the :doc:`Compose` class:
164+
Transformed environments are build using the :class:`TransformedEnv` primitive.
165+
Composed transforms are built using the :class:`Compose` class:
166166

167167
.. code-block::
168168
:caption: Transformed environment
@@ -179,7 +179,7 @@ operations that is to be computed.
179179

180180
A great advantage of environment wrappers is that one can consult the environment up to that wrapper.
181181
The same can be achieved with TorchRL transformed environments: the :doc:`parent` attribute will
182-
return a new :obj:`TransformedEnv` with all the transforms up to the transform of interest.
182+
return a new :class:`TransformedEnv` with all the transforms up to the transform of interest.
183183
Re-using the example above:
184184

185185
.. code-block::
@@ -213,17 +213,17 @@ in mind that the parent may come and go following what is being done with the tr
213213
Here are some examples: if we get a single transform from a :class:`Compose` object,
214214
this transform will keep its parent:
215215

216-
>>> third_transform = env.transform[2]
217-
>>> assert third_transform.parent is not None
216+
>>> third_transform = env.transform[2]
217+
>>> assert third_transform.parent is not None
218218

219219
This means that using this transform for another environment is prohibited, as
220220
the other environment would replace the parent and this may lead to unexpected
221221
behviours. Fortunately, the :class:`Transform` class comes with a :func:`clone`
222222
method that will erase the parent while keeping the identity of all the
223223
registered buffers:
224224

225-
>>> TransformedEnv(base_env, third_transform) # raises an Exception as third_transform already has a parent
226-
>>> TransformedEnv(base_env, third_transform.clone()) # works
225+
>>> TransformedEnv(base_env, third_transform) # raises an Exception as third_transform already has a parent
226+
>>> TransformedEnv(base_env, third_transform.clone()) # works
227227

228228
On a single process or if the buffers are placed in shared memory, this will
229229
result in all the clone transforms to keep the same behaviour even if the
@@ -237,14 +237,14 @@ indexing a :class:`Compose` transform results in another :class:`Compose` transf
237237
that does not have a parent environment. Hence, we have to clone the sub-transforms
238238
to be able to create this other composition:
239239

240-
>>> env = TransformedEnv(base_env, Compose(transform1, transform2, transform3))
241-
>>> last_two = env.transform[-2:]
242-
>>> assert isinstance(last_two, Compose)
243-
>>> assert last_two.parent is None
244-
>>> assert last_two[0] is not transform2
245-
>>> assert isinstance(last_two[0], transform2) # and the buffers will match
246-
>>> assert last_two[1] is not transform3
247-
>>> assert isinstance(last_two[1], transform3) # and the buffers will match
240+
>>> env = TransformedEnv(base_env, Compose(transform1, transform2, transform3))
241+
>>> last_two = env.transform[-2:]
242+
>>> assert isinstance(last_two, Compose)
243+
>>> assert last_two.parent is None
244+
>>> assert last_two[0] is not transform2
245+
>>> assert isinstance(last_two[0], type(transform2)) # and the buffers will match
246+
>>> assert last_two[1] is not transform3
247+
>>> assert isinstance(last_two[1], type(transform3)) # and the buffers will match
248248

249249
.. autosummary::
250250
:toctree: generated/

0 commit comments

Comments
 (0)