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 is the environment layer for MOUSE, a modular PyTorch library for in-context reinforcement learning.
Why mouse-env exists
In standard RL, episodes are independent — the algorithm resets, collects one episode, and repeats. What happened in episode 1 has no bearing on episode 2.
In in-context RL, the policy is a sequence model whose context window spans multiple episodes. The model adapts its behavior from recent history in a single forward pass, without gradient updates between episodes.
mouse-env is built for this regime. You call step() in a loop forever — the environment resets itself when an episode ends and keeps going. Episode boundaries show up as done=1 or done=2 in the data, and the following step delivers the fresh starting observation. Your training loop never needs to detect episode endings or call reset() itself.
Core API
Using mouse-env looks like this:
- Build one vectorized environment with
make_vector_env(...) - Call
step(actions)in a loop; receivedata,metadata, andmetricsevery step
For each sub-environment index i:
data[i](model-visible)observationrewarddonetime
metadata[i](training-only)q_starreward_episodicepisode_indexgroup_id- plus optional env-specific metadata (for example
ns_params)
metrics[i](logging)- true episodic return and episode length, emitted only on episode end
This API is shared across tabular envs, Gymnasium control tasks, Atari, and non-stationary setups.
Install
pip install mouse-env
Development setup:
git clone https://github.com/micahr234/mouse-env.git
cd mouse-env
source scripts/install.sh
Quick start
from mouse.envs import EnvConfig, make_vector_env
cfg = EnvConfig.cartpole(seed=0, num_envs=4, max_episode_steps=500)
env = make_vector_env(cfg)
for _ in range(1000):
actions = env.sample_random_actions()
data, metadata, metrics = env.step(actions)
env.close()
Important stepping semantics
- Use
step()only — do not callreset().- The first
step()performs an internal reset and returns the initial observation withreward=0,done=0,time=0. - Actions passed on that first call are ignored.
- The first
- Autoreset is built in.
- After termination/truncation, the next emitted transition includes the reset observation (
reward=0,done=0,time=0) before normal stepping resumes.
- After termination/truncation, the next emitted transition includes the reset observation (
- Observations/actions are typed dicts of tensors.
- Observation channels can include
discrete,continuous, and/orimage. - Actions follow the same keyed structure.
- Observation channels can include
doneis integer-coded.0= running,1= terminated,2= truncated.
See docs/guide.md for full field-level documentation, plus runnable notebooks in examples/.
Included environments and integrations
1) Procedural Frozen Lake
- ID:
Procedural-FrozenLake-v1 - Config helper:
EnvConfig.procedural_frozenlake() - Random valid grid generation (size, holes, start/goal), optional per-goal rewards.
- Distinct from Gymnasium's fixed
FrozenLake-v1benchmark.
2) Synthetic Environment
- ID:
SyntheticEnv-v1 - Config helper:
EnvConfig.synthetic() - Random finite discrete MDP for controlled tabular experiments.
3) NS-Gym integration (external framework)
mouse-env integrates NS-Gym to support non-stationary dynamics through the same API.
EnvConfig.ns_cartpole(non_stationary_params={...})for scheduler/update configNSGymInterfaceWrapperto normalize observations + exposemetadata[i]["ns_params"]- Vectorized non-stationary streams with standard
(data, metadata, metrics)outputs
Example: examples/03_ns_gym_oscillating.ipynb
NS-Gym docs: nsgym.io
4) Atari integration
mouse-env keeps ALE/Gymnasium Atari semantics intact and exposes them through the same API.
EnvConfig.atari()preset:AtariPreprocessing- frame skip 4
- grayscale 84×84
- noop warm-up
- Frames are surfaced in
data[i]["observation"]["image"](flattened)
Requirement: gymnasium[atari] (ale_py).
Example: examples/04_atari_preprocessing.ipynb
Training-oriented features
Expert Q-values (q_star_source)
- Exposed as
metadata[i]["q_star"]. - Backends:
sb3_rl_zoo: pretrained Stable-Baselines3 policies from Hugging Face Hub (CartPole preset uses this by default).metadata_q_star: exact Q* solved from tabular MDP dynamics (Procedural Frozen Lake + Synthetic Environment).
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; normalized training signal appears in metadata[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.3.0.tar.gz.
File metadata
- Download URL: mouse_env-0.3.0.tar.gz
- Upload date:
- Size: 51.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7830a5251148d396f4b9c8f5399e28ef08e735dd83ce3f88e910ea123e46734
|
|
| MD5 |
06d82d0deb4d595a62b952c758f30f93
|
|
| BLAKE2b-256 |
b1d42320ce3173dad30a1a0d930a7eece38afd34c05d1b3c4ccdcf39f27f8c09
|
Provenance
The following attestation bundles were made for mouse_env-0.3.0.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.3.0.tar.gz -
Subject digest:
d7830a5251148d396f4b9c8f5399e28ef08e735dd83ce3f88e910ea123e46734 - Sigstore transparency entry: 1611950050
- Sigstore integration time:
-
Permalink:
micahr234/mouse-env@a09f60b109f918e6d8a1b6af0a0f5f2697b87798 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/micahr234
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a09f60b109f918e6d8a1b6af0a0f5f2697b87798 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mouse_env-0.3.0-py3-none-any.whl.
File metadata
- Download URL: mouse_env-0.3.0-py3-none-any.whl
- Upload date:
- Size: 54.9 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 |
c798431242b864b96464d66534174c7509e4ed51471da36aede37c49faa55c5f
|
|
| MD5 |
50a84874bfd2653e95631cb856d1a215
|
|
| BLAKE2b-256 |
7a5653fe69757aaf3715066040b65c6a4d28ee94d4b20812d4567737bba3e8d1
|
Provenance
The following attestation bundles were made for mouse_env-0.3.0-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.3.0-py3-none-any.whl -
Subject digest:
c798431242b864b96464d66534174c7509e4ed51471da36aede37c49faa55c5f - Sigstore transparency entry: 1611950241
- Sigstore integration time:
-
Permalink:
micahr234/mouse-env@a09f60b109f918e6d8a1b6af0a0f5f2697b87798 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/micahr234
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a09f60b109f918e6d8a1b6af0a0f5f2697b87798 -
Trigger Event:
push
-
Statement type: