Skip to content

Commit ee23ad3

Browse files
araffinCopilot
andauthored
doc: switch to Markdown (MyST parser) (#324)
* doc: switch to Markdown (MyST parser) * Fix mypy error * Fix typos and missing requirement for rtd * Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent e03aa1e commit ee23ad3

30 files changed

Lines changed: 1973 additions & 2091 deletions

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Stable Baselines3 Contrib Documentation
1+
# Stable Baselines3 Contrib Documentation
22

33
This folder contains documentation for the RL baselines contribution repository.
44

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
.. _th_layers:
1+
(th-layers)=
22

3-
Torch Layers
4-
============
3+
# Torch Layers
54

5+
```{eval-rst}
66
.. automodule:: sb3_contrib.common.torch_layers
77
:members:
8+
```
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
.. _utils:
1+
(utils)=
22

3-
Utils
4-
=====
3+
# Utils
54

5+
```{eval-rst}
66
.. automodule:: sb3_contrib.common.utils
77
:members:
8+
```

docs/common/wrappers.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(wrappers)=
2+
3+
# Gym Wrappers
4+
5+
Additional [Gymnasium Wrappers](https://gymnasium.farama.org/api/wrappers/) to enhance Gymnasium environments.
6+
7+
```{eval-rst}
8+
.. automodule:: sb3_contrib.common.wrappers
9+
10+
```
11+
12+
## TimeFeatureWrapper
13+
14+
```{eval-rst}
15+
.. autoclass:: TimeFeatureWrapper
16+
:members:
17+
```

docs/common/wrappers.rst

Lines changed: 0 additions & 15 deletions
This file was deleted.

docs/conda_env.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ dependencies:
1818
- sphinx>=5,<8
1919
- sphinx_rtd_theme>=1.3.0
2020
- sphinx_copybutton
21+
- myst-parser>=4,<6

docs/conf.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"sphinx.ext.viewcode",
7171
# 'sphinx.ext.intersphinx',
7272
# 'sphinx.ext.doctest'
73+
"myst_parser",
7374
]
7475

7576
autodoc_typehints = "description"
@@ -86,8 +87,7 @@
8687
# The suffix(es) of source filenames.
8788
# You can specify multiple suffix as a list of string:
8889
#
89-
# source_suffix = ['.rst', '.md']
90-
source_suffix = ".rst"
90+
source_suffix = [".rst", ".md"]
9191

9292
# The master toctree document.
9393
master_doc = "index"
@@ -102,7 +102,7 @@
102102
# List of patterns, relative to source directory, that match files and
103103
# directories to ignore when looking for source files.
104104
# This pattern also affects html_static_path and html_extra_path .
105-
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
105+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "README.md"]
106106

107107
# The name of the Pygments (syntax highlighting) style to use.
108108
pygments_style = "sphinx"
@@ -200,6 +200,25 @@ def setup(app):
200200

201201
# -- Extension configuration -------------------------------------------------
202202

203+
myst_heading_anchors = 4
204+
# See: https://myst-parser.readthedocs.io/en/latest/syntax/optional.html
205+
myst_enable_extensions = [
206+
# "amsmath",
207+
"attrs_inline",
208+
"colon_fence",
209+
"deflist",
210+
"dollarmath",
211+
"fieldlist",
212+
# "html_admonition",
213+
"html_image",
214+
# "linkify",
215+
# "replacements",
216+
# "smartquotes",
217+
# "strikethrough",
218+
"substitution",
219+
# "tasklist",
220+
]
221+
203222
# Example configuration for intersphinx: refer to the Python standard library.
204223
# intersphinx_mapping = {
205224
# 'python': ('https://docs.python.org/3/', None),

docs/guide/algos.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# RL Algorithms
2+
3+
This table displays the rl algorithms that are implemented in the Stable Baselines3 contrib project,
4+
along with some useful characteristics: support for discrete/continuous actions, multiprocessing.
5+
6+
| Name | `Box` | `Discrete` | `MultiDiscrete` | `MultiBinary` | Multi Processing |
7+
| ------------ | ----- | ---------- | --------------- | ------------- | ---------------- |
8+
| ARS | ✔️ | ❌️ ||| ✔️ |
9+
| MaskablePPO || ✔️ | ✔️ | ✔️ | ✔️ |
10+
| CrossQ | ✔️ |||| ✔️ |
11+
| QR-DQN || ✔️ ||| ✔️ |
12+
| RecurrentPPO | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
13+
| TQC | ✔️ |||| ✔️ |
14+
| TRPO | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
15+
16+
:::{note}
17+
`Tuple` observation spaces are not supported by any environment,
18+
however, single-level `Dict` spaces are supported.
19+
:::
20+
21+
Actions `gym.spaces`:
22+
23+
- `Box`: A N-dimensional box that contains every point in the action
24+
space.
25+
- `Discrete`: A list of possible actions, where each timestep only
26+
one of the actions can be used.
27+
- `MultiDiscrete`: A list of possible actions, where each timestep only one action of each discrete set can be used.
28+
- `MultiBinary`: A list of possible actions, where each timestep any of the actions can be used in any combination.

