Skip to main content

Leitwerk

Leitwerk

Tune your magic numbers with stochastic optimization.

leitwerk is a schema-based evolutionary optimizer for long-running training loops.

It offers:

  • parameters as plain dataclasses in your code
  • JSON checkpoints you can inspect and resume
  • schema reconciliation, so you can keep developing and retain progress

Installation

Requires: Python 3.11 - 3.14

pip install leitwerk

For a local development setup with testing, linting and burnysc2:

pip install -e .[dev,docs,benchmark]

The StarCraft II example also requires the game itself or Docker to be installed.

Minimal Example

At base level, leitwerk is a sequential ask/tell function maximizer:

from dataclasses import dataclass

from leitwerk import Optimizer, parameter

@dataclass
class Params:
    x: float = parameter()

opt = Optimizer(Params)
for _ in range(100):
    x = opt.ask().x
    fx = -(x - 1)**2
    opt.tell(fx)
>>> opt.mean
Params(x=1.0000396079866551)

Everything else is wrapping for easier representation, bounds, typing and persistence.

Example - StarCraft II Bot

For a real training loop showcasing most features, see examples/train_sc2_bot.py:

  • a simple worker rush bot with two parameters
  • runs games continually against the built-in AI
  • scores each game using win/loss and a combat heuristic
  • persists state with OptimizerSession and plot results

Run it directly if you want to observe the games:

python examples/train_sc2_bot.py

Alternatively, use the headless Docker setup:

cd examples
docker compose up --build

On the first run, this will download and unpack the SC2 Linux installation inside the container. Afterward, it will run significantly faster than the rendered game on the host.

Training Results

The example saves progress in examples/data after each game:

  • params.json: optimizer state
  • plot.png: graphs showing parameter samples and results with a moving average
  • history.json: helper file

Example Plot

Developer Commands

  • make fix: auto-format
  • make check: lint and test
  • make docs: build docs
  • make docs-serve: serve docs locally

Metadata

Release files for leitwerk 0.9.1

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

Source distribution (sdist)

Source distribution for leitwerk 0.9.1
File Size Uploaded Provenance Actions
leitwerk-0.9.1.tar.gz 32.9 kB With provenance Details for leitwerk-0.9.1.tar.gz

Built distribution (wheel)

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

Total release size: 55.8 kB

Release files / leitwerk-0.9.1.tar.gz

Download URL leitwerk-0.9.1.tar.gz
Size 32.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f17b8e5c8f2aea68f3ed6bedee7a5538972b8260672fc3a06efbc6fc22d75bd6
BLAKE2b-256 checksum
How to use checksums
eaab48d357254e750389fb27a8215eb7506cda1a3ec84c71982fb74b183a7827
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

Release files / leitwerk-0.9.1-py3-none-any.whl

Download URL leitwerk-0.9.1-py3-none-any.whl
Size 22.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3c8d3e891d84ef312754b3474182eb76ba9822b32a86ac0cabcf7e07cc4163c6
BLAKE2b-256 checksum
How to use checksums
c2222df9da7c77d3a4201350d9987b41954a0a6217470dc8588b7bafc50bdbef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

Security for leitwerk 0.9.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for leitwerk-0.9.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

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