Skip to main content

ReplayBuffer for Reinforcement Learning written by C++ and Cython

Project description

img img img img img

img

Overview

cpprb is a python (CPython) module providing replay buffer classes for reinforcement learning.

Major target users are researchers and library developers.

You can build your own reinforcement learning algorithms together with your favorite deep learning library (e.g. TensorFlow, PyTorch).

cpprb forcuses speed, flexibility, and memory efficiency.

By utilizing Cython, complicated calculations (e.g. segment tree for prioritized experience replay) are offloaded onto C++. (The name cpprb comes from "C++ Replay Buffer".)

In terms of API, initially cpprb referred to OpenAI Baselines' implementation. In the current version, cpprb has much more flexibility. Any NumPy compatible types of any numbers of values can be stored (as long as memory capacity is sufficient). For example, you can store the next action and the next next observation, too.

Installation

cpprb requires following softwares before installation.

  • C++17 compiler (for installation from source)
  • Python 3
  • pip

Cuurently, clang, which is a default Xcode C/C++ compiler at Apple macOS, cannot compile cpprb.

If you are macOS user, you need to install GCC and set environment values of CC and CXX to g++, or just use virtual environment (e.g. Docker).

Step by step installation is described here.

Additionally, here are user's good feedbacks for installation at macOS and Ubuntu. (Thanks!)

Install from PyPI (Recommended)

The following command installs cpprb together with other dependancies.

pip install cpprb

Depending on your environment, you might need sudo or --user flag for installation.

On supported platflorms (Linux x86-64 and Windows amd64), binary packages are hosted on PyPI can be used, so that you don't need C++ compiler.

If you have trouble to install from binary, you can fall back to source installation to passk --no-binary option to the above pip command.

Currently, no other platforms, such as macOS, and 32bit or arm-architectured Linux and Windows, cannot install from binary, and need to compile by yourself. Please be patient, we will plan to support wider platforms in future.

Install from source code

First, download source code manually or clone the repository;

git clone https://gitlab.com/ymd_h/cpprb.git

Then you can install same way;

cd cpprb
pip install .

For this installation, you need to convert extended Python (.pyx) to C++ (.cpp) during installation, it takes longer time than installation from PyPI.

Usage

Here is a simple example for storing standard environment (aka. "obs", "act", "rew", "nextobs", and "done").

from cpprb import ReplayBuffer

buffer_size = 256
obs_shape = 3
act_dim = 1
rb = ReplayBuffer(buffer_size,
		  env_dict ={"obs": {"shape": obs_shape},
			     "act": {"shape": act_dim},
			     "rew": {},
			     "next_obs": {"shape": obs_shape},
			     "done": {}})

obs = np.ones(shape=(obs_shape))
act = np.ones(shape=(act_dim))
rew = 0
next_obs = np.ones(shape=(obs_shape))
done = 0

for i in range(500):
    rb.add(obs=obs,act=act,rew=rew,next_obs=next_obs,done=done)


batch_size = 32
sample = rb.sample(batch_size)
# sample is a dictionary whose keys are 'obs', 'act', 'rew', 'next_obs', and 'done'

Flexible environment values are defined by env_dict when buffer creation.

Since stored values have flexible name, you have to pass to ReplayBuffer.add member by keyword.

Features

cpprb provides buffer classes for building following algorithms.

