Meta-Optimization Using Sequential Experiences — environments
Project description
MOUSE Environments 🐭
Warning: MOUSE is in early development and is not yet ready for production use. APIs may change without notice.
mouse-env turns episodic reinforcement learning environments into continuing environments. Instead of asking user code to alternate between step() and reset(), mouse-env handles resets internally so a rollout can continue through one uninterrupted step() loop.
Most RL benchmarks are episodic: an agent acts until termination or truncation, the caller calls reset(), and a new trial begins. That is a good interface when each episode is an independent sample. It is less natural when the experiment studies behavior across multiple episodes, where what the agent observes or discovers in one episode can affect what it does in a later one.
You can stitch episodes together on top of Gymnasium yourself, but the result is usually ad hoc. Important choices become arbitrary: whether reset observations are kept, how episode boundaries are marked, and how rewards behave at the boundary. mouse-env makes the episode-to-continuing conversion explicit and consistent in three ways:
- Reset-free rollout. Users keep calling
step(actions). When an episode ends, mouse-env resets the underlying environment internally and returns the next observation without requiring a publicreset()call. - Visible episode structure. Terminations, truncations, and reset frames stay in the data returned by the environment, so agents and analysis code can see where one episode ended and the next began.
- Cross-episode friendly rewards. In episodic RL, credit is cut off at the reset boundary. A reward in the next episode does not encourage useful behavior in the previous one. mouse-env keeps raw environment rewards available, and also exposes a transformed reward signal that allows credit to pass across resets.
The result is a continuing interface for episodic RL: ordinary episodic Gymnasium environments can generate reset-free trajectories for multi-episode problems, with visible episode boundaries and rewards that allow value to propagate across trials.
Install 📦
pip install mouse-env
For development:
git clone https://github.com/micahr234/mouse-env.git
cd mouse-env
source scripts/install.sh
Quick start 🚀
Build an env, sample actions, and keep stepping:
from mouse_envs import EnvConfig, make_vector_env
cfg = EnvConfig(
group_id="CartPole-v1",
seed=0,
num_envs=4,
max_episode_steps=500,
)
env = make_vector_env(cfg)
for _ in range(1000):
actions = env.sample_random_actions()
results, metrics = env.step(actions)
env.close()
See docs/guide.md for full field-level documentation, plus runnable notebooks in examples/.
Core API ⚙️
There is no public rollout-time reset() call. The first step() quietly performs an internal reset and returns the initial observation using the same record shape as every other step. Actions passed on that first call are ignored.
After an episode terminates or truncates, the next call to step() emits the reset observation for the next episode before normal stepping resumes.
Each call returns two objects:
results— model-visible training data, including observations (discrete,continuous, and/orimagetensor channels), rewards, done flags, time, episode metadata, optionalq_startarget expert action-values, and environment-specific fieldsmetrics— logging data, such as true episodic return and episode length, emitted when episodes end
actions follow the same typed-dictionary structure as observations.
Episode boundaries are represented by integer-coded done values:
0= running1= terminated2= truncated
Reset frames are ordinary results records with:
- the first observation of the new episode
time=0- the configured
reset_reward, which is0by default done=0
This keeps the rollout stream uniform while still making episode structure explicit.
Gymnasium environments 🌎
Pass any Gymnasium environment id as group_id. mouse-env builds the underlying Gymnasium env, steps it internally, and exposes the concatenated non-episodic stream through the same API.
mouse-env also includes a couple of custom environments. Other envs that need their own package — Atari (gymnasium[atari]) or non-stationary NS-Gym (ns_gym) — have no special code here; you build them in an env_fn factory (see Bring your own env and the examples).
Procedural Frozen Lake
- ID:
Procedural-FrozenLake-v1 - Random valid grid generation: size, holes, start/goal, and optional per-goal rewards.
- Example: examples/02_q_star_expert.ipynb
Synthetic Environment
- ID:
SyntheticEnv-v1 - Random finite discrete MDP for controlled tabular experiments.
- Example: examples/07_synthetic_env.ipynb
Environment Tools 🛠️
mouse-env also includes a few knobs for augmenting and modifying environments.
Expert Q-values (q_star_source)
Expert Q-values are exposed as results[i]["q_star"]. They are useful for supervision, diagnostics, or comparing learned behavior against an expert or exact tabular solution.
Example: examples/02_q_star_expert.ipynb
Bring your own env (env_fn)
Instead of a group_id string, pass env_fn — a zero-arg factory that returns a freshly built (and already-wrapped, if you like) Gymnasium env. mouse-env calls it once per parallel env, so it must return a new env each time (not a shared instance). group_id is still used as the identity label, and max_episode_steps is still required (for reward normalisation); kwargs, render, and the internal max_episode_steps time limit are left to your factory.
def make_env():
env = gym.make("CartPole-v1", max_episode_steps=500)
return MyWrapper(env) # apply any Gymnasium wrappers here
cfg = EnvConfig(group_id="my-cartpole", seed=0, num_envs=4, max_episode_steps=500, env_fn=make_env)
This is also how you apply custom Gymnasium wrappers (preprocessing, observation transforms, etc.): wrap inside your factory.
Observation routing (observation_kind)
Force the observation channel with observation_kind ("continuous", "discrete", or "image"). Defaults to auto-detection from the observation space; required ("image") for image envs, which auto-detection cannot recognise.
Partial observability
Use observation_indices to mask dimensions on continuous-vector observation spaces.
Example: examples/05_partial_observability.ipynb
Reward shaping
Use reward_scale and reward_shift; the normalized training signal appears in results[i]["reward_episodic"].
Example: examples/06_reward_shaping.ipynb
Contributing
See CONTRIBUTING.md.
License
GNU General Public License v3.0 — see 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 mouse_env-0.4.1.tar.gz.
File metadata
- Download URL: mouse_env-0.4.1.tar.gz
- Upload date:
- Size: 47.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51a6b8b21dc8df5ac06dc3b2270e928e5c6d295a262278ea2304d8724cbdcf89
|
|
| MD5 |
45c4ab2b5e6872f51bc5c1dc5c0bc847
|
|
| BLAKE2b-256 |
675e8d977c84b7bdc03a12a3766ffec54fa7b27bc007e1045dfb65e46cfff0ea
|
Provenance
The following attestation bundles were made for mouse_env-0.4.1.tar.gz:
Publisher:
publish.yml on micahr234/mouse-env
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mouse_env-0.4.1.tar.gz -
Subject digest:
51a6b8b21dc8df5ac06dc3b2270e928e5c6d295a262278ea2304d8724cbdcf89 - Sigstore transparency entry: 1735224697
- Sigstore integration time:
-
Permalink:
micahr234/mouse-env@ee47e139c31f72b57d94777c99df2d89b6f4fe73 -
Branch / Tag:
refs/tags/v0.4.1 - Owner: https://github.com/micahr234
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ee47e139c31f72b57d94777c99df2d89b6f4fe73 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mouse_env-0.4.1-py3-none-any.whl.
File metadata
- Download URL: mouse_env-0.4.1-py3-none-any.whl
- Upload date:
- Size: 49.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bba9456d83ce74b93dc942701c12c18a1468f43046df045309a9a8c9109f43c
|
|
| MD5 |
e96013a9f547560990056e5775a1adce
|
|
| BLAKE2b-256 |
c9c506d3a8d753e328d5247d3192d3578c59e5fe5615be54157ec544e6369593
|
Provenance
The following attestation bundles were made for mouse_env-0.4.1-py3-none-any.whl:
Publisher:
publish.yml on micahr234/mouse-env
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mouse_env-0.4.1-py3-none-any.whl -
Subject digest:
8bba9456d83ce74b93dc942701c12c18a1468f43046df045309a9a8c9109f43c - Sigstore transparency entry: 1735224712
- Sigstore integration time:
-
Permalink:
micahr234/mouse-env@ee47e139c31f72b57d94777c99df2d89b6f4fe73 -
Branch / Tag:
refs/tags/v0.4.1 - Owner: https://github.com/micahr234
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ee47e139c31f72b57d94777c99df2d89b6f4fe73 -
Trigger Event:
push
-
Statement type: