Skip to main content

Retro Speedlab Core

CI Python 3.12 Last commit License: GPL-3.0 Ruff codecov

Tool-assisted speedrun search for classic video games. The engine searches the fastest movie of buttons to press on every frame from power-on, verifies that it replays, and streams the run to Retro Speedlab. Game packages supply the game knowledge (RAM map, states, rewards, actions); this repository turns it into a speedrun.

Highlights

  • Power-on start like a real speedrun: every movie boots the game at its title screen; levels are states of one full-game run
  • Go-Explore segment search on many emulator processes, split at the state machine's transitions
  • Every segment is verified: the whole movie replays from power-on before a new segment counts
  • Route memory from earlier runs guides the search towards a state's exit
  • .bk2 movie and MP4 video of the verified run
  • Live relay of the newest verified segment, the run's time, level splits and the lab's status to the Retro Speedlab backend
  • Lab runs: when the search is stuck or stalls, Claude Code improves the game package on its own branch

Architecture

flowchart TD
    Game["Game package<br/>RAM · States · Rewards · Actions"]
    Env["Stable Retro emulator<br/>StateMachineGymWrapper"]
    Search["Segment search<br/>one worker per process"]
    Movie["Verified movie<br/>progress.msgpack · tas.bk2 · tas.mp4"]
    Relay["Live relay<br/>snapshot · latest segment"]
    Lab["Lab run<br/>agent/daily.sh"]

    Game --> Env
    Env --> Search
    Search --> Movie
    Movie --> Relay
    Movie -- "stuck or stalled" --> Lab
    Lab --> Game

The app's default workflow is speedrun: it writes the fastest movie from power-on for any game package and improves it forever:

python -m datenwissenschaften.tas.run search <wrapper> <config> <until-state>
python -m datenwissenschaften.tas.run improve <wrapper> <config>
python -m datenwissenschaften.tas.run verify <wrapper> <config> <progress>

The run is split at the state machine's transitions. Each segment is searched Go-Explore style on speedrun.workers emulator processes: an archive keeps the fastest savestate per cell (state, 8 px position, height, airborne and RamInfo.dynamics(), the game's coarse view of whatever moves nearby) and branches from rarely visited cells with short random input bursts. Half the time it branches from the tenth of cells that earned the most of the segment's reward, and it favours cells the route memory knows to be few decisions from the exit; a full archive drops its least promising cell. Workers step the emulator core without rendering. A crossing into a later state ends a branch and counts only when the new state holds; deaths and backward transitions drop it. Of the three fastest distinct crossings, the one whose next segment is also fastest is kept, and frames it does not need are shaved off. A segment gets speedrun.segment_seconds per round and twice as long with each retry. Random numbers live in the savestates, so the search plans against the real RNG and can wait frames to change it. A segment without a way out is marked stuck in cache/tas/stuck.json and the way into it is searched again.

After every segment the whole movie is replayed from power-on; segments that do not reproduce are searched again. cache/tas/progress.msgpack lets a run resume, cache/tas/tas.bk2 is the verified movie, tas.mp4 its video and search.log the search's log. metadata.speedrun tells the stream the run's time from power-on and from Start, its segments, the level splits (from GameWrapper.levels), each state's goal, the game and its record sources, the engine's events, milestones and time history (journal.json) and the segment being searched. While a segment is searched every worker writes its cells, frames, map visits and RAM to live/<seed>.msgpack every 2 s, one worker its latest frame to live/attempt.jpg twice a second; the main process folds them into search, map, ram and position every 5 s and the relay puts the frame to /live/attempt.jpg. The newest verified segment plays as the stream's latest episode. improve searches every segment again, bounded by its current frames; a faster crossing replaces it and the rest is searched anew. verify fails unless a progress file still replays with a game package.

Route memory

paths.models/<game>/<state>/route.json lists, per 8 px cell, how many decisions the fastest known run needed from there to the state's exit. The search weights cells on the route by how close they are to the exit. A state without the file is searched without guidance.

Workflows and the lab

Flyte runs the work as tasks (datenwissenschaften.workflow): speedrun relays the stream, publishes the lab's status and searches and improves the movie forever. lab first starts the critic (agent/critic.sh) once five new reports landed in agent/reports/ since its last review; the stream shows its lessons as metadata.critic. Then it starts a lab run (agent/daily.sh of the game package) at once when the search is stuck, or once the movie has not improved for agent.stall_minutes minutes. Claude Code works for agent.minutes minutes on its own git worktree of the game package, and its branch ships only when its checks pass and the current movie still replays with it (tas.run verify). The lead session delegates to the subagents defined in the game package's .claude/agents/; the stream shows each member's role, state and latest step and every hand-off with its short task, the lead's latest actions (only the kind of action and the source files it touches), its commit subjects with URLs and secret-like words hidden, and the lines it changed. Every task runs locally with flyte run --local.

