Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
21e4b15
Initial commit for torchrl documentation using Sphinx. Example script…
Nov 7, 2022
a612058
Addressing two issues (not displaying TorchRL documentation properly …
Nov 8, 2022
e176004
Merge branch 'pytorch:main' into tutorials_py
se-yi Nov 8, 2022
05f61b8
[Doc] Added two new tutorials - tensordict_module.py and multi_task.p…
Nov 9, 2022
7aeee38
tutos
vmoens Nov 9, 2022
5d168b4
Merge pull request #1 from vmoens/tutorials_py2
se-yi Nov 10, 2022
4e37932
Merge branch 'main' of https://github.com/se-yi/rl into tutorials_py
Nov 10, 2022
6b5f755
[Doc] Adding the 3 remaining scripts: coding_ddpg, coding_dqn, and to…
Nov 10, 2022
ab63318
Merge branch 'main' into tutorials_py
vmoens Nov 12, 2022
3337b94
Merge branch 'tutorials_py' of https://github.com/se-yi/rl into tutor…
vmoens Nov 12, 2022
cca8992
faster runs
vmoens Nov 12, 2022
84d36d6
lint and bf
vmoens Nov 13, 2022
8ffb086
lint and bf
vmoens Nov 14, 2022
1d4e2b8
bugfix
vmoens Nov 14, 2022
c0863b0
[Doc] Proofreading torchrl_demo.py script
Nov 15, 2022
c4c7448
Merge branch 'pytorch:main' into tutorials_py
se-yi Nov 15, 2022
3f4fe69
[Doc] Proofreading tensordict_tutorial/tensordict_module scripts
Nov 15, 2022
e83d4b1
Merge branch 'tutorials_py' of https://github.com/se-yi/rl into tutor…
Nov 15, 2022
3e0698b
[Doc] Proofreading multi_task and envs scripts.
Nov 15, 2022
f1bafe6
[Doc] Proofread coding_ddpg/dqn.
Nov 15, 2022
693b6cf
Merge branch 'main' into tutorials_py
vmoens Nov 15, 2022
dd14ff9
minor
vmoens Nov 15, 2022
7eae24f
Merge remote-tracking branch 'refs/remotes/se-yi/tutorials_py' into t…
vmoens Nov 15, 2022
112af7e
bf
vmoens Nov 15, 2022
e405651
lint
vmoens Nov 16, 2022
37db3dc
protobuf==3.20
vmoens Nov 16, 2022
e2f5729
test
vmoens Nov 16, 2022
2266de5
amend
vmoens Nov 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ jobs:
mkdir _tmp
cd _tmp
conda run -n build_binary \
python -c "import torchrl"
python -c "import torchrl;from torchrl.envs.libs.dm_control import DMControlEnv"
cd ..
- name: Build the docset
run: |
conda run -n build_binary python -m pip install -r docs/requirements.txt
cd ./docs
conda run -n build_binary make html
conda run -n build_binary make html SPHINXOPTS="-v"
cd ..
- name: Get output time
run: echo "The time was ${{ steps.build.outputs.time }}"
Expand Down
18 changes: 18 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,21 @@ sphinxcontrib-htmlhelp
-e git+https://github.com/pytorch/pytorch_sphinx_theme.git#egg=pytorch_sphinx_theme
myst-parser>=0.18.1
docutils>=0.19

functorch
gym[classic_control]
torchrl
torchvision
dm_control
gym
atari-py
ale-py
gym[accept-rom-license]
pygame
tqdm
ipython
imageio
imageio[ffmpeg]
imageio[pyav]
-e git+https://github.com/pytorch-labs/tensordict.git@main#egg=tensordict
protobuf==3.20
22 changes: 17 additions & 5 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@
# -- Project information -----------------------------------------------------
import os.path
import sys
import warnings

import pytorch_sphinx_theme
import torchrl

# Suppress warnings - TODO
# suppress_warnings = [ 'misc.highlighting_failure' ]
warnings.filterwarnings("ignore", category=UserWarning)

project = "torchrl"
copyright = "2022, Meta"
author = "Torch Contributors"
Expand All @@ -46,7 +51,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = "en"

# -- General configuration ---------------------------------------------------

Expand All @@ -61,15 +66,16 @@
"sphinx.ext.mathjax",
"sphinx.ext.napoleon",
"sphinx_gallery.gen_gallery",
"sphinxcontrib.aafig",
"myst_parser",
]

sphinx_gallery_conf = {
"examples_dirs": "../../gallery/", # path to your example scripts
"gallery_dirs": "auto_examples", # path to where to save gallery generated output
"examples_dirs": "reference/generated/tutorials/", # path to your example scripts
"gallery_dirs": "tutorials", # path to where to save gallery generated output
"backreferences_dir": "gen_modules/backreferences",
"doc_module": ("torchrl",),
"filename_pattern": "reference/generated/tutorials/", # files to parse
"notebook_images": "reference/generated/tutorials/media/", # images to parse
}

napoleon_use_ivar = True
Expand Down Expand Up @@ -155,6 +161,12 @@
# -- Generate knowledge base references -----------------------------------
current_path = os.path.dirname(os.path.realpath(__file__))
sys.path.append(current_path)
from knowledge_base import generate_knowledge_base_references
from content_generation import (
generate_knowledge_base_references,
generate_tutorial_references,
)

