Skip to content

Commit 3e7e4b3

Browse files
authored
[Doc] Create your pendulum tutorial (#911)
1 parent 79c13a1 commit 3e7e4b3

File tree

25 files changed

+1435
-409
lines changed

25 files changed

+1435
-409
lines changed

.circleci/docs/setup_env.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#apt-get update -y
2+
#apt-get install software-properties-common -y
3+
#add-apt-repository ppa:git-core/candidate -y
4+
#apt-get update -y
5+
#apt-get upgrade -y
6+
#apt-get -y install libglfw3 libglew2.0 gcc curl g++ unzip \
7+
# wget sudo git cmake libz-dev \
8+
# zlib1g-dev python3.8 python3-pip ninja
9+
10+
#yum install -y mesa-libGL freeglut egl-utils glew glfw
11+
#yum install -y glew glfw
12+
apt-get update && apt-get install -y git wget gcc g++
13+
14+
root_dir="$(pwd)"
15+
conda_dir="${root_dir}/conda"
16+
env_dir="${root_dir}/env"
17+
18+
os=Linux
19+
20+
# 1. Install conda at ./conda
21+
printf "* Installing conda\n"
22+
wget -O miniconda.sh "http://repo.continuum.io/miniconda/Miniconda3-latest-${os}-x86_64.sh"
23+
bash ./miniconda.sh -b -f -p "${conda_dir}"
24+
25+
eval "$(${conda_dir}/bin/conda shell.bash hook)"
26+
27+
printf "* Creating a test environment\n"
28+
conda create --prefix "${env_dir}" -y python="$PYTHON_VERSION"
29+
30+
printf "* Activating\n"
31+
conda activate "${env_dir}"
32+
33+
conda install -c conda-forge zlib -y
34+
35+
pip3 install --upgrade pip --quiet --root-user-action=ignore
36+
37+
printf "python version\n"
38+
python --version
39+
40+
pip3 install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cu118 --quiet --root-user-action=ignore
41+
#pip3 install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu --quiet --root-user-action=ignore
42+
43+
printf "Installing tensordict\n"
44+
pip3 install git+https://github.com/pytorch-labs/tensordict.git --quiet --root-user-action=ignore
45+
46+
printf "Installing torchrl\n"
47+
pip3 install -e . --quiet --root-user-action=ignore
48+
49+
printf "Installing requirements\n"
50+
pip3 install -r docs/requirements.txt --quiet --root-user-action=ignore
51+
printf "Installed all dependencies\n"
52+
53+
printf "smoke test\n"
54+
PYOPENGL_PLATFORM=egl MUJOCO_GL=egl python3 -c """from torchrl.envs.libs.dm_control import DMControlEnv
55+
print(DMControlEnv('cheetah', 'run').reset())
56+
"""
57+
58+
printf "building docs...\n"
59+
cd ./docs
60+
#timeout 7m bash -ic "MUJOCO_GL=egl sphinx-build SPHINXOPTS=-v ./source _local_build" || code=$?; if [[ $code -ne 124 && $code -ne 0 ]]; then exit $code; fi
61+
PYOPENGL_PLATFORM=egl MUJOCO_GL=egl sphinx-build ./source _local_build
62+
cd ..
63+
printf "done!\n"
64+
65+
git clone --branch gh-pages https://github.com/pytorch-labs/tensordict.git docs/_local_build/tensordict
66+
rm -rf docs/_local_build/tensordict/.git

.circleci/unittest/linux_libs/scripts_habitat/install.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ unset PYTORCH_VERSION
55
# so no need to set PYTORCH_VERSION.
66
# In fact, keeping PYTORCH_VERSION forces us to hardcode PyTorch version in config.
77
apt-get update && apt-get install -y git wget gcc g++
8+
#apt-get update && apt-get install -y git wget freeglut3 freeglut3-dev
89

910
set -e
1011

.github/workflows/docs.yml

Lines changed: 34 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -10,91 +10,53 @@ on:
1010
workflow_dispatch:
1111
jobs:
1212
build_docs_job:
13+
strategy:
14+
matrix:
15+
python_version: ["3.8"] # "3.8", "3.9", "3.10", "3.11"
16+
cuda_arch_version: ["11.8"] # "11.6", "11.7"
17+
fail-fast: false
18+
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
19+
with:
20+
runner: linux.g5.4xlarge.nvidia.gpu
21+
repository: pytorch/rl
22+
gpu-arch-type: cuda
23+
gpu-arch-version: ${{ matrix.cuda_arch_version }}
24+
docker-image: nvidia/cudagl:11.4.0-base
25+
timeout: 45
26+
script: |
27+
# Set env vars from matrix
28+
export PYTHON_VERSION=${{ matrix.python_version }}
29+
# Commenting these out for now because the GPU test are not working inside docker
30+
export CUDA_ARCH_VERSION=${{ matrix.cuda_arch_version }}
31+
export CU_VERSION="cu${CUDA_ARCH_VERSION:0:2}${CUDA_ARCH_VERSION:3:1}"
32+
# Remove the following line when the GPU tests are working inside docker, and uncomment the above lines
33+
#export CU_VERSION="cpu"
34+
35+
echo "PYTHON_VERSION: $PYTHON_VERSION"
36+
echo "CU_VERSION: $CU_VERSION"
37+
38+
cd /work
39+
40+
## setup_env.sh
41+
./.circleci/docs/setup_env.sh
42+
43+
deploy:
44+
needs: build_docs_job
1345
runs-on: ubuntu-20.04
1446
strategy:
1547
matrix:
1648
include:
17-
- os: linux.4xlarge.nvidia.gpu
49+
- os: linux.12xlarge
1850
python-version: 3.8
1951
defaults:
2052
run:
2153
shell: bash -l {0}
2254
container: nvidia/cuda:11.8.0-cudnn8-devel-ubuntu18.04
2355
steps:
24-
- name: Install deps
25-
run: |
26-
apt-get update -y
27-
apt-get install software-properties-common -y
28-
add-apt-repository ppa:git-core/candidate -y
29-
apt-get update -y
30-
apt-get upgrade -y
31-
apt-get -y install libglu1-mesa libgl1-mesa-glx libosmesa6 gcc curl g++ unzip wget libglfw3-dev libgles2-mesa-dev libglew-dev sudo git cmake libz-dev
32-
- name: Install rsync 📚
33-
run: |
34-
apt-get update && apt-get install -y rsync
35-
- name: Check ldd --version
36-
run: ldd --version
3756
- name: Checkout
3857
uses: actions/checkout@v3
39-
# Update references
40-
- name: Update pip
41-
run: |
42-
apt-get install python3.8 python3-pip -y
43-
pip3 install --upgrade pip
44-
- name: Setup conda
45-
run: |
46-
rm -rf $HOME/miniconda
47-
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh
48-
bash ~/miniconda.sh -b -p $HOME/miniconda
49-
- name: setup Path
50-
run: |
51-
echo "$HOME/miniconda/bin" >> $GITHUB_PATH
52-
echo "CONDA=$HOME/miniconda" >> $GITHUB_PATH
53-
- name: create and activate conda env
54-
run: |
55-
$HOME/miniconda/bin/conda create --name build_binary python=${{ matrix.python-version }}
56-
$HOME/miniconda/bin/conda info
57-
$HOME/miniconda/bin/activate build_binary
58-
- name: check python version
59-
run: |
60-
python --version
61-
- name: Check git version
62-
run: git version
63-
- name: setup Path
64-
run: |
65-
echo /usr/local/bin >> $GITHUB_PATH
66-
- name: Install PyTorch
67-
shell: bash
68-
run: |
69-
python -m pip install --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
70-
- name: Install tensordict
71-
run: |
72-
python3 -m pip install git+https://github.com/pytorch-labs/tensordict.git
73-
- name: Install TorchRL
74-
run: |
75-
python -m pip install -e .
76-
- name: Test torchrl installation
77-
shell: bash
78-
run: |
79-
mkdir _tmp
80-
cd _tmp
81-
python -c "import torchrl;from torchrl.envs.libs.dm_control import DMControlEnv"
82-
cd ..
83-
- name: Build the docset
84-
id: build_doc
85-
run: |
86-
python -m pip install -r docs/requirements.txt
87-
cd ./docs
88-
timeout 7m bash -ic "MUJOCO_GL=egl sphinx-build ./source _local_build" || code=$?; if [[ $code -ne 124 && $code -ne 0 ]]; then exit $code; fi
89-
cd ..
90-
- name: Pull TensorDict docs
91-
run: |
92-
git clone --branch gh-pages https://github.com/pytorch-labs/tensordict.git docs/_local_build/tensordict
93-
rm -rf docs/_local_build/tensordict/.git
94-
- name: Get output time
95-
run: echo "The time was ${{ steps.build.outputs.time }}"
9658
- name: Deploy
97-
if: ${{ github.ref == 'refs/heads/main' }}
59+
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' }}
9860
uses: JamesIves/github-pages-deploy-action@releases/v4
9961
with:
10062
token: ${{ secrets.GITHUB_TOKEN }}

docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# You can set these variables from the command line, and also
55
# from the environment for the first two.
6-
SPHINXOPTS ?=
6+
SPHINXOPTS = -v
77
SPHINXBUILD ?= sphinx-build
88
SOURCEDIR = source
99
BUILDDIR = build

docs/requirements.txt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ sphinxcontrib-htmlhelp
1212
myst-parser
1313
docutils
1414

15-
functorch
16-
gym[classic_control]
1715
torchvision
1816
dm_control
1917
atari-py
2018
ale-py
21-
gym[accept-rom-license]
19+
gym[classic_control,accept-rom-license]
2220
pygame
2321
tqdm
2422
ipython
25-
imageio
26-
imageio[ffmpeg]
27-
imageio[pyav]
23+
imageio[ffmpeg,pyav]
24+
memory_profiler
25+
pyrender

docs/source/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@
8888
"filename_pattern": "reference/generated/tutorials/", # files to parse
8989
"notebook_images": "reference/generated/tutorials/media/", # images to parse
9090
"download_all_examples": True,
91+
"abort_on_example_error": False,
92+
"only_warn_on_example_error": True,
93+
"show_memory": True,
9194
}
9295

9396
napoleon_use_ivar = True

docs/source/index.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,19 @@ Basics
3434
------
3535

3636
.. toctree::
37-
:maxdepth: 2
37+
:maxdepth: 1
3838

39-
tutorials/torchrl_demo
4039
tutorials/coding_ppo
40+
tutorials/pendulum
4141
tutorials/tensordict_tutorial
4242
tutorials/tensordict_module
43+
tutorials/torchrl_demo
4344

4445
Intermediate
4546
------------
4647

4748
.. toctree::
48-
:maxdepth: 2
49+
:maxdepth: 1
4950

5051
tutorials/torch_envs
5152
tutorials/pretrained_models
@@ -54,7 +55,7 @@ Advanced
5455
--------
5556

5657
.. toctree::
57-
:maxdepth: 2
58+
:maxdepth: 1
5859

5960
tutorials/multi_task
6061
tutorials/coding_ddpg

docs/source/reference/trainers.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,40 @@ The :obj:`trainer.train()` method can be sketched as follows:
1414
.. code-block::
1515
:caption: Trainer loops
1616
17+
>>> for batch in collector:
18+
... batch = self._process_batch_hook(batch) # "batch_process"
19+
... self._pre_steps_log_hook(batch) # "pre_steps_log"
20+
... self._pre_optim_hook() # "pre_optim_steps"
21+
... for j in range(self.optim_steps_per_batch):
22+
... sub_batch = self._process_optim_batch_hook(batch) # "process_optim_batch"
23+
... losses = self.loss_module(sub_batch)
24+
... self._post_loss_hook(sub_batch) # "post_loss"
25+
... self.optimizer.step()
26+
... self.optimizer.zero_grad()
27+
... self._post_optim_hook() # "post_optim"
28+
... self._post_optim_log(sub_batch) # "post_optim_log"
29+
... self._post_steps_hook() # "post_steps"
30+
... self._post_steps_log_hook(batch) # "post_steps_log"
31+
32+
There are 10 hooks that can be used in a trainer loop:
33+
34+
>>> for batch in collector:
35+
... batch = self._process_batch_hook(batch) # "batch_process"
36+
... self._pre_steps_log_hook(batch) # "pre_steps_log"
37+
... self._pre_optim_hook() # "pre_optim_steps"
38+
... for j in range(self.optim_steps_per_batch):
39+
... sub_batch = self._process_optim_batch_hook(batch) # "process_optim_batch"
40+
... losses = self.loss_module(sub_batch)
41+
... self._post_loss_hook(sub_batch) # "post_loss"
42+
... self.optimizer.step()
43+
... self.optimizer.zero_grad()
44+
... self._post_optim_hook() # "post_optim"
45+
... self._post_optim_log(sub_batch) # "post_optim_log"
46+
... self._post_steps_hook() # "post_steps"
47+
... self._post_steps_log_hook(batch) # "post_steps_log"
48+
49+
There are 10 hooks that can be used in a trainer loop:
50+
1751
>>> for batch in collector:
1852
... batch = self._process_batch_hook(batch) # "batch_process"
1953
... self._pre_steps_log_hook(batch) # "pre_steps_log"

