Skip to main content

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; receive data, metadata, and metrics every step

For each sub-environment index i:

  • data[i] (model-visible)
    • observation
    • reward
    • done
    • time
  • metadata[i] (training-only)
    • q_star
    • reward_episodic
    • episode_index
    • group_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 call reset().
    • The first step() performs an internal reset and returns the initial observation with reward=0, done=0, time=0.
    • Actions passed on that first call are ignored.
  • 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.
  • Observations/actions are typed dicts of tensors.
    • Observation channels can include discrete, continuous, and/or image.
    • Actions follow the same keyed structure.
  • done is 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-v1 benchmark.

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 config
  • NSGymInterfaceWrapper to normalize observations + expose metadata[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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mouse_env-0.3.0.tar.gz (51.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mouse_env-0.3.0-py3-none-any.whl (54.9 kB view details)

Uploaded Python 3

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

Hashes for mouse_env-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d7830a5251148d396f4b9c8f5399e28ef08e735dd83ce3f88e910ea123e46734
MD5 06d82d0deb4d595a62b952c758f30f93
BLAKE2b-256 b1d42320ce3173dad30a1a0d930a7eece38afd34c05d1b3c4ccdcf39f27f8c09

See more details on using hashes here.

Provenance

The following attestation bundles were made for mouse_env-0.3.0.tar.gz:

Publisher: publish.yml on micahr234/mouse-env

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for mouse_env-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c798431242b864b96464d66534174c7509e4ed51471da36aede37c49faa55c5f
MD5 50a84874bfd2653e95631cb856d1a215
BLAKE2b-256 7a5653fe69757aaf3715066040b65c6a4d28ee94d4b20812d4567737bba3e8d1

See more details on using hashes here.

Provenance

The following attestation bundles were made for mouse_env-0.3.0-py3-none-any.whl:

Publisher: publish.yml on micahr234/mouse-env

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page