Metadata-Version: 2.5
Name: env-ssl-wrapper
Version: 0.1.5
Summary: One torch-native interface for any MDP environment
Project-URL: Homepage, https://pypi.org/project/env-ssl-wrapper/
Project-URL: Repository, https://codeberg.org/lucidrains/env-ssl-wrapper
Author-email: Phil Wang <lucidrains@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Phil Wang
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: artificial intelligence,deep learning,reinforcement learning,self supervised learning
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.10
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Requires-Dist: discrete-continuous-embed-readout
Requires-Dist: einops>=0.8.1
Requires-Dist: einx>=0.3.0
Requires-Dist: memmap-replay-buffer
Requires-Dist: torch-einops-utils>=0.0.29
Requires-Dist: torch>=2.5
Requires-Dist: x-mlps-pytorch
Requires-Dist: x-transformers
Provides-Extra: examples
Provides-Extra: test
Requires-Dist: dm-control; extra == 'test'
Requires-Dist: gymnasium>=0.29.1; extra == 'test'
Requires-Dist: imageio; extra == 'test'
Requires-Dist: mujoco; extra == 'test'
Requires-Dist: pillow; extra == 'test'
Requires-Dist: populora; extra == 'test'
Requires-Dist: pygame; extra == 'test'
Requires-Dist: pytest; extra == 'test'
Description-Content-Type: text/markdown

# env-ssl-wrapper

One line turns any simulator's environment — gymnasium, dm_control, isaac, maniskill, pybullet, robosuite, pufferlib — into the same torch-native interface.

## Install

```bash
pip install env-ssl-wrapper
```

## Usage

```python
import torch
from env_ssl_wrapper import compose_env

env = compose_env(
    any_env,                                 # any env from any sim
    ('tensor', dict(device='cpu')),          # wrap with whatever you need
    'done_tracker',
)

obs, info = env.reset()                      # torch.float32, batched
while not env.all_done:
    actions = torch.randint(0, 2, (8,))
    obs, reward, terminated, truncated, info = env.step(actions)
```

Works identically for every simulator.

## Wrappers

Pass wrappers as strings (default config) or `(name, dict)` tuples (custom config), in any order.

| Wrapper | What it does |
|---|---|
| `standardize` | Normalizes any sim's `step`/`reset` signatures, vectorization, and autoreset into `(obs, reward, terminated, truncated, info)`. Applied automatically. |
| `time_limit` | Caps episodes, sets `truncated=True`. `('time_limit', dict(max_timesteps=200))` |
| `done_tracker` | Tracks per-env `episode_lengths`, exposes `env.all_done` / `env.needs_reset`. |
| `pad_episodes` | Standardizes padding for uneven vectorized episodes: done envs emit zeros (float/int) / `False` (bool) obs, and rewards are zeroed from the step after termination onward (the terminating step's own reward is the real terminal transition reward and is preserved). Applied automatically to vectorized envs. Works for autoreset (Isaac, gymnasium) and non-autoreset (pufferlib, maniskill) envs alike. |
| `auto_batch` | Gives single envs a leading batch dim: `(4,)` → `(1, 4)`. |
| `action_transform` | Rescales actions from a canonical `(0, 1)` range to the env's bounds. |
| `tensor` | NumPy → torch on a device, torch actions → numpy for the sim. |
| `flatten_obs` | Flattens dict/tuple observations into a single vector. |

Every env emits the same contract: obs `torch.float32`, rewards `torch.float32`, `terminated`/`truncated` `torch.bool`. `env.seed(n)` works on every sim.

Terminated envs are uniformly padded (zeros / `False` obs; rewards zeroed only after the terminating step, so the terminal transition's reward is never lost), and `info['final_observation']` — the true terminal obs, frozen per env and re-emitted while the env stays done — is always present once any env has terminated, with `info['_final_observation']` masking which envs it applies to. `env.is_done` always reflects the per-env done mask.

## Mock sims

`env_ssl_wrapper.mocks` ships dependency-free stand-ins emulating each simulator's quirks (`GymnasiumMockEnv`, `IsaacMockEnv`, `DMControlMockEnv`, ...) for testing your code without installing the real sims.

```python
from env_ssl_wrapper.mocks import IsaacMockEnv
env = compose_env(IsaacMockEnv(), 'tensor', 'done_tracker')
```

## Tests

```bash
uv sync --extra test
uv run pytest tests/test_real_envs.py
```