Live relay

With ui.enable: true and an upload key, the engine relays to the Retro Speedlab backend (upload.url) every few seconds the snapshot (the published metadata and the release) and the feed of the newest verified segment, whose video and frame statuses go up once, named by their content hash. The website's /stream page, opened with the stream key (?api_key=), plays them for OBS. The engine itself serves nothing.

Installation

Retro Speedlab Core requires Python 3.12.

git clone https://github.com/datenwissenschaften/retro-speedlab-core.git
cd retro-speedlab-core
uv sync
cp config.example.yaml config.yaml

The published package and import path are datenwissenschaften.

Minimal usage

This repository does not ship a playable game; a game package supplies the RAM layout, states, rewards and actions:

import numpy as np

from datenwissenschaften.environment.wrapper import StateMachineGymWrapper


class AirstrikerWrapper(StateMachineGymWrapper[AirstrikerRam]):
    start_state_cls = SurviveAndScore
    state_classes = (SurviveAndScore,)
    ram_info_cls = AirstrikerRam
    action_table = np.array([[[1] + [0] * 11, [0] * 12, [0] * 12, [0] * 12]], dtype=np.int8)
    levels = ()
python -m datenwissenschaften.tas.run search airstriker:AirstrikerWrapper config.yaml SurviveAndScore

Every state sets a one-line goal. The ROM is imported through Stable Retro from paths.roms; the engine's own test suite needs no ROM.

Configuration

Every key in config.example.yaml is required; missing or malformed values raise an error when the configuration is loaded.

Key Meaning
paths.roms, paths.integrations ROMs and custom Stable Retro integrations
paths.models Route memory per state
paths.cache The search's movie, progress, stuck marker, journal, live reports and log under tas/
paths.lab_run Marker file of a running lab run
training.game Stable Retro game id
upload.url, upload.api_key Retro Speedlab API; null disables the relay
ui.enable, ui.release Live relay on or off and the release label shown on stream
twitch.enabled Whether the stream page goes live on Twitch
agent.stall_minutes Minutes without a faster movie before the lab task starts a lab run
speedrun.workers, speedrun.segment_seconds Search processes and seconds per segment round
speedrun.id, speedrun.title, speedrun.platform The game as the stream names it
speedrun.category, speedrun.speedrun_com, speedrun.tasvideos The category run and where its records are read: speedrun.com game, category and variables, TASVideos publication
log_level Loguru log level

Testing

uv run pytest --cov=datenwissenschaften --cov-fail-under=95

Tests run on a scripted emulator, so they need no ROM.

Development

uv run ruff check .
uv run ruff format --check .

Relationship to Retro Speedlab

  • Retro Speedlab Core (this repository): the engine: segment search, verified movies, the live relay and the lab workflow.
  • Game packages: one repository per game with its RAM map, states, rewards, actions and Dokku deployment, improved by lab runs.
  • retrospeedlab.com: the lab's website, showing the stream and the speedrun.

License

Copyright © datenwissenschaften contributors.

Distributed under the GNU General Public License v3.0.

Metadata

Release files for datenwissenschaften 3.0.50

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

Source distribution (sdist)

Source distribution for datenwissenschaften 3.0.50
File Size Uploaded Provenance Actions
datenwissenschaften-3.0.50.tar.gz 46.3 kB Without provenance Details for datenwissenschaften-3.0.50.tar.gz

Built distribution (wheel)

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

Total release size: 105.7 kB

Release files / datenwissenschaften-3.0.50.tar.gz

Download URL datenwissenschaften-3.0.50.tar.gz
Size 46.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f2aa7302ccdbf6810e990cb7fc48de108febe72924b69e11afa4328656801fde
BLAKE2b-256 checksum
How to use checksums
164cbe56450a5d27ed463a04842f4b687fde7eb1be85134db4309834614bdedf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.12.15 Linux/7.0.0-1017-azure

Release files / datenwissenschaften-3.0.50-py3-none-any.whl

Download URL datenwissenschaften-3.0.50-py3-none-any.whl
Size 59.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aa9572fff7552084603e586eb579c0bfda4149fc2ce699a487c55fd8081a1942
BLAKE2b-256 checksum
How to use checksums
8bb38c9e554f477a89389d5946f59c38e8cc80053b09336f3e16d649efd98539
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.12.15 Linux/7.0.0-1017-azure

Security for datenwissenschaften 3.0.50

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.

Release history Release notifications | RSS feed

This release

3.0.50 This release

2 release files No provenance

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