FloPyArcade
Simulated groundwater-flow environments for reinforcement learning. Train and benchmark RL agents on MODFLOW-powered physics — no GPU, no cluster, 16 cores ≈ 1–2 days to beat human operators.
Table of Contents
- About
- Features
- Tech Stack
- Architecture
- Project Structure
- Getting Started
- Configuration
- Benchmarked Environments
- Benchmarks
- 3D Visualization
- Standalone Executables
- Testing
- Contributing
- What's Next
- Citing
- License
- Acknowledgements
- Author
About
FloPyArcade provides MODFLOW-powered groundwater simulation environments in the Gymnasium style. It builds on FloPy to enable pre- and postprocessing of MODFLOW and its related software.
The idea: provide benchmarking environments and examples to the groundwater community for experimenting with reinforcement learning algorithms in search of optimal control strategies.
💡 Why it matters: What is encapsulated in a game here can be envisioned as real-world operation of an arbitrary groundwater system. You can similarly optimize and test policy models for real-time site operation.
See the preprint for the full technical description.
Features
- 20+ environment types — discrete and continuous action spaces, multiple well configurations, cost-constrained and multi-objective variants
- Ray/RLlib integration — ready-made trainers for APExDQN, PPO, APPO, and IMPALA
- Classic DQN — Double Q-learning policy training
- Neuroevolution — genetic algorithm with optional novelty search
- 3D visualization —
pyrender-based cinematic rendering with camera orbit, glow particles, flow arrows - Manual arcade play — arrow-key control in the simplest environments
- Standalone executables — self-contained Linux/Windows/macOS binaries, no Python required
- Docker support — containerized deployment with bundled MODFLOW binaries
- BMI / MODFLOW 6 compliance — memory-based data exchange (replacing disk I/O)
- Benchmark suite — human vs. random vs. trained-network score comparisons
Tech Stack
| Layer | Technology |
|---|---|
| Language | Python 3.9 – 3.12 |
| Simulation | MODFLOW 2005, MODFLOW 6, MODPATH 6 |
| Python sim interface | FloPy ≥ 3.9.2 |
| RL framework | Gymnasium ≥ 0.29.1 |
| RL training | Ray / RLlib ≥ 2.43.0 |
| Deep learning | TensorFlow ≥ 2.16.0 |
| Rendering | Pygame 2.1.2, pyrender, Matplotlib |
| Scientific | NumPy ≥ 2.1.3, pandas ≥ 2.2.0, scikit-image ≥ 0.23.0 |
| Packaging | pyproject.toml (setuptools), cx_Freeze / PyInstaller for standalone |
Architecture
flowchart LR
A["User / RL Agent"] -->|action| B["FloPyEnv<br/>(Gymnasium API)"]
B -->|write input files| C["FloPy"]
C -->|subprocess| D["MODFLOW binary"]
D -->|head / flux output| C
C -->|observations + reward| B
B -->|obs, reward, done| A
Core loop:
- Agent selects an action (well rate, well position, or discrete choice).
FloPyEnvwrites the control values into a MODFLOW input file via FloPy.- The MODFLOW binary runs (subprocess, ~1–5 s per step).
FloPyEnvreads heads/fluxes, computes the reward (particle transport score, well capture penalty, head-boundary violation penalty).- Returns
(observation, reward, terminated, truncated, info)to the agent.
Project Structure
flopyarcade/ # CORE — Gymnasium environments
├── flopyarcade.py # FloPyEnv (Gymnasium API)
├── env_base.py # Environment base class & abstractions
├── env_config.py # Env-type parsing, grid setup, well placement
├── agent.py # Experimental solvers (DQN, neuroevolution)
├── arcade.py # Game loop & scoring
├── play.py # Manual / AI-controlled play entry point
├── play3d.py # 3D play entry point
├── render.py # 2D matplotlib rendering
├── render3d.py # 3D pyrender rendering (cinematic theme)
├── reward.py # Reward computation
├── observations.py # Observation vector assembly
├── actions.py # Action space dispatch
├── modflow_runner.py # MODFLOW 2005 / MP6 subprocess management
├── modpath_runner.py # MODPATH 6 particle tracking
├── simulators/ # Bundled MODFLOW / MP6 binaries (per-OS)
├── models/ # Trained policy checkpoints
├── examples/ # Training scripts & benchmark assets
│ ├── train_rllib_apexdqn.py # Ray RLlib APExDQN trainer
│ ├── train_rllib_ppo.py # Ray RLlib PPO trainer
│ ├── train_rllib_appo.py # Ray RLlib APPO trainer
│ ├── train_rllib_impala.py # Ray RLlib IMPALA trainer
│ ├── train_dqn.py # Classic Double DQN trainer
│ ├── train_neuroevolution.py # Genetic / novelty-search trainer
│ └── images/ # GIFs, notebooks, benchmark images
└── tests/ # pytest suite (fast + slow tiers)
Getting Started
Install
# Python >= 3.10 (numpy 2.x requirement)
# Environments only (lightweight, ~200 MB):
python -m pip install flopyarcade
# + experimental solvers (Double DQN, neuroevolution):
python -m pip install flopyarcade[solvers]
# + Ray/RLlib benchmarks:
python -m pip install flopyarcade[ray]
# Everything:
python -m pip install flopyarcade[all]
# Linux: also need a Fortran compiler (for MODFLOW binaries)
sudo apt install gfortran
Quick Start
from flopyarcade import FloPyEnv
from numpy.random import choice
env = FloPyEnv(ENVTYPE='3s-d')
reward_total = 0.0
while not env.done:
action = choice(env.actionSpace)
obs, reward, *rest = env.step(action)
reward_total += reward
env.render()
print(f"Episode reward: {reward_total:.1f}")
env.close()
Play Manually (Arcade Mode)
python -m flopyarcade.play --manualcontrol True --envtype 3r-d
Arrow keys to control. Alt+F4 to quit.
Train an Agent (Ray/RLlib) — requires pip install flopyarcade[ray]
# APExDQN on 16 cores (~1-2 days to beat human operators)
python flopyarcade/examples/train_rllib_apexdqn.py --envtype 3s-d --cpus 16
# Or PPO, APPO, IMPALA
python flopyarcade/examples/train_rllib_ppo.py --envtype 3s-d --cpus 16
Train with Classic DQN — requires pip install flopyarcade[solvers]
python flopyarcade/examples/train_dqn.py --envtype 3s-d --ngames 20000
Simulate with a Trained Policy
python flopyarcade/examples/train_rllib_apexdqn.py --playbenchmark True --envtype 3s-d
Render in 3D
python -m flopyarcade.play3d --envtype 3s-d
Dark cinematic theme, camera orbit, glow particles, flow arrows, game HUD.
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
ENVTYPE |
str |
'3s-d' |
Environment variant (see table below) |
flagRender |
bool |
True |
Render 2D matplotlib frames |
_seed |
int |
None |
Random seed for reproducibility |
NAGENTSPARALLEL |
int |
1 |
Parallel processes for neuroevolution |
num_cpus (Ray) |
int |
auto | CPU cores for distributed training |
train_batch_size (Ray) |
int |
2000 |
RLlib batch size |
minibatch_size (PPO) |
int |
2000 |
Must be ≤ train_batch_size |
rollout_fragment_length (PPO) |
int |
1000 |
GAE rollout length |
Environment variables: PYTHONWARNINGS=ignore::ResourceWarning recommended for MODFLOW subprocess cleanup.
Benchmarked Environments
| ENVTYPE | Action | Wells | Objective | Human-playable | Benchmark |
|---|---|---|---|---|---|
1s-d |
Discrete | 1 fixed | Particle transport | ✅ | ✅ |
1r-d |
Discrete | 1 random | Particle transport | ✅ | – |
2s-d |
Discrete | 2 fixed | Particle transport | ✅ | ✅ |
2r-d |
Discrete | 2 random | Particle transport | ✅ | – |
3s-d |
Discrete | 3 fixed | Particle transport | ✅ | ✅ |
3r-d |
Discrete | 3 random | Particle transport | ✅ | – |
1s-c / 1r-c |
Continuous | 1 | Multi-well control | – | – |
2s-c / 2r-c |
Continuous | 2 | Multi-well control | – | – |
3s-c / 3r-c |
Continuous | 3 | Multi-well control | – | – |
4s-c / 4r-c |
Continuous | 4 | Multi-well control | – | – |
5s-c / 5s-c-cost / 5r-c |
Continuous | 5 | Cost-constrained | – | – |
6s-c / 6r-c |
Continuous | 6 | Multi-objective | – | – |
0s-d |
Discrete (BMI) | – | Experimental (MODFLOW 6 BMI) | – | – |
The objective in all transport environments: Safely transport a virtual particle from the western to the eastern boundary following advection. Protect wells from capture. Keep the particle out of head-boundary cells (north/south). Highest score = shortest route or closest to it.
Environment GIFs (16 variants)
| 1s-d | 2s-d | 3s-d |
|---|---|---|
| 1r-d | 2r-d | 3r-d |
|---|---|---|
| 1s-c | 2s-c | 3s-c |
|---|---|---|
| 1r-c | 2r-c | 3r-c |
|---|---|---|
| 4s-c | 4r-c | 5s-c |
|---|---|---|
| 5s-c-cost | 5r-c | 6s-c |
|---|---|---|
| 6r-c | 0s-d |
|---|---|
| (experimental) |
Benchmarks
Score comparison across four operator types on 1s-d, 2s-d, 3s-d:
- Random actions
- Inexperienced human
- Experienced human
- Trained deep neural network (policy model)
The optimized policy model significantly outperforms human control.
| Metric | Image |
|---|---|
| Average score evolution | |
| Operator scores |
Reproduce:
python -m flopyarcade.train_rllib_apexdqn --envtype 3s-d --cpus 16
Monitor progress:
tensorboard --logdir /path/to/ray/logs
YouTube walkthroughs:
| 3s-d | 2s-d | 1s-d |
|---|---|---|
| ▶ Watch | ▶ Watch | ▶ Watch |
3D Visualization
render3d.py and play3d.py provide a cinematic 3D rendering pipeline via pyrender:
- Dark theme with dramatic lighting
- Glow particles along flow paths
- Comet-style trajectory trail
- 3D well visualization
- Camera orbit (mouse drag)
- Game HUD overlay (score, step, reward)
- Flow arrows on the surface
python -m flopyarcade.play3d --envtype 3s-d
Standalone Executables
Skip the Python install entirely — download a self-contained binary:
Linux x86-64
# From GitHub Releases
wget https://github.com/philipphoehn/flopyarcade/releases/download/latest/FloPyArcadePlay
chmod +x FloPyArcadePlay
./FloPyArcadePlay
Runs headless or with display (auto-detects). No Python, pip, or system dependencies required.
Windows
Download pre-built EXEs from GitHub Releases:
FloPyArcadePlay.exe(ENV 1s-d / 2s-d / 3s-d variants)
macOS
Built via PyInstaller. See build-branch/ for the build workflow.
Testing
# Fast suite (CI, ~30 s)
pytest flopyarcade/tests/ -m "not slow" -v --timeout=1800
# Full suite including Ray integration (~2 min)
pytest flopyarcade/tests/ -v --timeout=3000
# Single file
pytest flopyarcade/tests/test_rllib_cpu.py -v
| Tier | Markers | Time | Coverage |
|---|---|---|---|
| Fast | default | ~30 s | Unit, mock RLlib, render3d, regression |
| Slow | @pytest.mark.slow |
~2 min | Real Ray/RLlib 1-iteration training (DQN, PPO, APPO, IMPALA) |
Contributing
Pull requests and constructive discussions are welcome.
Flow:
- Fork → create a branch from
master - Make your changes
- Run the test suite:
pytest flopyarcade/tests/ -m "not slow" - Open a Pull Request
- For major changes, open an issue first to discuss
Guidelines:
- PEP-8 compliant (recommended, not strictly enforced)
- All new features require tests
- No breaking changes to the Gymnasium API surface without discussion
- Keep the
ENVTYPEstring contract stable (downstream scripts depend on it)
What's Next
See ROADMAP.md for the full prioritized backlog. Highlights:
- MODFLOW 6 BMI: in-memory data exchange (eliminate disk I/O)
- Distributed training on GPU clusters via Ray
- Continuous-action benchmarks (PPO / SAC)
- Multi-aquifer / 3D environment types
- Web-based playground (Browser WASM)
- Agent benchmark leaderboard API
Citing
@misc{FloPyArcade,
author = {Hoehn, Philipp},
title = {FloPyArcade: Simulated groundwater environments for reinforcement learning},
year = {2020},
publisher = {GitHub},
howpublished = {\url{https://github.com/philipphoehn/flopyarcade}},
}
Preprint: preprint_FloPyArcade.pdf
License
Acknowledgements
- FloPy — MODFLOW Python interface
- MODFLOW — USGS groundwater flow models
- Ray / RLlib — distributed RL framework
- Gymnasium — RL environment standard
- TensorFlow / Keras — deep learning
- NumPy — scientific computing
- Pygame — 2D rendering
- pyrender — 3D rendering
- pythonprogramming.net & sentdex — RL tutorials
Author
Philipp Hoehn
FloPyArcade prioritises functional correctness and benchmark reproducibility. The core loop is intentionally minimal to stay transparent and easy to extend. Developed in spare time — contributions are what make it better.
Metadata
Release files for flopyarcade 0.7.19
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 |
|---|---|---|---|---|
| flopyarcade-0.7.19.tar.gz | 43.1 MB | Without provenance | Details for flopyarcade-0.7.19.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flopyarcade-0.7.19-py3-none-any.whl | Python 3 | none | any | Details for flopyarcade-0.7.19-py3-none-any.whl |
Total release size: 86.2 MB
Release files / flopyarcade-0.7.19.tar.gz
| Download URL | flopyarcade-0.7.19.tar.gz |
|---|---|
| Size | 43.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d282c1ed24691f8d5fcfbdbc2cbb2be6504fb814af0a212b6e9181c9672ceb88
|
|
BLAKE2b-256 checksum How to use checksums |
363c5a9d12d5bb31b34030c4a86b60724b9d312b3db107c4f31c2085c9aa9c68
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / flopyarcade-0.7.19-py3-none-any.whl
| Download URL | flopyarcade-0.7.19-py3-none-any.whl |
|---|---|
| Size | 43.1 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
52817620e1145aafbc43d8182a07344e537249ccf5c163c1e6319786ea44bf8e
|
|
BLAKE2b-256 checksum How to use checksums |
160e64625d26bb0c273b494019baf90724bfbef4651cecc6a8a8c81fc922fb4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for flopyarcade 0.7.19
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.