Skip to main content

PRLearn

PRLearn is a Python library for Parallel Reinforcement Learning. It leverages multiprocessing to accelerate experience collection and agent training, making RL experimentation faster and more efficient.

Key Features

  • Flexible architecture: Easily extendable with custom agents, environments, and combiners.
  • Minimal dependencies: Only Python 3.11+ and (optionally) multiprocess.
  • Parallel data collection and training: Reduce training time via multiprocessing.
  • Agent combination: Multiple strategies for aggregating agents (statistical, random, fixed, etc.).
  • Flexible scheduling: Control training stages via ProcessActionScheduler.

Installation

pip install prlearn

Or with multiprocess support:

pip install prlearn[multiprocess]

Quick Start

Define Your Agent

from prlearn import Agent, Experience
from typing import Any, Dict, Tuple

class MyAgent(Agent):
    def action(self, state: Tuple[Any, Dict[str, Any]]) -> Any:
        observation, info = state
        # Action selection logic
        pass
    def train(self, experience: Experience):
        obs, actions, rewards, terminated, truncated, info = experience.get()
        # Training logic
        pass

Use Trainer for Parallel Training

import gymnasium as gym
from prlearn import Trainer
from prlearn.collection.agent_combiners import FixedStatAgentCombiner

env = gym.make("LunarLander-v2")
agent = MyAgent()

trainer = Trainer(
    agent=agent,
    env=env,
    n_workers=4,
    schedule=[
        ("finish", 1000, "episodes"),
        ("train_agent", 10, "episodes"),
    ],
    mode="parallel_learning",  # optional
    sync_mode="sync",          # optional
    combiner=FixedStatAgentCombiner("mean_reward"),  # optional
)

agent, result = trainer.run()

Custom Environment

from prlearn import Environment
from typing import Any, Dict, Tuple

class MyEnv(Environment):
    def reset(self) -> Tuple[Any, Dict[str, Any]]:
        # Reset logic
        return [[1, 2], [3, 4]], {"info": "description"}
    def step(self, action: Any) -> Tuple[Any, Any, bool, bool, Dict[str, Any]]:
        # Step logic
        return [[1, 2], [3, 4]], 1, False, False, {"info": "description"}

See more usage examples in docs/examples.md

Extending

  • Custom agent: Inherit from Agent, implement action and train methods.
  • Custom environment: Inherit from Environment, implement reset and step methods.
  • Custom combiner: Inherit from AgentCombiner, implement the combine method.

Testing

To run tests:

pytest tests/

License

MIT License. See LICENSE.

Metadata

Release files for prlearn 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prlearn 0.0.4
File Size Uploaded Provenance
prlearn-0.0.4.tar.gz 14.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for prlearn 0.0.4
File Interpreter ABI Platform
prlearn-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 34.1 kB

Release files / prlearn-0.0.4.tar.gz

Download URL prlearn-0.0.4.tar.gz
Size 14.6 kB
Tags Source
SHA-256 checksum
How to use checksums
bc1998acc65bb2f45bd383a6dda44722d758b91ba4fd088999a4019dba6d6e1e
BLAKE2b-256 checksum
How to use checksums
8362d0f674ab4fb756094a530e135473cab861654ac8c5d564a2859285f09f92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.12.10 Darwin/24.4.0

Release files / prlearn-0.0.4-py3-none-any.whl

Download URL prlearn-0.0.4-py3-none-any.whl
Size 19.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
547583f35f21a3fe6f056bfd8af9f490dc29d8f70d4645819cff011f69dc0b14
BLAKE2b-256 checksum
How to use checksums
fd33e42adccec08fbc2a9e05de59cdf13626bc72655e166fb6a7048a1efa71fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.12.10 Darwin/24.4.0

Security for prlearn 0.0.4

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page