Information-theoretic metrics for Gymnasium environments
Project description
gym_info
Information-theoretic diagnostics for Gymnasium environments.
gym_info helps you inspect state and action entropies in RL environments with minimal changes to your existing Gymnasium code. You wrap an environment once, run your usual interaction loop, and then query global or per-episode entropy metrics, tables, and simple reports.
Installation
pip install gym_info
# or, with uv:
# uv add gym_info
Requirements:
- Python: $\geq$ 3.10
- Gymnasium: $\geq$ 1.2.2
Quick Start
import gymnasium as gym
import gym_info as gi
# 1. Create and wrap the environment
env = gym.make("CartPole-v1")
env = gi.attach(env, preset="classic_control", run_id="demo-run")
# 2. Run your usual interaction loop
obs, info = env.reset(seed=0)
for _ in range(200):
action = env.action_space.sample()
obs, reward, terminated, truncated, info = env.step(action)
if terminated or truncated:
obs, info = env.reset()
# 3. Global entropies for the whole run (in bits)
metrics = gi.entropies(env)
print(metrics.H_S, metrics.H_A, metrics.H_A_given_S)
# 4. High-level summary
summ = gi.summary(env)
gi.print_table(summ) # text table
gi.plot_entropies(summ) # matplotlib figure
Per-episode Analysis
You can inspect entropies for each completed episode separately.
from gym_info import entropies_per_episode, episode_entropy_series, episode_entropy_dataframe
episode_metrics = entropies_per_episode(env)
for i, m in enumerate(episode_metrics):
print(f"Episode {i}: H(S)={m.H_S:.3f}, H(A)={m.H_A:.3f}, H(A|S)={m.H_A_given_S:.3f}")
series = episode_entropy_series(env)
df = episode_entropy_dataframe(env)
Discretization
gym_info works by discretizing continuous observations and actions into bins and then computing histogram-based entropies.
-
A preset encapsulates reasonable default binning strategies for a family of environments.
-
Currently, the main preset is:
- preset="classic_control": designed for standard classic control environments such as CartPole-v1 and MountainCar-v0.
You can override discretization globally by passing obs_bins and action_bins to attach:
env = gi.attach(
env,
preset="classic_control",
run_id="demo-run",
obs_bins=20, # here
action_bins=5, # here
)
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 gym_info-0.1.0.tar.gz.
File metadata
- Download URL: gym_info-0.1.0.tar.gz
- Upload date:
- Size: 105.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3d278da5a4aa40011c115766bfc50027172c64906bd340d8458b1a1f1f4c434
|
|
| MD5 |
2bac1cad64edeabbd58429de6a1b9efa
|
|
| BLAKE2b-256 |
7caa9ba4db78475f91364026e20ef11f9a75eea566bc70e40782cb5231136a39
|
File details
Details for the file gym_info-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gym_info-0.1.0-py3-none-any.whl
- Upload date:
- Size: 22.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d2c298c0a71cdc18b5aea6bc8489c8b97e1c63235a05d29d2db280d5604492b
|
|
| MD5 |
34b6f7375eb6605b140bcf85a9f039b9
|
|
| BLAKE2b-256 |
79c731cf0e7065ef06cbca497f9582935f4df8dcee3f403ce4e8fc8070983026
|