DeepGPR 0.0.12__tar.gz → 0.0.14__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.
Files changed (28) hide show
  1. {deepgpr-0.0.12/src/DeepGPR.egg-info → deepgpr-0.0.14}/PKG-INFO +72 -15
  2. deepgpr-0.0.12/PKG-INFO → deepgpr-0.0.14/README.md +61 -27
  3. deepgpr-0.0.14/license +21 -0
  4. deepgpr-0.0.14/pyproject.toml +63 -0
  5. deepgpr-0.0.14/src/DeepGPR/__init__.py +337 -0
  6. {deepgpr-0.0.12 → deepgpr-0.0.14}/src/DeepGPR/common.py +198 -11
  7. {deepgpr-0.0.12 → deepgpr-0.0.14}/src/DeepGPR/compute2.py +204 -37
  8. deepgpr-0.0.14/src/DeepGPR/lib/deepgpr.cu +1390 -0
  9. deepgpr-0.0.14/src/DeepGPR/lib/deepgpr.dll +0 -0
  10. deepgpr-0.0.14/src/DeepGPR/lib/deepgpr.so +0 -0
  11. deepgpr-0.0.14/src/DeepGPR/lib/deepgpr_cpu.c +1161 -0
  12. deepgpr-0.0.14/src/DeepGPR/lib/deepgpr_cpu.dll +0 -0
  13. deepgpr-0.0.14/src/DeepGPR/lib/deepgpr_cpu.dylib +0 -0
  14. deepgpr-0.0.14/src/DeepGPR/lib/deepgpr_cpu.so +0 -0
  15. deepgpr-0.0.14/src/DeepGPR/lib/libomp.dylib +0 -0
  16. {deepgpr-0.0.12 → deepgpr-0.0.14}/src/DeepGPR/multiscale.py +20 -0
  17. deepgpr-0.0.12/README.md → deepgpr-0.0.14/src/DeepGPR.egg-info/PKG-INFO +85 -15
  18. {deepgpr-0.0.12 → deepgpr-0.0.14}/src/DeepGPR.egg-info/SOURCES.txt +7 -1
  19. {deepgpr-0.0.12 → deepgpr-0.0.14}/src/DeepGPR.egg-info/requires.txt +2 -0
  20. deepgpr-0.0.12/pyproject.toml +0 -38
  21. deepgpr-0.0.12/src/DeepGPR/__init__.py +0 -210
  22. deepgpr-0.0.12/src/DeepGPR/lib/deepgpr.cu +0 -823
  23. deepgpr-0.0.12/src/DeepGPR/lib/deepgpr.dll +0 -0
  24. deepgpr-0.0.12/src/DeepGPR/lib/deepgpr.so +0 -0
  25. {deepgpr-0.0.12 → deepgpr-0.0.14}/setup.cfg +0 -0
  26. {deepgpr-0.0.12 → deepgpr-0.0.14}/src/DeepGPR/wavelet.py +0 -0
  27. {deepgpr-0.0.12 → deepgpr-0.0.14}/src/DeepGPR.egg-info/dependency_links.txt +0 -0
  28. {deepgpr-0.0.12 → deepgpr-0.0.14}/src/DeepGPR.egg-info/top_level.txt +0 -0
@@ -1,15 +1,25 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: DeepGPR
3
- Version: 0.0.12
3
+ Version: 0.0.14
4
4
  Summary: PyTorch and CUDA for GPR FWI
5
5
  Author-email: Lei Liu <liulei990222@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/songc0a/DeepGPR
8
+ Project-URL: Repository, https://github.com/songc0a/DeepGPR
6
9
  Classifier: Programming Language :: Python :: 3
7
10
  Classifier: Operating System :: Microsoft :: Windows
8
11
  Classifier: Operating System :: POSIX :: Linux
12
+ Classifier: Operating System :: MacOS :: MacOS X
13
+ Classifier: Topic :: Scientific/Engineering
14
+ Classifier: Topic :: Scientific/Engineering :: Physics
9
15
  Requires-Python: >=3.8
10
16
  Description-Content-Type: text/markdown
17
+ License-File: license
11
18
  Requires-Dist: numpy
