Skip to main content

Evolutionary strategy with JSON checkpoints and schema reconciliation.

Project description

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

Links

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

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

leitwerk-0.7.7.tar.gz (29.1 kB view details)

Uploaded Source

Built Distribution

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

leitwerk-0.7.7-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file leitwerk-0.7.7.tar.gz.

File metadata

  • Download URL: leitwerk-0.7.7.tar.gz
  • Upload date:
  • Size: 29.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for leitwerk-0.7.7.tar.gz
Algorithm Hash digest
SHA256 56cff7ba194032a4079f6e330c433c4da96c500268d132fa472abe77eb5d7f72
MD5 aa66d3414594c0141529c0dc7c8a3bf1
BLAKE2b-256 bdd09c63d903856fdbc3101bf0de8b7fec712ccffcc623a7b0ef264a201a9871

See more details on using hashes here.

Provenance

The following attestation bundles were made for leitwerk-0.7.7.tar.gz:

Publisher: ci.yml on phantomsc2/leitwerk

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

File details

Details for the file leitwerk-0.7.7-py3-none-any.whl.

File metadata

  • Download URL: leitwerk-0.7.7-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for leitwerk-0.7.7-py3-none-any.whl
Algorithm Hash digest
SHA256 f28b5f8d3c0a2f2d1375f306698c84e049b77a2f0c9c3d3ca89710f6c48bea2d
MD5 47c5d082c19b92de821b6c706cacfb14
BLAKE2b-256 946c72bd0be6aa880463b03e516c220f9a98c3725f798f0b24b32ddb791877ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for leitwerk-0.7.7-py3-none-any.whl:

Publisher: ci.yml on phantomsc2/leitwerk

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