docs/guide/algos.rst

Lines changed: 0 additions & 32 deletions
This file was deleted.

docs/guide/examples.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
(examples)=
2+
3+
# Examples
4+
5+
## TQC
6+
7+
Train a Truncated Quantile Critics (TQC) agent on the Pendulum environment.
8+
9+
```python
10+
from sb3_contrib import TQC
11+
12+
model = TQC("MlpPolicy", "Pendulum-v1", top_quantiles_to_drop_per_net=2, verbose=1)
13+
model.learn(total_timesteps=10_000, log_interval=4)
14+
model.save("tqc_pendulum")
15+
```
16+
17+
## QR-DQN
18+
19+
Train a Quantile Regression DQN (QR-DQN) agent on the CartPole environment.
20+
21+
```python
22+
from sb3_contrib import QRDQN
23+
24+
policy_kwargs = dict(n_quantiles=50)
25+
model = QRDQN("MlpPolicy", "CartPole-v1", policy_kwargs=policy_kwargs, verbose=1)
26+
model.learn(total_timesteps=10_000, log_interval=4)
27+
model.save("qrdqn_cartpole")
28+
```
29+
30+
## MaskablePPO
31+
32+
Train a PPO with invalid action masking agent on a toy environment.
33+
34+
:::{warning}
35+
You must use `MaskableEvalCallback` from `sb3_contrib.common.maskable.callbacks` instead of the base `EvalCallback` to properly evaluate a model with action masks.
36+
Similarly, you must use `evaluate_policy` from `sb3_contrib.common.maskable.evaluation` instead of the SB3 one.
37+
:::
38+
39+
```python
40+
from sb3_contrib import MaskablePPO
41+
from sb3_contrib.common.envs import InvalidActionEnvDiscrete
42+
43+
env = InvalidActionEnvDiscrete(dim=80, n_invalid_actions=60)
44+
model = MaskablePPO("MlpPolicy", env, verbose=1)
45+
model.learn(5000)
46+
model.save("maskable_toy_env")
47+
```
48+
49+
## TRPO
50+
51+
Train a Trust Region Policy Optimization (TRPO) agent on the Pendulum environment.
52+
53+
```python
54+
from sb3_contrib import TRPO
55+
56+
model = TRPO("MlpPolicy", "Pendulum-v1", gamma=0.9, verbose=1)
57+
model.learn(total_timesteps=100_000, log_interval=4)
58+
model.save("trpo_pendulum")
59+
```
60+
61+
## ARS
62+
63+
Train an agent using Augmented Random Search (ARS) agent on the Pendulum environment
64+
65+
```python
66+
from sb3_contrib import ARS
67+
68+
model = ARS("LinearPolicy", "Pendulum-v1", verbose=1)
69+
model.learn(total_timesteps=10000, log_interval=4)
70+
model.save("ars_pendulum")
71+
```
72+
73+
## RecurrentPPO
74+
75+
Train a PPO agent with a recurrent policy on the CartPole environment.
76+
77+
:::{note}
78+
It is particularly important to pass the `lstm_states`
79+
and `episode_start` argument to the `predict()` method,
80+
so the cell and hidden states of the LSTM are correctly updated.
81+
:::
82+
83+
```python
84+
import numpy as np
85+
86+
from sb3_contrib import RecurrentPPO
87+
88+
model = RecurrentPPO("MlpLstmPolicy", "CartPole-v1", verbose=1)
89+
model.learn(5000)
90+
91+
vec_env = model.get_env()
92+
obs = vec_env.reset()
93+
# Cell and hidden state of the LSTM
94+
lstm_states = None
95+
num_envs = 1
96+
# Episode start signals are used to reset the lstm states
97+
episode_starts = np.ones((num_envs,), dtype=bool)
98+
while True:
99+
action, lstm_states = model.predict(obs, state=lstm_states, episode_start=episode_starts, deterministic=True)
100+
# Note: vectorized environment resets automatically
101+
obs, rewards, dones, info = vec_env.step(action)
102+
episode_starts = dones
103+
vec_env.render("human")
104+
```
105+
106+
## CrossQ
107+
108+
Train a CrossQ agent on the Pendulum environment.
109+
110+
```python
111+
from sb3_contrib import CrossQ
112+
113+
model = CrossQ(
114+
"MlpPolicy",
115+
"Pendulum-v1",
116+
verbose=1,
117+
policy_kwargs=dict(
118+
net_arch=dict(
119+
pi=[256, 256],
120+
qf=[1024, 1024],
121+
)
122+
),
123+
)
124+
model.learn(total_timesteps=5_000, log_interval=4)
125+
model.save("crossq_pendulum")
126+
```

0 commit comments

Comments
 (0)