19
+ Requires-Dist: scipy
12
20
  Requires-Dist: matplotlib
21
+ Requires-Dist: torch
22
+ Dynamic: license-file
13
23
 
14
24
  # DeepGPR
15
25
 
@@ -24,22 +34,26 @@ Gradients of the output receiver data can be computed with respect to model para
24
34
 
25
35
  Utilizes CPML, allowing the width of the PML layer to be configured independently for each boundary.
26
36
 
27
- All operations are executed on the GPU.
37
+ The compute backend can run on CUDA GPUs or on CPU. The CPU backend is implemented in C and is selected automatically when `device='cpu'`.
38
+
39
+ The FDTD spatial finite-difference order can be selected with `fdtd_order=2`, `4`, or `8` (default: `2`).
40
+
41
+ The FWI gradient mode can be selected with `mode=2` or `mode=3`. `mode=2` keeps the previous Ez-only gradient behavior, while `mode=3` uses Ex, Ey, and Ez forward/adjoint electric-field contributions for relative permittivity and conductivity gradients.
28
42
 
29
43
  Supports techniques such as checkpointing, DDP, and the utilization of CPU memory to minimize GPU memory consumption, thereby enabling the execution of large-scale models.
30
44
 
31
45
 
32
46
  ## System Requirements
33
47
 
34
- - **OS**: Linux and Windows
35
- - **Environment**: Python 3.8+, CUDA Toolkit
36
- - **Libraries**: `torch` (with CUDA support), `numpy`, `scipy`, `matplotlib`
37
- - **Hardware**: NVIDIA GPU with sufficient VRAM for 3D computational grids.
48
+ - **OS**: Linux, Windows, and macOS for CPU execution; Linux and Windows for CUDA execution
49
+ - **Environment**: Python 3.8+, CUDA Toolkit for CUDA execution
50
+ - **Libraries**: `torch`, `numpy`, `scipy`, `matplotlib`
51
+ - **Hardware**: NVIDIA GPU with sufficient VRAM for CUDA execution; CPU execution works without a GPU.
38
52
 
39
53
 
40
54
  ## Start
41
55
 
42
- Before use, you must ensure that you have an NVIDIA graphics card and have installed a CUDA-enabled version of PyTorch.
56
+ Before CUDA use, you must ensure that you have an NVIDIA graphics card and have installed a CUDA-enabled version of PyTorch. For CPU use, install a CPU build of PyTorch and include a compiled `deepgpr_cpu` shared library in `src/DeepGPR/lib`.
43
57
 
44
58
  DeepGPR can then be installed using
45
59
 
@@ -57,7 +71,7 @@ import DeepGPR
57
71
  import matplotlib.pyplot as plt
58
72
 
59
73
  # Set up the parameters and models
60
- device=torch.device("cuda")
74
+ device=torch.device("cuda" if torch.cuda.is_available() else "cpu")
61
75
  dx=0.02
62
76
  dt=3e-11
63
77
  nt=2000
@@ -79,7 +93,8 @@ r = DeepGPR.compute(
79
93
  source_amplitudes=source_amplitudes,
80
94
  source_location=source_location,
81
95
  receiver_location=receiver_location,
82
- er=er, se=se
96
+ er=er, se=se,
97
+ fdtd_order=2
83
98
  )
84
99
 
85
100
  (r[-1]**2).sum().backward()
