Skip to main content

A lightweight, framework-agnostic abstraction for reinforcement learning policy inference.

Project description

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

All wrappers subclass PolicyWrapper. To support a new backend, implement _load_model and __call__:

from poliwrap import PolicyWrapper


class MyPolicyWrapper(PolicyWrapper):
    def _load_model(self) -> None:
        self.model = ...  # load from self.model_path

    def __call__(self, observations):
        return self.model(observations)

PolicyWrapper also has overridable preprocess_observations, postprocess_actions, and reset hooks for input/output transforms and stateful (e.g. RNN) policies.

License

MIT

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

poliwrap-0.0.8.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

poliwrap-0.0.8-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file poliwrap-0.0.8.tar.gz.

File metadata

  • Download URL: poliwrap-0.0.8.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for poliwrap-0.0.8.tar.gz
Algorithm Hash digest
SHA256 9a238fb4d03205cfb1d4a913519451d816128416d14e6d06edc53a2748e620ae
MD5 7a101aeeee28b67266144ec8e473f6b9
BLAKE2b-256 4c336cf817f9ba0342cfffbc171963b3b5843b7a492cd5261517c73f893f0140

See more details on using hashes here.

File details

Details for the file poliwrap-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: poliwrap-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for poliwrap-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 668f374cb08e57976cf7fba6b8a47da5a8e7fd98cd048b8bfe28e7206f18c171
MD5 26b3fac8e1292ac105c285b208dbe12e
BLAKE2b-256 5ddd4feefab003c88efa180e87d887c8c23dcb6b993dec7a917daeb5c122976c

See more details on using hashes here.

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