Skip to main content

Deep reinforcement learning framework for fast prototyping based on PyTorch

Project description

logo

Python version: 3.6 | 3.7 | 3.8 | 3.9 | 3.10 License Code style: black Imports: isort pre-commit PyPI version

Welcome to actorch, a deep reinforcement learning framework for fast prototyping based on PyTorch. The following algorithms have been implemented so far:


💡 Key features

  • Support for OpenAI Gymnasium environments
  • Support for custom observation/action spaces
  • Support for custom multimodal input multimodal output models
  • Support for recurrent models (e.g. RNNs, LSTMs, GRUs, etc.)
  • Support for custom policy/value distributions
  • Support for custom preprocessing/postprocessing pipelines
  • Support for custom exploration strategies
  • Support for normalizing flows
  • Batched environments (both for training and evaluation)
  • Batched trajectory replay
  • Batched and distributional value estimation (e.g. batched and distributional Retrace and V-trace)
  • Data parallel and distributed data parallel multi-GPU training and evaluation
  • Automatic mixed precision training
  • Integration with Ray Tune for experiment execution and hyperparameter tuning at any scale
  • Effortless experiment definition through Python-based configuration files
  • Built-in visualization tool to plot performance metrics
  • Modular object-oriented design
  • Detailed API documentation

🛠️️ Installation

For Windows, make sure the latest Visual C++ runtime is installed.

Using Pip

First of all, install Python 3.6 or later. Open a terminal and run:

pip install actorch

Using Conda virtual environment

Clone or download and extract the repository, navigate to <path-to-repository>/bin and run the installation script (install.sh for Linux/macOS, install.bat for Windows). actorch and its dependencies (pinned to a specific version) will be installed in a Conda virtual environment named actorch-env.

NOTE: you can directly use actorch-env and the actorch package in the local project directory for development (see For development).

Using Docker (Linux/macOS only)

First of all, install Docker and NVIDIA Container Runtime. Clone or download and extract the repository, navigate to <path-to-repository>, open a terminal and run:

docker build -t <desired-image-name> .                  # Build image
docker run -it --runtime=nvidia <desired-image-name>    # Run container from image

actorch and its dependencies (pinned to a specific version) will be installed in the specified Docker image.

NOTE: you can directly use the actorch package in the local project directory inside a Docker container run from the specified Docker image for development (see For development).

From source

First of all, install Python 3.6 or later. Clone or download and extract the repository, navigate to <path-to-repository>, open a terminal and run:

pip install .

For development

First of all, install Python 3.6 or later and Git. Clone or download and extract the repository, navigate to <path-to-repository>, open a terminal and run:

pip install -e .[all]
pre-commit install -f

This will install the package in editable mode (any change to the package in the local project directory will automatically reflect on the environment-wide package installed in the site-packages directory of your environment) along with its development, test and optional dependencies. Additionally, it installs a git commit hook. Each time you commit, unit tests, static type checkers, code formatters and linters are run automatically. Run pre-commit run --all-files to check that the hook was successfully installed. For more details, see pre-commit's documentation.


▶️ Quickstart

In this example we will solve the OpenAI Gymnasium environment CartPole-v1 using REINFORCE. Copy the following configuration in a file named REINFORCE_CartPole-v1.py (with the same indentation):

import gymnasium as gym
from torch.optim import Adam

from actorch import *


experiment_params = ExperimentParams(
    run_or_experiment=REINFORCE,
    stop={"training_iteration": 50},
    resources_per_trial={"cpu": 1, "gpu": 0},
    checkpoint_freq=10,
    checkpoint_at_end=True,
    log_to_file=True,
    export_formats=["checkpoint", "model"],
    config=REINFORCE.Config(
        train_env_builder=lambda **config: ParallelBatchedEnv(
            lambda **kwargs: gym.make("CartPole-v1", **kwargs),
            config,
            num_workers=2,
        ),
        train_num_episodes_per_iter=5,
        eval_freq=10,
        eval_env_config={"render_mode": None},
        eval_num_episodes_per_iter=10,
        policy_network_model_builder=FCNet,
        policy_network_model_config={
            "torso_fc_configs": [{"out_features": 64, "bias": True}],
        },
        policy_network_optimizer_builder=Adam,
        policy_network_optimizer_config={"lr": 1e-1},
        discount=0.99,
        entropy_coeff=0.001,
        max_grad_l2_norm=0.5,
        seed=0,
        enable_amp=False,
        enable_reproducibility=True,
        log_sys_usage=True,
        suppress_warnings=True,
    ),
)