@@ -133,16 +148,22 @@ def compute(device, dx=None, dt=None,
133
148
  E=None, H=None, PML=None,
134
149
  pmlthick=10, source_direction=2, reciever_direction=2,
135
150
  model_gradient_sampling_interval=1,
136
- use_async_offload=False):
151
+ use_async_offload=False,
152
+ fdtd_order=2,
153
+ mode=2,
154
+ debug=False):
137
155
  ```
138
156
  ## 📥 Input Parameters
139
157
  ### 1. Basic Physics & Grid Parameters
140
158
 
141
159
  | Parameter | Data Type | Description |
142
160
  | :--- | :--- | :--- |
143
- | **`device`** | `torch.device` / `str` | PyTorch computation device, e.g., `'cuda:0'`. Determines where the computation takes place. |
161
+ | **`device`** | `torch.device` / `str` | PyTorch computation device, e.g., `'cuda:0'` or `'cpu'`. CUDA loads `deepgpr.so/.dll`; CPU loads `deepgpr_cpu.so/.dll/.dylib`. |
144
162
  | **`dx`** | `float` | Spatial grid step size (assuming an isotropic grid, i.e., $dx = dy = dz$). Typically in meters (m). |
145
163
  | **`dt`** | `float` | Time step size. **Note**: Must strictly satisfy the CFL (Courant-Friedrichs-Lewy) stability condition, or an exception will be raised. Typically in seconds (s). |
164
+ | **`fdtd_order`** | `int` | Spatial finite-difference order used by the FDTD field updates. Supported values are `2`, `4`, and `8`; default is `2` for compatibility with earlier versions. |
165
+ | **`mode`** | `int` | FWI gradient mode. `2` keeps the previous Ez-only model-gradient calculation. `3` uses Ex, Ey, and Ez electric-field contributions for relative permittivity and conductivity gradients. |
166
+ | **`debug`** | `bool` | Runs expensive NaN/Inf and zero-field validation checks when `True`. The default `False` keeps these checks disabled for faster production runs. |
146
167
  ### 2. Medium Model Parameters
147
168
 
148
169
  This section defines the electromagnetic properties of the simulation space. For 2D simulations, set `nz=1`.
@@ -161,7 +182,7 @@ This section defines the geometric observation system (coordinates) and the exci
161
182
 
162
183
  | Parameter | Data Type | Shape | Description |
163
184
  | :--- | :--- | :--- | :--- |
164
- | **`source_amplitudes`** | `Tensor` (float) | `(num_waveforms, nt)` | Source excitation waveforms. `nt` is the total number of time steps.<br>- If `num_waveforms == 1`: All sources share this single waveform.<br>- If `num_waveforms == nsr`: Each source uses its corresponding waveform. |
185
+ | **`source_amplitudes`** | `Tensor` (float) | `(num_waveforms, nt, 1)` | Source excitation waveforms. `nt` is the total number of time steps.<br>- If `num_waveforms == 1`: All sources share this single waveform.<br>- If `num_waveforms == nsr`: Each source uses its corresponding waveform. |
165
186
  | **`source_location`** | `Tensor` (int) | `(nstep, nsr, 3)` | Grid coordinate indices of the sources.<br>The last dimension corresponds to `[x_idx, y_idx, z_idx]`. |
166
187
  | **`receiver_location`** | `Tensor` (int) | `(nstep, nrx, 3)` | Grid coordinate indices of the receivers.<br>The last dimension corresponds to `[x_idx, y_idx, z_idx]`. |
167
188
  | **`source_direction`** | `int` | Scalar | Polarization direction/component of the source excitation.<br>`0` = X, `1` = Y, `2` = Z (e.g., exciting $E_z$). |
@@ -179,7 +200,41 @@ This section defines the geometric observation system (coordinates) and the exci
179
200
  | :--- | :--- | :--- | :--- |
180
201
  | **`pmlthick`** | `int` / `list` / `Tensor`| Scalar or list of 6 | Thickness (in grid layers) of the PML (Perfectly Matched Layer) absorbing boundaries.<br>- Integer `p`: All six boundaries have thickness `p` (Z-boundaries are ignored in 2D).<br>- List `[x0, xm, y0, ym, z0, zm]`: Specific thicknesses for the 6 boundaries. |
181
202
  | **`model_gradient_sampling_interval`**| `int` | Scalar | Wavefield sampling interval during forward propagation (Default: 1).<br>A larger integer reduces the VRAM usage for the saved `Eall` tensor, but may decrease the accuracy of backpropagated gradients. |
182
- | **`use_async_offload`** | `bool` | Scalar | VRAM optimization flag (Default: `False`).<br>If `True`, the internal full wavefield tensor (`Eall`) is asynchronously offloaded to page-locked host memory (`pin_memory` CPU RAM). This drastically reduces GPU VRAM consumption at the cost of slightly slower computation times due to PCIe data transfer latency. |
203
+ | **`use_async_offload`** | `bool` | Scalar | CUDA-only VRAM optimization flag (Default: `False`).<br>If `True`, the internal full wavefield tensor (`Eall`) is asynchronously offloaded to page-locked host memory (`pin_memory` CPU RAM). This drastically reduces GPU VRAM consumption at the cost of slightly slower computation times due to PCIe data transfer latency. On CPU this option is ignored. |
204
+
205
+ ### 4.1 FWI Gradient Mode
206
+
207
+ `mode` only changes how the model gradients are accumulated during backpropagation:
208
+
209
+ - `mode=2` (default): Saves Ez in `Eall` and computes relative permittivity/conductivity gradients from Ez only. This keeps the old behavior.
210
+ - `mode=3`: Saves Ex, Ey, and Ez in `Eall` and computes relative permittivity/conductivity gradients from all three electric-field components. This is intended for complete 3D Maxwell FWI. The adjoint source polarization is not changed by this option.
211
+
212
+ ## CPU Backend Build
213
+
214
+ The CPU backend is a plain C shared library and is built with OpenMP by default. Build it into `src/DeepGPR/lib` before running with `device='cpu'`. You can control CPU thread count with `OMP_NUM_THREADS`.
215
+
216
+ ```bash
217
+ # Linux
218
+ cc -std=c99 -O3 -fopenmp -fPIC -shared -o src/DeepGPR/lib/deepgpr_cpu.so src/DeepGPR/lib/deepgpr_cpu.c
219
+
220
+ # macOS
221
+ brew install libomp
222
+ LIBOMP_PREFIX="$(brew --prefix libomp)"
223
+ LIBOMP_RUNTIME_NAME="/opt/llvm-openmp/lib/libomp.dylib"
224
+ cc -std=c99 -O3 -Xpreprocessor -fopenmp -DDEEPGPR_USE_OPENMP -I"$LIBOMP_PREFIX/include" -L"$LIBOMP_PREFIX/lib" -fPIC -shared -o src/DeepGPR/lib/deepgpr_cpu.dylib src/DeepGPR/lib/deepgpr_cpu.c -lomp
225
+ cp "$LIBOMP_PREFIX/lib/libomp.dylib" src/DeepGPR/lib/libomp.dylib
226
+ install_name_tool -id "$LIBOMP_RUNTIME_NAME" src/DeepGPR/lib/libomp.dylib
227
+ LIBOMP_DEP="$(otool -L src/DeepGPR/lib/deepgpr_cpu.dylib | awk '/libomp\.dylib/ {print $1; exit}')"
228
+ install_name_tool -change "$LIBOMP_DEP" "$LIBOMP_RUNTIME_NAME" src/DeepGPR/lib/deepgpr_cpu.dylib
229
+ codesign --force --sign - src/DeepGPR/lib/libomp.dylib
230
+ codesign --force --sign - src/DeepGPR/lib/deepgpr_cpu.dylib
231
+ ```
232
+
233
+ On Windows, build `src\DeepGPR\lib\deepgpr_cpu.dll` with MSVC:
234
+
235
+ ```powershell
236
+ cl /LD /O2 /openmp /Fe:src\DeepGPR\lib\deepgpr_cpu.dll src\DeepGPR\lib\deepgpr_cpu.c
237
+ ```
183
238
 
184
239
  ### 5. Field Variable States (Checkpoints / Initial Fields)
185
240
 
@@ -201,8 +256,10 @@ The function returns a tuple of 5 elements. These are used to extract synthetic
201
256
  return Eall, (Ex, Ey, Ez), (Hx, Hy, Hz), (x0EPhi1...zmHPhi2), receiver_amplitudes
202
257
  ```
