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.8.0

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.8.0
File Size Uploaded Provenance Actions
leitwerk-0.8.0.tar.gz 30.4 kB With provenance Details for leitwerk-0.8.0.tar.gz

Built distribution (wheel)

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

Total release size: 53.0 kB

Release files / leitwerk-0.8.0.tar.gz

Download URL leitwerk-0.8.0.tar.gz
Size 30.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3a4ec04a0101227932e65a6151bf0483c4d6640489f7bcfcd81b4c522d45eac3
BLAKE2b-256 checksum
How to use checksums
59ceec318072d34a92c3e8a1a45747df51806121f0f915fae31edd3e6cd53c67
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 Aug 7, 2026.

Transparency log

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

Download URL leitwerk-0.8.0-py3-none-any.whl
Size 22.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b98d99e9aaf19cc0f314b44a4fbe6103a1f9037b1aadea1cc111b1b4fdef7511
BLAKE2b-256 checksum
How to use checksums
9846fa689baa963ebe120d93c1ff5ce26bdf897de4b9888c0614b8135140d36c
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 Aug 7, 2026.

Transparency log

Security for leitwerk 0.8.0

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.8.0.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 Aug 7, 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