DeepGPR 0.0.8__tar.gz → 0.0.10__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.
- deepgpr-0.0.8/README.md → deepgpr-0.0.10/PKG-INFO +70 -45
- deepgpr-0.0.8/PKG-INFO → deepgpr-0.0.10/README.md +53 -59
- deepgpr-0.0.10/pyproject.toml +48 -0
- deepgpr-0.0.10/setup.cfg +4 -0
- deepgpr-0.0.10/src/DeepGPR/__init__.py +293 -0
- {deepgpr-0.0.8 → deepgpr-0.0.10}/src/DeepGPR/common.py +199 -28
- {deepgpr-0.0.8 → deepgpr-0.0.10}/src/DeepGPR/compute2.py +181 -20
- {deepgpr-0.0.8 → deepgpr-0.0.10}/src/DeepGPR/lib/deepgpr.cu +555 -110
- deepgpr-0.0.10/src/DeepGPR/lib/deepgpr.dll +0 -0
- deepgpr-0.0.10/src/DeepGPR/lib/deepgpr.so +0 -0
- deepgpr-0.0.10/src/DeepGPR/lib/deepgpr_cpu.c +1128 -0
- deepgpr-0.0.10/src/DeepGPR/lib/deepgpr_cpu.dll +0 -0
- deepgpr-0.0.10/src/DeepGPR/lib/deepgpr_cpu.so +0 -0
- {deepgpr-0.0.8 → deepgpr-0.0.10}/src/DeepGPR/multiscale.py +21 -1
- deepgpr-0.0.10/src/DeepGPR.egg-info/PKG-INFO +272 -0
- deepgpr-0.0.10/src/DeepGPR.egg-info/SOURCES.txt +18 -0
- deepgpr-0.0.10/src/DeepGPR.egg-info/requires.txt +4 -0
- deepgpr-0.0.10/src/DeepGPR.egg-info/top_level.txt +1 -0
- deepgpr-0.0.8/.gitignore +0 -7
- deepgpr-0.0.8/CMakeLists.txt +0 -70
- deepgpr-0.0.8/Fig/2dfwiinit.png +0 -0
- deepgpr-0.0.8/Fig/2dfwipred.png +0 -0
- deepgpr-0.0.8/Fig/2dfwitrue.png +0 -0
- deepgpr-0.0.8/Fig/3dfwiinit.png +0 -0
- deepgpr-0.0.8/Fig/3dfwipred.png +0 -0
- deepgpr-0.0.8/Fig/3dfwitrue.png +0 -0
- deepgpr-0.0.8/Fig/example.png +0 -0
- deepgpr-0.0.8/examples/1.Forward.ipynb +0 -95
- deepgpr-0.0.8/examples/2.2DFWI.ipynb +0 -579
- deepgpr-0.0.8/examples/2DFWImodel.npy +0 -0
- deepgpr-0.0.8/examples/3.3DFWI.ipynb +0 -842
- deepgpr-0.0.8/examples/OverThrust.npy +0 -0
- deepgpr-0.0.8/license +0 -21
- deepgpr-0.0.8/pyproject.toml +0 -52
- deepgpr-0.0.8/src/DeepGPR/DeepGPR.egg-info/PKG-INFO +0 -85
- deepgpr-0.0.8/src/DeepGPR/DeepGPR.egg-info/SOURCES.txt +0 -6
- deepgpr-0.0.8/src/DeepGPR/DeepGPR.egg-info/top_level.txt +0 -1
- deepgpr-0.0.8/src/DeepGPR/__init__.py +0 -199
- deepgpr-0.0.8/src/DeepGPR/__pycache__/__init__.cpython-310.pyc +0 -0
- deepgpr-0.0.8/src/DeepGPR/__pycache__/common.cpython-310.pyc +0 -0
- deepgpr-0.0.8/src/DeepGPR/__pycache__/compute2.cpython-310.pyc +0 -0
- deepgpr-0.0.8/src/DeepGPR/__pycache__/multiscale.cpython-310.pyc +0 -0
- deepgpr-0.0.8/src/DeepGPR/__pycache__/visual.cpython-310.pyc +0 -0
- deepgpr-0.0.8/src/DeepGPR/requirements.txt +0 -1
- {deepgpr-0.0.8 → deepgpr-0.0.10}/src/DeepGPR/wavelet.py +0 -0
- {deepgpr-0.0.8/src/DeepGPR → deepgpr-0.0.10/src}/DeepGPR.egg-info/dependency_links.txt +0 -0
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: DeepGPR
|
|
3
|
+
Version: 0.0.10
|
|
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
|
+
Classifier: Topic :: Scientific/Engineering
|
|
10
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: numpy
|
|
14
|
+
Requires-Dist: scipy
|
|
15
|
+
Requires-Dist: matplotlib
|
|
16
|
+
Requires-Dist: torch
|
|
17
|
+
|
|
1
18
|
# DeepGPR
|
|
2
19
|
|
|
3
20
|
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.
|
|
@@ -11,52 +28,26 @@ Gradients of the output receiver data can be computed with respect to model para
|
|
|
11
28
|
|
|
12
29
|
Utilizes CPML, allowing the width of the PML layer to be configured independently for each boundary.
|
|
13
30
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
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.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
## System Requirements
|
|
20
|
-
|
|
21
|
-
- **OS**: Linux and Windows
|
|
22
|
-
- **Python**: Python 3.8+
|
|
23
|
-
- **GPU**: NVIDIA GPU with sufficient VRAM for 2D/3D computational grids
|
|
24
|
-
- **CUDA**: NVIDIA driver and CUDA Toolkit
|
|
25
|
-
- **Libraries**:
|
|
26
|
-
- `torch` with CUDA support
|
|
27
|
-
- `numpy`
|
|
28
|
-
- `scipy`
|
|
29
|
-
- `matplotlib`
|
|
30
|
-
|
|
31
|
-
### Additional Requirements for Building from Source
|
|
31
|
+
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'`.
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
The FDTD spatial finite-difference order can be selected with `fdtd_order=2`, `4`, or `8` (default: `2`).
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
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.
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
- GCC/G++ compiler compatible with the installed CUDA version
|
|
39
|
-
- CMake 3.23 or later
|
|
37
|
+
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.
|
|
40
38
|
|
|
41
|
-
#### Windows
|
|
42
39
|
|
|
43
|
-
|
|
44
|
-
- CMake 3.23 or later
|
|
45
|
-
- Microsoft Visual Studio Build Tools or Visual Studio Community
|
|
46
|
-
- The **Desktop development with C++** workload
|
|
47
|
-
- MSVC C++ compiler `cl.exe`
|
|
48
|
-
- Windows SDK
|
|
49
|
-
- Optional: `ninja`
|
|
40
|
+
## System Requirements
|
|
50
41
|
|
|
51
|
-
|
|
42
|
+
- **OS**: Linux, Windows, and macOS for CPU execution; Linux and Windows for CUDA execution
|
|
43
|
+
- **Environment**: Python 3.8+, CUDA Toolkit for CUDA execution
|
|
44
|
+
- **Libraries**: `torch`, `numpy`, `scipy`, `matplotlib`
|
|
45
|
+
- **Hardware**: NVIDIA GPU with sufficient VRAM for CUDA execution; CPU execution works without a GPU.
|
|
52
46
|
|
|
53
|
-
```bash
|
|
54
|
-
pip install .
|
|
55
|
-
```
|
|
56
47
|
|
|
57
48
|
## Start
|
|
58
49
|
|
|
59
|
-
Before use, you must ensure that you have an NVIDIA graphics card and have installed a CUDA-enabled version of PyTorch.
|
|
50
|
+
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`.
|
|
60
51
|
|
|
61
52
|
DeepGPR can then be installed using
|
|
62
53
|
|
|
@@ -74,7 +65,7 @@ import DeepGPR
|
|
|
74
65
|
import matplotlib.pyplot as plt
|
|
75
66
|
|
|
76
67
|
# Set up the parameters and models
|
|
77
|
-
device=torch.device("cuda")
|
|
68
|
+
device=torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
78
69
|
dx=0.02
|
|
79
70
|
dt=3e-11
|
|
80
71
|
nt=2000
|
|
@@ -96,7 +87,8 @@ r = DeepGPR.compute(
|
|
|
96
87
|
source_amplitudes=source_amplitudes,
|
|
97
88
|
source_location=source_location,
|
|
98
89
|
receiver_location=receiver_location,
|
|
99
|
-
er=er, se=se
|
|
90
|
+
er=er, se=se,
|
|
91
|
+
fdtd_order=2
|
|
100
92
|
)
|
|
101
93
|
|
|
102
94
|
(r[-1]**2).sum().backward()
|
|
@@ -150,16 +142,20 @@ def compute(device, dx=None, dt=None,
|
|
|
150
142
|
E=None, H=None, PML=None,
|
|
151
143
|
pmlthick=10, source_direction=2, reciever_direction=2,
|
|
152
144
|
model_gradient_sampling_interval=1,
|
|
153
|
-
use_async_offload=False
|
|
145
|
+
use_async_offload=False,
|
|
146
|
+
fdtd_order=2,
|
|
147
|
+
mode=2):
|
|
154
148
|
```
|
|
155
149
|
## 📥 Input Parameters
|
|
156
150
|
### 1. Basic Physics & Grid Parameters
|
|
157
151
|
|
|
158
152
|
| Parameter | Data Type | Description |
|
|
159
153
|
| :--- | :--- | :--- |
|
|
160
|
-
| **`device`** | `torch.device` / `str` | PyTorch computation device, e.g., `'cuda:0'`.
|
|
154
|
+
| **`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`. |
|
|
161
155
|
| **`dx`** | `float` | Spatial grid step size (assuming an isotropic grid, i.e., $dx = dy = dz$). Typically in meters (m). |
|
|
162
156
|
| **`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). |
|
|
157
|
+
| **`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. |
|
|
158
|
+
| **`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. |
|
|
163
159
|
### 2. Medium Model Parameters
|
|
164
160
|
|
|
165
161
|
This section defines the electromagnetic properties of the simulation space. For 2D simulations, set `nz=1`.
|
|
@@ -178,7 +174,7 @@ This section defines the geometric observation system (coordinates) and the exci
|
|
|
178
174
|
|
|
179
175
|
| Parameter | Data Type | Shape | Description |
|
|
180
176
|
| :--- | :--- | :--- | :--- |
|
|
181
|
-
| **`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. |
|
|
177
|
+
| **`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. |
|
|
182
178
|
| **`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]`. |
|
|
183
179
|
| **`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]`. |
|
|
184
180
|
| **`source_direction`** | `int` | Scalar | Polarization direction/component of the source excitation.<br>`0` = X, `1` = Y, `2` = Z (e.g., exciting $E_z$). |
|
|
@@ -196,7 +192,34 @@ This section defines the geometric observation system (coordinates) and the exci
|
|
|
196
192
|
| :--- | :--- | :--- | :--- |
|
|
197
193
|
| **`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. |
|
|
198
194
|
| **`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. |
|
|
199
|
-
| **`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. |
|
|
195
|
+
| **`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. |
|
|
196
|
+
|
|
197
|
+
### 4.1 FWI Gradient Mode
|
|
198
|
+
|
|
199
|
+
`mode` only changes how the model gradients are accumulated during backpropagation:
|
|
200
|
+
|
|
201
|
+
- `mode=2` (default): Saves Ez in `Eall` and computes relative permittivity/conductivity gradients from Ez only. This keeps the old behavior.
|
|
202
|
+
- `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.
|
|
203
|
+
|
|
204
|
+
## CPU Backend Build
|
|
205
|
+
|
|
206
|
+
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`.
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
# Linux
|
|
210
|
+
cc -std=c99 -O3 -fopenmp -fPIC -shared -o src/DeepGPR/lib/deepgpr_cpu.so src/DeepGPR/lib/deepgpr_cpu.c
|
|
211
|
+
|
|
212
|
+
# macOS
|
|
213
|
+
brew install libomp
|
|
214
|
+
LIBOMP_PREFIX="$(brew --prefix libomp)"
|
|
215
|
+
cc -std=c99 -O3 -Xpreprocessor -fopenmp -DDEEPGPR_USE_OPENMP -I"$LIBOMP_PREFIX/include" -Wl,-rpath,"$LIBOMP_PREFIX/lib" -L"$LIBOMP_PREFIX/lib" -fPIC -shared -o src/DeepGPR/lib/deepgpr_cpu.dylib src/DeepGPR/lib/deepgpr_cpu.c -lomp
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
On Windows, build `src\DeepGPR\lib\deepgpr_cpu.dll` with MSVC:
|
|
219
|
+
|
|
220
|
+
```powershell
|
|
221
|
+
cl /LD /O2 /openmp /Fe:src\DeepGPR\lib\deepgpr_cpu.dll src\DeepGPR\lib\deepgpr_cpu.c
|
|
222
|
+
```
|
|
200
223
|
|
|
201
224
|
### 5. Field Variable States (Checkpoints / Initial Fields)
|
|
202
225
|
|
|
@@ -218,8 +241,10 @@ The function returns a tuple of 5 elements. These are used to extract synthetic
|
|
|
218
241
|
return Eall, (Ex, Ey, Ez), (Hx, Hy, Hz), (x0EPhi1...zmHPhi2), receiver_amplitudes
|
|
219
242
|
```
|
|
220
243
|
|
|
221
|
-
1. **`Eall`**: The
|
|
222
|
-
* **Shape
|
|
244
|
+
1. **`Eall`**: The electric field history saved for gradient calculation.
|
|
245
|
+
* **Shape when `mode=2`**: `(nt_saved, nstep, nx, ny, nz)`, storing Ez only.
|
|
246
|
+
* **Shape when `mode=3`**: `(3, nt_saved, nstep, nx, ny, nz)`, storing components in `[Ex, Ey, Ez]` order.
|
|
247
|
+
* `nt_saved` depends on `nt` and `model_gradient_sampling_interval`.
|
|
223
248
|
2. **`(Ex, Ey, Ez)`**: The 3D electric field state at the final time step.
|
|
224
249
|
3. **`(Hx, Hy, Hz)`**: The 3D magnetic field state at the final time step.
|
|
225
250
|
4. **`(PML_Tuple)`**: A tuple of 24 Tensors recording the final time step state of the PML auxiliary $\Phi$ variables.
|
|
@@ -244,4 +269,4 @@ If you find our codes useful, please kindly cite this article. Thanks.
|
|
|
244
269
|
|
|
245
270
|
publisher={Elsevier}
|
|
246
271
|
|
|
247
|
-
}
|
|
272
|
+
}
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.2
|
|
2
|
-
Name: DeepGPR
|
|
3
|
-
Version: 0.0.8
|
|
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
|
-
Requires-Dist: numpy
|
|
11
|
-
Requires-Dist: scipy
|
|
12
|
-
Requires-Dist: matplotlib
|
|
13
|
-
Description-Content-Type: text/markdown
|
|
14
|
-
|
|
15
1
|
# DeepGPR
|
|
16
2
|
|
|
17
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.
|
|
@@ -25,52 +11,26 @@ Gradients of the output receiver data can be computed with respect to model para
|
|
|
25
11
|
|
|
26
12
|
Utilizes CPML, allowing the width of the PML layer to be configured independently for each boundary.
|
|
27
13
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
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.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
## System Requirements
|
|
34
|
-
|
|
35
|
-
- **OS**: Linux and Windows
|
|
36
|
-
- **Python**: Python 3.8+
|
|
37
|
-
- **GPU**: NVIDIA GPU with sufficient VRAM for 2D/3D computational grids
|
|
38
|
-
- **CUDA**: NVIDIA driver and CUDA Toolkit
|
|
39
|
-
- **Libraries**:
|
|
40
|
-
- `torch` with CUDA support
|
|
41
|
-
- `numpy`
|
|
42
|
-
- `scipy`
|
|
43
|
-
- `matplotlib`
|
|
44
|
-
|
|
45
|
-
### Additional Requirements for Building from Source
|
|
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'`.
|
|
46
15
|
|
|
47
|
-
|
|
16
|
+
The FDTD spatial finite-difference order can be selected with `fdtd_order=2`, `4`, or `8` (default: `2`).
|
|
48
17
|
|
|
49
|
-
|
|
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.
|
|
50
19
|
|
|
51
|
-
|
|
52
|
-
- GCC/G++ compiler compatible with the installed CUDA version
|
|
53
|
-
- CMake 3.23 or later
|
|
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.
|
|
54
21
|
|
|
55
|
-
#### Windows
|
|
56
22
|
|
|
57
|
-
|
|
58
|
-
- CMake 3.23 or later
|
|
59
|
-
- Microsoft Visual Studio Build Tools or Visual Studio Community
|
|
60
|
-
- The **Desktop development with C++** workload
|
|
61
|
-
- MSVC C++ compiler `cl.exe`
|
|
62
|
-
- Windows SDK
|
|
63
|
-
- Optional: `ninja`
|
|
23
|
+
## System Requirements
|
|
64
24
|
|
|
65
|
-
|
|
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.
|
|
66
29
|
|
|
67
|
-
```bash
|
|
68
|
-
pip install .
|
|
69
|
-
```
|
|
70
30
|
|
|
71
31
|
## Start
|
|
72
32
|
|
|
73
|
-
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`.
|
|
74
34
|
|
|
75
35
|
DeepGPR can then be installed using
|
|
76
36
|
|
|
@@ -88,7 +48,7 @@ import DeepGPR
|
|
|
88
48
|
import matplotlib.pyplot as plt
|
|
89
49
|
|
|
90
50
|
# Set up the parameters and models
|
|
91
|
-
device=torch.device("cuda")
|
|
51
|
+
device=torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
92
52
|
dx=0.02
|
|
93
53
|
dt=3e-11
|
|
94
54
|
nt=2000
|
|
@@ -110,7 +70,8 @@ r = DeepGPR.compute(
|
|
|
110
70
|
source_amplitudes=source_amplitudes,
|
|
111
71
|
source_location=source_location,
|
|
112
72
|
receiver_location=receiver_location,
|
|
113
|
-
er=er, se=se
|
|
73
|
+
er=er, se=se,
|
|
74
|
+
fdtd_order=2
|
|
114
75
|
)
|
|
115
76
|
|
|
116
77
|
(r[-1]**2).sum().backward()
|
|
@@ -164,16 +125,20 @@ def compute(device, dx=None, dt=None,
|
|
|
164
125
|
E=None, H=None, PML=None,
|
|
165
126
|
pmlthick=10, source_direction=2, reciever_direction=2,
|
|
166
127
|
model_gradient_sampling_interval=1,
|
|
167
|
-
use_async_offload=False
|
|
128
|
+
use_async_offload=False,
|
|
129
|
+
fdtd_order=2,
|
|
130
|
+
mode=2):
|
|
168
131
|
```
|
|
169
132
|
## 📥 Input Parameters
|
|
170
133
|
### 1. Basic Physics & Grid Parameters
|
|
171
134
|
|
|
172
135
|
| Parameter | Data Type | Description |
|
|
173
136
|
| :--- | :--- | :--- |
|
|
174
|
-
| **`device`** | `torch.device` / `str` | PyTorch computation device, e.g., `'cuda:0'`.
|
|
137
|
+
| **`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`. |
|
|
175
138
|
| **`dx`** | `float` | Spatial grid step size (assuming an isotropic grid, i.e., $dx = dy = dz$). Typically in meters (m). |
|
|
176
139
|
| **`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). |
|
|
140
|
+
| **`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. |
|
|
141
|
+
| **`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. |
|
|
177
142
|
### 2. Medium Model Parameters
|
|
178
143
|
|
|
179
144
|
This section defines the electromagnetic properties of the simulation space. For 2D simulations, set `nz=1`.
|
|
@@ -192,7 +157,7 @@ This section defines the geometric observation system (coordinates) and the exci
|
|
|
192
157
|
|
|
193
158
|
| Parameter | Data Type | Shape | Description |
|
|
194
159
|
| :--- | :--- | :--- | :--- |
|
|
195
|
-
| **`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. |
|
|
160
|
+
| **`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. |
|
|
196
161
|
| **`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]`. |
|
|
197
162
|
| **`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]`. |
|
|
198
163
|
| **`source_direction`** | `int` | Scalar | Polarization direction/component of the source excitation.<br>`0` = X, `1` = Y, `2` = Z (e.g., exciting $E_z$). |
|
|
@@ -210,7 +175,34 @@ This section defines the geometric observation system (coordinates) and the exci
|
|
|
210
175
|
| :--- | :--- | :--- | :--- |
|
|
211
176
|
| **`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. |
|
|
212
177
|
| **`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. |
|
|
213
|
-
| **`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. |
|
|
178
|
+
| **`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. |
|
|
179
|
+
|
|
180
|
+
### 4.1 FWI Gradient Mode
|
|
181
|
+
|
|
182
|
+
`mode` only changes how the model gradients are accumulated during backpropagation:
|
|
183
|
+
|
|
184
|
+
- `mode=2` (default): Saves Ez in `Eall` and computes relative permittivity/conductivity gradients from Ez only. This keeps the old behavior.
|
|
185
|
+
- `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.
|
|
186
|
+
|
|
187
|
+
## CPU Backend Build
|
|
188
|
+
|
|
189
|
+
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`.
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
# Linux
|
|
193
|
+
cc -std=c99 -O3 -fopenmp -fPIC -shared -o src/DeepGPR/lib/deepgpr_cpu.so src/DeepGPR/lib/deepgpr_cpu.c
|
|
194
|
+
|
|
195
|
+
# macOS
|
|
196
|
+
brew install libomp
|
|
197
|
+
LIBOMP_PREFIX="$(brew --prefix libomp)"
|
|
198
|
+
cc -std=c99 -O3 -Xpreprocessor -fopenmp -DDEEPGPR_USE_OPENMP -I"$LIBOMP_PREFIX/include" -Wl,-rpath,"$LIBOMP_PREFIX/lib" -L"$LIBOMP_PREFIX/lib" -fPIC -shared -o src/DeepGPR/lib/deepgpr_cpu.dylib src/DeepGPR/lib/deepgpr_cpu.c -lomp
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
On Windows, build `src\DeepGPR\lib\deepgpr_cpu.dll` with MSVC:
|
|
202
|
+
|
|
203
|
+
```powershell
|
|
204
|
+
cl /LD /O2 /openmp /Fe:src\DeepGPR\lib\deepgpr_cpu.dll src\DeepGPR\lib\deepgpr_cpu.c
|
|
205
|
+
```
|
|
214
206
|
|
|
215
207
|
### 5. Field Variable States (Checkpoints / Initial Fields)
|
|
216
208
|
|
|
@@ -232,8 +224,10 @@ The function returns a tuple of 5 elements. These are used to extract synthetic
|
|
|
232
224
|
return Eall, (Ex, Ey, Ez), (Hx, Hy, Hz), (x0EPhi1...zmHPhi2), receiver_amplitudes
|
|
233
225
|
```
|
|
234
226
|
|
|
235
|
-
1. **`Eall`**: The
|
|
236
|
-
* **Shape
|
|
227
|
+
1. **`Eall`**: The electric field history saved for gradient calculation.
|
|
228
|
+
* **Shape when `mode=2`**: `(nt_saved, nstep, nx, ny, nz)`, storing Ez only.
|
|
229
|
+
* **Shape when `mode=3`**: `(3, nt_saved, nstep, nx, ny, nz)`, storing components in `[Ex, Ey, Ez]` order.
|
|
230
|
+
* `nt_saved` depends on `nt` and `model_gradient_sampling_interval`.
|
|
237
231
|
2. **`(Ex, Ey, Ez)`**: The 3D electric field state at the final time step.
|
|
238
232
|
3. **`(Hx, Hy, Hz)`**: The 3D magnetic field state at the final time step.
|
|
239
233
|
4. **`(PML_Tuple)`**: A tuple of 24 Tensors recording the final time step state of the PML auxiliary $\Phi$ variables.
|
|
@@ -258,4 +252,4 @@ If you find our codes useful, please kindly cite this article. Thanks.
|
|
|
258
252
|
|
|
259
253
|
publisher={Elsevier}
|
|
260
254
|
|
|
261
|
-
}
|
|
255
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=70", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "DeepGPR"
|
|
7
|
+
version = "0.0.10"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Lei Liu", email = "liulei990222@gmail.com" }
|
|
10
|
+
]
|
|
11
|
+
description = "PyTorch and CUDA for GPR FWI"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.8"
|
|
14
|
+
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Operating System :: Microsoft :: Windows",
|
|
18
|
+
"Operating System :: POSIX :: Linux",
|
|
19
|
+
"Topic :: Scientific/Engineering",
|
|
20
|
+
"Topic :: Scientific/Engineering :: Physics"
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
dependencies = [
|
|
24
|
+
"numpy",
|
|
25
|
+
"scipy",
|
|
26
|
+
"matplotlib",
|
|
27
|
+
"torch"
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[tool.setuptools]
|
|
31
|
+
package-dir = { "" = "src" }
|
|
32
|
+
include-package-data = true
|
|
33
|
+
|
|
34
|
+
[tool.setuptools.packages.find]
|
|
35
|
+
where = ["src"]
|
|
36
|
+
|
|
37
|
+
[tool.setuptools.package-data]
|
|
38
|
+
DeepGPR = [
|
|
39
|
+
"lib/*.cu",
|
|
40
|
+
"lib/*.cuh",
|
|
41
|
+
"lib/*.h",
|
|
42
|
+
"lib/*.hpp",
|
|
43
|
+
"lib/*.cpp",
|
|
44
|
+
"lib/*.c",
|
|
45
|
+
"lib/*.dll",
|
|
46
|
+
"lib/*.so",
|
|
47
|
+
"lib/*.pyd"
|
|
48
|
+
]
|
deepgpr-0.0.10/setup.cfg
ADDED