DeepGPR 0.0.4__tar.gz → 0.0.6__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.6/PKG-INFO ADDED
@@ -0,0 +1,224 @@
1
+ Metadata-Version: 2.4
2
+ Name: DeepGPR
3
+ Version: 0.0.6
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.7
10
+ Description-Content-Type: text/markdown
11
+
12
+ # DeepGPR
13
+
14
+ 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.
15
+
16
+
17
+ ## Features
18
+
19
+ Supports 2D and 3D forward modeling of Maxwell's equations—via the Finite-Difference Time-Domain (FDTD) method—for both single and multiple excitation scenarios.
20
+
21
+ Gradients of the output receiver data can be computed with respect to model parameters (relative permittivity, conductivity), the initial wavefield, and source amplitudes.
22
+
23
+ Utilizes CPML, allowing the width of the PML layer to be configured independently for each boundary.
24
+
25
+ All operations are executed on the GPU.
26
+
27
+ 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.
28
+
29
+
30
+ ## System Requirements
31
+
32
+ - **OS**: Linux and Windows
33
+ - **Environment**: Python 3.8+, CUDA Toolkit
34
+ - **Libraries**: `torch` (with CUDA support), `numpy`, `scipy`, `matplotlib`
35
+ - **Hardware**: NVIDIA GPU with sufficient VRAM for 3D computational grids.
36
+
37
+
38
+ ## Start
39
+
40
+ Before use, you must ensure that you have an NVIDIA graphics card and have installed a CUDA-enabled version of PyTorch.
41
+
42
+ DeepGPR can then be installed using
43
+
44
+ ```bash
45
+ pip install DeepGPR
46
+ ```
47
+
48
+
49
+
50
+ ## A Small Forward Modeling Test
51
+
52
+ ```python
53
+ import torch
54
+ import DeepGPR
55
+ import matplotlib.pyplot as plt
56
+
57
+ # Set up the parameters and models
58
+ device=torch.device("cuda")
59
+ dx=0.02
60
+ dt=3e-11
61
+ nt=2000
62
+ er = torch.ones(100, 100,1) * 2
63
+ er[50:,:]=5
64
+ se = torch.zeros_like(er)
65
+ er.requires_grad_()
66
+ source_location=torch.tensor([[[10,10,0]]],device=device,dtype=torch.int)
67
+ receiver_location=torch.tensor([[[10,90,0]]],device=device,dtype=torch.int)
68
+ freq=2e8
69
+ peak_time = 1 / freq
70
+ source_amplitudes = torch.zeros((1,nt,1),device=device)
71
+ source_amplitudes[0,:,0]=DeepGPR.ricker(freq, nt, dt, peak_time).to(device)
72
+
73
+
74
+ #forward modeling
75
+ r = DeepGPR.compute(
76
+ device=device, dx=dx, dt=dt,
77
+ source_amplitudes=source_amplitudes,
78
+ source_location=source_location,
79
+ receiver_location=receiver_location,
80
+ er=er, se=se
81
+ )
82
+
83
+ (r[-1]**2).sum().backward()
84
+
85
+ _, ax = plt.subplots(1, 2, figsize=(10, 3))
86
+ ax[0].plot(r[-1].detach().flatten().cpu().numpy())
87
+ ax[0].set_title("Receiver data")
88
+ ax[1].imshow(er.grad.detach())
89
+ ax[1].set_title("Gradient")
90
+ plt.show()
91
+ ```
92
+
93
+ ![result](./Fig/example.png)
94
+
95
+ There are more examples in the ./examples.
96
+
97
+
98
+
99
+ The following figures present representative 2D and 3D full-waveform inversion (FWI) examples. For each case, the true model, initial model, and inverted result are shown to evaluate the reconstruction performance of the proposed method.
100
+
101
+ ### 2D FWI Result
102
+
103
+ The 2D example illustrates the inversion performance on a two-dimensional subsurface model. The comparison between the true model, initial model, and inverted result shows that the proposed method can effectively recover the main structural features from the initial model.
104
+
105
+ | True Model | Initial Model | Inverted Result |
106
+ |---|---|---|
107
+ | ![2D true model](./Fig/2dfwitrue.png) | ![2D initial model](./Fig/2dfwiinit.png) | ![2D inverted result](./Fig/2dfwipred.png) |
108
+
109
+ ### 3D FWI Result
110
+
111
+ The 3D example demonstrates the applicability of the proposed method to three-dimensional full-waveform inversion. For visualization, the figures below show the central slice of the 3D model, including the true model, the initial model, and the inverted result. The comparison indicates that the proposed method can reconstruct the dominant subsurface structures in the 3D case and improve the model consistency relative to the initial model.
112
+
113
+ | Model Type | Central Slice of 3D Model |
114
+ |---|---|
115
+ | True Model | ![3D true model central slice](./Fig/3dfwitrue.png) |
116
+ | Initial Model | ![3D initial model central slice](./Fig/3dfwiinit.png) |
117
+ | Inverted Result | ![3D inverted result central slice](./Fig/3dfwipred.png) |
118
+
119
+ # `compute` Interface Documentation
120
+
121
+ `compute` is a core function for 3D/2D Finite-Difference Time-Domain (FDTD) forward modeling, primarily designed for Ground Penetrating Radar (GPR) and electromagnetic wave propagation. It fully supports backpropagation (e.g., for Full Waveform Inversion, FWI) utilizing PyTorch's `autograd` engine.
122
+
123
+ ## 📝 Function Signature
124
+
125
+ ```python
126
+ def compute(device, dx=None, dt=None,
127
+ source_amplitudes=None,
128
+ source_location=None,
129
+ receiver_location=None,
130
+ er=None, se=None, mr=None,
131
+ E=None, H=None, PML=None,
132
+ pmlthick=10, source_direction=2, reciever_direction=2,
133
+ model_gradient_sampling_interval=1,
134
+ use_async_offload=False):
135
+ ```
136
+ ## 📥 Input Parameters
137
+ ### 1. Basic Physics & Grid Parameters
138
+
139
+ | Parameter | Data Type | Description |
140
+ | :--- | :--- | :--- |
141
+ | **`device`** | `torch.device` / `str` | PyTorch computation device, e.g., `'cuda:0'`. Determines where the computation takes place. |
142
+ | **`dx`** | `float` | Spatial grid step size (assuming an isotropic grid, i.e., $dx = dy = dz$). Typically in meters (m). |
143
+ | **`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). |
144
+ ### 2. Medium Model Parameters
145
+
146
+ This section defines the electromagnetic properties of the simulation space. For 2D simulations, set `nz=1`.
147
+
148
+ | Parameter | Data Type | Shape | Description |
149
+ | :--- | :--- | :--- | :--- |
150
+ | **`er`** | `Tensor` (float) | `(nx, ny, nz)` or `(nx, ny)` | Relative permittivity ($\epsilon_r$). Values must be $\ge 1$. |
151
+ | **`se`** | `Tensor` (float) | `(nx, ny, nz)` or `(nx, ny)` | Electrical conductivity ($\sigma$). Values must be non-negative. |
152
+ | **`mr`** | `Tensor` (float) | `(nx, ny, nz)` or `(nx, ny)` | Relative permeability ($\mu_r$). Optional; defaults to 1 for the entire space. Shape must match `er`. |
153
+
154
+ > **Dimension Key**: `nx`, `ny`, and `nz` represent the number of grid cells along the X, Y, and Z axes, respectively.
155
+
156
+ ### 3. Source & Receiver Setup
157
+
158
+ This section defines the geometric observation system (coordinates) and the excitation waveforms.
159
+
160
+ | Parameter | Data Type | Shape | Description |
161
+ | :--- | :--- | :--- | :--- |
162
+ | **`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. |
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]`. |
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]`. |
165
+ | **`source_direction`** | `int` | Scalar | Polarization direction/component of the source excitation.<br>`0` = X, `1` = Y, `2` = Z (e.g., exciting $E_z$). |
166
+ | **`reciever_direction`** | `int` | Scalar | The component direction recorded by the receivers. (Note: typo in variable name is kept as-is to match code).<br>`0` = $E_x$, `1` = $E_y$, `2` = $E_z$. |
167
+
168
+ > **Core Shape Definitions**:
169
+ > * `nstep`: Number of shots/batches (independent simulation tasks running in parallel).
170
+ > * `nsr`: Number of **sources** per single simulation.
171
+ > * `nrx`: Number of **receivers** per single simulation.
172
+ > * `nt`: Total number of time steps to simulate.
173
+
174
+ ### 4. Boundary Conditions & Optimization
175
+
176
+ | Parameter | Data Type | Format | Description |
177
+ | :--- | :--- | :--- | :--- |
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. |
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. |
180
+ | **`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. |
181
+
182
+ ### 5. Field Variable States (Checkpoints / Initial Fields)
183
+
184
+ For starting a forward simulation from scratch ($t=0$), these three parameters should be passed as `None` (the system will automatically initialize zero-tensors).
185
+
186
+ | Parameter | Data Type | Shape | Description |
187
+ | :--- | :--- | :--- | :--- |
188
+ | **`E`** | `tuple` / `None` | 3 Tensors | Initial state of the electric field components `(Ex, Ey, Ez)`. Each tensor shape is `(nstep, nx+1, ny+1, nz+1)`. |
189
+ | **`H`** | `tuple` / `None` | 3 Tensors | Initial state of the magnetic field components `(Hx, Hy, Hz)`. Shapes identical to `E`. |
190
+ | **`PML`** | `tuple` / `None` | 24 Tensors | Auxiliary state variables ($\Phi$ fields) for the PML boundary updates. |
191
+
192
+ ---
193
+
194
+ ## 📤 Return Values
195
+
196
+ The function returns a tuple of 5 elements. These are used to extract synthetic data, initiate the gradient flow for backpropagation, or serve as initial parameters (`E`, `H`, `PML`) for subsequent time-stepped calculations.
197
+
198
+ ```python
199
+ return Eall, (Ex, Ey, Ez), (Hx, Hy, Hz), (x0EPhi1...zmHPhi2), receiver_amplitudes
200
+ ```
201
+
202
+ 1. **`Eall`**: The global electric field history saved for gradient calculation.
203
+ * **Shape**: `(nt_saved, nstep, nx, ny, nz)` (where `nt_saved` depends on `nt` and `model_gradient_sampling_interval`).
204
+ 2. **`(Ex, Ey, Ez)`**: The 3D electric field state at the final time step.
205
+ 3. **`(Hx, Hy, Hz)`**: The 3D magnetic field state at the final time step.
206
+ 4. **`(PML_Tuple)`**: A tuple of 24 Tensors recording the final time step state of the PML auxiliary $\Phi$ variables.
207
+ 5. **`receiver_amplitudes`**: **The core output.** The waveform signals recorded by the receivers over the entire simulation time.
208
+ * **Shape**: `(nstep, nt, nrx)`
209
+ * **Meaning**: `[Shot Index, Time Step, Receiver Index]`. Note that this output is already sliced to extract only the component specified by `reciever_direction`.
210
+
211
+
212
+ # Cite information
213
+ If you find our codes useful, please kindly cite this article.
214
+
215
+ @article{liu2025fast,
216
+
217
+ title={Fast ground penetrating radar dual-parameter full waveform inversion method accelerated by hybrid compilation of CUDA kernel function and PyTorch},
218
+
219
+ author={Liu, Lei and Song, Chao and He, Liangsheng and Wang, Silin and Feng, Xuan and Liu, Cai},
220
+
221
+ journal={Computers & Geosciences},
222
+
223
+ year={2026}
224
+ }
@@ -0,0 +1,213 @@
1
+ # DeepGPR
2
+
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.
4
+
5
+
6
+ ## Features
7
+
8
+ Supports 2D and 3D forward modeling of Maxwell's equations—via the Finite-Difference Time-Domain (FDTD) method—for both single and multiple excitation scenarios.
9
+
10
+ Gradients of the output receiver data can be computed with respect to model parameters (relative permittivity, conductivity), the initial wavefield, and source amplitudes.
11
+
12
+ Utilizes CPML, allowing the width of the PML layer to be configured independently for each boundary.
13
+
14
+ All operations are executed on the GPU.
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
+ - **Environment**: Python 3.8+, CUDA Toolkit
23
+ - **Libraries**: `torch` (with CUDA support), `numpy`, `scipy`, `matplotlib`
24
+ - **Hardware**: NVIDIA GPU with sufficient VRAM for 3D computational grids.
25
+
26
+
27
+ ## Start
28
+
29
+ Before use, you must ensure that you have an NVIDIA graphics card and have installed a CUDA-enabled version of PyTorch.
30
+
31
+ DeepGPR can then be installed using
32
+
33
+ ```bash
34
+ pip install DeepGPR
35
+ ```
36
+
37
+
38
+
39
+ ## A Small Forward Modeling Test
40
+
41
+ ```python
42
+ import torch
43
+ import DeepGPR
44
+ import matplotlib.pyplot as plt
45
+
46
+ # Set up the parameters and models
47
+ device=torch.device("cuda")
48
+ dx=0.02
49
+ dt=3e-11
50
+ nt=2000
51
+ er = torch.ones(100, 100,1) * 2
52
+ er[50:,:]=5
53
+ se = torch.zeros_like(er)
54
+ er.requires_grad_()
55
+ source_location=torch.tensor([[[10,10,0]]],device=device,dtype=torch.int)
56
+ receiver_location=torch.tensor([[[10,90,0]]],device=device,dtype=torch.int)
57
+ freq=2e8
58
+ peak_time = 1 / freq
59
+ source_amplitudes = torch.zeros((1,nt,1),device=device)
60
+ source_amplitudes[0,:,0]=DeepGPR.ricker(freq, nt, dt, peak_time).to(device)
61
+
62
+
63
+ #forward modeling
64
+ r = DeepGPR.compute(
65
+ device=device, dx=dx, dt=dt,
66
+ source_amplitudes=source_amplitudes,
67
+ source_location=source_location,
68
+ receiver_location=receiver_location,
69
+ er=er, se=se
70
+ )
71
+
72
+ (r[-1]**2).sum().backward()
73
+
74
+ _, ax = plt.subplots(1, 2, figsize=(10, 3))
75
+ ax[0].plot(r[-1].detach().flatten().cpu().numpy())
76
+ ax[0].set_title("Receiver data")
77
+ ax[1].imshow(er.grad.detach())
78
+ ax[1].set_title("Gradient")
79
+ plt.show()
80
+ ```
81
+
82
+ ![result](./Fig/example.png)
83
+
84
+ There are more examples in the ./examples.
85
+
86
+
87
+
88
+ The following figures present representative 2D and 3D full-waveform inversion (FWI) examples. For each case, the true model, initial model, and inverted result are shown to evaluate the reconstruction performance of the proposed method.
89
+
90
+ ### 2D FWI Result
91
+
92
+ The 2D example illustrates the inversion performance on a two-dimensional subsurface model. The comparison between the true model, initial model, and inverted result shows that the proposed method can effectively recover the main structural features from the initial model.
93
+
94
+ | True Model | Initial Model | Inverted Result |
95
+ |---|---|---|
96
+ | ![2D true model](./Fig/2dfwitrue.png) | ![2D initial model](./Fig/2dfwiinit.png) | ![2D inverted result](./Fig/2dfwipred.png) |
97
+
98
+ ### 3D FWI Result
99
+
100
+ The 3D example demonstrates the applicability of the proposed method to three-dimensional full-waveform inversion. For visualization, the figures below show the central slice of the 3D model, including the true model, the initial model, and the inverted result. The comparison indicates that the proposed method can reconstruct the dominant subsurface structures in the 3D case and improve the model consistency relative to the initial model.
101
+
102
+ | Model Type | Central Slice of 3D Model |
103
+ |---|---|
104
+ | True Model | ![3D true model central slice](./Fig/3dfwitrue.png) |
105
+ | Initial Model | ![3D initial model central slice](./Fig/3dfwiinit.png) |
106
+ | Inverted Result | ![3D inverted result central slice](./Fig/3dfwipred.png) |
107
+
108
+ # `compute` Interface Documentation
109
+
110
+ `compute` is a core function for 3D/2D Finite-Difference Time-Domain (FDTD) forward modeling, primarily designed for Ground Penetrating Radar (GPR) and electromagnetic wave propagation. It fully supports backpropagation (e.g., for Full Waveform Inversion, FWI) utilizing PyTorch's `autograd` engine.
111
+
112
+ ## 📝 Function Signature
113
+
114
+ ```python
115
+ def compute(device, dx=None, dt=None,
116
+ source_amplitudes=None,
117
+ source_location=None,
118
+ receiver_location=None,
119
+ er=None, se=None, mr=None,
120
+ E=None, H=None, PML=None,
121
+ pmlthick=10, source_direction=2, reciever_direction=2,
122
+ model_gradient_sampling_interval=1,
123
+ use_async_offload=False):
124
+ ```
125
+ ## 📥 Input Parameters
126
+ ### 1. Basic Physics & Grid Parameters
127
+
128
+ | Parameter | Data Type | Description |
129
+ | :--- | :--- | :--- |
130
+ | **`device`** | `torch.device` / `str` | PyTorch computation device, e.g., `'cuda:0'`. Determines where the computation takes place. |
131
+ | **`dx`** | `float` | Spatial grid step size (assuming an isotropic grid, i.e., $dx = dy = dz$). Typically in meters (m). |
132
+ | **`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). |
133
+ ### 2. Medium Model Parameters
134
+
135
+ This section defines the electromagnetic properties of the simulation space. For 2D simulations, set `nz=1`.
136
+
137
+ | Parameter | Data Type | Shape | Description |
138
+ | :--- | :--- | :--- | :--- |
139
+ | **`er`** | `Tensor` (float) | `(nx, ny, nz)` or `(nx, ny)` | Relative permittivity ($\epsilon_r$). Values must be $\ge 1$. |
140
+ | **`se`** | `Tensor` (float) | `(nx, ny, nz)` or `(nx, ny)` | Electrical conductivity ($\sigma$). Values must be non-negative. |
141
+ | **`mr`** | `Tensor` (float) | `(nx, ny, nz)` or `(nx, ny)` | Relative permeability ($\mu_r$). Optional; defaults to 1 for the entire space. Shape must match `er`. |
142
+
143
+ > **Dimension Key**: `nx`, `ny`, and `nz` represent the number of grid cells along the X, Y, and Z axes, respectively.
144
+
145
+ ### 3. Source & Receiver Setup
146
+
147
+ This section defines the geometric observation system (coordinates) and the excitation waveforms.
148
+
149
+ | Parameter | Data Type | Shape | Description |
150
+ | :--- | :--- | :--- | :--- |
151
+ | **`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. |
152
+ | **`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]`. |
153
+ | **`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]`. |
154
+ | **`source_direction`** | `int` | Scalar | Polarization direction/component of the source excitation.<br>`0` = X, `1` = Y, `2` = Z (e.g., exciting $E_z$). |
155
+ | **`reciever_direction`** | `int` | Scalar | The component direction recorded by the receivers. (Note: typo in variable name is kept as-is to match code).<br>`0` = $E_x$, `1` = $E_y$, `2` = $E_z$. |
156
+
157
+ > **Core Shape Definitions**:
158
+ > * `nstep`: Number of shots/batches (independent simulation tasks running in parallel).
159
+ > * `nsr`: Number of **sources** per single simulation.
160
+ > * `nrx`: Number of **receivers** per single simulation.
161
+ > * `nt`: Total number of time steps to simulate.
162
+
163
+ ### 4. Boundary Conditions & Optimization
164
+
165
+ | Parameter | Data Type | Format | Description |
166
+ | :--- | :--- | :--- | :--- |
167
+ | **`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. |
168
+ | **`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. |
169
+ | **`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. |
170
+
171
+ ### 5. Field Variable States (Checkpoints / Initial Fields)
172
+
173
+ For starting a forward simulation from scratch ($t=0$), these three parameters should be passed as `None` (the system will automatically initialize zero-tensors).
174
+
175
+ | Parameter | Data Type | Shape | Description |
176
+ | :--- | :--- | :--- | :--- |
177
+ | **`E`** | `tuple` / `None` | 3 Tensors | Initial state of the electric field components `(Ex, Ey, Ez)`. Each tensor shape is `(nstep, nx+1, ny+1, nz+1)`. |
178
+ | **`H`** | `tuple` / `None` | 3 Tensors | Initial state of the magnetic field components `(Hx, Hy, Hz)`. Shapes identical to `E`. |
179
+ | **`PML`** | `tuple` / `None` | 24 Tensors | Auxiliary state variables ($\Phi$ fields) for the PML boundary updates. |
180
+
181
+ ---
182
+
183
+ ## 📤 Return Values
184
+
185
+ The function returns a tuple of 5 elements. These are used to extract synthetic data, initiate the gradient flow for backpropagation, or serve as initial parameters (`E`, `H`, `PML`) for subsequent time-stepped calculations.
186
+
187
+ ```python
188
+ return Eall, (Ex, Ey, Ez), (Hx, Hy, Hz), (x0EPhi1...zmHPhi2), receiver_amplitudes
189
+ ```
190
+
191
+ 1. **`Eall`**: The global electric field history saved for gradient calculation.
192
+ * **Shape**: `(nt_saved, nstep, nx, ny, nz)` (where `nt_saved` depends on `nt` and `model_gradient_sampling_interval`).
193
+ 2. **`(Ex, Ey, Ez)`**: The 3D electric field state at the final time step.
194
+ 3. **`(Hx, Hy, Hz)`**: The 3D magnetic field state at the final time step.
195
+ 4. **`(PML_Tuple)`**: A tuple of 24 Tensors recording the final time step state of the PML auxiliary $\Phi$ variables.
196
+ 5. **`receiver_amplitudes`**: **The core output.** The waveform signals recorded by the receivers over the entire simulation time.
197
+ * **Shape**: `(nstep, nt, nrx)`
198
+ * **Meaning**: `[Shot Index, Time Step, Receiver Index]`. Note that this output is already sliced to extract only the component specified by `reciever_direction`.
199
+
200
+
201
+ # Cite information
202
+ If you find our codes useful, please kindly cite this article.
203
+
204
+ @article{liu2025fast,
205
+
206
+ title={Fast ground penetrating radar dual-parameter full waveform inversion method accelerated by hybrid compilation of CUDA kernel function and PyTorch},
207
+
208
+ author={Liu, Lei and Song, Chao and He, Liangsheng and Wang, Silin and Feng, Xuan and Liu, Cai},
209
+
210
+ journal={Computers & Geosciences},
211
+
212
+ year={2026}
213
+ }
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "DeepGPR"
7
- version = "0.0.4"
7
+ version = "0.0.6"
8
8
  authors = [
9
9
  { name="Lei Liu", email="liulei990222@gmail.com" },
10
10
  ]
