Evolutionary strategy with file persistence and schema reconciliation.
Project description
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 .
For a development setup with tests, docs, benchmarks and burnysc2:
pip install -e .[dev,docs,benchmark]
The SC2 example requires the game itself or Docker to be installed.
Minimal Example
At base level, leitwerk is a sequential ask/tell function maximizer:
from leitwerk import Optimizer, Parameter
opt = Optimizer({"x": Parameter()})
for _ in range(100):
x = opt.ask()["x"]
fx = -(x - 1)**2
opt.tell(fx)
>>> opt.mean
{'x': 1.0007710964577097}
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
OptimizerSessionand 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 stateplot.png: graphs showing parameter samples and results with a moving averagehistory.json: helper file
Developer Commands
make fix: auto-formatmake check: lint and testmake docs: build docsmake docs-serve: serve docs locally
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file leitwerk-0.7.1.tar.gz.
File metadata
- Download URL: leitwerk-0.7.1.tar.gz
- Upload date:
- Size: 28.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49da5df3da3809ab41d1df96913ad83764946fe29bd05ec761baa7c1c0e34cb8
|
|
| MD5 |
40405a10b08e4835df360ede7177a787
|
|
| BLAKE2b-256 |
91108ed684928ef939293764207ccd93e0196f39e5f8b799080e4038276fa741
|
Provenance
The following attestation bundles were made for leitwerk-0.7.1.tar.gz:
Publisher:
ci.yml on phantomsc2/leitwerk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
leitwerk-0.7.1.tar.gz -
Subject digest:
49da5df3da3809ab41d1df96913ad83764946fe29bd05ec761baa7c1c0e34cb8 - Sigstore transparency entry: 1188943762
- Sigstore integration time:
-
Permalink:
phantomsc2/leitwerk@28930735845836efde6e56acb8faf3e7b93c5794 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/phantomsc2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@28930735845836efde6e56acb8faf3e7b93c5794 -
Trigger Event:
push
-
Statement type:
File details
Details for the file leitwerk-0.7.1-py3-none-any.whl.
File metadata
- Download URL: leitwerk-0.7.1-py3-none-any.whl
- Upload date:
- Size: 21.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
853aa6c39a7ed943f2a980497a45851ce66eadc34aa13a1e895aa6687eb1bfc1
|
|
| MD5 |
e91cbbdc6ad9a2f61fee30d0f198c63c
|
|
| BLAKE2b-256 |
6400c643cbe863889976dc21283dc299242f71d9f9912be9dcd5cec31e3c9773
|
Provenance
The following attestation bundles were made for leitwerk-0.7.1-py3-none-any.whl:
Publisher:
ci.yml on phantomsc2/leitwerk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
leitwerk-0.7.1-py3-none-any.whl -
Subject digest:
853aa6c39a7ed943f2a980497a45851ce66eadc34aa13a1e895aa6687eb1bfc1 - Sigstore transparency entry: 1188943765
- Sigstore integration time:
-
Permalink:
phantomsc2/leitwerk@28930735845836efde6e56acb8faf3e7b93c5794 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/phantomsc2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@28930735845836efde6e56acb8faf3e7b93c5794 -
Trigger Event:
push
-
Statement type: