Mouse Gym 🐭
Traditional episodic reinforcement learning typically measures how well a policy performs within an episode. What it does not directly measure is how quickly an agent can improve after experiencing multiple episodes.
mouse-gym recasts Gymnasium environments around this idea. Instead of treating each episode as an isolated trial, it groups multiple episodes into a task. Episodes within a task share the same underlying problem, so the agent can remember previous attempts, adapt, and improve while it works.
The question becomes not just How well can an agent perform a task? but How quickly can it improve as it gains experience with that task? Adaptation happens within a task, across episodes — the same thing people do when they learn on the job.
mouse-gym preserves episode boundaries while presenting experience as a continuous stream, so recurrent models, transformers, and other adaptive agents can carry information forward across episodes.
News
- 2026-08-18 — 1.0.0 First stable release. Public step contract is
episode_done/task_doneon a reset-freestep()stream. - 2026-07-07 — NumPy I/O Step inputs and outputs use NumPy arrays (Gymnasium-native types). PyTorch is no longer required.
- 2026-07-02 —
tracker→metricsRenamedenv.tracker/Tracker/GroupTrackertoenv.metrics/Metrics/GroupMetrics. Example notebook renamed to 04 — Metrics. - 2026-06-29 — Repository split Mouse Gym is now its own package. Reset-free rollout infrastructure lives here; custom environment implementations live elsewhere.
- 2026-06-26 —
SingleEnv/GroupEnvmake_envreturns one env;make_group_envhandles parallel rollouts.
See CHANGELOG.md for the full release history.
Install
Requirements: Python 3.13+, Gymnasium ≥ 1.3, NumPy ≥ 1.26 (NumPy is also pulled in by Gymnasium).
pip install mouse-gym
For development:
git clone https://github.com/micahr234/mouse-gym.git
cd mouse-gym
source scripts/install.sh
Quick start
from mouse_gym import EnvConfig, make_env
cfg = EnvConfig(
id="CartPole-v1",
reset_seed=0,
episodes_per_task=5,
)
env = make_env(cfg)
for _ in range(1000):
output = env.step(env.sample_random_input())
print(env.metrics.episode_cum_rewards)
env.close()
Differences from Gymnasium
mouse-gym builds on Gymnasium — you wrap ordinary Gymnasium envs and keep their observations, rewards, and spaces. What's different is the rollout interface:
-
Reset-free rollouts. Only call
step()—SingleEnv.reset()is not part of the API, including at task boundaries. When an episode or task ends, the nextstep()returns a reset frame: initial observation,step_index=0,episode_done=0,task_done=0,reset_reward; the input is ignored. (Mouse-gym calls the underlying env's Gymnasiumreset()internally on that step — you never call it yourself.) One continuous loop; boundaries are fields in the output, not a separatereset()beforestep(). -
Dict I/O instead of Gymnasium's action + tuple. Pass
{"action": ...}tostep()(usesample_random_input()for random rollouts). Eachstep()returns one dict with named fields —task_index,episode_index,step_index,reward,episode_done,task_done,observation, andinfo— rather than(observation, reward, terminated, truncated, info). -
Tasks group episodes. A task is a consecutive run of episodes — length set by
episodes_per_taskinEnvConfig(default0: no task boundary). When a task ends, the nextstep()is a reset frame withtask_indexincremented andepisode_indexreset to0.task_done=2marks the last step of a task (episode budget exhausted).task_done=1is reserved and unused. -
episode_doneandtask_donereplaceterminated/truncated. Two independent integer fields per step, both using0/1/2:episode_done(Gymnasium episode outcome only):0— Running. A normal mid-episode step, or a reset frame (step_index=0,reward=reset_reward).1— Episode terminated. Underlying env returnedterminated=True. Do not bootstrap; the nextstep()is a reset frame.2— Episode truncated. Underlying env returnedtruncated=True. Same episode-end semantics as1.
task_done(task-boundary outcome; not copied from Gymnasium):0— Not a task boundary.1— Task terminated. Reserved; never emitted today (no task-success/failure signal yet).2— Task truncated. This episode completed and it was the last episode in the task (episodes_per_taskreached). Bootstrap here; the nextstep()is a reset frame that starts a new task (task_indexincrements,episode_indexresets to0).
- On the last episode of a task both fields fire together — e.g.
episode_done=1andtask_done=2. Withepisodes_per_task=0(default),task_donestays0. Gymnasium has no task grouping or equivalent codes.
Additions to Gymnasium
On top of the standard env API, mouse-gym adds:
-
Metrics on the env. Episode returns and lengths accumulate in
env.metrics, not in thestep()return value. Whenepisodes_per_task > 0, completed tasks also record reward and length sums inenv.metrics.task_cum_rewardsandenv.metrics.task_lengths. See 04 — Metrics. -
Grouped envs.
GroupEnvsteps multipleSingleEnvinstances in onestep()call and returns a flatlist[dict]— useful for mixed or multi-task setups without a vectorized wrapper. By default (max_threads=0) stepping is sequential on the calling thread; setmax_threads > 0to distribute envs across that many worker threads. See 02 — Multiple envs. -
Input/output specs.
input_specandoutput_specdescribe the construction-time contract for step dict shapes and dtypes (onGroupEnv,input_specs[i]andoutput_specs[i]). See 01 — Random rollout.
Examples
The notebooks in examples/ are the detailed reference for EnvConfig, input/output fields, and day-to-day usage. Install notebook dependencies with pip install "mouse-gym[examples]", then work through them in order:
01 — Random rollout — Start here. Build an env from EnvConfig, run the reset-free step() loop, and inspect what comes back on each call: input dict (action), output dict (task_index, episode_index, step_index, reward, episode_done, task_done, observation, info), reset frames, and done codes. Also covers input_spec / output_spec and optional env_fn factories.
02 — Multiple envs — Combine several env instances with make_group_env. Step heterogeneous envs (different ids, spaces, and seeds) in one loop; optionally parallelize with max_threads; read flat list[dict] inputs and outputs; use env.names, input_specs[i], and output_specs[i].
03 — RNG seeding control — Reproduce or vary behavior with reset_seed (internal reset stream) and env.action_space.seed() (random action sampling), independently.
04 — Metrics — Read episode returns and lengths from env.metrics, clear between eval runs, and aggregate stats across a GroupEnv.
Contributing
See CONTRIBUTING.md.
License
GNU General Public License v3.0 — see LICENSE.
Metadata
Release files for mouse-gym 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mouse_gym-1.0.0.tar.gz | 34.2 kB | With provenance | Details for mouse_gym-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mouse_gym-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for mouse_gym-1.0.0-py3-none-any.whl |
Total release size: 62.5 kB
Release files / mouse_gym-1.0.0.tar.gz
| Download URL | mouse_gym-1.0.0.tar.gz |
|---|---|
| Size | 34.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
04147c2bdd2749ecc85b8e3d1d3a47e3edd7111bcb2c087d0455119d8eb767d1
|
|
BLAKE2b-256 checksum How to use checksums |
0cb243ea7f75d33acac6beabc3871c26c2e07a63feb93da3142efef8ff74ef74
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 18, 2026.
Transparency logRelease files / mouse_gym-1.0.0-py3-none-any.whl
| Download URL | mouse_gym-1.0.0-py3-none-any.whl |
|---|---|
| Size | 28.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8acb31e0ddf51cb8bec5e7ba5d2900d51a2b7763d153b7714732251747fc1f48
|
|
BLAKE2b-256 checksum How to use checksums |
281544927fc005cd26d1c10de12e5a81781a3f0a641d76bbdb377c520281cff5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 18, 2026.
Transparency logSecurity for mouse-gym 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for mouse_gym-1.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 18, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.