Skip to main content

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.

banner

PyPI Tests Coverage Python License Binder


Table of Contents


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:

  1. Agent selects an action (well rate, well position, or discrete choice).
  2. FloPyEnv writes the control values into a MODFLOW input file via FloPy.
  3. The MODFLOW binary runs (subprocess, ~1–5 s per step).
  4. FloPyEnv reads heads/fluxes, computes the reward (particle transport score, well capture penalty, head-boundary violation penalty).
  5. 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
1s-d 2s-d 3s-d
1r-d 2r-d 3r-d
1r-d 2r-d 3r-d
1s-c 2s-c 3s-c
1s-c 2s-c 3s-c
1r-c 2r-c 3r-c
1r-c 2r-c 3r-c
4s-c 4r-c 5s-c
4s-c 4r-c 5s-c
5s-c-cost 5r-c 6s-c
5s-c-cost 5r-c 6s-c
6r-c 0s-d
6r-c (experimental)

Benchmarks

Score comparison across four operator types on 1s-d, 2s-d, 3s-d:

  1. Random actions
  2. Inexperienced human
  3. Experienced human
  4. Trained deep neural network (policy model)

The optimized policy model significantly outperforms human control.

Benchmarks

Metric Image
Average score evolution Evolutions
Operator scores 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

3D environment


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:

  1. Fork → create a branch from master
  2. Make your changes
  3. Run the test suite: pytest flopyarcade/tests/ -m "not slow"
  4. Open a Pull Request
  5. 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 ENVTYPE string 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

GNU GPLv3


Acknowledgements


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.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flopyarcade 0.7.10
File Size Uploaded Provenance Actions
flopyarcade-0.7.10.tar.gz 51.6 MB Without provenance Details for flopyarcade-0.7.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for flopyarcade 0.7.10
File Interpreter ABI Platform Actions
flopyarcade-0.7.10-py3-none-any.whl Python 3 none any Details for flopyarcade-0.7.10-py3-none-any.whl

Total release size: 103.2 MB

Release files / flopyarcade-0.7.10.tar.gz

Download URL flopyarcade-0.7.10.tar.gz
Size 51.6 MB
Tags Source
SHA-256 checksum
How to use checksums
2886433d2da2aa9ffce1a8e512cbbe94691bf3ec793d23b8e8ceee43c0ea2521
BLAKE2b-256 checksum
How to use checksums
9a5b9b792c37ed9a4851da84f59ff04d5e0167fe8a4168343fccf30eb65c6299
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.10-py3-none-any.whl

Download URL flopyarcade-0.7.10-py3-none-any.whl
Size 51.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
29d213a165449af6a6586810d1edf78c2ba5400cfa0fdbaf98ec02e9e04b93d4
BLAKE2b-256 checksum
How to use checksums
9ad9036be9df5c2413af5c12e82165f4586b8cfe5b944f35286c44ddbb3fd2eb
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.10

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.

Release history Release notifications | RSS feed

This release

0.7.10 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page