Metadata-Version: 2.4
Name: miniverse-sdk
Version: 0.9.2
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Rust
Classifier: Topic :: Scientific/Engineering
Requires-Dist: rerun-sdk==0.42.*
Requires-Dist: onnx ; extra == 'onnx'
Provides-Extra: onnx
Summary: Miniverse training-run logging and the local miniverse executable
Home-Page: https://github.com/DollhouseRobotics/miniverse
License-Expression: Apache-2.0
Requires-Python: >=3.11
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Repository, https://github.com/DollhouseRobotics/miniverse

# miniverse-sdk

`pip install miniverse-sdk` installs two things: the `miniverse` Python package,
which logs training runs, and the native `miniverse` executable, which serves
them locally and pushes them to miniverse.bot. It replaces the 0.8 and earlier
`miniverse-sdk` releases, whose `miniverse_sdk` package uploaded to the
removed cloud APIs.

```python
import miniverse

run = miniverse.init("runs/walk-7", base="walker.mini", name="Walk 7")
for step in range(10_000):
    loss, reward = train_one_step()
    run.log({"train/loss": loss, "train/reward": reward}, step=step)
    if step % 1000 == 0:
        torch.onnx.export(policy, example, "exports/policy.onnx")
        run.checkpoint(step, {"policy": "exports/policy.onnx"})
run.finish()
```

```bash
miniverse serve runs
```

- `miniverse.init(run_dir, base, *, name, description, rank, push)` writes
  `run.json`, copies the base `.mini` to `base.mini`, and opens a new metric
  file for this process. Resuming a run requires the same base bytes.
- `run.log(metrics, step=)` writes each value as a Rerun Scalar at
  `metrics/<name>` on the `step` timeline. A later value at the same step
  replaces the earlier one.
- `run.checkpoint(step, models, label=)` copies one ONNX file per base model
  ID into `checkpoints/step-<step>/` and publishes the marker last.
- `run.finish()` flushes the metric file. `with miniverse.init(...) as run:`
  calls it for you, and so does interpreter exit.

Under torchrun, every rank calls the same code. Each rank writes its own
`metrics/rank<N>-attempt<K>.rrd`; only rank 0 writes run metadata and
checkpoints. The rank comes from `RANK`, or pass `rank=`.

`push=True` also mirrors the run to miniverse.bot while it trains, by running
`miniverse push --watch` and one final `miniverse push` at finish. Set
`MINIVERSE_TOKEN` to a personal access token for the first push.

`miniverse.onnx.embed_contract(model, contract, output)` embeds the v0.3
simulation contract in an exported model. It needs `pip install 'miniverse-sdk[onnx]'`.

The files are plain JSON, ZIP, ONNX, and Rerun 0.42 RRD. Jobs that already log
with `rerun-sdk` can write the same layout without this package; run
`miniverse agent-help run-directory` for the contract.

## Building

Build `@dollhouse/miniverse` and `@dollhouse/miniverse-training-ui` first,
because the executable embeds them, then build platform wheels with maturin.
Each wheel holds the Python package and that platform's executable. The wheel
workflow builds Linux x86_64/aarch64 for musl and glibc, macOS x86_64/arm64,
and Windows x86_64 and uploads CI artifacts only. Nothing publishes to PyPI
automatically. The package version comes from Cargo and must be above 0.8.0
before the first upload.

