flopyarcade 0.7.0__tar.gz → 0.7.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {flopyarcade-0.7.0/flopyarcade.egg-info → flopyarcade-0.7.2}/PKG-INFO +63 -37
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/README.md +46 -28
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/__init__.py +10 -2
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/actions.py +81 -1
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/agent.py +20 -21
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/arcade.py +6 -1
- flopyarcade-0.7.2/flopyarcade/benchmark.py +388 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/env_base.py +19 -8
- flopyarcade-0.7.2/flopyarcade/examples/__init__.py +1 -0
- {flopyarcade-0.7.0/flopyarcade → flopyarcade-0.7.2/flopyarcade/examples}/train_rllib_apexdqn.py +320 -333
- {flopyarcade-0.7.0/flopyarcade → flopyarcade-0.7.2/flopyarcade/examples}/train_rllib_appo.py +359 -373
- {flopyarcade-0.7.0/flopyarcade → flopyarcade-0.7.2/flopyarcade/examples}/train_rllib_impala.py +359 -373
- {flopyarcade-0.7.0/flopyarcade → flopyarcade-0.7.2/flopyarcade/examples}/train_rllib_ppo.py +357 -371
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/flopyarcade.py +5 -2
- flopyarcade-0.7.2/flopyarcade/mf6_mp7_runner.py +282 -0
- flopyarcade-0.7.2/flopyarcade/mf6_prt_runner.py +286 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/render.py +62 -19
- flopyarcade-0.7.2/flopyarcade/tests/conftest.py +18 -0
- flopyarcade-0.7.2/flopyarcade/tests/test_a10_overlap.py +147 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/tests/test_agent_dqn.py +1 -1
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/tests/test_agent_neuroevolution.py +1 -1
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/tests/test_blit.py +3 -0
- flopyarcade-0.7.2/flopyarcade/tests/test_c7_action_space.py +145 -0
- flopyarcade-0.7.2/flopyarcade/tests/test_cov_agent2.py +1666 -0
- flopyarcade-0.7.2/flopyarcade/tests/test_cov_agent_bench.py +2156 -0
- flopyarcade-0.7.2/flopyarcade/tests/test_cov_big.py +773 -0
- flopyarcade-0.7.2/flopyarcade/tests/test_cov_envbase.py +1657 -0
- flopyarcade-0.7.2/flopyarcade/tests/test_cov_final_push.py +608 -0
- flopyarcade-0.7.2/flopyarcade/tests/test_cov_final_push2.py +1166 -0
- flopyarcade-0.7.2/flopyarcade/tests/test_cov_modflow_deep.py +841 -0
- flopyarcade-0.7.2/flopyarcade/tests/test_cov_play_actions_obs.py +851 -0
- flopyarcade-0.7.2/flopyarcade/tests/test_cov_play_archive.py +655 -0
- flopyarcade-0.7.2/flopyarcade/tests/test_cov_play_rl.py +1106 -0
- flopyarcade-0.7.2/flopyarcade/tests/test_cov_push2.py +753 -0
- flopyarcade-0.7.2/flopyarcade/tests/test_cov_render.py +953 -0
- flopyarcade-0.7.2/flopyarcade/tests/test_cov_runners_actions.py +862 -0
- flopyarcade-0.7.2/flopyarcade/tests/test_coverage_90.py +121 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/tests/test_coverage_deep.py +1 -106
- flopyarcade-0.7.2/flopyarcade/tests/test_coverage_final.py +281 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/tests/test_coverage_gaps.py +9 -7
- flopyarcade-0.7.2/flopyarcade/tests/test_coverage_gaps2.py +142 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/tests/test_coverage_max.py +1 -1
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/tests/test_fps.py +3 -0
- flopyarcade-0.7.2/flopyarcade/tests/test_mf6_runners.py +295 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/tests/test_mock_rllib.py +4 -4
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/tests/test_play.py +1 -0
- flopyarcade-0.7.2/flopyarcade/tests/test_regression_ci.py +157 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2/flopyarcade.egg-info}/PKG-INFO +63 -37
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade.egg-info/SOURCES.txt +32 -10
- flopyarcade-0.7.2/flopyarcade.egg-info/entry_points.txt +2 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade.egg-info/requires.txt +23 -7
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/pyproject.toml +38 -19
- flopyarcade-0.7.0/flopyarcade/simulators/simulators_linux.zip +0 -0
- flopyarcade-0.7.0/flopyarcade/simulators/simulators_mac.zip +0 -0
- flopyarcade-0.7.0/flopyarcade/simulators/simulators_win32.zip +0 -0
- flopyarcade-0.7.0/flopyarcade/simulators/simulators_win64.zip +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/LICENSE +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/MANIFEST.in +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/archive_hdf5.py +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/env_config.py +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/examples/policymodels/1s-d/1s-d +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/examples/policymodels/1s-d/1s-d.tune_metadata +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/examples/policymodels/2s-d/2s-d +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/examples/policymodels/2s-d/2s-d.tune_metadata +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/examples/policymodels/3s-d/3s-d +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/examples/policymodels/3s-d/3s-d.tune_metadata +0 -0
- {flopyarcade-0.7.0/flopyarcade → flopyarcade-0.7.2/flopyarcade/examples}/train_dqn.py +0 -0
- {flopyarcade-0.7.0/flopyarcade → flopyarcade-0.7.2/flopyarcade/examples}/train_neuroevolution.py +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/modflow_runner.py +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/modpath_runner.py +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/observations.py +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/play.py +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/play3d.py +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/play_againstai.py +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/render3d.py +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/reward.py +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/tests/test_archive_hdf5.py +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/tests/test_c2_novelty_length.py +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/tests/test_coverage_push.py +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/tests/test_regression.py +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/tests/test_render3d.py +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/tests/test_reward_reset.py +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade/tests/test_rllib_cpu.py +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade.egg-info/dependency_links.txt +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/flopyarcade.egg-info/top_level.txt +0 -0
- {flopyarcade-0.7.0 → flopyarcade-0.7.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flopyarcade
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.2
|
|
4
4
|
Summary: Simulated groundwater flow environments for reinforcement learning.
|
|
5
5
|
Author-email: Philipp Hoehn <philipp.hoehn@yahoo.com>
|
|
6
6
|
License: GNU GPLv3
|
|
@@ -23,27 +23,35 @@ Classifier: Topic :: Education
|
|
|
23
23
|
Requires-Python: <3.13,>=3.7
|
|
24
24
|
Description-Content-Type: text/markdown
|
|
25
25
|
License-File: LICENSE
|
|
26
|
-
Requires-Dist: coverage
|
|
27
26
|
Requires-Dist: flopy>=3.9.2
|
|
28
|
-
Requires-Dist: gymnasium
|
|
27
|
+
Requires-Dist: gymnasium<1.2,>=0.29.1; python_version < "3.11"
|
|
28
|
+
Requires-Dist: gymnasium>=0.29.1; python_version >= "3.11"
|
|
29
29
|
Requires-Dist: imageio>=2.22.4
|
|
30
|
-
Requires-Dist:
|
|
30
|
+
Requires-Dist: importlib-metadata>=4.13.0
|
|
31
31
|
Requires-Dist: joblib>=1.2.0
|
|
32
32
|
Requires-Dist: lz4>=4.0.2
|
|
33
33
|
Requires-Dist: matplotlib>=3.6.2
|
|
34
|
-
Requires-Dist: importlib-metadata>=4.13.0
|
|
35
34
|
Requires-Dist: numpy>=2.1.3
|
|
36
35
|
Requires-Dist: pandas>=2.2.0
|
|
37
36
|
Requires-Dist: pathos>=0.3.0
|
|
38
37
|
Requires-Dist: pillow>=10.4.0
|
|
39
38
|
Requires-Dist: pygame>=2.1.2
|
|
40
|
-
Requires-Dist: ray[all]>=2.43.0
|
|
41
|
-
Requires-Dist: ray[tune]>=2.43.0
|
|
42
|
-
Requires-Dist: ray[rllib]>=2.43.0
|
|
43
39
|
Requires-Dist: scikit-image>=0.23.0
|
|
44
|
-
Requires-Dist: tensorflow>=2.16.0
|
|
45
40
|
Requires-Dist: tqdm>=4.64.1
|
|
46
41
|
Requires-Dist: xmipy==1.3.0
|
|
42
|
+
Provides-Extra: solvers
|
|
43
|
+
Requires-Dist: tensorflow>=2.16.0; extra == "solvers"
|
|
44
|
+
Requires-Dist: ipython>=7.34.0; extra == "solvers"
|
|
45
|
+
Provides-Extra: ray
|
|
46
|
+
Requires-Dist: ray[all]>=2.43.0; extra == "ray"
|
|
47
|
+
Requires-Dist: ray[tune]>=2.43.0; extra == "ray"
|
|
48
|
+
Requires-Dist: ray[rllib]>=2.43.0; extra == "ray"
|
|
49
|
+
Provides-Extra: all
|
|
50
|
+
Requires-Dist: flopyarcade[ray,solvers]; extra == "all"
|
|
51
|
+
Provides-Extra: dev
|
|
52
|
+
Requires-Dist: pytest; extra == "dev"
|
|
53
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
54
|
+
Requires-Dist: coverage; extra == "dev"
|
|
47
55
|
Dynamic: license-file
|
|
48
56
|
|
|
49
57
|
# FloPyArcade
|
|
@@ -152,30 +160,32 @@ flowchart LR
|
|
|
152
160
|
## Project Structure
|
|
153
161
|
|
|
154
162
|
```
|
|
155
|
-
flopyarcade/
|
|
156
|
-
├── flopyarcade.py
|
|
157
|
-
├── env_base.py
|
|
158
|
-
├──
|
|
159
|
-
├──
|
|
160
|
-
├──
|
|
161
|
-
├──
|
|
162
|
-
├──
|
|
163
|
-
├──
|
|
164
|
-
├──
|
|
165
|
-
├──
|
|
166
|
-
├──
|
|
167
|
-
├──
|
|
168
|
-
├──
|
|
169
|
-
├──
|
|
170
|
-
├──
|
|
171
|
-
├──
|
|
172
|
-
├──
|
|
173
|
-
├──
|
|
174
|
-
├──
|
|
175
|
-
├──
|
|
176
|
-
├──
|
|
177
|
-
├──
|
|
178
|
-
|
|
163
|
+
flopyarcade/ # CORE — Gymnasium environments
|
|
164
|
+
├── flopyarcade.py # FloPyEnv (Gymnasium API)
|
|
165
|
+
├── env_base.py # Environment base class & abstractions
|
|
166
|
+
├── env_config.py # Env-type parsing, grid setup, well placement
|
|
167
|
+
├── agent.py # Experimental solvers (DQN, neuroevolution)
|
|
168
|
+
├── arcade.py # Game loop & scoring
|
|
169
|
+
├── play.py # Manual / AI-controlled play entry point
|
|
170
|
+
├── play3d.py # 3D play entry point
|
|
171
|
+
├── render.py # 2D matplotlib rendering
|
|
172
|
+
├── render3d.py # 3D pyrender rendering (cinematic theme)
|
|
173
|
+
├── reward.py # Reward computation
|
|
174
|
+
├── observations.py # Observation vector assembly
|
|
175
|
+
├── actions.py # Action space dispatch
|
|
176
|
+
├── modflow_runner.py # MODFLOW 2005 / MP6 subprocess management
|
|
177
|
+
├── modpath_runner.py # MODPATH 6 particle tracking
|
|
178
|
+
├── simulators/ # Bundled MODFLOW / MP6 binaries (per-OS)
|
|
179
|
+
├── models/ # Trained policy checkpoints
|
|
180
|
+
├── examples/ # Training scripts & benchmark assets
|
|
181
|
+
│ ├── train_rllib_apexdqn.py # Ray RLlib APExDQN trainer
|
|
182
|
+
│ ├── train_rllib_ppo.py # Ray RLlib PPO trainer
|
|
183
|
+
│ ├── train_rllib_appo.py # Ray RLlib APPO trainer
|
|
184
|
+
│ ├── train_rllib_impala.py # Ray RLlib IMPALA trainer
|
|
185
|
+
│ ├── train_dqn.py # Classic Double DQN trainer
|
|
186
|
+
│ ├── train_neuroevolution.py # Genetic / novelty-search trainer
|
|
187
|
+
│ └── images/ # GIFs, notebooks, benchmark images
|
|
188
|
+
└── tests/ # pytest suite (fast + slow tiers)
|
|
179
189
|
```
|
|
180
190
|
|
|
181
191
|
---
|
|
@@ -186,8 +196,18 @@ flopyarcade/
|
|
|
186
196
|
|
|
187
197
|
```bash
|
|
188
198
|
# Python 3.9–3.12
|
|
199
|
+
# Environments only (lightweight, ~200 MB):
|
|
189
200
|
python -m pip install flopyarcade
|
|
190
201
|
|
|
202
|
+
# + experimental solvers (Double DQN, neuroevolution):
|
|
203
|
+
python -m pip install flopyarcade[solvers]
|
|
204
|
+
|
|
205
|
+
# + Ray/RLlib benchmarks:
|
|
206
|
+
python -m pip install flopyarcade[ray]
|
|
207
|
+
|
|
208
|
+
# Everything:
|
|
209
|
+
python -m pip install flopyarcade[all]
|
|
210
|
+
|
|
191
211
|
# Linux: also need a Fortran compiler (for MODFLOW binaries)
|
|
192
212
|
sudo apt install gfortran
|
|
193
213
|
```
|
|
@@ -216,20 +236,26 @@ python -m flopyarcade.play --manualcontrol True --envtype 3r-d
|
|
|
216
236
|
|
|
217
237
|
Arrow keys to control. Alt+F4 to quit.
|
|
218
238
|
|
|
219
|
-
### Train an Agent (Ray/RLlib)
|
|
239
|
+
### Train an Agent (Ray/RLlib) — requires `pip install flopyarcade[ray]`
|
|
220
240
|
|
|
221
241
|
```bash
|
|
222
242
|
# APExDQN on 16 cores (~1-2 days to beat human operators)
|
|
223
|
-
python
|
|
243
|
+
python flopyarcade/examples/train_rllib_apexdqn.py --envtype 3s-d --cpus 16
|
|
224
244
|
|
|
225
245
|
# Or PPO, APPO, IMPALA
|
|
226
|
-
python
|
|
246
|
+
python flopyarcade/examples/train_rllib_ppo.py --envtype 3s-d --cpus 16
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Train with Classic DQN — requires `pip install flopyarcade[solvers]`
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
python flopyarcade/examples/train_dqn.py --envtype 3s-d --ngames 20000
|
|
227
253
|
```
|
|
228
254
|
|
|
229
255
|
### Simulate with a Trained Policy
|
|
230
256
|
|
|
231
257
|
```bash
|
|
232
|
-
python
|
|
258
|
+
python flopyarcade/examples/train_rllib_apexdqn.py --playbenchmark True --envtype 3s-d
|
|
233
259
|
```
|
|
234
260
|
|
|
235
261
|
### Render in 3D
|
|
@@ -104,30 +104,32 @@ flowchart LR
|
|
|
104
104
|
## Project Structure
|
|
105
105
|
|
|
106
106
|
```
|
|
107
|
-
flopyarcade/
|
|
108
|
-
├── flopyarcade.py
|
|
109
|
-
├── env_base.py
|
|
110
|
-
├──
|
|
111
|
-
├──
|
|
112
|
-
├──
|
|
113
|
-
├──
|
|
114
|
-
├──
|
|
115
|
-
├──
|
|
116
|
-
├──
|
|
117
|
-
├──
|
|
118
|
-
├──
|
|
119
|
-
├──
|
|
120
|
-
├──
|
|
121
|
-
├──
|
|
122
|
-
├──
|
|
123
|
-
├──
|
|
124
|
-
├──
|
|
125
|
-
├──
|
|
126
|
-
├──
|
|
127
|
-
├──
|
|
128
|
-
├──
|
|
129
|
-
├──
|
|
130
|
-
|
|
107
|
+
flopyarcade/ # CORE — Gymnasium environments
|
|
108
|
+
├── flopyarcade.py # FloPyEnv (Gymnasium API)
|
|
109
|
+
├── env_base.py # Environment base class & abstractions
|
|
110
|
+
├── env_config.py # Env-type parsing, grid setup, well placement
|
|
111
|
+
├── agent.py # Experimental solvers (DQN, neuroevolution)
|
|
112
|
+
├── arcade.py # Game loop & scoring
|
|
113
|
+
├── play.py # Manual / AI-controlled play entry point
|
|
114
|
+
├── play3d.py # 3D play entry point
|
|
115
|
+
├── render.py # 2D matplotlib rendering
|
|
116
|
+
├── render3d.py # 3D pyrender rendering (cinematic theme)
|
|
117
|
+
├── reward.py # Reward computation
|
|
118
|
+
├── observations.py # Observation vector assembly
|
|
119
|
+
├── actions.py # Action space dispatch
|
|
120
|
+
├── modflow_runner.py # MODFLOW 2005 / MP6 subprocess management
|
|
121
|
+
├── modpath_runner.py # MODPATH 6 particle tracking
|
|
122
|
+
├── simulators/ # Bundled MODFLOW / MP6 binaries (per-OS)
|
|
123
|
+
├── models/ # Trained policy checkpoints
|
|
124
|
+
├── examples/ # Training scripts & benchmark assets
|
|
125
|
+
│ ├── train_rllib_apexdqn.py # Ray RLlib APExDQN trainer
|
|
126
|
+
│ ├── train_rllib_ppo.py # Ray RLlib PPO trainer
|
|
127
|
+
│ ├── train_rllib_appo.py # Ray RLlib APPO trainer
|
|
128
|
+
│ ├── train_rllib_impala.py # Ray RLlib IMPALA trainer
|
|
129
|
+
│ ├── train_dqn.py # Classic Double DQN trainer
|
|
130
|
+
│ ├── train_neuroevolution.py # Genetic / novelty-search trainer
|
|
131
|
+
│ └── images/ # GIFs, notebooks, benchmark images
|
|
132
|
+
└── tests/ # pytest suite (fast + slow tiers)
|
|
131
133
|
```
|
|
132
134
|
|
|
133
135
|
---
|
|
@@ -138,8 +140,18 @@ flopyarcade/
|
|
|
138
140
|
|
|
139
141
|
```bash
|
|
140
142
|
# Python 3.9–3.12
|
|
143
|
+
# Environments only (lightweight, ~200 MB):
|
|
141
144
|
python -m pip install flopyarcade
|
|
142
145
|
|
|
146
|
+
# + experimental solvers (Double DQN, neuroevolution):
|
|
147
|
+
python -m pip install flopyarcade[solvers]
|
|
148
|
+
|
|
149
|
+
# + Ray/RLlib benchmarks:
|
|
150
|
+
python -m pip install flopyarcade[ray]
|
|
151
|
+
|
|
152
|
+
# Everything:
|
|
153
|
+
python -m pip install flopyarcade[all]
|
|
154
|
+
|
|
143
155
|
# Linux: also need a Fortran compiler (for MODFLOW binaries)
|
|
144
156
|
sudo apt install gfortran
|
|
145
157
|
```
|
|
@@ -168,20 +180,26 @@ python -m flopyarcade.play --manualcontrol True --envtype 3r-d
|
|
|
168
180
|
|
|
169
181
|
Arrow keys to control. Alt+F4 to quit.
|
|
170
182
|
|
|
171
|
-
### Train an Agent (Ray/RLlib)
|
|
183
|
+
### Train an Agent (Ray/RLlib) — requires `pip install flopyarcade[ray]`
|
|
172
184
|
|
|
173
185
|
```bash
|
|
174
186
|
# APExDQN on 16 cores (~1-2 days to beat human operators)
|
|
175
|
-
python
|
|
187
|
+
python flopyarcade/examples/train_rllib_apexdqn.py --envtype 3s-d --cpus 16
|
|
176
188
|
|
|
177
189
|
# Or PPO, APPO, IMPALA
|
|
178
|
-
python
|
|
190
|
+
python flopyarcade/examples/train_rllib_ppo.py --envtype 3s-d --cpus 16
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Train with Classic DQN — requires `pip install flopyarcade[solvers]`
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
python flopyarcade/examples/train_dqn.py --envtype 3s-d --ngames 20000
|
|
179
197
|
```
|
|
180
198
|
|
|
181
199
|
### Simulate with a Trained Policy
|
|
182
200
|
|
|
183
201
|
```bash
|
|
184
|
-
python
|
|
202
|
+
python flopyarcade/examples/train_rllib_apexdqn.py --playbenchmark True --envtype 3s-d
|
|
185
203
|
```
|
|
186
204
|
|
|
187
205
|
### Render in 3D
|
|
@@ -4,7 +4,7 @@ FloPyArcade.
|
|
|
4
4
|
Simulated groundwater flow environments to test reinforcement learning algorithms.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
|
-
__version__ = '0.
|
|
7
|
+
__version__ = '0.7.0'
|
|
8
8
|
__author__ = 'Philipp Hoehn'
|
|
9
9
|
|
|
10
10
|
|
|
@@ -43,6 +43,14 @@ if not exists(join(wrkspc, 'simulators', 'win64')):
|
|
|
43
43
|
|
|
44
44
|
from .flopyarcade import FloPyEnv
|
|
45
45
|
from .arcade import FloPyArcade
|
|
46
|
-
|
|
46
|
+
|
|
47
|
+
# Solvers are optional — require tensorflow (pip install flopyarcade[solvers])
|
|
48
|
+
try:
|
|
49
|
+
from flopyarcade_solvers import FloPyAgent
|
|
50
|
+
except ImportError:
|
|
51
|
+
try:
|
|
52
|
+
from .agent import FloPyAgent
|
|
53
|
+
except ImportError:
|
|
54
|
+
FloPyAgent = None
|
|
47
55
|
|
|
48
56
|
__all__ = ['FloPyEnv', 'FloPyArcade', 'FloPyAgent']
|
|
@@ -225,9 +225,17 @@ class ActionsMixin:
|
|
|
225
225
|
['up', 'keep', 'down', 'left', 'right', 'moreQ', 'keepQ', 'lessQ'],
|
|
226
226
|
2.5, 100.0)
|
|
227
227
|
|
|
228
|
+
# C7 fix: avoid OOM from materializing 5^20 / 8^20 product list.
|
|
229
|
+
# Store per-well action set; full action is an array of ints (MultiDiscrete).
|
|
230
|
+
self._multiwell_discrete_per_well = len(self.actionSpaceIndividual)
|
|
231
|
+
self._multiwell_discrete_total = self.nHelperWells
|
|
232
|
+
# Keep a small reference list for backward compat / testing
|
|
233
|
+
# C7: cap the reference list to avoid OOM (all multi-well envs have 20 wells)
|
|
234
|
+
_cap = 2 if int(self.nHelperWells) > 2 else int(self.nHelperWells)
|
|
228
235
|
self.actionSpace = [
|
|
229
|
-
''.join(comb) for comb in product(self.actionSpaceIndividual, repeat=
|
|
236
|
+
''.join(comb) for comb in product(self.actionSpaceIndividual, repeat=_cap)
|
|
230
237
|
]
|
|
238
|
+
self.actionSpaceSize = self.nHelperWells
|
|
231
239
|
|
|
232
240
|
def _setup_continuous_multiwell_actions(self):
|
|
233
241
|
"""Set up continuous action space for multiwell environments.
|
|
@@ -413,12 +421,81 @@ class ActionsMixin:
|
|
|
413
421
|
self.wellCoords = [self.wellX, self.wellY, self.wellZ]
|
|
414
422
|
|
|
415
423
|
|
|
424
|
+
def _resolve_well_overlap(self, max_retries=50):
|
|
425
|
+
"""Resolve protection-zone overlap between helper wells and main well.
|
|
426
|
+
|
|
427
|
+
Uses rejection sampling: if a helper well is too close to the main well
|
|
428
|
+
or to another helper well, re-randomise its position within bounds.
|
|
429
|
+
|
|
430
|
+
Minimum separations:
|
|
431
|
+
helper-to-helper: 2 * helperWellRadius
|
|
432
|
+
helper-to-main: wellRadius + helperWellRadius
|
|
433
|
+
|
|
434
|
+
Args:
|
|
435
|
+
self (object): Instance with helperWells, wellX, wellY, etc.
|
|
436
|
+
max_retries (int): Max re-sampling attempts per well.
|
|
437
|
+
|
|
438
|
+
"""
|
|
439
|
+
if not hasattr(self, 'helperWells') or not self.helperWells:
|
|
440
|
+
return
|
|
441
|
+
n = self.nHelperWells
|
|
442
|
+
hw = self.helperWells
|
|
443
|
+
hw_radius = getattr(self, 'helperWellRadius', self.wellRadius / 4)
|
|
444
|
+
min_sep_helper = 2.0 * hw_radius
|
|
445
|
+
min_sep_main = self.wellRadius + hw_radius
|
|
446
|
+
x_lo, x_hi = 1.1 * self.dCol, self.extentX - 1.1 * self.dCol
|
|
447
|
+
y_lo, y_hi = 1.1 * self.dRow, self.extentY - 1.1 * self.dRow
|
|
448
|
+
# Use a local RNG so re-sampling doesn't pollute the global random stream
|
|
449
|
+
import random as _random
|
|
450
|
+
_rng = _random.Random(0)
|
|
451
|
+
|
|
452
|
+
for i in range(n):
|
|
453
|
+
w = str(i + 1)
|
|
454
|
+
for attempt in range(max_retries):
|
|
455
|
+
cx = hw.get(f'wellX{w}')
|
|
456
|
+
cy = hw.get(f'wellY{w}')
|
|
457
|
+
if cx is None or cy is None:
|
|
458
|
+
break
|
|
459
|
+
overlap = False
|
|
460
|
+
# Check against main well
|
|
461
|
+
dx_main = cx - self.wellX
|
|
462
|
+
dy_main = cy - self.wellY
|
|
463
|
+
if (dx_main ** 2 + dy_main ** 2) < min_sep_main ** 2:
|
|
464
|
+
overlap = True
|
|
465
|
+
# Check against other helper wells
|
|
466
|
+
if not overlap:
|
|
467
|
+
for j in range(n):
|
|
468
|
+
if j == i:
|
|
469
|
+
continue
|
|
470
|
+
wj = str(j + 1)
|
|
471
|
+
ox = hw.get(f'wellX{wj}')
|
|
472
|
+
oy = hw.get(f'wellY{wj}')
|
|
473
|
+
if ox is None or oy is None:
|
|
474
|
+
continue
|
|
475
|
+
dx = cx - ox
|
|
476
|
+
dy = cy - oy
|
|
477
|
+
if (dx ** 2 + dy ** 2) < min_sep_helper ** 2:
|
|
478
|
+
overlap = True
|
|
479
|
+
break
|
|
480
|
+
if not overlap:
|
|
481
|
+
break
|
|
482
|
+
# Re-randomise this well (local RNG, doesn't pollute global stream)
|
|
483
|
+
hw[f'wellX{w}'] = _rng.uniform(x_lo, x_hi)
|
|
484
|
+
hw[f'wellY{w}'] = _rng.uniform(y_lo, y_hi)
|
|
485
|
+
hw[f'actionValueX{w}'] = hw[f'wellX{w}']
|
|
486
|
+
hw[f'actionValueY{w}'] = hw[f'wellY{w}']
|
|
487
|
+
if w in hw and f'wellCoords{w}' in hw:
|
|
488
|
+
hw[f'wellCoords{w}'] = [
|
|
489
|
+
hw[f'wellX{w}'], hw[f'wellY{w}'], hw.get(f'wellZ{w}', 0.0)
|
|
490
|
+
]
|
|
491
|
+
|
|
416
492
|
def _update_helper_wells_location(self):
|
|
417
493
|
"""
|
|
418
494
|
Update helper wells' locations if environment type allows.
|
|
419
495
|
|
|
420
496
|
Sets helper wells' X and Y coordinates from action values and updates
|
|
421
497
|
their coordinate lists. Z coordinate remains unchanged.
|
|
498
|
+
Resolves protection-zone overlap after position update.
|
|
422
499
|
|
|
423
500
|
Args:
|
|
424
501
|
self (object): Instance with attributes:
|
|
@@ -444,6 +521,9 @@ class ActionsMixin:
|
|
|
444
521
|
self.helperWells[f'wellZ{w}']
|
|
445
522
|
]
|
|
446
523
|
|
|
524
|
+
# A10: prevent protection-zone overlap after position update
|
|
525
|
+
self._resolve_well_overlap()
|
|
526
|
+
|
|
447
527
|
def _update_helper_wells_Q(self):
|
|
448
528
|
"""Update helper wells' Q values from action value Qs.
|
|
449
529
|
|
|
@@ -86,6 +86,8 @@ import flopy.utils.binaryfile as bf
|
|
|
86
86
|
from logging import getLogger, FATAL
|
|
87
87
|
environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
|
|
88
88
|
getLogger('tensorflow').setLevel(FATAL)
|
|
89
|
+
getLogger('flopy').setLevel(FATAL)
|
|
90
|
+
logger = getLogger(__name__)
|
|
89
91
|
|
|
90
92
|
# currently ignoring nested array error
|
|
91
93
|
# from numpy import VisibleDeprecationWarning
|
|
@@ -419,7 +421,7 @@ class FloPyAgent:
|
|
|
419
421
|
if self.average_rewardCV >= self.envSettings['REWARDMINTOSAVE']:
|
|
420
422
|
self.mainModel.save(join(self.wrkspc, 'models', filename))
|
|
421
423
|
|
|
422
|
-
|
|
424
|
+
logger.info('DQN results max=%.1f avg=%.1f min=%.1f', self.max_rewardCV, self.average_rewardCV, self.min_rewardCV)
|
|
423
425
|
|
|
424
426
|
def _decay_epsilon(self):
|
|
425
427
|
"""Decay exploration rate epsilon."""
|
|
@@ -488,12 +490,10 @@ class FloPyAgent:
|
|
|
488
490
|
self.agentsDuplicate.append(iAgent)
|
|
489
491
|
|
|
490
492
|
def _log_generation_rewards(self):
|
|
491
|
-
|
|
492
|
-
print('average reward', mean(self.rewards))
|
|
493
|
-
print('highest reward', max(self.rewards))
|
|
493
|
+
logger.info('rewards: low=%.1f avg=%.1f high=%.1f', min(self.rewards), mean(self.rewards), max(self.rewards))
|
|
494
494
|
if self.envSettings['SEEDSRANDOM']:
|
|
495
495
|
self.bestRewards.append(max(self.rewards))
|
|
496
|
-
|
|
496
|
+
logger.info('sliding best (n=50)=%.1f', mean(self.bestRewards[-50:]))
|
|
497
497
|
|
|
498
498
|
def _sort_and_save_top_agents(self):
|
|
499
499
|
sortedParentIdxs = argsort(self.rewards)[::-1][:self.hyParams['NAGENTELITES']]
|
|
@@ -504,21 +504,21 @@ class FloPyAgent:
|
|
|
504
504
|
if not self.searchNovelty:
|
|
505
505
|
return
|
|
506
506
|
|
|
507
|
-
|
|
507
|
+
logger.info('Performing novelty search')
|
|
508
508
|
t0 = time()
|
|
509
509
|
self._prepare_novelty_archive(env)
|
|
510
|
-
|
|
510
|
+
logger.info('Preparing novelty search took %.2fs', time() - t0)
|
|
511
511
|
|
|
512
512
|
self._print_novelty_stats()
|
|
513
513
|
|
|
514
514
|
t0 = time()
|
|
515
515
|
args, update_flags = self._build_novelty_args()
|
|
516
|
-
|
|
516
|
+
logger.info('Calculated novelty search arguments, took %.2fs', time() - t0)
|
|
517
517
|
|
|
518
|
-
|
|
518
|
+
logger.info('Started novelty search ...')
|
|
519
519
|
t0 = time()
|
|
520
520
|
novelties = self._run_novelty_search(args)
|
|
521
|
-
|
|
521
|
+
logger.info('Finished novelty search, took %.2fs', time() - t0)
|
|
522
522
|
|
|
523
523
|
self._update_agent_novelties(novelties, update_flags)
|
|
524
524
|
self._save_novelties()
|
|
@@ -1075,7 +1075,7 @@ class FloPyAgent:
|
|
|
1075
1075
|
nChunksRemaining = copy(nChunks)
|
|
1076
1076
|
# batch processing to avoid memory explosion
|
|
1077
1077
|
# https://stackoverflow.com/questions/18414020/memory-usage-keep-growing-with-pythons-multiprocessing-pool/20439272
|
|
1078
|
-
|
|
1078
|
+
logger.info('--- generation %d ---', self.geneticGeneration + 1)
|
|
1079
1079
|
for chunk in chunksTotal:
|
|
1080
1080
|
t0 = time()
|
|
1081
1081
|
if len(runtimes) == 0:
|
|
@@ -1088,14 +1088,13 @@ class FloPyAgent:
|
|
|
1088
1088
|
runtimeGenEstimate = '%.3f' % (runtimeGenEstimate/(60*60))
|
|
1089
1089
|
runtimeGensEstimate = '%.3f' % (runtimeGensEstimate/(60*60))
|
|
1090
1090
|
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
runtimeGensEstimate + ' h for all generations')
|
|
1091
|
+
logger.info(
|
|
1092
|
+
'Currently: %d/%d agents, game %d/%d, gen %d/%d | ETA: %s h/gen, %s h total',
|
|
1093
|
+
min(chunk), max(agentCounts)+1,
|
|
1094
|
+
self.currentGame, self.hyParams['NGAMESAVERAGED'],
|
|
1095
|
+
self.geneticGeneration + 1, self.hyParams['NGENERATIONS'],
|
|
1096
|
+
runtimeGenEstimate, runtimeGensEstimate
|
|
1097
|
+
)
|
|
1099
1098
|
|
|
1100
1099
|
if self.envSettings['ENVTYPE'] in ['0s-c']:
|
|
1101
1100
|
# necessary as some ctypes object related to the dll used with BMI is not pickleable
|
|
@@ -1114,7 +1113,7 @@ class FloPyAgent:
|
|
|
1114
1113
|
runtimes.append(time() - t0)
|
|
1115
1114
|
nChunksRemaining -= 1
|
|
1116
1115
|
tRuns = time()-t0Runs
|
|
1117
|
-
|
|
1116
|
+
logger.info('Processing agents took %.2fs', tRuns)
|
|
1118
1117
|
|
|
1119
1118
|
return reward_agents
|
|
1120
1119
|
|
|
@@ -1139,7 +1138,7 @@ class FloPyAgent:
|
|
|
1139
1138
|
agent = self.loadModelFromMutationHistory(creationSeed, mutationSeeds)
|
|
1140
1139
|
tRecreateFromMutationHistory = (self.hyParams['NAGENTS']/self.envSettings['NAGENTSPARALLEL']) * (t0RecreateFromMutationHistory - time())
|
|
1141
1140
|
if agentCount == 1:
|
|
1142
|
-
|
|
1141
|
+
logger.info('model recreation took about %.2fs', tRecreateFromMutationHistory)
|
|
1143
1142
|
|
|
1144
1143
|
MODELNAMETEMP = ('Temp' + self.pid +
|
|
1145
1144
|
'_' + str(agentCount + 1))
|
|
@@ -86,6 +86,8 @@ import flopy.utils.binaryfile as bf
|
|
|
86
86
|
from logging import getLogger, FATAL
|
|
87
87
|
environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
|
|
88
88
|
getLogger('tensorflow').setLevel(FATAL)
|
|
89
|
+
getLogger('flopy').setLevel(FATAL)
|
|
90
|
+
logger = getLogger(__name__)
|
|
89
91
|
|
|
90
92
|
# currently ignoring nested array error
|
|
91
93
|
# from numpy import VisibleDeprecationWarning
|
|
@@ -291,7 +293,10 @@ class FloPyArcade:
|
|
|
291
293
|
self.done = self.env.done
|
|
292
294
|
if self.keepTimeSeries:
|
|
293
295
|
self._init_time_series(self.observations)
|
|
294
|
-
|
|
296
|
+
if self.env.actionType == 'continuous':
|
|
297
|
+
self.actionSpace = list(range(self.env.actionSpaceSize))
|
|
298
|
+
else:
|
|
299
|
+
self.actionSpace = self.env.actionSpace
|
|
295
300
|
from flopyarcade.agent import FloPyAgent
|
|
296
301
|
self.agentObj = FloPyAgent(actionSpace=self.actionSpace)
|
|
297
302
|
self.success = False
|