flopyarcade 0.7.1__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.1/flopyarcade.egg-info → flopyarcade-0.7.2}/PKG-INFO +3 -2
- flopyarcade-0.7.2/flopyarcade/mf6_mp7_runner.py +282 -0
- flopyarcade-0.7.2/flopyarcade/tests/test_regression_ci.py +157 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2/flopyarcade.egg-info}/PKG-INFO +3 -2
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade.egg-info/SOURCES.txt +2 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade.egg-info/requires.txt +6 -1
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/pyproject.toml +3 -2
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/LICENSE +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/MANIFEST.in +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/README.md +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/__init__.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/actions.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/agent.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/arcade.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/archive_hdf5.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/benchmark.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/env_base.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/env_config.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/examples/__init__.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/examples/policymodels/1s-d/1s-d +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/examples/policymodels/1s-d/1s-d.tune_metadata +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/examples/policymodels/2s-d/2s-d +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/examples/policymodels/2s-d/2s-d.tune_metadata +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/examples/policymodels/3s-d/3s-d +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/examples/policymodels/3s-d/3s-d.tune_metadata +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/examples/train_dqn.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/examples/train_neuroevolution.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/examples/train_rllib_apexdqn.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/examples/train_rllib_appo.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/examples/train_rllib_impala.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/examples/train_rllib_ppo.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/flopyarcade.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/mf6_prt_runner.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/modflow_runner.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/modpath_runner.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/observations.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/play.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/play3d.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/play_againstai.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/render.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/render3d.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/reward.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/conftest.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_a10_overlap.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_agent_dqn.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_agent_neuroevolution.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_archive_hdf5.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_blit.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_c2_novelty_length.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_c7_action_space.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_cov_agent2.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_cov_agent_bench.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_cov_big.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_cov_envbase.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_cov_final_push.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_cov_final_push2.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_cov_modflow_deep.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_cov_play_actions_obs.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_cov_play_archive.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_cov_play_rl.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_cov_push2.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_cov_render.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_cov_runners_actions.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_coverage_90.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_coverage_deep.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_coverage_final.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_coverage_gaps.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_coverage_gaps2.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_coverage_max.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_coverage_push.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_fps.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_mf6_runners.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_mock_rllib.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_play.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_regression.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_render3d.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_reward_reset.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/tests/test_rllib_cpu.py +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade.egg-info/dependency_links.txt +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade.egg-info/entry_points.txt +0 -0
- {flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade.egg-info/top_level.txt +0 -0
- {flopyarcade-0.7.1 → 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
|
|
@@ -24,7 +24,8 @@ Requires-Python: <3.13,>=3.7
|
|
|
24
24
|
Description-Content-Type: text/markdown
|
|
25
25
|
License-File: LICENSE
|
|
26
26
|
Requires-Dist: flopy>=3.9.2
|
|
27
|
-
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"
|
|
28
29
|
Requires-Dist: imageio>=2.22.4
|
|
29
30
|
Requires-Dist: importlib-metadata>=4.13.0
|
|
30
31
|
Requires-Dist: joblib>=1.2.0
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
#!/usr/bin/python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
# FloPyArcade - mf6_mp7_runner
|
|
5
|
+
# MODFLOW 6 + MODPATH 7 backend for all environment types.
|
|
6
|
+
# Mirrors the MF2005+MP6 pipeline with equivalent parameters.
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
from os.path import join, dirname, abspath, exists
|
|
10
|
+
from os import makedirs
|
|
11
|
+
from platform import system as platformSystem
|
|
12
|
+
from tempfile import TemporaryDirectory
|
|
13
|
+
from uuid import uuid4
|
|
14
|
+
from numpy import ones, zeros, int32, float32, linspace, pi
|
|
15
|
+
|
|
16
|
+
from flopy.mf6 import (
|
|
17
|
+
MFSimulation, ModflowTdis, ModflowIms, ModflowGwf,
|
|
18
|
+
ModflowGwfdis, ModflowGwfic, ModflowGwfchd, ModflowGwfnpf,
|
|
19
|
+
ModflowGwfoc, ModflowGwfrcha,
|
|
20
|
+
)
|
|
21
|
+
from flopy.mf6.modflow.mfgwfwel import ModflowGwfwel
|
|
22
|
+
from flopy.mf6.modflow.mfgwfsto import ModflowGwfsto
|
|
23
|
+
from flopy.modpath import Modpath7, Modpath7Bas
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class MF6MP7Runner:
|
|
27
|
+
"""MODFLOW 6 + MODPATH 7 simulation runner.
|
|
28
|
+
|
|
29
|
+
Replicates the MF2005+MP6 pipeline using MF6 packages and MP7 particle
|
|
30
|
+
tracking. All parameters mirror the original build_model_other() and
|
|
31
|
+
runMODPATH() methods.
|
|
32
|
+
|
|
33
|
+
Parameters
|
|
34
|
+
----------
|
|
35
|
+
self : object
|
|
36
|
+
Instance containing environment configuration (from EnvBaseMixin).
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
def __init__(self, self_ref):
|
|
40
|
+
self._s = self_ref # reference to the environment instance
|
|
41
|
+
|
|
42
|
+
# ------------------------------------------------------------------
|
|
43
|
+
# Model construction (MF6 equivalent of build_model_other)
|
|
44
|
+
# ------------------------------------------------------------------
|
|
45
|
+
|
|
46
|
+
def build_model(self):
|
|
47
|
+
"""Build the full MF6 model equivalent of build_model_other()."""
|
|
48
|
+
s = self._s
|
|
49
|
+
makedirs(s.model_ws, exist_ok=True)
|
|
50
|
+
|
|
51
|
+
# --- Simulation ---
|
|
52
|
+
s.sim = MFSimulation(
|
|
53
|
+
sim_name=s.MODELNAME,
|
|
54
|
+
version='mf6',
|
|
55
|
+
exe_name=s.exe_name,
|
|
56
|
+
sim_ws=s.model_ws,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
# --- TDIS ---
|
|
60
|
+
if s.periodSteadiness:
|
|
61
|
+
s.tdis = ModflowTdis(
|
|
62
|
+
s.sim, time_units='DAYS', nper=1,
|
|
63
|
+
perioddata=[(1.0, 1, 1.0)]
|
|
64
|
+
)
|
|
65
|
+
else:
|
|
66
|
+
s.tdis = ModflowTdis(
|
|
67
|
+
s.sim, time_units='DAYS', nper=s.periods,
|
|
68
|
+
perioddata=[(2 * s.periodLength, s.periodSteps, 1.0)]
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
# --- IMS (matching MF2005 PCG defaults: hclose=1e-1, rclose=1e-1) ---
|
|
72
|
+
s.ims = ModflowIms(
|
|
73
|
+
s.sim,
|
|
74
|
+
print_option='SUMMARY',
|
|
75
|
+
outer_dvclose=1e-1,
|
|
76
|
+
outer_maximum=100,
|
|
77
|
+
inner_dvclose=1e-1,
|
|
78
|
+
inner_maximum=100,
|
|
79
|
+
linear_acceleration='BICGSTAB',
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
# --- GWF Model ---
|
|
83
|
+
s.gwf = ModflowGwf(
|
|
84
|
+
s.sim,
|
|
85
|
+
modelname=s.MODELNAME,
|
|
86
|
+
print_input=False,
|
|
87
|
+
save_flows=True,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
# --- DIS ---
|
|
91
|
+
s.gwf_dis = ModflowGwfdis(
|
|
92
|
+
s.gwf,
|
|
93
|
+
nlay=s.nLay,
|
|
94
|
+
nrow=s.nRow,
|
|
95
|
+
ncol=s.nCol,
|
|
96
|
+
delr=s.dRow,
|
|
97
|
+
delc=s.dCol,
|
|
98
|
+
top=s.zTop,
|
|
99
|
+
botm=s.botM[1:],
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
# --- IC (Initial Conditions) ---
|
|
103
|
+
s.gwf_ic = ModflowGwfic(s.gwf, strt=s.strt)
|
|
104
|
+
|
|
105
|
+
# --- NPF (equivalent of LPF: hk=10, vka=10, ss=1e-5, sy=0.15) ---
|
|
106
|
+
s.gwf_npf = ModflowGwfnpf(
|
|
107
|
+
s.gwf,
|
|
108
|
+
hk=10.0,
|
|
109
|
+
vka=10.0,
|
|
110
|
+
ss=1e-5,
|
|
111
|
+
porosity=0.15,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
# --- CHD (equivalent of boundary heads in strt) ---
|
|
115
|
+
self._add_chd()
|
|
116
|
+
|
|
117
|
+
# --- WEL ---
|
|
118
|
+
self._add_wel()
|
|
119
|
+
|
|
120
|
+
# --- RCH (for envs with recharge) ---
|
|
121
|
+
if hasattr(s, 'rechTimeSeries') and s.rechTimeSeries is not None:
|
|
122
|
+
rch_data = {0: s.rechTimeSeries[0]}
|
|
123
|
+
s.gwf_rcha = ModflowGwfrcha(s.gwf, stress_period_data=rch_data)
|
|
124
|
+
|
|
125
|
+
# --- OC (Output Control) ---
|
|
126
|
+
s.gwf_oc = ModflowGwfoc(s.gwf, head='END', budget='END')
|
|
127
|
+
|
|
128
|
+
# Write all input
|
|
129
|
+
s.sim.write_sim()
|
|
130
|
+
|
|
131
|
+
def _add_chd(self):
|
|
132
|
+
"""Add CHD boundary conditions matching _assign_boundary_heads()."""
|
|
133
|
+
s = self._s
|
|
134
|
+
chd_data = []
|
|
135
|
+
env = s.ENVTYPE
|
|
136
|
+
|
|
137
|
+
if env in {'1s-d', '1s-c', '1r-d', '1r-c'}:
|
|
138
|
+
# West (col 0), East (col -1), South (row 0), North (row -1)
|
|
139
|
+
for r in range(1, s.nRow - 1):
|
|
140
|
+
chd_data.append([(0, r, 0), s.headSpecWest])
|
|
141
|
+
chd_data.append([(0, r, s.nCol - 1), s.headSpecEast])
|
|
142
|
+
for c in range(s.nCol):
|
|
143
|
+
chd_data.append([(0, 0, c), s.actionValueSouth])
|
|
144
|
+
chd_data.append([(0, s.nRow - 1, c), s.actionValueNorth])
|
|
145
|
+
|
|
146
|
+
elif env in {'2s-d', '2s-c', '2r-d', '2r-c'}:
|
|
147
|
+
for r in range(s.nRow - 1):
|
|
148
|
+
chd_data.append([(0, r, 0), s.headSpecWest])
|
|
149
|
+
chd_data.append([(0, r, s.nCol - 1), s.headSpecEast])
|
|
150
|
+
for c in range(s.nCol):
|
|
151
|
+
chd_data.append([(0, s.nRow - 1, c), s.actionValue])
|
|
152
|
+
|
|
153
|
+
else:
|
|
154
|
+
# 3s, 4s, 5s, 6s, 3r, 4r, 5r, 6r
|
|
155
|
+
for r in range(1, s.nRow - 1):
|
|
156
|
+
chd_data.append([(0, r, 0), s.headSpecWest])
|
|
157
|
+
chd_data.append([(0, r, s.nCol - 1), s.headSpecEast])
|
|
158
|
+
for c in range(s.nCol):
|
|
159
|
+
chd_data.append([(0, 0, c), s.headSpecSouth])
|
|
160
|
+
chd_data.append([(0, s.nRow - 1, c), s.headSpecNorth])
|
|
161
|
+
|
|
162
|
+
s.gwf_chd = ModflowGwfchd(
|
|
163
|
+
s.gwf,
|
|
164
|
+
maxbound=len(chd_data),
|
|
165
|
+
stress_period_data=chd_data,
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
def _add_wel(self):
|
|
169
|
+
"""Add WEL package with main and helper wells."""
|
|
170
|
+
s = self._s
|
|
171
|
+
l = s.wellCellLayer - 1
|
|
172
|
+
c = s.wellCellColumn - 1
|
|
173
|
+
r = s.wellCellRow - 1
|
|
174
|
+
wells = [[l, r, c, s.wellQ]]
|
|
175
|
+
|
|
176
|
+
if s.nHelperWells > 0:
|
|
177
|
+
for i in range(s.nHelperWells):
|
|
178
|
+
idx = str(i + 1)
|
|
179
|
+
hl = s.helperWells[f'l{idx}'] - 1
|
|
180
|
+
hc = s.helperWells[f'c{idx}'] - 1
|
|
181
|
+
hr = s.helperWells[f'r{idx}'] - 1
|
|
182
|
+
hq = s.helperWells[f'wellQ{idx}']
|
|
183
|
+
wells.append([hl, hr, hc, hq])
|
|
184
|
+
|
|
185
|
+
s.gwf_wel = ModflowGwfwel(
|
|
186
|
+
s.gwf,
|
|
187
|
+
stress_period_data={0: wells},
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
# ------------------------------------------------------------------
|
|
191
|
+
# Run MODFLOW 6
|
|
192
|
+
# ------------------------------------------------------------------
|
|
193
|
+
|
|
194
|
+
def run_modflow(self):
|
|
195
|
+
"""Run the MF6 simulation and load heads."""
|
|
196
|
+
s = self._s
|
|
197
|
+
s.sim.run_sim(silent=True)
|
|
198
|
+
|
|
199
|
+
# Load heads from MF6 output
|
|
200
|
+
head_file = s.gwf.output().head
|
|
201
|
+
s.heads = head_file.get_data()
|
|
202
|
+
if hasattr(s.heads, 'to_numpy'):
|
|
203
|
+
s.heads = s.heads.to_numpy()
|
|
204
|
+
|
|
205
|
+
# ------------------------------------------------------------------
|
|
206
|
+
# MODPATH 7 (equivalent of runMODPATH)
|
|
207
|
+
# ------------------------------------------------------------------
|
|
208
|
+
|
|
209
|
+
def run_modpath7(self):
|
|
210
|
+
"""Run MODPATH 7 particle tracking (equivalent of runMODPATH)."""
|
|
211
|
+
s = self._s
|
|
212
|
+
s._transform_particle_coords()
|
|
213
|
+
|
|
214
|
+
if s.timeStep == 1:
|
|
215
|
+
self._init_mp7()
|
|
216
|
+
|
|
217
|
+
self._write_mp7_particle()
|
|
218
|
+
s.mp7.run_model(silent=True)
|
|
219
|
+
|
|
220
|
+
def _init_mp7(self):
|
|
221
|
+
"""Initialize MODPATH 7 objects."""
|
|
222
|
+
s = self._s
|
|
223
|
+
mp7_exe = join(dirname(abspath(__file__)), 'simulators', 'linux', 'mp7')
|
|
224
|
+
if not exists(mp7_exe):
|
|
225
|
+
raise FileNotFoundError(
|
|
226
|
+
f"MP7 binary not found at {mp7_exe}. "
|
|
227
|
+
"Download from https://github.com/MODPATH/modpath7/releases"
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
s.mp7 = Modpath7(
|
|
231
|
+
s.MODELNAME,
|
|
232
|
+
exe_name=mp7_exe,
|
|
233
|
+
modflowmodel=s.gwf,
|
|
234
|
+
model_ws=s.model_ws,
|
|
235
|
+
)
|
|
236
|
+
s.mp7bas = Modpath7Bas(
|
|
237
|
+
s.mp7,
|
|
238
|
+
prsity=0.2,
|
|
239
|
+
prsityCB=0.2,
|
|
240
|
+
)
|
|
241
|
+
s.mp7sim = s.mp7.create_mp7sim(
|
|
242
|
+
trackdir='forward',
|
|
243
|
+
simtype='pathline',
|
|
244
|
+
packages='RCH',
|
|
245
|
+
)
|
|
246
|
+
s.mp7.write_input()
|
|
247
|
+
|
|
248
|
+
def _write_mp7_particle(self):
|
|
249
|
+
"""Write particle location file for MP7."""
|
|
250
|
+
s = self._s
|
|
251
|
+
l, c, r = s.cellInfoFromCoordinates(s.particleCoords)
|
|
252
|
+
|
|
253
|
+
frac_col = 1.0 - ((s.particleCoords[0] / s.dCol) - int(s.particleCoords[0] / s.dCol))
|
|
254
|
+
frac_row = ((s.particleCoords[1] / s.dRow) - int(s.particleCoords[1] / s.dRow))
|
|
255
|
+
frac_ver = s.particleCoords[2] / s.dVer
|
|
256
|
+
|
|
257
|
+
mploc_path = join(s.model_ws, s.MODELNAME + '.mploc')
|
|
258
|
+
with open(mploc_path, 'w') as f:
|
|
259
|
+
f.write('1\n1\nparticle\n1\n')
|
|
260
|
+
f.write(
|
|
261
|
+
f"1 1 1 {s.nLay - l + 1} {s.nRow - r + 1} "
|
|
262
|
+
f"{s.nCol - c + 1} {frac_col:.6f} {frac_row:.6f} "
|
|
263
|
+
f"{frac_ver:.6f} 0.000000 particle\n"
|
|
264
|
+
)
|
|
265
|
+
f.write('particle\n')
|
|
266
|
+
f.write('1 0.000000 1\n')
|
|
267
|
+
|
|
268
|
+
def load_particle_data(self):
|
|
269
|
+
"""Load particle tracking results from MP7 output."""
|
|
270
|
+
s = self._s
|
|
271
|
+
# MP7 outputs in .pth file (pathline) or .ptc file (travel time)
|
|
272
|
+
import flopy.modpath.mp7particledata as mp7pd
|
|
273
|
+
pth_file = join(s.model_ws, f'{s.MODELNAME}.pth')
|
|
274
|
+
if not exists(pth_file):
|
|
275
|
+
# Try .ptc
|
|
276
|
+
pth_file = join(s.model_ws, f'{s.MODELNAME}.ptc')
|
|
277
|
+
if not exists(pth_file):
|
|
278
|
+
raise FileNotFoundError(f"MP7 output file not found in {s.model_ws}")
|
|
279
|
+
|
|
280
|
+
import pandas as pd
|
|
281
|
+
df = pd.read_csv(pth_file, header=None)
|
|
282
|
+
return df
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"""
|
|
2
|
+
CI-safe golden value regression tests.
|
|
3
|
+
|
|
4
|
+
Validates exact-match against golden outputs for 4 representative environment types:
|
|
5
|
+
- 1s-d: discrete, single well
|
|
6
|
+
- 1s-c: continuous, single well
|
|
7
|
+
- 3s-d: discrete, multi-well
|
|
8
|
+
- 6r-c: continuous, multi-layer, multi-well
|
|
9
|
+
|
|
10
|
+
These catch structural regressions (dimension changes, normalization breaks,
|
|
11
|
+
reward formula changes) on every push without running all 20 env types.
|
|
12
|
+
|
|
13
|
+
The full suite (all 20 env types) lives in test_regression.py (marked slow).
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
import pathlib
|
|
18
|
+
import numpy as np
|
|
19
|
+
import pytest
|
|
20
|
+
|
|
21
|
+
GOLDEN_PATH = pathlib.Path(__file__).parent / "golden_outputs.json"
|
|
22
|
+
|
|
23
|
+
CI_ENV_TYPES = ["1s-d", "1s-c", "3s-d", "6r-c"]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _load_golden():
|
|
27
|
+
with open(GOLDEN_PATH) as f:
|
|
28
|
+
data = json.load(f)
|
|
29
|
+
return {k: v for k, v in data.items() if k in CI_ENV_TYPES}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
GOLDEN = _load_golden()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _make_action(envtype, golden_entry):
|
|
36
|
+
at = golden_entry["actionType"]
|
|
37
|
+
if at == "discrete":
|
|
38
|
+
return 2
|
|
39
|
+
else:
|
|
40
|
+
shape = golden_entry["action_space_shape"]
|
|
41
|
+
if isinstance(shape, list) and len(shape) > 0:
|
|
42
|
+
return np.full(tuple(shape), 0.5, dtype=np.float32)
|
|
43
|
+
return np.array([0.5], dtype=np.float32)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _run_env(envtype, n_steps=5):
|
|
47
|
+
from flopyarcade import FloPyEnv
|
|
48
|
+
entry = GOLDEN[envtype]
|
|
49
|
+
env = FloPyEnv(
|
|
50
|
+
ENVTYPE=envtype,
|
|
51
|
+
MODELNAME=f"ci_reg_{envtype}",
|
|
52
|
+
flagSavePlot=False,
|
|
53
|
+
flagManualControl=False,
|
|
54
|
+
flagRender=False,
|
|
55
|
+
_seed=entry["seed"],
|
|
56
|
+
nLay=entry["nLay"],
|
|
57
|
+
nRow=entry["nRow"],
|
|
58
|
+
nCol=entry["nCol"],
|
|
59
|
+
)
|
|
60
|
+
obs, _ = env.reset()
|
|
61
|
+
action = _make_action(envtype, entry)
|
|
62
|
+
results = []
|
|
63
|
+
for _ in range(n_steps):
|
|
64
|
+
obs, reward, terminated, truncated, _ = env.step(action)
|
|
65
|
+
results.append({
|
|
66
|
+
"reward": float(reward),
|
|
67
|
+
"terminated": bool(terminated),
|
|
68
|
+
"truncated": bool(truncated),
|
|
69
|
+
"obs": np.array(obs, dtype=np.float64).flatten().tolist(),
|
|
70
|
+
})
|
|
71
|
+
if terminated or truncated:
|
|
72
|
+
break
|
|
73
|
+
env.close()
|
|
74
|
+
return results
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class TestGoldenRegressionCI:
|
|
78
|
+
"""Exact-match golden value regression for CI (4 env types)."""
|
|
79
|
+
|
|
80
|
+
@pytest.mark.parametrize("envtype", CI_ENV_TYPES)
|
|
81
|
+
def test_rewards_exact(self, envtype):
|
|
82
|
+
entry = GOLDEN[envtype]
|
|
83
|
+
steps = entry["steps"]
|
|
84
|
+
results = _run_env(envtype, len(steps))
|
|
85
|
+
for i, (got, expected) in enumerate(zip(results, steps)):
|
|
86
|
+
assert abs(got["reward"] - expected["reward"]) < 1e-6, (
|
|
87
|
+
f"{envtype}: step {i} reward {got[chr(39)+chr(114)+chr(101)+chr(119)+chr(97)+chr(114)+chr(100)+chr(39)]} != expected {expected[chr(39)+chr(114)+chr(101)+chr(119)+chr(97)+chr(114)+chr(100)+chr(39)]}"
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
@pytest.mark.parametrize("envtype", CI_ENV_TYPES)
|
|
91
|
+
def test_observations_match(self, envtype):
|
|
92
|
+
entry = GOLDEN[envtype]
|
|
93
|
+
steps = entry["steps"]
|
|
94
|
+
results = _run_env(envtype, len(steps))
|
|
95
|
+
for i, (got, expected) in enumerate(zip(results, steps)):
|
|
96
|
+
got_obs = np.array(got["obs"])
|
|
97
|
+
exp_obs = np.array(expected["obs"])
|
|
98
|
+
assert got_obs.shape == exp_obs.shape, (
|
|
99
|
+
f"{envtype}: step {i} obs shape mismatch"
|
|
100
|
+
)
|
|
101
|
+
assert np.allclose(got_obs, exp_obs, atol=1e-5), (
|
|
102
|
+
f"{envtype}: step {i} obs mismatch, max diff={np.max(np.abs(got_obs - exp_obs))}"
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
@pytest.mark.parametrize("envtype", CI_ENV_TYPES)
|
|
106
|
+
def test_termination_matches(self, envtype):
|
|
107
|
+
entry = GOLDEN[envtype]
|
|
108
|
+
steps = entry["steps"]
|
|
109
|
+
results = _run_env(envtype, len(steps))
|
|
110
|
+
for i, (got, expected) in enumerate(zip(results, steps)):
|
|
111
|
+
assert got["terminated"] == expected["terminated"], (
|
|
112
|
+
f"{envtype}: step {i} terminated mismatch"
|
|
113
|
+
)
|
|
114
|
+
assert got["truncated"] == expected["truncated"], (
|
|
115
|
+
f"{envtype}: step {i} truncated mismatch"
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
@pytest.mark.parametrize("envtype", CI_ENV_TYPES)
|
|
119
|
+
def test_obs_finite(self, envtype):
|
|
120
|
+
results = _run_env(envtype, 3)
|
|
121
|
+
for i, r in enumerate(results):
|
|
122
|
+
arr = np.array(r["obs"])
|
|
123
|
+
assert np.all(np.isfinite(arr)), (
|
|
124
|
+
f"{envtype}: step {i} has non-finite observations"
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
@pytest.mark.parametrize("envtype", CI_ENV_TYPES)
|
|
128
|
+
def test_determinism(self, envtype):
|
|
129
|
+
"""Same seed + same actions = same rewards."""
|
|
130
|
+
entry = GOLDEN[envtype]
|
|
131
|
+
n = len(entry["steps"])
|
|
132
|
+
r1 = _run_env(envtype, n)
|
|
133
|
+
r2 = _run_env(envtype, n)
|
|
134
|
+
for i in range(min(len(r1), len(r2))):
|
|
135
|
+
assert r1[i]["reward"] == r2[i]["reward"], (
|
|
136
|
+
f"{envtype}: step {i} not deterministic"
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
@pytest.mark.parametrize("envtype", CI_ENV_TYPES)
|
|
140
|
+
def test_env_spaces_valid(self, envtype):
|
|
141
|
+
from flopyarcade import FloPyEnv
|
|
142
|
+
entry = GOLDEN[envtype]
|
|
143
|
+
env = FloPyEnv(
|
|
144
|
+
ENVTYPE=envtype,
|
|
145
|
+
MODELNAME=f"ci_sp_{envtype}",
|
|
146
|
+
flagSavePlot=False,
|
|
147
|
+
flagManualControl=False,
|
|
148
|
+
flagRender=False,
|
|
149
|
+
_seed=entry["seed"],
|
|
150
|
+
nLay=entry["nLay"],
|
|
151
|
+
nRow=entry["nRow"],
|
|
152
|
+
nCol=entry["nCol"],
|
|
153
|
+
)
|
|
154
|
+
obs, _ = env.reset()
|
|
155
|
+
assert env.action_space is not None
|
|
156
|
+
assert env.observation_space is not None
|
|
157
|
+
env.close()
|
|
@@ -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
|
|
@@ -24,7 +24,8 @@ Requires-Python: <3.13,>=3.7
|
|
|
24
24
|
Description-Content-Type: text/markdown
|
|
25
25
|
License-File: LICENSE
|
|
26
26
|
Requires-Dist: flopy>=3.9.2
|
|
27
|
-
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"
|
|
28
29
|
Requires-Dist: imageio>=2.22.4
|
|
29
30
|
Requires-Dist: importlib-metadata>=4.13.0
|
|
30
31
|
Requires-Dist: joblib>=1.2.0
|
|
@@ -11,6 +11,7 @@ flopyarcade/benchmark.py
|
|
|
11
11
|
flopyarcade/env_base.py
|
|
12
12
|
flopyarcade/env_config.py
|
|
13
13
|
flopyarcade/flopyarcade.py
|
|
14
|
+
flopyarcade/mf6_mp7_runner.py
|
|
14
15
|
flopyarcade/mf6_prt_runner.py
|
|
15
16
|
flopyarcade/modflow_runner.py
|
|
16
17
|
flopyarcade/modpath_runner.py
|
|
@@ -73,6 +74,7 @@ flopyarcade/tests/test_mf6_runners.py
|
|
|
73
74
|
flopyarcade/tests/test_mock_rllib.py
|
|
74
75
|
flopyarcade/tests/test_play.py
|
|
75
76
|
flopyarcade/tests/test_regression.py
|
|
77
|
+
flopyarcade/tests/test_regression_ci.py
|
|
76
78
|
flopyarcade/tests/test_render3d.py
|
|
77
79
|
flopyarcade/tests/test_reward_reset.py
|
|
78
80
|
flopyarcade/tests/test_rllib_cpu.py
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
flopy>=3.9.2
|
|
2
|
-
gymnasium>=0.29.1
|
|
3
2
|
imageio>=2.22.4
|
|
4
3
|
importlib-metadata>=4.13.0
|
|
5
4
|
joblib>=1.2.0
|
|
@@ -14,6 +13,12 @@ scikit-image>=0.23.0
|
|
|
14
13
|
tqdm>=4.64.1
|
|
15
14
|
xmipy==1.3.0
|
|
16
15
|
|
|
16
|
+
[:python_version < "3.11"]
|
|
17
|
+
gymnasium<1.2,>=0.29.1
|
|
18
|
+
|
|
19
|
+
[:python_version >= "3.11"]
|
|
20
|
+
gymnasium>=0.29.1
|
|
21
|
+
|
|
17
22
|
[all]
|
|
18
23
|
flopyarcade[ray,solvers]
|
|
19
24
|
|
|
@@ -3,7 +3,7 @@ requires = ["setuptools >= 64", "wheel"]
|
|
|
3
3
|
build-backend = "setuptools.build_meta"
|
|
4
4
|
[project]
|
|
5
5
|
name = "flopyarcade"
|
|
6
|
-
version = "0.7.
|
|
6
|
+
version = "0.7.2"
|
|
7
7
|
description="Simulated groundwater flow environments for reinforcement learning."
|
|
8
8
|
readme = "README.md"
|
|
9
9
|
urls = {Homepage = "https://github.com/philipphoehn/flopyarcade", Documentation = "https://flopyarcade.readthedocs.io"}
|
|
@@ -14,7 +14,8 @@ requires-python = ">=3.7, <3.13"
|
|
|
14
14
|
license={text = "GNU GPLv3"}
|
|
15
15
|
dependencies = [
|
|
16
16
|
"flopy >= 3.9.2",
|
|
17
|
-
"gymnasium >= 0.29.1",
|
|
17
|
+
"gymnasium >= 0.29.1, < 1.2; python_version < '3.11'",
|
|
18
|
+
"gymnasium >= 0.29.1; python_version >= '3.11'",
|
|
18
19
|
"imageio >= 2.22.4",
|
|
19
20
|
"importlib-metadata >= 4.13.0",
|
|
20
21
|
"joblib >= 1.2.0",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/examples/policymodels/1s-d/1s-d.tune_metadata
RENAMED
|
File without changes
|
|
File without changes
|
{flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/examples/policymodels/2s-d/2s-d.tune_metadata
RENAMED
|
File without changes
|
|
File without changes
|
{flopyarcade-0.7.1 → flopyarcade-0.7.2}/flopyarcade/examples/policymodels/3s-d/3s-d.tune_metadata
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|