ModularRL
ModularRL is a Python library for creating and training reinforcement learning agents using various algorithms. The library is designed to be easily customizable and modular, allowing users to quickly set up and train agents for various environments without being limited to a specific algorithm.
Installation
pip install modular_rl
Features
- Implementations of various reinforcement learning algorithms, such as Proximal Policy Optimization (PPO), Monte Carlo Tree Search (MCTS), Monte Carlo Information Set (MCIS), and Modular's sIMulator (MIM)
- Customizable agent settings and network architectures
- Modular structure for easy adaptation and extension across different algorithms
- Model saving and loading functionality for easy reuse of trained models
Supported Algorithms
- Proximal Policy Optimization (PPO)
- Monte Carlo Tree Search (MCTS)
- Monte Carlo Information Set (MCIS)
- Modular's sIMulator (MIM)
Refer to the respective agent classes for each algorithm:
- AgentPPO (+ Modular)
- AgentMCTS (+ Modular)
- AgentMCIS (+ Modular)
- AgentMIM (+ Modular)
Example Usage
You can use the tester.py script provided in the library to create and train an instance of an agent with default or modified settings:
import modular_rl.tester as tester
tester.init_ppo()
# or
tester.init_ppo_modular()
tester.init_mcts()
As more algorithms are added, the tester functions will follow the naming convention init*[algorithm_name] or init*[algorithm_name]_modular.
Please note that not all algorithms support modular training due to the nature of their design. For such algorithms, you will need to use the non-modular training method provided by the respective agent class. You can refer to the list of supported algorithms to determine which training method is appropriate.
Alternatively, you can create and train an instance of the AgentPPO(example) class directly in your code:
from modular_rl.agents.agent_ppo import AgentPPO
from modular_rl.settings import AgentSettings
def init():
env = AgentPPO(env=None, setting=AgentSettings.default)
env.learn()
init()
To create and train an instance of the AgentPPO(example) class with modified settings, use the following code:
from modular_rl.agents.agent_ppo import AgentPPO
from modular_rl.settings import AgentSettings
def init_modular():
# Semi-automatic (defined record usage)
# Implement your environment and pass it to 'env' parameter.
env = AgentPPO(env=None, setting=AgentSettings.default_modular)
env.reset()
env.learn_reset()
action, reward, is_done = env.learn_next()
env.learn_check()
env.update()
# Proceed with the learning manually.
env.reset()
# Implement the 'reset' method in your environment.
'''
def reset(self):
...
return initial_state
'''
env.learn_reset()
initial_state = env.learn_reset()
action, dist = env.select_action(initial_state)
'''
Note:
Please implement the resulting state of update_step in the step function of your environment.
For example:
def step(self, action):
...
return next_state, reward, is_done, _
'''
env.update_step(initial_state, dist, action, -1)
env.learn_check()
env.update()
env.learn_close()
init_modular()
Saving and Loading Models
Agents can save and load their models using the save_model(file_name) and load_model(file_name) methods. The file_name parameter should be the name of the file to save or load the model to/from.
Example:
agent = AgentPPO(env, setting)
agent.train()
agent.save_model("my_saved_model.pth")
loaded_agent = AgentPPO(env, setting)
loaded_agent.load_model("my_saved_model.pth")
Key Classes
- AgentPPO, AgentMCTS, AgentMCIS, AgentMIM: The main agent classes implementing various reinforcement learning algorithms.
- PolicyNetwork, ValueNetwork, ActorCriticNetwork: Customizable neural networks for the agent's policy and value functions.
- AgentSettings: A configuration class for setting up the agents.
License
MIT License
Metadata
Release files for modular-rl 0.4.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| modular_rl-0.4.3.tar.gz | 38.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| modular_rl-0.4.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 110.7 kB
Release files / modular_rl-0.4.3.tar.gz
| Download URL | modular_rl-0.4.3.tar.gz |
|---|---|
| Size | 38.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e9495fc0d28bb9786067e84794a70e9b57430d07b114430fe861048e4c85b77f
|
|
BLAKE2b-256 checksum How to use checksums |
fee984e5af1c63f2a9542300d895d40001f20fab5a11dd549baa9c88ca8fe03b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Release files / modular_rl-0.4.3-py3-none-any.whl
| Download URL | modular_rl-0.4.3-py3-none-any.whl |
|---|---|
| Size | 72.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
249fb8a34786595a6471b5313e993aea32204f96514594a59fc2932b0c4f55cc
|
|
BLAKE2b-256 checksum How to use checksums |
3ed00450ac324c574c0ca2bf221fcb01809a785cef4aa77124fac673792d82b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Security for modular-rl 0.4.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.