integrate-module 1.0.0__tar.gz → 1.0.3__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.
- {integrate_module-1.0.0/integrate_module.egg-info → integrate_module-1.0.3}/PKG-INFO +17 -11
- {integrate_module-1.0.0 → integrate_module-1.0.3}/README.md +10 -7
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/pages/prior.py +1 -1
- {integrate_module-1.0.0 → integrate_module-1.0.3}/integrate/__init__.py +10 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/integrate/anemone_forward.py +134 -11
- {integrate_module-1.0.0 → integrate_module-1.0.3}/integrate/gaaem_forward.py +2 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/integrate/integrate.py +324 -219
- {integrate_module-1.0.0 → integrate_module-1.0.3}/integrate/integrate_borehole.py +50 -196
- {integrate_module-1.0.0 → integrate_module-1.0.3}/integrate/integrate_io.py +588 -217
- {integrate_module-1.0.0 → integrate_module-1.0.3}/integrate/integrate_plot.py +700 -52
- {integrate_module-1.0.0 → integrate_module-1.0.3}/integrate/integrate_query.py +133 -9
- {integrate_module-1.0.0 → integrate_module-1.0.3}/integrate/integrate_rejection.py +907 -186
- {integrate_module-1.0.0 → integrate_module-1.0.3}/integrate/integrate_rejection_cli.py +59 -13
- {integrate_module-1.0.0 → integrate_module-1.0.3}/integrate/integrate_rejection_jax.py +184 -70
- {integrate_module-1.0.0 → integrate_module-1.0.3}/integrate/simpeg_forward.py +2 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/integrate/sr2_gex.py +30 -12
- {integrate_module-1.0.0 → integrate_module-1.0.3/integrate_module.egg-info}/PKG-INFO +17 -11
- {integrate_module-1.0.0 → integrate_module-1.0.3}/integrate_module.egg-info/SOURCES.txt +11 -1
- {integrate_module-1.0.0 → integrate_module-1.0.3}/integrate_module.egg-info/requires.txt +7 -3
- {integrate_module-1.0.0 → integrate_module-1.0.3}/pyproject.toml +27 -9
- integrate_module-1.0.3/tests/test_anemone_core.py +428 -0
- integrate_module-1.0.3/tests/test_coherent_area.py +43 -0
- integrate_module-1.0.3/tests/test_likelihood_gaussian.py +168 -0
- integrate_module-1.0.3/tests/test_likelihood_kernels.py +100 -0
- integrate_module-1.0.3/tests/test_prior_timing.py +82 -0
- integrate_module-1.0.3/tests/test_rejection_backends.py +254 -0
- integrate_module-1.0.3/tests/test_rejection_cli.py +63 -0
- integrate_module-1.0.3/tests/test_rejection_em_height.py +264 -0
- integrate_module-1.0.3/tests/test_rejection_per_type_T.py +224 -0
- integrate_module-1.0.3/tests/test_voronoi_grid.py +139 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/LICENSE +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/__init__.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/__main__.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/app.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/components.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/config.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/pages/__init__.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/pages/_forms.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/pages/_jobs_ui.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/pages/borehole.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/pages/files.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/pages/forward.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/pages/geoprior.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/pages/inversion.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/pages/plotting.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/pages/profile.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/pages/query.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/pages/results.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/pages/stubs.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/pages/workflow.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/pages/workspace_ui.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/services/__init__.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/services/figures.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/services/files.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/services/integrate_api.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/services/jobs.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/services/session.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/services/worker.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/services/workspace.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/services/xlsx.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/static/app.css +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/static/fonts/archivo-latin-ext.woff2 +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/static/fonts/archivo-latin.woff2 +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/static/fonts/archivo-vietnamese.woff2 +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/static/htmx.min.js +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/static/modernist.css +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/frontend/static/picker.js +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/integrate/em_system.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/integrate/gex.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/integrate/integrate_hdf5_info_cli.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/integrate/integrate_timing_cli.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/integrate/mlmapping.py +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/integrate_module.egg-info/dependency_links.txt +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/integrate_module.egg-info/entry_points.txt +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/integrate_module.egg-info/top_level.txt +0 -0
- {integrate_module-1.0.0 → integrate_module-1.0.3}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: integrate_module
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
4
4
|
Summary: Localized probabilistic data integration
|
|
5
5
|
Author-email: Thomas Mejer Hansen <tmeha@geo.au.dk>
|
|
6
6
|
License: MIT
|
|
@@ -20,11 +20,12 @@ Requires-Dist: scipy
|
|
|
20
20
|
Requires-Dist: psutil
|
|
21
21
|
Requires-Dist: tqdm
|
|
22
22
|
Requires-Dist: requests
|
|
23
|
-
Requires-Dist: geoprior1d>=0.
|
|
23
|
+
Requires-Dist: geoprior1d>=1.0.1
|
|
24
24
|
Requires-Dist: shapely
|
|
25
25
|
Requires-Dist: ga-aem-forward-win; platform_system == "Windows"
|
|
26
26
|
Requires-Dist: simpeg>=0.25
|
|
27
|
-
Requires-Dist:
|
|
27
|
+
Requires-Dist: anemone-core>=0.1.1
|
|
28
|
+
Requires-Dist: jupyter>=1.0.1
|
|
28
29
|
Requires-Dist: jupytext
|
|
29
30
|
Requires-Dist: ipykernel
|
|
30
31
|
Requires-Dist: pandas
|
|
@@ -40,8 +41,10 @@ Requires-Dist: threadpoolctl
|
|
|
40
41
|
Provides-Extra: dev
|
|
41
42
|
Requires-Dist: pytest; extra == "dev"
|
|
42
43
|
Requires-Dist: black; extra == "dev"
|
|
44
|
+
Provides-Extra: ui
|
|
45
|
+
Requires-Dist: integrate_ui; extra == "ui"
|
|
43
46
|
Provides-Extra: ml
|
|
44
|
-
Requires-Dist: tensorflow; extra == "ml"
|
|
47
|
+
Requires-Dist: tensorflow[and-cuda]; extra == "ml"
|
|
45
48
|
Requires-Dist: scikit-learn; extra == "ml"
|
|
46
49
|
Requires-Dist: keras_tuner; extra == "ml"
|
|
47
50
|
Provides-Extra: examples
|
|
@@ -226,17 +229,20 @@ First install Homebrew, then run:
|
|
|
226
229
|
|
|
227
230
|
## Alternative EM forward backends (anemone, SimPEG)
|
|
228
231
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
`
|
|
232
|
+
**anemone** is the default TDEM forward modeller. If it is not installed, INTEGRATE falls
|
|
233
|
+
back to GA-AEM and then SimPEG (preference: anemone, GA-AEM, SimPEG). Select a backend with
|
|
234
|
+
`method=` in `ig.forward_em()` / `ig.prior_data_em()` (or via the `EM_FORWARD_METHOD`
|
|
235
|
+
environment variable):
|
|
232
236
|
|
|
233
|
-
ig.prior_data_em(f_prior_h5, file_gex=gex
|
|
237
|
+
ig.prior_data_em(f_prior_h5, file_gex=gex) # default: anemone
|
|
234
238
|
ig.prior_data_em(f_prior_h5, file_gex=gex, method='anemone') # PyTorch, GPU-capable
|
|
239
|
+
ig.prior_data_em(f_prior_h5, file_gex=gex, method='ga-aem') # GA-AEM
|
|
235
240
|
ig.prior_data_em(f_prior_h5, file_gex=gex, method='simpeg') # SimPEG 1D layered TDEM
|
|
236
241
|
|
|
237
|
-
* **anemone** (PyTorch, GPU-capable):
|
|
238
|
-
|
|
239
|
-
install
|
|
242
|
+
* **anemone** (PyTorch, GPU-capable): installed with `integrate_module` (core dependency
|
|
243
|
+
`anemone-core`, imported as `anemone`). Source: https://github.com/hydrogeophysicsgroup/anemone,
|
|
244
|
+
PyPI: https://pypi.org/project/anemone-core/. For GPU use, install a CUDA build of `torch`
|
|
245
|
+
for your hardware (https://pytorch.org).
|
|
240
246
|
* **SimPEG**: installed with `integrate_module` (core dependency, `simpeg>=0.25`).
|
|
241
247
|
Use `ig.forward_simpeg()` / `ig.prior_data_simpeg()`. The `.gex` low-pass filters
|
|
242
248
|
and gate integration are applied by INTEGRATE on top of SimPEG's
|
|
@@ -168,17 +168,20 @@ First install Homebrew, then run:
|
|
|
168
168
|
|
|
169
169
|
## Alternative EM forward backends (anemone, SimPEG)
|
|
170
170
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
`
|
|
171
|
+
**anemone** is the default TDEM forward modeller. If it is not installed, INTEGRATE falls
|
|
172
|
+
back to GA-AEM and then SimPEG (preference: anemone, GA-AEM, SimPEG). Select a backend with
|
|
173
|
+
`method=` in `ig.forward_em()` / `ig.prior_data_em()` (or via the `EM_FORWARD_METHOD`
|
|
174
|
+
environment variable):
|
|
174
175
|
|
|
175
|
-
ig.prior_data_em(f_prior_h5, file_gex=gex
|
|
176
|
+
ig.prior_data_em(f_prior_h5, file_gex=gex) # default: anemone
|
|
176
177
|
ig.prior_data_em(f_prior_h5, file_gex=gex, method='anemone') # PyTorch, GPU-capable
|
|
178
|
+
ig.prior_data_em(f_prior_h5, file_gex=gex, method='ga-aem') # GA-AEM
|
|
177
179
|
ig.prior_data_em(f_prior_h5, file_gex=gex, method='simpeg') # SimPEG 1D layered TDEM
|
|
178
180
|
|
|
179
|
-
* **anemone** (PyTorch, GPU-capable):
|
|
180
|
-
|
|
181
|
-
install
|
|
181
|
+
* **anemone** (PyTorch, GPU-capable): installed with `integrate_module` (core dependency
|
|
182
|
+
`anemone-core`, imported as `anemone`). Source: https://github.com/hydrogeophysicsgroup/anemone,
|
|
183
|
+
PyPI: https://pypi.org/project/anemone-core/. For GPU use, install a CUDA build of `torch`
|
|
184
|
+
for your hardware (https://pytorch.org).
|
|
182
185
|
* **SimPEG**: installed with `integrate_module` (core dependency, `simpeg>=0.25`).
|
|
183
186
|
Use `ig.forward_simpeg()` / `ig.prior_data_simpeg()`. The `.gex` low-pass filters
|
|
184
187
|
and gate integration are applied by INTEGRATE on top of SimPEG's
|
|
@@ -45,7 +45,7 @@ _RHO = [
|
|
|
45
45
|
_RHO_DIST = ("select", ["log-uniform", "uniform", "normal", "lognormal"])
|
|
46
46
|
# smooth (L2): 'lognormal' keeps the historical correlated-GP-in-log output;
|
|
47
47
|
# 'log-uniform'/'uniform' swap the per-layer marginal via a Gaussian copula.
|
|
48
|
-
_RHO_DIST_L2 = ("select", ["lognormal", "log-uniform", "uniform"
|
|
48
|
+
_RHO_DIST_L2 = ("select", ["lognormal", "log-uniform", "uniform"])
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
# --------------------------------------------------------------------------- #
|
|
@@ -3,6 +3,8 @@ multiprocessing.freeze_support()
|
|
|
3
3
|
|
|
4
4
|
# Import rejection sampling functions from new module
|
|
5
5
|
from integrate.integrate_rejection import integrate_rejection
|
|
6
|
+
from integrate.integrate_rejection import integrate_rejection_em_height
|
|
7
|
+
from integrate.integrate_rejection import em_height_bins
|
|
6
8
|
from integrate.integrate_rejection import integrate_rejection_range
|
|
7
9
|
from integrate.integrate_rejection import integrate_posterior_chunk
|
|
8
10
|
from integrate.integrate_rejection import integrate_posterior_main
|
|
@@ -70,6 +72,8 @@ from integrate.integrate_io import load_prior_data
|
|
|
70
72
|
from integrate.integrate_io import save_prior_data
|
|
71
73
|
from integrate.integrate_io import load_prior_model
|
|
72
74
|
from integrate.integrate_io import save_prior_model
|
|
75
|
+
from integrate.integrate_io import save_compute_time
|
|
76
|
+
from integrate.integrate_io import get_prior_timing
|
|
73
77
|
from integrate.integrate_io import load_data
|
|
74
78
|
from integrate.integrate_io import get_geometry
|
|
75
79
|
from integrate.integrate_io import extract_feature_at_elevation
|
|
@@ -123,6 +127,11 @@ from integrate.integrate_plot import plot_xy
|
|
|
123
127
|
from integrate.integrate_plot import find_points_along_line_segments
|
|
124
128
|
from integrate.integrate_plot import plot_boreholes
|
|
125
129
|
from integrate.integrate_plot import plot_voronoi_cells
|
|
130
|
+
from integrate.integrate_plot import post_to_voronoi_columns
|
|
131
|
+
from integrate.integrate_plot import voronoi_columns_to_grid
|
|
132
|
+
from integrate.integrate_plot import post_to_voronoi_grid
|
|
133
|
+
from integrate.integrate_plot import plot_voronoi_3d
|
|
134
|
+
from integrate.integrate_plot import plot_voronoi_slices
|
|
126
135
|
|
|
127
136
|
# Import from borehole module
|
|
128
137
|
from integrate.integrate_borehole import compute_P_obs_discrete
|
|
@@ -155,6 +164,7 @@ from integrate.integrate_query import query_test_llm
|
|
|
155
164
|
from integrate.integrate_query import voronoi_graph
|
|
156
165
|
from integrate.integrate_query import voronoi_cells_ordered
|
|
157
166
|
from integrate.integrate_query import cells_to_polygon
|
|
167
|
+
from integrate.integrate_query import touching_neighbors
|
|
158
168
|
from integrate.integrate_query import flag_edge_cells
|
|
159
169
|
from integrate.integrate_query import grow_connected_region
|
|
160
170
|
from integrate.integrate_query import find_coherent_area
|
|
@@ -17,7 +17,9 @@ from integrate.em_system import (_butter_rows, _polygon_area, # shared helpers
|
|
|
17
17
|
|
|
18
18
|
_IMPORT_HINT = (
|
|
19
19
|
"anemone backend requires 'anemone' and 'torch': "
|
|
20
|
-
"pip install
|
|
20
|
+
"pip install anemone-core "
|
|
21
|
+
"(https://pypi.org/project/anemone-core/, "
|
|
22
|
+
"https://github.com/hydrogeophysicsgroup/anemone)"
|
|
21
23
|
)
|
|
22
24
|
|
|
23
25
|
|
|
@@ -91,13 +93,57 @@ def _gex_signature(g):
|
|
|
91
93
|
return hashlib.md5(repr(sorted(str(d).encode())[:0] or str(d)).encode()).hexdigest()
|
|
92
94
|
|
|
93
95
|
|
|
94
|
-
|
|
96
|
+
from collections import OrderedDict
|
|
97
|
+
|
|
98
|
+
# Cache of anemone setups, one per (GEX, Tx height, device, tolerance), in
|
|
99
|
+
# least-recently-used order. With a varying flight height there is one setup
|
|
100
|
+
# per height bin (~50 MB of GPU memory each for SkyTEM), so on CUDA the cache
|
|
101
|
+
# is bounded by free GPU memory: the least recently used setups on the device
|
|
102
|
+
# are dropped while less than _CUDA_MIN_FREE_GB (or _CUDA_MIN_FREE_FRAC of
|
|
103
|
+
# the total) is free.
|
|
104
|
+
_FORWARD_CACHE = OrderedDict()
|
|
105
|
+
_CUDA_MIN_FREE_GB = 1.0
|
|
106
|
+
_CUDA_MIN_FREE_FRAC = 0.15
|
|
95
107
|
|
|
96
108
|
|
|
97
109
|
def _clear_forward_cache():
|
|
98
110
|
_FORWARD_CACHE.clear()
|
|
99
111
|
|
|
100
112
|
|
|
113
|
+
def _evict_cuda_cache(device, torch, all_entries=False):
|
|
114
|
+
"""Drop least recently used CUDA setups on ``device`` until enough GPU
|
|
115
|
+
memory is free (or all of them with ``all_entries``). Returns the number
|
|
116
|
+
of setups dropped."""
|
|
117
|
+
import gc
|
|
118
|
+
dev = torch.device(device)
|
|
119
|
+
if dev.type != "cuda" or not torch.cuda.is_available():
|
|
120
|
+
return 0
|
|
121
|
+
idx = dev.index if dev.index is not None else torch.cuda.current_device()
|
|
122
|
+
dev_keys = lambda: [k for k in _FORWARD_CACHE
|
|
123
|
+
if torch.device(k[2]).type == "cuda"
|
|
124
|
+
and (torch.device(k[2]).index or 0) == idx]
|
|
125
|
+
|
|
126
|
+
def low_memory():
|
|
127
|
+
free, total = torch.cuda.mem_get_info(idx)
|
|
128
|
+
return free < max(_CUDA_MIN_FREE_GB * 1024 ** 3, _CUDA_MIN_FREE_FRAC * total)
|
|
129
|
+
|
|
130
|
+
n = 0
|
|
131
|
+
while dev_keys() and (all_entries or low_memory()):
|
|
132
|
+
# Drop a few at a time; freed memory is only visible after
|
|
133
|
+
# gc + empty_cache.
|
|
134
|
+
for k in dev_keys()[:1 if not all_entries else None]:
|
|
135
|
+
del _FORWARD_CACHE[k]
|
|
136
|
+
n += 1
|
|
137
|
+
gc.collect()
|
|
138
|
+
torch.cuda.empty_cache()
|
|
139
|
+
return n
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _is_cuda_oom(err, torch):
|
|
143
|
+
oom = getattr(torch, "OutOfMemoryError", None) or getattr(torch.cuda, "OutOfMemoryError", ())
|
|
144
|
+
return isinstance(err, oom) or "CUDA out of memory" in str(err)
|
|
145
|
+
|
|
146
|
+
|
|
101
147
|
def _remake_loop(loop, tx_z, torch):
|
|
102
148
|
from anemone.system import Loop
|
|
103
149
|
if tx_z is None:
|
|
@@ -135,6 +181,15 @@ class _DampedLowPass:
|
|
|
135
181
|
def omega_filter(self, omega):
|
|
136
182
|
return self(omega / (2.0 * np.pi))
|
|
137
183
|
|
|
184
|
+
def poles(self):
|
|
185
|
+
"""Poles in rad/s (used by anemone's FilterChain.stepoff_response)."""
|
|
186
|
+
return 2.0 * np.pi * self.fcut * np.roots([1.0, 2.0 * self.damping, 1.0])
|
|
187
|
+
|
|
188
|
+
def stepoff_response(self, t):
|
|
189
|
+
"""Step-off response at times ``t`` (used by a one-filter FilterChain)."""
|
|
190
|
+
from anemone.system import allpole_stepoff_response
|
|
191
|
+
return allpole_stepoff_response(self.poles(), t)
|
|
192
|
+
|
|
138
193
|
|
|
139
194
|
# ---------------------------------------------------------------------------
|
|
140
195
|
# System response (.sr2) support
|
|
@@ -312,8 +367,25 @@ def _build_forward(system, tx_z, device):
|
|
|
312
367
|
tx_z_key = "src" if tx_z is None else round(float(tx_z), 3)
|
|
313
368
|
key = (system["gex_signature"], tx_z_key, str(device), system.get("tolerance"))
|
|
314
369
|
if key in _FORWARD_CACHE:
|
|
370
|
+
_FORWARD_CACHE.move_to_end(key)
|
|
315
371
|
return _FORWARD_CACHE[key]
|
|
316
372
|
|
|
373
|
+
_evict_cuda_cache(device, torch)
|
|
374
|
+
try:
|
|
375
|
+
return _build_forward_uncached(system, tx_z, device, key)
|
|
376
|
+
except RuntimeError as err:
|
|
377
|
+
# Out of GPU memory: drop all cached setups on the device and retry once
|
|
378
|
+
if not _is_cuda_oom(err, torch) or _evict_cuda_cache(device, torch, all_entries=True) == 0:
|
|
379
|
+
raise
|
|
380
|
+
return _build_forward_uncached(system, tx_z, device, key)
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
def _build_forward_uncached(system, tx_z, device, key):
|
|
384
|
+
_, torch = _require_anemone()
|
|
385
|
+
from anemone.forwards import Forward
|
|
386
|
+
from anemone.system import Receiver
|
|
387
|
+
|
|
388
|
+
n_moments = len(system["moments"])
|
|
317
389
|
dev = torch.device(device)
|
|
318
390
|
|
|
319
391
|
# Hoist and build shared source, receiver, filterfunc from first moment
|
|
@@ -807,9 +879,15 @@ def forward_anemone(M=np.array(()), thickness=np.array(()), file_gex=None,
|
|
|
807
879
|
signal at 45 m; a ``UserWarning`` is given above 30 m. The reference
|
|
808
880
|
setup uses ``tolerance / 10`` (about 20% more kernel terms) to keep the
|
|
809
881
|
rescaling accurate. Has no effect for a fixed height.
|
|
882
|
+
altitude_bin_width : float, optional
|
|
883
|
+
Bin width in m (default 1.0) for a varying ``tx_height``: heights are
|
|
884
|
+
rounded to bins and one anemone setup is made per bin. ``0``/``None``
|
|
885
|
+
makes one setup per distinct height. Ignored with
|
|
886
|
+
``rescale_height=True`` and for a fixed height.
|
|
810
887
|
batch_size : int, optional
|
|
811
888
|
Number of soundings sent through anemone per call (default 1000).
|
|
812
889
|
Bounds peak (GPU) memory; ``0``/``None`` forwards everything at once.
|
|
890
|
+
|
|
813
891
|
file_sr2, sr_filters, n_previous_pulses
|
|
814
892
|
System-response / pulse options, see :func:`gex_to_anemone_system`.
|
|
815
893
|
A GEX with ``SystemResponseConvolution=1`` picks up ``<gex stem>.sr2``
|
|
@@ -820,6 +898,37 @@ def forward_anemone(M=np.array(()), thickness=np.array(()), file_gex=None,
|
|
|
820
898
|
tolerance : float or None
|
|
821
899
|
Kernel pruning tolerance (default ``1e-6``); larger is faster and less
|
|
822
900
|
accurate, see :func:`gex_to_anemone_system`.
|
|
901
|
+
|
|
902
|
+
Notes
|
|
903
|
+
-----
|
|
904
|
+
**Setup cache and GPU memory.** Each anemone setup (one per GEX, Tx
|
|
905
|
+
height, device and tolerance) is kept in a module cache and reused by
|
|
906
|
+
later calls. On CUDA a setup takes some tens of MB of GPU memory (about
|
|
907
|
+
50 MB for a dual-moment SkyTEM system), so with a varying flight height
|
|
908
|
+
(one setup per height bin, e.g. ~135 bins for 12-148 m) the cache alone
|
|
909
|
+
can exceed the GPU memory. The cache is therefore kept in
|
|
910
|
+
least-recently-used order, and before a new CUDA setup is built the least
|
|
911
|
+
recently used setups on that device are dropped until at least
|
|
912
|
+
``_CUDA_MIN_FREE_GB`` (1 GB) or ``_CUDA_MIN_FREE_FRAC`` (15 %) of the GPU
|
|
913
|
+
memory, whichever is larger, is free. If building a setup still runs out
|
|
914
|
+
of GPU memory, all cached setups on the device are dropped and the build
|
|
915
|
+
is retried once. Consequences:
|
|
916
|
+
|
|
917
|
+
* A fixed flight height uses one setup and is not affected.
|
|
918
|
+
* With more height bins than fit in the cache, a repeated call rebuilds
|
|
919
|
+
(almost) every setup, ~1 s each, because the bins are visited in the
|
|
920
|
+
same order every call (worst case for LRU).
|
|
921
|
+
* Free memory is measured on the whole GPU, so memory used by other
|
|
922
|
+
processes leads to more evictions (slower, not an error).
|
|
923
|
+
* Memory is only checked before building a setup, not while forwarding
|
|
924
|
+
the batches; lower ``batch_size`` if the forward itself runs out of
|
|
925
|
+
GPU memory.
|
|
926
|
+
* The CPU cache is not bounded.
|
|
927
|
+
|
|
928
|
+
The limits are module attributes, e.g.
|
|
929
|
+
``integrate.anemone_forward._CUDA_MIN_FREE_GB = 0.5``;
|
|
930
|
+
``integrate.anemone_forward._clear_forward_cache()`` empties the cache.
|
|
931
|
+
``rescale_height=True`` uses a single setup and avoids the cache churn.
|
|
823
932
|
"""
|
|
824
933
|
anemone, torch = _require_anemone()
|
|
825
934
|
import time
|
|
@@ -984,16 +1093,26 @@ def _rescaled_batch(fwr, M_b, T_b, dh_b, torch):
|
|
|
984
1093
|
Same evaluation as ``Forward.__call__`` (reflection coefficient, then the
|
|
985
1094
|
``H2t`` matrix), except that each model's reflection coefficient is first
|
|
986
1095
|
multiplied by ``exp(-2*dh*lmb)``: Tx and Rx both move by ``dh``, so
|
|
987
|
-
``sfield_dz`` grows by ``2*dh``.
|
|
1096
|
+
``sfield_dz`` grows by ``2*dh``. The primary field depends only on the
|
|
1097
|
+
Tx-Rx offset, which does not change, so ``fwr.primary`` is added as is.
|
|
1098
|
+
Returns an (n_models, n_gates) tensor.
|
|
1099
|
+
|
|
1100
|
+
Follows anemone-core >= 0.1.1: ``H2t`` already includes ``mu0``, and
|
|
1101
|
+
``Forward.__call__`` adds ``primary``.
|
|
988
1102
|
"""
|
|
989
1103
|
from anemone.physics import rte_raiche1999 as rte
|
|
990
|
-
from anemone import
|
|
991
|
-
|
|
992
|
-
rho = ((M_b.T + 0j)[..., None, None]).to(cdtype)
|
|
993
|
-
thick = ((T_b.T + 0j)[..., None, None]).to(cdtype)
|
|
994
|
-
cRTE = rte(1. / rho, thick, fwr.omega, fwr.
|
|
995
|
-
cRTE = cRTE * torch.exp(-2. * dh_b[:, None] * fwr.
|
|
996
|
-
|
|
1104
|
+
from anemone import cdtype, rdtype
|
|
1105
|
+
|
|
1106
|
+
rho = ((M_b.T + 0j)[..., None, None]).to(cdtype())
|
|
1107
|
+
thick = ((T_b.T + 0j)[..., None, None]).to(cdtype())
|
|
1108
|
+
cRTE = rte(1. / rho, thick, fwr.omega, fwr.lamda).reshape(M_b.shape[0], -1)
|
|
1109
|
+
cRTE = cRTE * torch.exp(-2. * dh_b[:, None] * fwr.lamda.real.reshape(1, -1))
|
|
1110
|
+
if fwr.H2t.dtype == rdtype(): # no filter: anemone keeps a real H2t
|
|
1111
|
+
cRTE = cRTE.real.to(rdtype())
|
|
1112
|
+
D = torch.einsum('ik,nk->ni', fwr.H2t, cRTE).real.to(rdtype())
|
|
1113
|
+
if torch.is_tensor(fwr.primary):
|
|
1114
|
+
D = D + fwr.primary
|
|
1115
|
+
return D
|
|
997
1116
|
|
|
998
1117
|
|
|
999
1118
|
def _forward_rescaled_height(system, M_c, T_c, tx_height, scale, device,
|
|
@@ -1088,7 +1207,9 @@ def prior_data_anemone(f_prior_h5, file_gex=None, N=0, doMakePriorCopy=True,
|
|
|
1088
1207
|
``rescale_height=True`` (varying ``M{im_height}`` only) does one anemone
|
|
1089
1208
|
setup and rescales it to each model's height instead of one setup per
|
|
1090
1209
|
``altitude_bin_width`` bin; much faster for varying flight height, see
|
|
1091
|
-
:func:`forward_anemone`.
|
|
1210
|
+
:func:`forward_anemone`. Setups are cached between calls; on CUDA the
|
|
1211
|
+
cache is bounded by free GPU memory (least recently used setups are
|
|
1212
|
+
dropped), see the Notes of :func:`forward_anemone`.
|
|
1092
1213
|
Returns the path to the prior-data h5 (always the return value).
|
|
1093
1214
|
"""
|
|
1094
1215
|
import multiprocessing
|
|
@@ -1096,6 +1217,7 @@ def prior_data_anemone(f_prior_h5, file_gex=None, N=0, doMakePriorCopy=True,
|
|
|
1096
1217
|
import h5py
|
|
1097
1218
|
import integrate as ig
|
|
1098
1219
|
from integrate.integrate import _report_progress
|
|
1220
|
+
t0_compute = time.time() # stored as /D{id} attr compute_time
|
|
1099
1221
|
|
|
1100
1222
|
if multiprocessing.current_process().name != "MainProcess":
|
|
1101
1223
|
return None
|
|
@@ -1195,6 +1317,7 @@ def prior_data_anemone(f_prior_h5, file_gex=None, N=0, doMakePriorCopy=True,
|
|
|
1195
1317
|
for name, rval in (cal.get("residual") or {}).items():
|
|
1196
1318
|
a["calibration_residual_%s" % name] = float(rval)
|
|
1197
1319
|
|
|
1320
|
+
ig.save_compute_time(f_prior_data_h5, Dname, time.time() - t0_compute, "prior_data_anemone", t0_compute)
|
|
1198
1321
|
ig.integrate_update_prior_attributes(f_prior_data_h5)
|
|
1199
1322
|
_report_progress(progress_callback, N, N, "completed",
|
|
1200
1323
|
"Forward data saved to %s" % f_prior_data_h5)
|
|
@@ -456,6 +456,7 @@ def prior_data_gaaem(f_prior_h5, file_gex=None, stmfiles=None, N=0, doMakePriorC
|
|
|
456
456
|
import integrate as ig
|
|
457
457
|
from integrate.integrate import _report_progress
|
|
458
458
|
import os
|
|
459
|
+
t0_compute = time.time() # stored as /D{id} attr compute_time
|
|
459
460
|
# Safety guard: if somehow called from a worker process, do nothing.
|
|
460
461
|
if multiprocessing.current_process().name != 'MainProcess':
|
|
461
462
|
return None
|
|
@@ -706,6 +707,7 @@ def prior_data_gaaem(f_prior_h5, file_gex=None, stmfiles=None, N=0, doMakePriorC
|
|
|
706
707
|
f_prior[Dname].attrs['Nhank'] = Nhank
|
|
707
708
|
f_prior[Dname].attrs['Nfreq'] = Nfreq
|
|
708
709
|
|
|
710
|
+
ig.save_compute_time(f_prior_data_h5, Dname, time.time() - t0_compute, "prior_data_gaaem", t0_compute)
|
|
709
711
|
ig.integrate_update_prior_attributes(f_prior_data_h5)
|
|
710
712
|
|
|
711
713
|
_report_progress(progress_callback, N, N,
|