Algorithms cpprb class Paper
Experience Replay `ReplayBuffer` [L. J. Lin](https://link.springer.com/article/10.1007/BF00992699)
Prioritized Experience Replay `PrioritizedReplayBuffer` [T. Schaul et. al.](https://arxiv.org/abs/1511.05952)
Multi-step Learning `ReplayBuffer`, `PrioritizedReplayBuffer`  

cpprb features and its usage are described at following pages:

Contributing to cpprb

Any contribution are very welcome!

Making Community Larger

Bigger commumity makes development more active and improve cpprb.

  • Star this repository (and/or GitHub Mirror)
  • Publish your code using cpprb
  • Share this repository to your friend and/or followers.

Report Issue

When you have any problems or requests, you can check issues on GitLab.com. If you still cannot find any information, you can open your own issue.

Merge Request (Pull Request)

cpprb follows local rules:

  • Branch Name
    • "HotFix***" for bug fix
    • "Feature***" for new feature implementation
  • docstring
  • Unit Test
    • Put test code under "test/" directory
    • Can test by python -m unittest <Your Test Code> command
    • Continuous Integration on GitLab CI configured by .gitlab-ci.yaml
  • Open an issue and associate it to Merge Request

Step by step instruction for beginners is described at here.

Links

cpprb sites

cpprb users' repositories

Lisence

cpprb is available under MIT lisence.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

cpprb-8.4.4.tar.gz (307.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cpprb-8.4.4-cp38-cp38-manylinux2010_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.12+ x86-64

cpprb-8.4.4-cp38-cp38-manylinux1_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.8

cpprb-8.4.4-cp37-cp37m-manylinux2010_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.12+ x86-64

cpprb-8.4.4-cp37-cp37m-manylinux1_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.7m

cpprb-8.4.4-cp36-cp36m-manylinux2010_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.12+ x86-64

cpprb-8.4.4-cp36-cp36m-manylinux1_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.6m

cpprb-8.4.4-cp35-cp35m-manylinux2010_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.5mmanylinux: glibc 2.12+ x86-64

cpprb-8.4.4-cp35-cp35m-manylinux1_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.5m

File details

Details for the file cpprb-8.4.4.tar.gz.

File metadata

  • Download URL: cpprb-8.4.4.tar.gz
  • Upload date:
  • Size: 307.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for cpprb-8.4.4.tar.gz
Algorithm Hash digest
SHA256 0505bb65256e9828595705be470387643c7aed4ca772647cd70b6aa60b62061b
MD5 160607b531cc50111f584f96a09f345b
BLAKE2b-256 3c9e995c673c73ce54453f6ad2a752e71eaa1a884addbb2cafe8f34357c0f169

See more details on using hashes here.

File details

Details for the file cpprb-8.4.4-cp38-cp38-manylinux2010_x86_64.whl.

File metadata

  • Download URL: cpprb-8.4.4-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for cpprb-8.4.4-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 c669ec71750bfc43856f3185e510197f3caf3fe80b87ff82a27d710075916a76
MD5 ce5a0a46fe928d0eaf5d5f0c9d8edf21
BLAKE2b-256 9ac92a68e9aac502bbb59e482e0f5903b882f08f4d9c7b55ab8a2b5bb9dd06c9

See more details on using hashes here.

File details

Details for the file cpprb-8.4.4-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: cpprb-8.4.4-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for cpprb-8.4.4-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 6e62a48b94f7f511697e95edbf9d949c71e12dc2aa1ead518f693987e915e1b4
MD5 b4939715993a0cbeb2474fab46cd0ceb
BLAKE2b-256 e2a15da8bdfe6724f483aa9717f942b36e6d6c85da47ae5e53d0fd0311ec9987

See more details on using hashes here.

File details

Details for the file cpprb-8.4.4-cp37-cp37m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: cpprb-8.4.4-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for cpprb-8.4.4-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 a41a234bf56979a876118452523b803616c35c92ac64d2986d1777701af7746d
MD5 43cb9d0e046ec0840d9e3bf7054ab806
BLAKE2b-256 8f2db47f302069591864234d97f88eb0233033d39ed70cc64b04ec30089e05b0

See more details on using hashes here.

File details

Details for the file cpprb-8.4.4-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: cpprb-8.4.4-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for cpprb-8.4.4-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 7e7d62dace61fe03e6425a43040ba31431ac0078b28f3a8d9acd3e90cdc13330
MD5 d60a01565cfb1d6cdae2337069a325b2
BLAKE2b-256 aef9bb7625df0be61af80ae82ae4eec00587acbb3e88bdea7f09dc9e3841f382

See more details on using hashes here.

File details

Details for the file cpprb-8.4.4-cp36-cp36m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: cpprb-8.4.4-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for cpprb-8.4.4-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 702954c13895fbf9fea6c899bc1c2810c592839d2c564dc34ef6a58002450c2b
MD5 e22dfb97c9cef45fd6747f66851ec843
BLAKE2b-256 9713ef3ba7ec9dfd8fdb3320e428bec4f26ec12bf91a6dff6b057a1bc7d1f361

See more details on using hashes here.

File details

Details for the file cpprb-8.4.4-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: cpprb-8.4.4-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for cpprb-8.4.4-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 a0096dbe74467d600eec5ee01f4abdf57e6f1151a0245774b861fa4ffc37b82c
MD5 9c143a056c7f899e207f19cf5a3f0c54
BLAKE2b-256 00f4ea850ab844dabe7bfbf0d9ce7a89fab00ecc61813c9b1c6b4301a0bd5091

See more details on using hashes here.

File details

Details for the file cpprb-8.4.4-cp35-cp35m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: cpprb-8.4.4-cp35-cp35m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.5m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for cpprb-8.4.4-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 1a98899c056ddd9554cd2e6df6837629b044005bfefbf69f4c05a0a3873afa1b
MD5 025b50bf712415b00488f86ed88d13fd
BLAKE2b-256 5099772379a72d668ea89797ce813b79b13b1e164089547816a4f623fa58b897

See more details on using hashes here.

File details

Details for the file cpprb-8.4.4-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

  • Download URL: cpprb-8.4.4-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for cpprb-8.4.4-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 43a6763d8e157db582b8eab48e0cfb5efbedc1f7c9ffefaf10592af82edf8b59
MD5 db09e66a2380a5bc5c3608f582277c7b
BLAKE2b-256 455bb389a20b856bfffd3bb80cad0491c2d4865228ad232865bb351ea7345040

See more details on using hashes here.

Supported by

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