Skip to main content

Blazing-fast Stable Retro fork with native vectorization and preprocessing

Project description

stable-retro-turbo

🚀 Blazing-fast Stable Retro fork with native vectorization and preprocessing 🚀

stable-retro-turbo is a Python library for reinforcement-learning developers who need faster batched rollouts from classic console games. It keeps Stable Retro's game integrations and single-environment API, and adds RetroVecEnv, a Gymnasium vector environment that steps many libretro emulators and preprocesses observations in native code.

Install the package, import your legally obtained ROMs, and use the upstream-compatible stable_retro import. The native path is useful for parallel training workloads that would otherwise spend substantial time crossing between Python wrappers and individual emulator instances.

Install

Release wheels require Python 3.14 and support macOS on Apple Silicon and Linux on x86-64.

uv venv --python 3.14
source .venv/bin/activate
uv pip install stable-retro-turbo
python -m stable_retro.import /path/to/your/roms

ROMs are not included. The importer matches supported ROMs to Stable Retro's game integrations.

Check the games available on your machine, then open one in the interactive player:

stable-retro-turbo play --list
stable-retro-turbo play nes

Pass a full game ID such as SuperMarioBros-Nes-v0, or use all to open one imported game per platform. Add --show-obs to display the raw game beside its PPO-style preprocessed observation.

Use

import stable_retro as retro

env = retro.RetroVecEnv(
    "SuperMarioBros-Nes-v0",
    state="Level1-1",
    num_envs=32,
    num_threads=16,
    render_mode="rgb_array",
    obs_crop=(32, 0, 0, 0),
    obs_crop_mode="mask",
    obs_resize=(84, 84),
    obs_resize_algorithm="area",
    obs_grayscale=True,
    obs_layout="chw",
    frame_skip=4,
    frame_stack=4,
    maxpool_last_two=True,
    info_filter="terminal",
)

obs, infos = env.reset(seed=123)
obs, rewards, terminations, truncations, infos = env.step(
    env.action_space.sample()
)

done = terminations | truncations
if done.any():
    obs, reset_infos = env.reset(options={"reset_mask": done})

env.close()

RetroVecEnv uses Gymnasium's disabled-autoreset semantics. A finished lane keeps its terminal observation and cannot be stepped again until it is selected by a masked reset; unselected lanes keep their emulator state, RNG stream, frame stack, and sticky-action history.

The fast path also supports:

  • native crop, mask, resize, grayscale, layout conversion, frame skip, frame stack, and two-frame max-pooling;
  • fixed, per-lane, or weighted saved-state selection for curricula and task-conditioned training;
  • copy-safe, safe-view, and benchmark-only unsafe-view observation ownership;
  • sticky actions, random no-op starts, reward clipping, and native info filtering;
  • Atari through the packaged Stella core, using the same RetroEnv and RetroVecEnv APIs.

The inherited RetroEnv API remains available for single-environment use. RetroVecEnv supports one player, image observations, and no movie recording.

Develop

git clone https://github.com/tsilva/stable-retro-turbo.git
cd stable-retro-turbo
uv sync --frozen

Source builds require Python 3.14, CMake, a C/C++ compiler, and the platform dependencies needed by the selected emulator cores.

Commands

Run these commands from the repository root:

uv run --frozen stable-retro-turbo play --list                                      # list imported games by platform
uv run --frozen python scripts/benchmark_vec_env.py --list-profiles                 # list benchmark profiles
uv run --frozen python scripts/benchmark_vec_env.py --profile supermario-level1-1  # benchmark native and classic paths
uv run --frozen --with pytest pytest tests/test_python/test_cli.py tests/test_python/test_benchmark_vec_env.py  # run quick tests
uv run --frozen --with build python -m build                                        # build source and wheel artifacts

Benchmark definitions live in scripts/benchmark_vec_env.json. Use real saved states for representative throughput measurements; State.NONE is reserved for explicit direct-ROM diagnostics and requires --allow-state-none.

Notes

  • The distribution is stable-retro-turbo; the Python package is stable_retro. The legacy retro import remains as a compatibility shim.
  • RetroVecEnv implements Gymnasium's vector API directly. It is not a Stable-Baselines3 VecEnv, and Stable-Baselines3 is not a runtime dependency.
  • A scalar reset seed expands to seed + lane_index. Seed sequences must contain one integer or None per lane.
  • state_catalog preloads an ordered saved-state catalog. Select reset lanes with reset_mask and their exact catalog entries with state_indices; Turbo does not sample states.
  • active_state_indices() returns a read-only NumPy view. Copy it when you need a stable snapshot.
  • Stable Retro remains the source for inherited game, integration, and emulator documentation.
  • Bundled emulator cores have their own licenses; see LICENSES.md.

Architecture

stable-retro-turbo architecture diagram

License

MIT

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

stable_retro_turbo-1.0.1.post31-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (91.6 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

stable_retro_turbo-1.0.1.post31-cp314-cp314-macosx_14_0_arm64.whl (85.9 MB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

File details

Details for the file stable_retro_turbo-1.0.1.post31-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for stable_retro_turbo-1.0.1.post31-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 019743b970b5af486192fbc97dc16bf279b458b17ec700aef294ae45f75cf854
MD5 b7372c665d9e0662b1a0aa02913524b1
BLAKE2b-256 83eb13f675f3492c08717704a85d5d9ec2a30f0cd5985277f0b3eeddc88f76d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for stable_retro_turbo-1.0.1.post31-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on tsilva/stable-retro-turbo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stable_retro_turbo-1.0.1.post31-cp314-cp314-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for stable_retro_turbo-1.0.1.post31-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 82167c5f2dc2e18a6dbc054f7301b527a8a320846e8725632827280f7a447709
MD5 8a72f04d665f619901549c4b54f1f912
BLAKE2b-256 2f18446404e64de3361831c7276b3486ff4c24e7346ac85bef318a4abc918691

See more details on using hashes here.

Provenance

The following attestation bundles were made for stable_retro_turbo-1.0.1.post31-cp314-cp314-macosx_14_0_arm64.whl:

Publisher: release.yml on tsilva/stable-retro-turbo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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