Open a terminal in the directory where you saved the configuration file and run (if you installed actorch in a virtual environment, you first need to activate it, e.g. conda activate actorch-env if you installed actorch using Conda):

pip install gymnasium[classic_control]  # Install dependencies for CartPole-v1
actorch run REINFORCE_CartPole-v1.py    # Run experiment

NOTE: training artifacts (e.g. checkpoints, metrics, etc.) are saved in nested subdirectories. This might cause issues on Windows, since the maximum path length is 260 characters. In that case, move the configuration file (or set local_dir) to an upper level directory (e.g. Desktop), shorten the configuration file name, and/or shorten the algorithm name (e.g. DistributedDataParallelREINFORCE.rename("DDPR")).

Wait for a few minutes until the training ends. The mean cumulative reward over the last 100 episodes should exceed 475, which means that the environment was successfully solved. You can now plot the performance metrics saved in the auto-generated TensorBoard (or CSV) log files using Plotly (or Matplotlib):

pip install actorch[vistool]  # Install dependencies for VisTool
cd experiments/REINFORCE_CartPole-v1/<auto-generated-experiment-name>
actorch vistool plotly tensorboard

You can find the generated plots in plots.

Congratulations, you ran your first experiment!

See examples for additional configuration file examples.

HINT: since a configuration file is a regular Python script, you can use all the features of the language (e.g. inheritance).


🔗 Useful links


@ Citation

@misc{DellaLibera2022ACTorch,
  author = {Luca Della Libera},
  title = {{ACTorch}: a Deep Reinforcement Learning Framework for Fast Prototyping},
  year = {2022},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/lucadellalib/actorch}},
}

📧 Contact

luca.dellalib@gmail.com


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

actorch-0.0.5.tar.gz (148.4 kB view details)

Uploaded Source

Built Distributions

