[!NOTE] Tianshou version 2 is here!
We have released the new major version of Tianshou on PyPI.
Version 2 is a complete overhaul of the software design of the procedural API, in which * we establish a clear separation between learning algorithms and policies (via the separate abstractionsAlgorithmandPolicy). * we provide more well-defined, more usable interfaces with extensive documentation of all algorithm and trainer parameters, renaming some parameters to make their names more consistent and intuitive. * the class hierarchy is fully revised, establishing a clear separation between on-policy, off-policy and offline algorithms at the type level and ensuring that all inheritance relationships are meaningful.Because of the extent of the changes, this version is not backwards compatible with previous versions of Tianshou. For migration information, please see the change log.
Tianshou (天授) is a reinforcement learning (RL) library based on pure PyTorch and Gymnasium. Tianshou's main features at a glance are:
Unlike other reinforcement learning libraries, which may have complex codebases, unfriendly high-level APIs, or are not optimized for speed, Tianshou provides a high-performance, modularized framework and user-friendly interfaces for building deep reinforcement learning agents. One more aspect that sets Tianshou apart is its generality: it supports online and offline RL, multi-agent RL, and model-based algorithms.
Tianshou aims at enabling concise implementations, both for researchers and practitioners, without sacrificing flexibility.
Supported algorithms include:
Other noteworthy features:
In Chinese, Tianshou means divinely ordained, being derived to the gift of being born. Tianshou is a reinforcement learning platform, and the nature of RL is not learn from humans. So taking "Tianshou" means that there is no teacher to learn from, but rather to learn by oneself through constant interaction with the environment.
“天授”意指上天所授,引申为与生具有的天赋。天授是强化学习平台,而强化学习算法并不是向人类学习的,所以取“天授”意思是没有老师来教,而是自己通过跟环境不断交互来进行学习。
Tianshou is currently hosted on PyPI and conda-forge. It requires Python >= 3.11.
For installing the most recent version of Tianshou, the best way is clone the repository and install it with poetry (which you need to install on your system first)
git clone git@github.com:thu-ml/tianshou.git
cd tianshou
poetry install
You can also install the dev requirements by adding --with dev or the extras
for say mujoco and acceleration by envpool
by adding --extras "mujoco envpool"
If you wish to install multiple extras, ensure that you include them in a single command. Sequential calls to poetry install --extras xxx will overwrite prior installations, leaving only the last specified extras installed.
Or you may install all the following extras by adding --all-extras.
Available extras are:
atari (for Atari environments)box2d (for Box2D environments)classic_control (for classic control (discrete) environments)mujoco (for MuJoCo environments)mujoco-py (for legacy mujoco-py environments[^1])pybullet (for pybullet environments)robotics (for gymnasium-robotics environments)vizdoom (for ViZDoom environments)envpool (for envpool integration)argparse (in order to be able to run the high level API examples)[^1]:
mujoco-py is a legacy package and is not recommended for new projects.
It is only included for compatibility with older projects.
Also note that there may be compatibility issues with macOS newer than
Monterey.
Otherwise, you can install the latest release from PyPI (currently far behind the master) with the following command:
$ pip install tianshou
If you are using Anaconda or Miniconda, you can install Tianshou from conda-forge:
$ conda install tianshou -c conda-forge
Alternatively to the poetry install, you can also install the latest source version through GitHub:
$ pip install git+https://github.com/thu-ml/tianshou.git@master --upgrade
Finally, you may check the installation via your Python console as follows:
import tianshou
print(tianshou.__version__)
If no errors are reported, you have successfully installed Tianshou.
Find example scripts in the test/ and examples/ folders.
Tutorials and API documentation are hosted on tianshou.readthedocs.io.
| RL Platform | Documentation | Code Coverage | Type Hints | Last Update |
|---|---|---|---|---|
| Stable-Baselines3 | :heavy_check_mark: | |||
| Ray/RLlib | :heavy_minus_sign:(1) | :heavy_check_mark: | ||
| SpinningUp | :x: |
$ claude mcp add tianshou \
-- python -m otcore.mcp_server <graph>