203
258
 
204
- 1. **`Eall`**: The global electric field history saved for gradient calculation.
205
- * **Shape**: `(nt_saved, nstep, nx, ny, nz)` (where `nt_saved` depends on `nt` and `model_gradient_sampling_interval`).
259
+ 1. **`Eall`**: The electric field history saved for gradient calculation.
260
+ * **Shape when `mode=2`**: `(nt_saved, nstep, nx, ny, nz)`, storing Ez only.
261
+ * **Shape when `mode=3`**: `(3, nt_saved, nstep, nx, ny, nz)`, storing components in `[Ex, Ey, Ez]` order.
262
+ * `nt_saved` depends on `nt` and `model_gradient_sampling_interval`.
206
263
  2. **`(Ex, Ey, Ez)`**: The 3D electric field state at the final time step.
207
264
  3. **`(Hx, Hy, Hz)`**: The 3D magnetic field state at the final time step.
208
265
  4. **`(PML_Tuple)`**: A tuple of 24 Tensors recording the final time step state of the PML auxiliary $\Phi$ variables.
@@ -1,16 +1,3 @@
1
- Metadata-Version: 2.4
2
- Name: DeepGPR
3
- Version: 0.0.12
4
- Summary: PyTorch and CUDA for GPR FWI
5
- Author-email: Lei Liu <liulei990222@gmail.com>
6
- Classifier: Programming Language :: Python :: 3
7
- Classifier: Operating System :: Microsoft :: Windows
8
- Classifier: Operating System :: POSIX :: Linux
9
- Requires-Python: >=3.8
10
- Description-Content-Type: text/markdown
11
- Requires-Dist: numpy
12
- Requires-Dist: matplotlib
13
-
14
1
  # DeepGPR
