PoliWrap
A lightweight, framework-agnostic wrapper for reinforcement learning policy inference.
Installation
pip install poliwrap # core only (numpy)
pip install poliwrap[onnx] # + ONNX Runtime backend (CPU)
pip install poliwrap[onnx-gpu] # + ONNX Runtime backend (CUDA)
pip install poliwrap[torch] # + PyTorch backend
pip install poliwrap[all] # all backends (CPU ONNX)
Each wrapper is importable only when its backend is installed.
Usage
ONNX
from poliwrap import ONNXPolicyWrapper
policy = ONNXPolicyWrapper("policy.onnx")
actions = policy({"actor_obs": obs}) # obs: dict[str, np.ndarray]
PyTorch
from poliwrap import TorchPolicyWrapper
policy = TorchPolicyWrapper("policy.pt")
actions = policy({"actor_obs": obs}) # obs: dict[str, torch.Tensor]
Extending
PolicyWrapper is generic over observation and action types. File-backed
implementations can inherit from FilePolicyWrapper, which provides a
model_path:
from pathlib import Path
import numpy as np
from poliwrap import FilePolicyWrapper
class MyPolicyWrapper(FilePolicyWrapper[dict[str, np.ndarray], np.ndarray]):
def __init__(self, model_path: str | Path) -> None:
super().__init__(model_path)
self._load_model()
def _load_model(self) -> None:
self.model = ... # load from self.model_path
def __call__(self, observations: dict[str, np.ndarray]) -> np.ndarray:
return self.model(observations)
PolicyWrapper has no path requirement, so policies backed by other sources can
subclass it directly. Both base classes provide preprocess_observations,
postprocess_actions, and reset hooks.
License
MIT
Metadata
Release files for poliwrap 0.0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| poliwrap-0.0.9.tar.gz | 4.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| poliwrap-0.0.9-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.0 kB
Release files / poliwrap-0.0.9.tar.gz
| Download URL | poliwrap-0.0.9.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b0b6c3780a127d7ab0c8564b3ba950e5b8342cedbc1c665912eb9d1986ce1d42
|
|
BLAKE2b-256 checksum How to use checksums |
b857c1f66df1d38b8648278108498bb3c80f378d1bb3c899cb4239979293f2a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.22 {"installer":{"name":"uv","version":"0.11.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / poliwrap-0.0.9-py3-none-any.whl
| Download URL | poliwrap-0.0.9-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
34179537f270cb467e58301dac74f5513ca0657f295f7da0b46712e3018a99c8
|
|
BLAKE2b-256 checksum How to use checksums |
005619323a619d7e5e4dc1c8be2d090c7899f457335dcd7d819f2764bf275b67
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.22 {"installer":{"name":"uv","version":"0.11.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|