Metadata-Version: 2.4
Name: lockstep-train
Version: 0.6.1
Requires-Dist: numpy>=1.26
Requires-Dist: gymnasium>=1.0
Requires-Dist: pytest>=8 ; extra == 'dev'
Requires-Dist: pettingzoo>=1.24 ; extra == 'dev'
Requires-Dist: pettingzoo>=1.24 ; extra == 'pettingzoo'
Provides-Extra: dev
Provides-Extra: pettingzoo
Provides-Extra: vector
Summary: Every Lockstep environment as a Gymnasium / PettingZoo environment — one package, driven by each engine's own declaration.
Requires-Python: >=3.11
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Homepage, https://lockstep.it

# lockstep-train

Every [Lockstep](https://lockstep.it) environment — a robot, a fraud desk, a
market, a jetpack duel — as a standard [Gymnasium](https://gymnasium.farama.org)
or [PettingZoo](https://pettingzoo.farama.org) environment. One package for
all of them: each environment's engine declares its own observations, actions,
reward and scoring, and `lockstep-train` turns that declaration into spaces.

It runs the same engine the platform's ranked matches and assessments run, so
what you train against locally is exactly what you will be scored on.

## Install

```
pip install lockstep-train               # Gymnasium
pip install "lockstep-train[pettingzoo]" # + multi-agent
```

Python 3.11+, prebuilt wheels for macOS (Apple silicon), Linux (x86_64,
aarch64) and Windows (x86_64).

## Quick start

```python
import gymnasium as gym
import lockstep_train.env  # registers Lockstep/Env-v0
from lockstep_train.fetch import fetch

engine = fetch("jetpack-joust", mode="default", out="engines/jetpack-joust")["engine.wasm"]
env = gym.make("Lockstep/Env-v0", engine_source=str(engine))
obs, info = env.reset(seed=0)
obs, reward, terminated, truncated, info = env.step(env.action_space.sample())
```

`fetch` downloads an environment's current release (its engine, plus any data
it ships) once; `engine_source` takes that path, any other local `engine.wasm`,
or an http(s) URL. Observations are a `Dict` of named arrays and actions a
`Box` with per-element bounds, both straight from the engine's declaration.
Browse the environments at [exhibitions.lockstep.it](https://exhibitions.lockstep.it).

Works with Stable-Baselines3, CleanRL, TorchRL or your own loop.

**Seeds.** `reset(seed=s)` fixes the session seed, and every later reset
without a seed (each autoreset included) continues deterministically from
`s`, so one seed reproduces a whole run, not just its first episode. An env
that was never seeded draws each episode's seed from the OS.

## Vectorized training

```python
from lockstep_train.env import LockstepVectorEnv

envs = LockstepVectorEnv(num_envs=8, engine_source=str(engine))
obs, infos = envs.reset(seed=0)
obs, rewards, terminations, truncations, infos = envs.step(envs.action_space.sample())
```

N sessions step on native threads with the GIL released — no worker
processes. `gym.make_vec("Lockstep/Env-v0", num_envs=8, engine_source=...)`
works too. Autoreset is `SAME_STEP`: an ended episode's last observation is in
`infos["final_obs"]`.

## Multi-agent

`LockstepEnv` drives one seat; any other seats play the engine's declared
neutral action. To train every seat:

```python
from lockstep_train.env import LockstepParallelEnv  # needs lockstep-train[pettingzoo]

env = LockstepParallelEnv(engine_source=str(engine))
observations, infos = env.reset(seed=1)  # agents: seat_0, seat_1, ...
observations, rewards, terminations, truncations, infos = env.step(
    {agent: env.action_space(agent).sample() for agent in env.agents}
)
```

## Command line

```
python -m lockstep_train.info --env jetpack-joust [--mode M] [--json]
python -m lockstep_train.fetch --environment jetpack-joust [--mode M] [--out DIR]
```

`info` prints an environment's brief — the goal, what earns reward, what ends
an episode, how you are scored, and every observation and action with its units
and bounds. `fetch` is the command-line form of `fetch()` above.

## Assessment environments

Environments a company invited you to are assessment-only: their releases
download only with your API key. Mint one on the Authorization page at
[lockstep.it](https://lockstep.it) and set it before fetching:

```
export LOCKSTEP_API_KEY=<your key>          # PowerShell: $env:LOCKSTEP_API_KEY = "<your key>"
```

## Going further

The [lockstep-template](https://github.com/lockstep-it/lockstep-template) wraps
all of this in a complete workflow — create an agent, train it, run local
matches, watch replays, and upload.