15
2
 
16
3
  DeepGPR provides a wave propagation module for PyTorch, designed for applications such as Ground Penetrating Radar (GPR) imaging and inversion. Its core concepts are derived from Deepwave. You can use it to perform both forward modeling and backpropagation—thereby enabling the simulation of wave propagation to generate synthetic data—as well as for Full Waveform Inversion (FWI). Furthermore, you can integrate this wave propagation functionality into a larger operational pipeline—incorporating various wavelets, loss functions, and other components—to achieve end-to-end forward and reverse propagation, powered by automatic differentiation and our high-performance operators.
@@ -24,22 +11,26 @@ Gradients of the output receiver data can be computed with respect to model para
24
11
 
25
12
  Utilizes CPML, allowing the width of the PML layer to be configured independently for each boundary.
26
13
 
27
- All operations are executed on the GPU.
14
+ The compute backend can run on CUDA GPUs or on CPU. The CPU backend is implemented in C and is selected automatically when `device='cpu'`.
15
+
16
+ The FDTD spatial finite-difference order can be selected with `fdtd_order=2`, `4`, or `8` (default: `2`).
17
+
18
+ The FWI gradient mode can be selected with `mode=2` or `mode=3`. `mode=2` keeps the previous Ez-only gradient behavior, while `mode=3` uses Ex, Ey, and Ez forward/adjoint electric-field contributions for relative permittivity and conductivity gradients.
28
19
 
29
20
  Supports techniques such as checkpointing, DDP, and the utilization of CPU memory to minimize GPU memory consumption, thereby enabling the execution of large-scale models.
30
21
 
31
22
 
32
23
  ## System Requirements
33
24
 
34
- - **OS**: Linux and Windows
35
- - **Environment**: Python 3.8+, CUDA Toolkit
36
- - **Libraries**: `torch` (with CUDA support), `numpy`, `scipy`, `matplotlib`
37
- - **Hardware**: NVIDIA GPU with sufficient VRAM for 3D computational grids.
25
+ - **OS**: Linux, Windows, and macOS for CPU execution; Linux and Windows for CUDA execution
26
+ - **Environment**: Python 3.8+, CUDA Toolkit for CUDA execution
27
+ - **Libraries**: `torch`, `numpy`, `scipy`, `matplotlib`
28
+ - **Hardware**: NVIDIA GPU with sufficient VRAM for CUDA execution; CPU execution works without a GPU.
38
29
 
39
30
 
40
31
  ## Start
41
32
 
42
- Before use, you must ensure that you have an NVIDIA graphics card and have installed a CUDA-enabled version of PyTorch.
33
+ Before CUDA use, you must ensure that you have an NVIDIA graphics card and have installed a CUDA-enabled version of PyTorch. For CPU use, install a CPU build of PyTorch and include a compiled `deepgpr_cpu` shared library in `src/DeepGPR/lib`.
43
34
 
44
35
  DeepGPR can then be installed using
45
36
 
