Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RLlib] auto API reference pages: rllib/env package only. #20486

Merged
merged 7 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions doc/source/images/rllib/env_classes_overview.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ Papers
rllib-offline.rst
rllib-concepts.rst
rllib-examples.rst
rllib-package-ref.rst
rllib/package_ref/index.rst
rllib-dev.rst

.. toctree::
Expand Down
19 changes: 5 additions & 14 deletions doc/source/rllib-package-ref.rst
Original file line number Diff line number Diff line change
@@ -1,40 +1,31 @@
.. include:: rllib/we_are_hiring.rst

RLlib Package Reference
=======================

ray.rllib.policy
----------------
================

.. automodule:: ray.rllib.policy
:members:

ray.rllib.env
-------------

.. automodule:: ray.rllib.env
:members:

ray.rllib.evaluation
--------------------
====================

.. automodule:: ray.rllib.evaluation
:members:

ray.rllib.execution
--------------------
===================

.. automodule:: ray.rllib.execution
:members:

ray.rllib.models
----------------
================

.. automodule:: ray.rllib.models
:members:

ray.rllib.utils
---------------
===============

.. automodule:: ray.rllib.utils
:members:
5 changes: 5 additions & 0 deletions doc/source/rllib/__WIP__.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This folder is WIP and will eventually contain all the revamped documentation source
files.

Some rst files for the new RLlib documentation have already moved into
here, others are still residing directly under the main doc/source directory.
47 changes: 47 additions & 0 deletions doc/source/rllib/package_ref/env.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
.. _env-reference-docs:

Environment APIs
================

.. toctree::
:maxdepth: 1

env/base_env.rst
env/multi_agent_env.rst
env/vector_env.rst
env/external_env.rst

Any environment type provided by you to RLlib (e.g. a user-defined ``gym.Env`` class),
is converted internally into the ``BaseEnv`` API, whose main methods are ``poll()`` and ``send_actions()``:

.. https://docs.google.com/drawings/d/1NtbVk-Mo89liTRx-sHu_7fqi3Kn7Hjdf3i6jIMbxGlY/edit
.. image:: ../../images/rllib/env_classes_overview.svg


The ``BaseEnv`` API allows RLlib to support:

1) Vectorization of sub-environments (i.e. individual ``gym.Env`` instances, stacked to form a vector of envs) in order to batch the action computing model forward passes.
2) External simulators requiring async execution (e.g. envs that run on separate machines and independently request actions from a policy server).
3) Stepping through the individual sub-environments in parallel via pre-converting them into separate @ray.remote actors.
4) Multi-agent RL via dicts mapping agent IDs to observations/rewards/etc..

For example, if you provide a custom ``gym.Env`` class to RLlib, auto-conversion to ``BaseEnv`` goes as follows:

- User provides a ``gym.Env`` -> ``_VectorizedGymEnv`` (is-a ``VectorEnv``) -> ``BaseEnv``

Here is a simple example:

.. literalinclude:: ../../../../rllib/examples/documentation/custom_gym_env.py
:language: python

.. start-after: __sphinx_doc_model_construct_1_begin__
.. end-before: __sphinx_doc_model_construct_1_end__

However, you may also conveniently sub-class any of the other supported RLlib-specific
environment types. The automated paths from those env types (or callables returning instances of those types) to
an RLlib ``BaseEnv`` is as follows:

- User provides a custom ``MultiAgentEnv`` (is-a ``gym.Env``) -> ``VectorEnv`` -> ``BaseEnv``
- User uses a policy client (via an external simulator) -> ``ExternalEnv|ExternalMultiAgentEnv`` -> ``BaseEnv``
- User provides a custom ``VectorEnv`` -> ``BaseEnv``
- User provides a custom ``BaseEnv`` -> do nothing
10 changes: 10 additions & 0 deletions doc/source/rllib/package_ref/env/base_env.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. _base-env-reference-docs:

BaseEnv API
===========

rllib.env.base_env.BaseEnv
--------------------------

.. autoclass:: ray.rllib.env.base_env.BaseEnv
:members:
28 changes: 28 additions & 0 deletions doc/source/rllib/package_ref/env/external_env.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.. _external-env-reference-docs:

ExternalEnv API
===============

ExternalEnv (Single-Agent Case)
-------------------------------

rllib.env.external_env.ExternalEnv
++++++++++++++++++++++++++++++++++

.. autoclass:: ray.rllib.env.external_env.ExternalEnv
:special-members: __init__
:members:


ExternalMultiAgentEnv (Multi-Agent Case)
----------------------------------------

rllib.env.external_multi_agent_env.ExternalMultiAgentEnv
++++++++++++++++++++++++++++++++++++++++++++++++++++++++

If your external environment needs to support multi-agent RL, you should instead
sub-class ``ExternalMultiAgentEnv``:

.. autoclass:: ray.rllib.env.external_multi_agent_env.ExternalMultiAgentEnv
:special-members: __init__
:members:
22 changes: 22 additions & 0 deletions doc/source/rllib/package_ref/env/multi_agent_env.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.. _multi-agent-env-reference-docs:

MultiAgentEnv API
=================

rllib.env.multi_agent_env.MultiAgentEnv
---------------------------------------

.. autoclass:: ray.rllib.env.multi_agent_env.MultiAgentEnv

.. automethod:: __init__
.. automethod:: reset
.. automethod:: step
.. automethod:: render
.. automethod:: with_agent_groups


Convert gym.Env into MultiAgentEnv
----------------------------------

.. automodule:: ray.rllib.env.multi_agent_env
:members: make_multi_agent
22 changes: 22 additions & 0 deletions doc/source/rllib/package_ref/env/vector_env.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.. _vector-env-reference-docs:

VectorEnv API
=============

rllib.env.vector_env.VectorEnv
------------------------------

.. autoclass:: ray.rllib.env.vector_env.VectorEnv
:special-members: __init__
:members:


Gym.Env to VectorEnv
--------------------

Internally, RLlib uses the following wrapper class to convert your provided ``gym.Env`` class into
a ``VectorEnv`` first. After that, RLlib will convert the resulting objects into a ``BaseEnv``.

.. autoclass:: ray.rllib.env.vector_env._VectorizedGymEnv
:special-members: __init__
:members:
21 changes: 21 additions & 0 deletions doc/source/rllib/package_ref/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.. include:: ../we_are_hiring.rst

.. _rllib-reference-docs:

RLlib API Reference
===================

.. tip:: We'd love to hear your feedback on using RLlib - `sign up to our forum and start asking questions <https://discuss.ray.io>`_!

This section contains an overview of RLlib's package- and API reference.
If you think there is anything missing, please open an issue on `Github`_.

.. _`GitHub`: https://github.com/ray-project/ray/issues

.. TODO: Eventually, move all reference pages into this dir here (doc/source/rllib/package_ref/)

.. toctree::
:maxdepth: 2

env.rst
../../rllib-package-ref