Skip to main content

so much room for activities

Project description

PyPI Python Versions License: MIT Code Style: Black Linter: Ruff CircleCI

bettermdptools

Bettermdptools is a lightweight toolkit for working with Gymnasium environments using classic planning and tabular reinforcement learning methods.

It is designed to help users get up and running quickly, explore standard RL algorithms, and experiment with environments like FrozenLake, Taxi, Blackjack, and CartPole without heavy framework overhead.


Getting started

Install

Install from PyPI:

pip install bettermdptools
pygame installation issues (Python 3.11+)

If you encounter errors installing pygame on Python 3.11 or newer, try:

pip install pygame --pre
Google Colab notes (NumPy + Gymnasium)

Some Gymnasium-compatible environments may require a NumPy downgrade.

When using Google Colab - after installing numpy<2 you must restart the Colab session for the change to take effect.

Typical workflow:

pip install "numpy<2"

Then:

Runtime → Restart session


Quick example (FrozenLake)

Below is a minimal example using value iteration on FrozenLake:

import gymnasium as gym
from bettermdptools.algorithms.planner import Planner
from bettermdptools.utils.plots import Plots

env = gym.make("FrozenLake8x8-v1", render_mode=None)

V, V_track, pi = Planner(env.P).value_iteration()

Plots.values_heat_map(
    V,
    title="FrozenLake Value Iteration - State Values",
    size=(8, 8),
)

grid_state_values

Example notebooks

The fastest way to explore the library is through the example notebooks in the examples/ directory.

Core environments

Experiments API

  • examples/experiments_demo.ipynb
    Demonstrates the optional bettermdptools.experiments.run(...) entrypoint across:
    • FrozenLake (VI and Q-learning)
    • Blackjack (Q-learning)
    • CartPole (discretized)

Utilities and plotting

These notebooks are intended as examples and starting points, not benchmarks.


Experiments API (optional)

Bettermdptools includes an optional high-level experiments entrypoint that wires together:

  • environment creation
  • transition model handling
  • algorithm dispatch
  • optional policy evaluation

Primary entrypoint:

from bettermdptools.experiments import run

See:


Development and tooling

Dependency management

The project supports standard pip workflows. For development, using Poetry is recommended to ensure reproducible environments.

Example:

poetry install
poetry shell

Code quality

The codebase uses the following tools during development:

  • ruff for fast linting
  • black for code formatting

Typical usage:

ruff check .
black .

Documentation

API documentation is generated using pdoc (not pdoc3) and lives in the docs/ directory.

To regenerate documentation locally:

pdoc --include-undocumented -d numpy -t docs-templates --output-dir docs bettermdptools

Contributing

Pull requests are welcome.

Guidelines:

  • Use numpy-style docstrings
  • Add or update tests when introducing new functionality
  • Prefer explicit, readable code over clever or showy abstractions
  • Format code with black and check linting with ruff before submitting
  • Keep public APIs stable and avoid breaking changes unless clearly justified
  • Prefer small, focused pull requests with a limited number of file changes

Basic workflow:

  1. Fork the repository
  2. Create a feature branch
  3. Commit changes
  4. Open a pull request

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

bettermdptools-0.8.4.tar.gz (922.0 kB view details)

Uploaded Source

File details

Details for the file bettermdptools-0.8.4.tar.gz.

File metadata

  • Download URL: bettermdptools-0.8.4.tar.gz
  • Upload date:
  • Size: 922.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.66.1 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for bettermdptools-0.8.4.tar.gz
Algorithm Hash digest
SHA256 9c797d95690b3b5d65766e4edd03715742f1b03e52ed304bd1c96b0da87923e6
MD5 c96367e512f7e35393ff005cb38b6877
BLAKE2b-256 8c27ab10df0a5b58c19b6de8771847c7e381d9a9b478d6f99b5bd2893ee13a86

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