@@ -57,7 +48,7 @@ import DeepGPR
57
48
  import matplotlib.pyplot as plt
58
49
 
59
50
  # Set up the parameters and models
60
- device=torch.device("cuda")
51
+ device=torch.device("cuda" if torch.cuda.is_available() else "cpu")
61
52
  dx=0.02
62
53
  dt=3e-11
63
54
  nt=2000
@@ -79,7 +70,8 @@ r = DeepGPR.compute(
79
70
  source_amplitudes=source_amplitudes,
80
71
  source_location=source_location,
81
72
  receiver_location=receiver_location,
82
- er=er, se=se
73
+ er=er, se=se,
74
+ fdtd_order=2
83
75
  )
84
76
 
85
77
  (r[-1]**2).sum().backward()
@@ -133,16 +125,22 @@ def compute(device, dx=None, dt=None,
133
125
  E=None, H=None, PML=None,
134
126
  pmlthick=10, source_direction=2, reciever_direction=2,
135
127
  model_gradient_sampling_interval=1,
136
- use_async_offload=False):
128
+ use_async_offload=False,
129
+ fdtd_order=2,
130
+ mode=2,
131
+ debug=False):
137
132
  ```
138
133
  ## 📥 Input Parameters
139
134
  ### 1. Basic Physics & Grid Parameters
140
135
 
141
136
  | Parameter | Data Type | Description |
142
137
  | :--- | :--- | :--- |
143
- | **`device`** | `torch.device` / `str` | PyTorch computation device, e.g., `'cuda:0'`. Determines where the computation takes place. |
138
+ | **`device`** | `torch.device` / `str` | PyTorch computation device, e.g., `'cuda:0'` or `'cpu'`. CUDA loads `deepgpr.so/.dll`; CPU loads `deepgpr_cpu.so/.dll/.dylib`. |
144
139
  | **`dx`** | `float` | Spatial grid step size (assuming an isotropic grid, i.e., $dx = dy = dz$). Typically in meters (m). |
145
140
  | **`dt`** | `float` | Time step size. **Note**: Must strictly satisfy the CFL (Courant-Friedrichs-Lewy) stability condition, or an exception will be raised. Typically in seconds (s). |
141
+ | **`fdtd_order`** | `int` | Spatial finite-difference order used by the FDTD field updates. Supported values are `2`, `4`, and `8`; default is `2` for compatibility with earlier versions. |
142
+ | **`mode`** | `int` | FWI gradient mode. `2` keeps the previous Ez-only model-gradient calculation. `3` uses Ex, Ey, and Ez electric-field contributions for relative permittivity and conductivity gradients. |
143
+ | **`debug`** | `bool` | Runs expensive NaN/Inf and zero-field validation checks when `True`. The default `False` keeps these checks disabled for faster production runs. |
146
144
  ### 2. Medium Model Parameters
147
145
 
148
146
  This section defines the electromagnetic properties of the simulation space. For 2D simulations, set `nz=1`.
@@ -161,7 +159,7 @@ This section defines the geometric observation system (coordinates) and the exci
161
159
 
162
160
  | Parameter | Data Type | Shape | Description |
163
161
  | :--- | :--- | :--- | :--- |
164
- | **`source_amplitudes`** | `Tensor` (float) | `(num_waveforms, nt)` | Source excitation waveforms. `nt` is the total number of time steps.<br>- If `num_waveforms == 1`: All sources share this single waveform.<br>- If `num_waveforms == nsr`: Each source uses its corresponding waveform. |
162
+ | **`source_amplitudes`** | `Tensor` (float) | `(num_waveforms, nt, 1)` | Source excitation waveforms. `nt` is the total number of time steps.<br>- If `num_waveforms == 1`: All sources share this single waveform.<br>- If `num_waveforms == nsr`: Each source uses its corresponding waveform. |
165
163
  | **`source_location`** | `Tensor` (int) | `(nstep, nsr, 3)` | Grid coordinate indices of the sources.<br>The last dimension corresponds to `[x_idx, y_idx, z_idx]`. |
166
164
  | **`receiver_location`** | `Tensor` (int) | `(nstep, nrx, 3)` | Grid coordinate indices of the receivers.<br>The last dimension corresponds to `[x_idx, y_idx, z_idx]`. |
167
165
  | **`source_direction`** | `int` | Scalar | Polarization direction/component of the source excitation.<br>`0` = X, `1` = Y, `2` = Z (e.g., exciting $E_z$). |
@@ -179,7 +177,41 @@ This section defines the geometric observation system (coordinates) and the exci
179
177
  | :--- | :--- | :--- | :--- |
180
178
  | **`pmlthick`** | `int` / `list` / `Tensor`| Scalar or list of 6 | Thickness (in grid layers) of the PML (Perfectly Matched Layer) absorbing boundaries.<br>- Integer `p`: All six boundaries have thickness `p` (Z-boundaries are ignored in 2D).<br>- List `[x0, xm, y0, ym, z0, zm]`: Specific thicknesses for the 6 boundaries. |
181
179
  | **`model_gradient_sampling_interval`**| `int` | Scalar | Wavefield sampling interval during forward propagation (Default: 1).<br>A larger integer reduces the VRAM usage for the saved `Eall` tensor, but may decrease the accuracy of backpropagated gradients. |
182
- | **`use_async_offload`** | `bool` | Scalar | VRAM optimization flag (Default: `False`).<br>If `True`, the internal full wavefield tensor (`Eall`) is asynchronously offloaded to page-locked host memory (`pin_memory` CPU RAM). This drastically reduces GPU VRAM consumption at the cost of slightly slower computation times due to PCIe data transfer latency. |
180
+ | **`use_async_offload`** | `bool` | Scalar | CUDA-only VRAM optimization flag (Default: `False`).<br>If `True`, the internal full wavefield tensor (`Eall`) is asynchronously offloaded to page-locked host memory (`pin_memory` CPU RAM). This drastically reduces GPU VRAM consumption at the cost of slightly slower computation times due to PCIe data transfer latency. On CPU this option is ignored. |
181
+
182
+ ### 4.1 FWI Gradient Mode
183
+
184
+ `mode` only changes how the model gradients are accumulated during backpropagation:
185
+
186
+ - `mode=2` (default): Saves Ez in `Eall` and computes relative permittivity/conductivity gradients from Ez only. This keeps the old behavior.
187
+ - `mode=3`: Saves Ex, Ey, and Ez in `Eall` and computes relative permittivity/conductivity gradients from all three electric-field components. This is intended for complete 3D Maxwell FWI. The adjoint source polarization is not changed by this option.
188
+
189
+ ## CPU Backend Build
190
+
191
+ The CPU backend is a plain C shared library and is built with OpenMP by default. Build it into `src/DeepGPR/lib` before running with `device='cpu'`. You can control CPU thread count with `OMP_NUM_THREADS`.
192
+
193
+ ```bash
194
+ # Linux
195
+ cc -std=c99 -O3 -fopenmp -fPIC -shared -o src/DeepGPR/lib/deepgpr_cpu.so src/DeepGPR/lib/deepgpr_cpu.c
196
+
197
+ # macOS
198
+ brew install libomp
199
+ LIBOMP_PREFIX="$(brew --prefix libomp)"
200
+ LIBOMP_RUNTIME_NAME="/opt/llvm-openmp/lib/libomp.dylib"
201
+ cc -std=c99 -O3 -Xpreprocessor -fopenmp -DDEEPGPR_USE_OPENMP -I"$LIBOMP_PREFIX/include" -L"$LIBOMP_PREFIX/lib" -fPIC -shared -o src/DeepGPR/lib/deepgpr_cpu.dylib src/DeepGPR/lib/deepgpr_cpu.c -lomp
202
+ cp "$LIBOMP_PREFIX/lib/libomp.dylib" src/DeepGPR/lib/libomp.dylib
203
+ install_name_tool -id "$LIBOMP_RUNTIME_NAME" src/DeepGPR/lib/libomp.dylib
204
+ LIBOMP_DEP="$(otool -L src/DeepGPR/lib/deepgpr_cpu.dylib | awk '/libomp\.dylib/ {print $1; exit}')"
205
+ install_name_tool -change "$LIBOMP_DEP" "$LIBOMP_RUNTIME_NAME" src/DeepGPR/lib/deepgpr_cpu.dylib
206
+ codesign --force --sign - src/DeepGPR/lib/libomp.dylib
207
+ codesign --force --sign - src/DeepGPR/lib/deepgpr_cpu.dylib
208
+ ```
209
+
210
+ On Windows, build `src\DeepGPR\lib\deepgpr_cpu.dll` with MSVC:
211
+
212
+ ```powershell
213
+ cl /LD /O2 /openmp /Fe:src\DeepGPR\lib\deepgpr_cpu.dll src\DeepGPR\lib\deepgpr_cpu.c
214
+ ```
183
215
 
184
216
  ### 5. Field Variable States (Checkpoints / Initial Fields)
185
217
 
@@ -201,8 +233,10 @@ The function returns a tuple of 5 elements. These are used to extract synthetic
201
233
  return Eall, (Ex, Ey, Ez), (Hx, Hy, Hz), (x0EPhi1...zmHPhi2), receiver_amplitudes
202
234
  ```