knowledge_base/MUJOCO_INSTALLATION.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,23 @@ issues when running `import mujoco_py` and some troubleshooting for each of them
129129
#include <GL/glew.h>
130130
^~~~~~~~~~~
131131
```
132+
132133
_Solution_: make sure glew is installed (see above: `conda install -c conda-forge glew` or the `apt-get` version of it).
133134
2.
134135
```
135136
include/GL/glu.h:38:10: fatal error: GL/gl.h: No such file or directory
136137
#include <GL/gl.h>
137138
^~~~~~~~~
138139
```
140+
139141
_Solution_: This should disappear once `mesalib` is installed: `conda install -y -c conda-forge mesalib`
140-
3.
142+
4.
141143
```
142144
FileNotFoundError: [Errno 2] No such file or directory: 'patchelf'
143145
```
144146
145-
_Solution_: `pip install patchelf`
146-
4.
147+
_Solution_: `pip install patchelf`
148+
5.
147149
```
148150
ImportError: /usr/lib/x86_64-linux-gnu/libOpenGL.so.0: undefined symbol: _glapi_tls_Current
149151
```
@@ -155,7 +157,7 @@ issues when running `import mujoco_py` and some troubleshooting for each of them
155157
conda env config vars set LD_PRELOAD=/path/to/conda/envs/mujoco_env/x86_64-conda-linux-gnu/sysroot/usr/lib64/libGLdispatch.so.0
156158
```
157159
158-
5.
160+
6.
159161
```
160162
mujoco.FatalError: gladLoadGL error
161163
@@ -166,6 +168,7 @@ issues when running `import mujoco_py` and some troubleshooting for each of them
166168
167169
168170
**Sanity check**
171+
169172
To check that your mujoco-py has been built against the GPU, run
170173
```python
171174
>>> import mujoco_py
@@ -191,17 +194,18 @@ RuntimeError: Failed to initialize OpenGL
191194
192195
2. Rendered images are completely black.
193196

194-
> Make sure to call `env.render()` before reading the pixels.
197+
_Solution_: Make sure to call `env.render()` before reading the pixels.
195198

196199
3. `patchelf` dependency is missing.
197200

198-
> Install using `conda install patchelf` or `pip install patchelf`
201+
_Solution_: Install using `conda install patchelf` or `pip install patchelf`
199202

200203
4. Errors like "Onscreen rendering needs 101 device"
201204

202-
> Make sure to set `DISPLAY` environment variable correctly.
205+
_Solution_: Make sure to set `DISPLAY` environment variable correctly.
203206

204207
5. `ImportError: Cannot initialize a headless EGL display.`
205-
Make sure you have installed mujoco and all its dependencies (see instructions above).
206-
Make sure you have set the `MUJOCO_GL=egl`.
207-
Make sure you have a GPU accessible on your machine.
208+
209+
_Solution_: Make sure you have installed mujoco and all its dependencies (see instructions above).
210+
Make sure you have set the `MUJOCO_GL=egl`.
211+
Make sure you have a GPU accessible on your machine.

0 commit comments

Comments
 (0)