Synthetic monitoring environments for reinforcement learning
Project description
SME-RL: Synthetic Monitoring Environments for Reinforcement Learning
Figure 1: Evaluation performance during training (column 1) and final within-distribution and out-of-distribution performance for PPO, SAC and TD3 across different complexities of the optimal policy the agent seeks to mirror (C_pi*, columns 2-4). Performance is defined as the complement of the mean average error between action and optimal action. States within $\mathbb{R}^2(0,1)$ are within-distribution. States beyond the unit square are out-of-distribution. SD = State Dimension.
SME-RL provides highly configurable Synthetic Monitoring Environments for evaluating Deep Reinforcement Learning algorithms. Designed for rapid prototyping, sanity checking, and fundamental RL research, SME integrates natively with the Gymnasium API.
Installation
You can install the package directly from PyPI:
pip install sme-rl
Note: SME-RL supports Python 3.8+ and relies on PyTorch and Gymnasium.
Quick Start
SME-RL is registered as a standard Gymnasium environment. You can initialize it using gymnasium.make() and immediately use it with standard RL libraries like Stable-Baselines3.
import gymnasium
import sme_rl # Registers the environment
from stable_baselines3 import PPO
# 1. Initialize the environment
env = gymnasium.make(
"SME-v0",
n_state_channels=8,
n_action_channels=4,
episode_length=100
)
# 2. Train an agent
model = PPO("MlpPolicy", env, verbose=1)
model.learn(total_timesteps=100_000)
# 3. Evaluate your agent
env.eval(model)
Configuration Parameters
You can heavily customize the complexity and rules of the environment during instantiation:
| Parameter | Symbol | Type | Default | Description |
|---|---|---|---|---|
n_state_channels |
N_s | int | Required | Dimensionality of the state space. |
n_action_channels |
N_a | int | Required | Dimensionality of the action space. |
episode_length |
— | int | 100 | Maximum steps per episode before truncation. |
reward_every |
k | int | 1 | Step interval for reward distribution. |
min_reward |
r_min | float | 0.0 | Minimum threshold for a step reward to be registered. |
kill_threshold |
D | float | 0.0 | Reward threshold below which the episode terminates early (survival difficulty). |
policy_complexity |
C_pi* | int | 1 | Depth of the optimal policy network. |
seed |
— | int | 1 | Global seed for procedural generation and reproducibility. |
Within- and Out-of-Distribution Evaluation
SME-RL features a built-in evaluation framework to benchmark your trained agent's generalization capabilities. By using the .eval() method, you can probe the policy across both within-distribution (WD) states (typically bounded between 0 and 1) and wide out-of-distribution (OOD) states.
The evaluation computes the mean absolute error between your agent's choices and the ground-truth optimal policy network, mapping performance to a normalized reward score.
Usage Example
# After training your model (e.g., using Stable-Baselines3)
states, opt_actions, model_actions, rewards = env.eval(
model=model,
storepath="results/eval_run", # Saves data as an .npz archive
channel_min=-1.0, # Lower bound for OOD exploration
channel_max=2.0, # Upper bound for OOD exploration
probes=10000, # Number of evaluation sample points
wd_weight=0.5 # 50% within-distribution, 50% out-of-distribution
)
print(f"Evaluated {len(states)} states.")
print(f"Mean evaluation score: {rewards.mean():.4f}")
Evaluation Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
model |
object |
Required | The trained RL agent (expects a .predict() interface compatible with SB3). |
storepath |
str / Path |
None |
Filepath directory where evaluation metrics are written out as a compressed .npz file. |
channel_min |
float |
0.0 |
Minimum bounds for sampling evaluation state channels. Limits below 0 test OOD behavior. |
channel_max |
float |
1.0 |
Maximum bounds for sampling evaluation state channels. Limits above 1 test OOD behavior. |
probes |
int |
10000 |
The total number of evaluation samples generated. |
wd_weight |
float |
0.5 |
Ratio of within-distribution samples ([0, 1]) relative to wide distribution samples. |
Returned Outputs
The evaluation function returns a tuple of four arrays:
| Output | Description |
|---|---|
states |
The sampled synthetic verification states. |
opt_a |
Target action tensors generated by the ground-truth optimal policy structure. |
a |
Action predictions selected by your trained model. |
raw_reward |
Normalized scores scaled between 0.0 and 1.0 indicating how tightly your model mirrors optimal actions. |
evaluation metrics are written out as a compressed .npz file if the storepath parameter in the eval() method is specified.
📖 Citation
If you use this environment in your research, please cite our paper:
@misc{pleiss2026smerl,
title={Synthetic Monitoring Environments for Reinforcement Learning},
author={Leonard Pleiss},
year={2026},
eprint={2603.06252},
archivePrefix={arXiv},
primaryClass={cs.LG}
}
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sme_rl-0.1.0.tar.gz.
File metadata
- Download URL: sme_rl-0.1.0.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
743f56051cd89c8400ddf4a3b3c357ca96246dfc824acbc60d825b8fb039ef7a
|
|
| MD5 |
7b56cd70cfe73d9bd77885c7fb1c1ba6
|
|
| BLAKE2b-256 |
8970fdb8944a679e1a497eb7a885a14586775ba09a3ee3436a3f311f2a1aa6e5
|
File details
Details for the file sme_rl-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sme_rl-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c54be1a287964f606fbfad37f7732b10f226f546a10d93f37b3a7e893a0d0207
|
|
| MD5 |
33dc20faeba9a24079faef5a1c2aaa5d
|
|
| BLAKE2b-256 |
fbcad6fa613b460c9020571cf463676a63d592d7938ad74813e6d61925d9233c
|