actorch-0.0.5-pp38-pypy38_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (300.6 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

actorch-0.0.5-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (295.6 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

actorch-0.0.5-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (295.3 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

actorch-0.0.5-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (295.1 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

actorch-0.0.5-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (291.4 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

actorch-0.0.5-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (291.0 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

actorch-0.0.5-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (291.2 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

actorch-0.0.5-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (290.9 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

actorch-0.0.5-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (296.1 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

actorch-0.0.5-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (290.9 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

actorch-0.0.5-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (290.9 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

actorch-0.0.5-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (290.5 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

actorch-0.0.5-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (290.9 kB view details)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

actorch-0.0.5-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (290.5 kB view details)

Uploaded CPython 3.6m manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

File details

Details for the file actorch-0.0.5.tar.gz.

File metadata

  • Download URL: actorch-0.0.5.tar.gz
  • Upload date:
  • Size: 148.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/49.6.0.post20200925 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for actorch-0.0.5.tar.gz
Algorithm Hash digest
SHA256 81159e35af9c37737a2d179045c833e41bb3bde013c38806f9d7ab54de331834
MD5 4c632de8e743cf52b95e7b93fa5fa985
BLAKE2b-256 b0579be1293447d8be048f8fcf1ae793093ffd40f696558ad7c698ac7f899484

See more details on using hashes here.

File details

Details for the file actorch-0.0.5-pp38-pypy38_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for actorch-0.0.5-pp38-pypy38_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 63cdb69cf8ba3ae16bf924c871b65bb342b4759e36fe653cda18ab8ffdc295b0
MD5 42b435e94eb0c9b742043f3ebf59b7ab
BLAKE2b-256 2e33c5d1bc14dd3aeaef5ede5faa2da43cc81164a15a2dafee138e74f55a9af4

See more details on using hashes here.

File details

Details for the file actorch-0.0.5-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for actorch-0.0.5-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 ac02b1b220a343d79dc4d62cd5472e490ba4b2b2821987e1a249f6895e129cd3
MD5 5a0355095a90f341cf8c2fbe23fc5feb
BLAKE2b-256 ec96a9323396e6ada0eab550ec124d1e14f8412f55c288b1498b263c813780d9

See more details on using hashes here.

File details

Details for the file actorch-0.0.5-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for actorch-0.0.5-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 357ec660434fe955006983af89f463e6d5fbdac162c9cfa869f3967887ff53b6
MD5 9229f1287204c5c6b20442c5630f0422
BLAKE2b-256 e8f752638632318f6037e9a0aef3e822980e1c5e3f97bf6e308d43df0c91dd1e

See more details on using hashes here.

File details

Details for the file actorch-0.0.5-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for actorch-0.0.5-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 3c2f6d017f04453bb9588d63d4f11956b51662230cb79bd8f5a4bc2ad2308a0a
MD5 a44b6e010da5d9c9b667d8d4be417ba5
BLAKE2b-256 1354dced970c044ddad8de8ea681de4e7e5bbb7793c3497203048f533b7b5bb3

See more details on using hashes here.

File details

Details for the file actorch-0.0.5-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for actorch-0.0.5-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0f32128cba63ae8952d71edd1fa8123f0e02fd19d170c2ddb0287893b28fb6c1
MD5 2f479c9217a33d0ef9bdcdcd85658650
BLAKE2b-256 441ea21150e403878cf27811623a6b939812db04829eee022974933d50067c2f

See more details on using hashes here.

File details

Details for the file actorch-0.0.5-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for actorch-0.0.5-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 01895519c3f23bc620a9e2092c841f88f1e39dc3be888d330938099ac8f704d2
MD5 e92cd0c442cdf366cac65bac572e7603
BLAKE2b-256 58d78c3b1c193a9480161e74cd41c2c4d18446274236f037a536795eec566ad4

See more details on using hashes here.

File details

Details for the file actorch-0.0.5-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for actorch-0.0.5-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6c38bd4fccf5a8a5e646fcd8eb87ff088634e71c4ec4c9817e6c52ff641b0bd5
MD5 37be03748c9b2d767ae327afa65f9b54
BLAKE2b-256 a2770dc692c92f0368949ce56dc387aaa525d6a04873972410d52ee8a926ae54

See more details on using hashes here.

File details

Details for the file actorch-0.0.5-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for actorch-0.0.5-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 dc19d7f598ef8faaa3bb20a58861aca04384cfc9cdd05f1eaf6bef299341256d
MD5 1cbf502f1b2c464473b6c0b084d12684
BLAKE2b-256 a4338b8397eedc9fa7f11eae81d33ecb2a0f3fb21ecfa9605052c26dc213709b

See more details on using hashes here.

File details

Details for the file actorch-0.0.5-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for actorch-0.0.5-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 28e2472d8c2dabd39a0fb1745d894cdabc0dd07719c9f4f6199672ec38260f25
MD5 47ce0aab7169fef12fe019bea047baa8
BLAKE2b-256 03652e18731abea305bdd430466303a19f2d0a7e809faf567feb7b9214baf33a

See more details on using hashes here.

File details

Details for the file actorch-0.0.5-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for actorch-0.0.5-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 bea764860f690623f55770a8cef0af4be3a9a4201934304aa5938db50135d40b
MD5 ffa83b9d1b1df2f3c17fae3e12ac5c6e
BLAKE2b-256 09154b3978167afb3490efd9db7653b306ba25ba4cc5ea1160ad3013d2f6438d

See more details on using hashes here.

File details

Details for the file actorch-0.0.5-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for actorch-0.0.5-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 42e31f0eeefd78b89c8646f7c16915b2c3d2733b832b63199af04a00c23e5703
MD5 a854c06c606a81cc6cc009e2fbdbdb51
BLAKE2b-256 c00cc533c1ae1d84a70cdfb86515aad41e0df0cd82b324db2ac33dc598b27dcd

See more details on using hashes here.

File details

Details for the file actorch-0.0.5-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for actorch-0.0.5-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b9decbeadaf4b27cece09f7d85c99449614755156f8189c96e9727c90ba6bfa9
MD5 3dad7e80492e75db2e995473ce898047
BLAKE2b-256 195302dabbe830bcc041fc41665aa43212ff3a27dea8676d041d060eb20498fe

See more details on using hashes here.

File details

Details for the file actorch-0.0.5-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for actorch-0.0.5-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 85c2cc1cd02809d2ebd59207b173b68fbf84a155a08db0129c722d539d0d3d95
MD5 feeec3ee0090c1ecae9d04d6584f2d89
BLAKE2b-256 63fa3015f2724052ca76b5d32b41f5177ddafba73d9a76deb1ac4c4d1c032356

See more details on using hashes here.

File details

Details for the file actorch-0.0.5-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for actorch-0.0.5-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 3866fda7bd5583eb1fa840501ca1db522bbfe066b94b775835aadcd11e113ff0
MD5 90924dde5a6ff1768064e29b29072408
BLAKE2b-256 f6784a293e596ee25c908f2a4209536b68103043e0b38aff0c86289f98365463

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page