@@ -0,0 +1,139 @@
1
+ import ctypes
2
+ import os
3
+ import subprocess
4
+ import platform
5
+ from pathlib import Path
6
+
7
+
8
+ system_name = platform.system()
9
+ lib_dir = Path(__file__).parent / 'lib'
10
+ cu_file = lib_dir / 'deepgpr.cu'
11
+
12
+ if system_name == "Windows":
13
+ lib_extension = ".dll"
14
+ lib_filename = f'deepgpr{lib_extension}'
15
+ lib_path_obj = lib_dir / lib_filename
16
+
17
+ nvcc_cmd = [
18
+ 'nvcc', '-shared',
19
+ '-o', str(lib_path_obj),
20
+ str(cu_file)
21
+ ]
22
+ else:
23
+ lib_extension = ".so"
24
+ lib_filename = f'deepgpr{lib_extension}'
25
+ lib_path_obj = lib_dir / lib_filename
26
+
27
+ nvcc_cmd = [
28
+ 'nvcc', '-shared', '-Xcompiler', '-fPIC',
29
+ '-D_GLIBCXX_USE_CXX11_ABI=0',
30
+ '-o', str(lib_path_obj),
31
+ str(cu_file)
32
+ ]
33
+
34
+ if not lib_path_obj.is_file():
35
+ print(f'Compiling CUDA extension for {system_name} directly via nvcc...')
36
+ try:
37
+ subprocess.run(nvcc_cmd, check=True)
38
+ except FileNotFoundError:
39
+ raise RuntimeError(
40
+ "Compilation failed: 'nvcc' command not found. "
41
+ "Please ensure NVIDIA CUDA Toolkit is installed and 'nvcc' is added to your system PATH."
42
+ )
43
+ except subprocess.CalledProcessError as e:
44
+ raise RuntimeError(f"Compilation failed with error code {e.returncode}.")
45
+
46
+ lib_path = str(lib_path_obj)
47
+ c_lib = ctypes.cdll.LoadLibrary(lib_path)
48
+
49
+
50
+ c_lib.forward.argtypes = [
51
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
52
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
53
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
54
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
55
+ ctypes.POINTER(ctypes.c_float),
56
+ ctypes.POINTER(ctypes.c_float),
57
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
58
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
59
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
60
+
61
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
62
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
63
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
64
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
65
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
66
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
67
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
68
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
69
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
70
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
71
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
72
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
73
+
74
+ ctypes.c_int, ctypes.c_int, ctypes.c_int,
75
+ ctypes.c_int, ctypes.c_int, ctypes.c_int,
76
+
77
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
78
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
79
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
80
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
81
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
82
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
83
+
84
+ ctypes.c_float,ctypes.c_int,ctypes.c_int,ctypes.c_int,ctypes.c_float,
85
+ ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_float),
86
+ ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int,
87
+ ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_float),
88
+ ctypes.c_int
89
+ ]
90
+ c_lib.forward.restype = None
91
+
92
+ c_lib.backward.argtypes = [
93
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
94
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
95
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
96
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
97
+ ctypes.POINTER(ctypes.c_float),
98
+ ctypes.POINTER(ctypes.c_float),
99
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
100
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
101
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),#16
102
+
103
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
104
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
105
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
106
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
107
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
108
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
109
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
110
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
111
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
112
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
113
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
114
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),#40
115
+
116
+ ctypes.c_int, ctypes.c_int, ctypes.c_int,
117
+ ctypes.c_int, ctypes.c_int, ctypes.c_int,
118
+
119
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
120
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
121
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
122
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
123
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
124
+ ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float), #58
125
+
126
+ ctypes.c_float,ctypes.c_int,ctypes.c_int,ctypes.c_int,ctypes.c_float,
127
+ ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int,
128
+ ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_float),
129
+ ctypes.c_int ,ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
130
+ ctypes.c_int, ctypes.c_int
131
+ ]
132
+ c_lib.backward.restype = None
133
+ __all__ = ['c_lib']
134
+
135
+
136
+ from .common import *
137
+ from .compute2 import *
138
+ from .multiscale import *
139
+ from .wavelet import *