203
235
 
204
- 1. **`Eall`**: The global electric field history saved for gradient calculation.
205
- * **Shape**: `(nt_saved, nstep, nx, ny, nz)` (where `nt_saved` depends on `nt` and `model_gradient_sampling_interval`).
236
+ 1. **`Eall`**: The electric field history saved for gradient calculation.
237
+ * **Shape when `mode=2`**: `(nt_saved, nstep, nx, ny, nz)`, storing Ez only.
238
+ * **Shape when `mode=3`**: `(3, nt_saved, nstep, nx, ny, nz)`, storing components in `[Ex, Ey, Ez]` order.
239
+ * `nt_saved` depends on `nt` and `model_gradient_sampling_interval`.
206
240
  2. **`(Ex, Ey, Ez)`**: The 3D electric field state at the final time step.
207
241
  3. **`(Hx, Hy, Hz)`**: The 3D magnetic field state at the final time step.
208
242
  4. **`(PML_Tuple)`**: A tuple of 24 Tensors recording the final time step state of the PML auxiliary $\Phi$ variables.
deepgpr-0.0.14/license ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lei Liu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,63 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "DeepGPR"
7
+ version = "0.0.14"
8
+ authors = [
9
+ { name = "Lei Liu", email = "liulei990222@gmail.com" }
10
+ ]
11
+ description = "PyTorch and CUDA for GPR FWI"
12
+ readme = "README.md"
13
+ license = "MIT"
14
+ license-files = ["license"]
15
+ requires-python = ">=3.8"
16
+
17
+ classifiers = [
18
+ "Programming Language :: Python :: 3",
19
+ "Operating System :: Microsoft :: Windows",
20
+ "Operating System :: POSIX :: Linux",
21
+ "Operating System :: MacOS :: MacOS X",
22
+ "Topic :: Scientific/Engineering",
23
+ "Topic :: Scientific/Engineering :: Physics"
24
+ ]
25
+
26
+ dependencies = [
27
+ "numpy",
28
+ "scipy",
29
+ "matplotlib",
30
+ "torch"
31
+ ]
32
+
33
+ [project.urls]
34
+ Homepage = "https://github.com/songc0a/DeepGPR"
35
+ Repository = "https://github.com/songc0a/DeepGPR"
36
+
37
+ [tool.setuptools]
38
+ package-dir = { "" = "src" }
39
+ include-package-data = true
40
+
41
+ [tool.setuptools.packages.find]
42
+ where = ["src"]
43
+
44
+ [tool.setuptools.package-data]
45
+ DeepGPR = [
46
+ "lib/*.cu",
47
+ "lib/*.cuh",
48
+ "lib/*.h",
49
+ "lib/*.hpp",
50
+ "lib/*.cpp",
51
+ "lib/*.c",
52
+ "lib/*.dll",
53
+ "lib/*.so",
54
+ "lib/*.dylib",
55
+ "lib/*.pyd"
56
+ ]
57
+
58
+ [tool.setuptools.exclude-package-data]
59
+ DeepGPR = [
60
+ ".DS_Store",
61
+ "__pycache__/*",
62
+ "*.pyc"
63
+ ]