generate_knowledge_base_references("../../knowledge_base")
generate_tutorial_references("../../tutorials/sphinx-tutorials/", "tutorial")
generate_tutorial_references("../../tutorials/src/", "src")
generate_tutorial_references("../../tutorials/media/", "media")
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import os
import shutil
from pathlib import Path
from typing import List

FILE_DIR = os.path.dirname(__file__)
GEN_DIR = "reference/generated/knowledge_base"
KNOWLEDGE_GEN_DIR = "reference/generated/knowledge_base"
TUTORIALS_GEN_DIR = "reference/generated/tutorials"
TUTORIALS_SRC_GEN_DIR = "reference/generated/tutorials/src"
TUTORIALS_MEDIA_GEN_DIR = "reference/generated/tutorials/media"


def _get_file_content(name: str) -> List[str]:
Expand Down Expand Up @@ -38,7 +42,7 @@ def generate_knowledge_base_references(knowledge_base_path: str) -> None:
knowledge_base_path (str): path to the knowledge base.
"""
# Create target dir
target_path = os.path.join(FILE_DIR, GEN_DIR)
target_path = os.path.join(FILE_DIR, KNOWLEDGE_GEN_DIR)
Path(target_path).mkdir(parents=True, exist_ok=True)

# Iterate knowledge base files
Expand All @@ -53,3 +57,32 @@ def generate_knowledge_base_references(knowledge_base_path: str) -> None:
# Existing files will be overwritten in 'w' mode
with open(os.path.join(target_path, f"{name}.rst"), "w") as file:
file.writelines(_get_file_content(name))


def generate_tutorial_references(tutorial_path: str, file_type: str) -> None:
"""Creates a python file per tutorial script.

Sphinx natively doesn't support adding files from outside its root directory. To include the tutorials in
our docs (https://pytorch.org/rl/) each entry is locally copied.

Args:
tutorial_path (str): path to the tutorial scripts.
"""
# Create target dir
if file_type == "tutorial":
target_path = os.path.join(FILE_DIR, TUTORIALS_GEN_DIR)
elif file_type == "src":
target_path = os.path.join(FILE_DIR, TUTORIALS_SRC_GEN_DIR)
else:
target_path = os.path.join(FILE_DIR, TUTORIALS_MEDIA_GEN_DIR)
Path(target_path).mkdir(parents=True, exist_ok=True)

# Iterate tutorial files and copy
file_paths = [
os.path.join(tutorial_path, f)
for f in os.listdir(tutorial_path)
if f.endswith((".py", ".rst", ".png"))
]

for file_path in file_paths:
shutil.copyfile(file_path, os.path.join(target_path, Path(file_path).name))
15 changes: 13 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,21 @@ for :doc:`cost functions <reference/objectives>`, :ref:`returns <reference/objec

TorchRL aims at a high modularity and good runtime performance.

.. toctree::
:maxdepth: 2
:caption: Tutorials:

tutorials/torchrl_demo
tutorials/tensordict_tutorial
tutorials/tensordict_module
tutorials/torch_envs
tutorials/multi_task
tutorials/coding_ddpg
tutorials/coding_dqn

.. toctree::
:maxdepth: 3
:caption: Contents:
:maxdepth: 2
:caption: References:

reference/index
reference/knowledge_base
Expand Down
2 changes: 1 addition & 1 deletion docs/source/reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ API Reference
=============

.. toctree::
:maxdepth: 1
:maxdepth: 3

collectors
data
Expand Down
9 changes: 7 additions & 2 deletions docs/source/reference/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ TensorDict modules
ActorValueOperator
ActorCriticOperator
ActorCriticWrapper
is_tensordict_compatible
ensure_tensordict_compatible
tensordict_module.common.is_tensordict_compatible
tensordict_module.common.ensure_tensordict_compatible

Hooks
-----
Expand Down Expand Up @@ -101,12 +101,17 @@ Distributions
Utils
-----

.. currentmodule:: torchrl.modules.utils

.. autosummary::
:toctree: generated/
:template: rl_template_noinherit.rst

mappings
inv_softplus
biased_softplus

.. currentmodule:: torchrl.modules.models.utils

SqueezeLayer
Squeeze2dLayer
8 changes: 7 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,13 @@ def _main(argv):
"build_ext": BuildExtension.with_options(no_python_abi_suffix=True),
"clean": clean,
},
install_requires=[pytorch_package_dep, "numpy", "packaging", "cloudpickle"],
install_requires=[
pytorch_package_dep,
"numpy",
"packaging",
"cloudpickle",
"tensordict",
],
extras_require={
"atari": [
"gym<=0.24",
Expand Down
2 changes: 1 addition & 1 deletion torchrl/modules/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

from .mappings import mappings, inv_softplus, biased_softplus
from torchrl.modules.utils.mappings import mappings, inv_softplus, biased_softplus
4 changes: 4 additions & 0 deletions tutorials/sphinx-tutorials/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
README Demos
================

Below are examples using my module:
Loading