PyTorch and CUDA for GPR FWI
Project description
DeepGPR
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.
Features
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.
Gradients of the output receiver data can be computed with respect to model parameters (relative permittivity, conductivity), the initial wavefield, and source amplitudes.
Utilizes CPML, allowing the width of the PML layer to be configured independently for each boundary.
All operations are executed on the GPU.
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.
System Requirements
- OS: Linux and Windows
- Environment: Python 3.8+, CUDA Toolkit
- Libraries:
torch(with CUDA support),numpy,scipy,matplotlib - Hardware: NVIDIA GPU with sufficient VRAM for 3D computational grids.
Start
Before use, you must ensure that you have an NVIDIA graphics card and have installed a CUDA-enabled version of PyTorch.
DeepGPR can then be installed using
pip install DeepGPR
A Small Forward Modeling Test
import torch
import DeepGPR
import matplotlib.pyplot as plt
# Set up the parameters and models
device=torch.device("cuda")
dx=0.02
dt=3e-11
nt=2000
er = torch.ones(100, 100,1) * 2
er[50:,:]=5
se = torch.zeros_like(er)
er.requires_grad_()
source_location=torch.tensor([[[10,10,0]]],device=device,dtype=torch.int)
receiver_location=torch.tensor([[[10,90,0]]],device=device,dtype=torch.int)
freq=2e8
peak_time = 1 / freq
source_amplitudes = torch.zeros((1,nt,1),device=device)
source_amplitudes[0,:,0]=DeepGPR.ricker(freq, nt, dt, peak_time).to(device)
#forward modeling
r = DeepGPR.compute(
device=device, dx=dx, dt=dt,
source_amplitudes=source_amplitudes,
source_location=source_location,
receiver_location=receiver_location,
er=er, se=se
)
(r[-1]**2).sum().backward()
_, ax = plt.subplots(1, 2, figsize=(10, 3))
ax[0].plot(r[-1].detach().flatten().cpu().numpy())
ax[0].set_title("Receiver data")
ax[1].imshow(er.grad.detach())
ax[1].set_title("Gradient")
plt.show()
There are more examples in the ./examples.
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.
2D FWI Result
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.
| True Model | Initial Model | Inverted Result |
|---|---|---|
3D FWI Result
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.
| Model Type | Central Slice of 3D Model |
|---|---|
| True Model | |
| Initial Model | |
| Inverted Result |
compute Interface Documentation
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.
📝 Function Signature
def compute(device, dx=None, dt=None,
source_amplitudes=None,
source_location=None,
receiver_location=None,
er=None, se=None, mr=None,
E=None, H=None, PML=None,
pmlthick=10, source_direction=2, reciever_direction=2,
model_gradient_sampling_interval=1,
use_async_offload=False):
📥 Input Parameters
1. Basic Physics & Grid Parameters
| Parameter | Data Type | Description |
|---|---|---|
device |
torch.device / str |
PyTorch computation device, e.g., 'cuda:0'. Determines where the computation takes place. |
dx |
float |
Spatial grid step size (assuming an isotropic grid, i.e., $dx = dy = dz$). Typically in meters (m). |
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). |
2. Medium Model Parameters
This section defines the electromagnetic properties of the simulation space. For 2D simulations, set nz=1.
| Parameter | Data Type | Shape | Description |
|---|---|---|---|
er |
Tensor (float) |
(nx, ny, nz) or (nx, ny) |
Relative permittivity ($\epsilon_r$). Values must be $\ge 1$. |
se |
Tensor (float) |
(nx, ny, nz) or (nx, ny) |
Electrical conductivity ($\sigma$). Values must be non-negative. |
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. |
Dimension Key:
nx,ny, andnzrepresent the number of grid cells along the X, Y, and Z axes, respectively.
3. Source & Receiver Setup
This section defines the geometric observation system (coordinates) and the excitation waveforms.
| Parameter | Data Type | Shape | Description |
|---|---|---|---|
source_amplitudes |
Tensor (float) |
(num_waveforms, nt) |
Source excitation waveforms. nt is the total number of time steps.- If num_waveforms == 1: All sources share this single waveform.- If num_waveforms == nsr: Each source uses its corresponding waveform. |
source_location |
Tensor (int) |
(nstep, nsr, 3) |
Grid coordinate indices of the sources. The last dimension corresponds to [x_idx, y_idx, z_idx]. |
receiver_location |
Tensor (int) |
(nstep, nrx, 3) |
Grid coordinate indices of the receivers. The last dimension corresponds to [x_idx, y_idx, z_idx]. |
source_direction |
int |
Scalar | Polarization direction/component of the source excitation.0 = X, 1 = Y, 2 = Z (e.g., exciting $E_z$). |
reciever_direction |
int |
Scalar | The component direction recorded by the receivers. (Note: typo in variable name is kept as-is to match code).0 = $E_x$, 1 = $E_y$, 2 = $E_z$. |
Core Shape Definitions:
nstep: Number of shots/batches (independent simulation tasks running in parallel).nsr: Number of sources per single simulation.nrx: Number of receivers per single simulation.nt: Total number of time steps to simulate.
4. Boundary Conditions & Optimization
| Parameter | Data Type | Format | Description |
|---|---|---|---|
pmlthick |
int / list / Tensor |
Scalar or list of 6 | Thickness (in grid layers) of the PML (Perfectly Matched Layer) absorbing boundaries. - Integer p: All six boundaries have thickness p (Z-boundaries are ignored in 2D).- List [x0, xm, y0, ym, z0, zm]: Specific thicknesses for the 6 boundaries. |
model_gradient_sampling_interval |
int |
Scalar | Wavefield sampling interval during forward propagation (Default: 1). A larger integer reduces the VRAM usage for the saved Eall tensor, but may decrease the accuracy of backpropagated gradients. |
use_async_offload |
bool |
Scalar | VRAM optimization flag (Default: False).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. |
5. Field Variable States (Checkpoints / Initial Fields)
For starting a forward simulation from scratch ($t=0$), these three parameters should be passed as None (the system will automatically initialize zero-tensors).
| Parameter | Data Type | Shape | Description |
|---|---|---|---|
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). |
H |
tuple / None |
3 Tensors | Initial state of the magnetic field components (Hx, Hy, Hz). Shapes identical to E. |
PML |
tuple / None |
24 Tensors | Auxiliary state variables ($\Phi$ fields) for the PML boundary updates. |
📤 Return Values
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.
return Eall, (Ex, Ey, Ez), (Hx, Hy, Hz), (x0EPhi1...zmHPhi2), receiver_amplitudes
Eall: The global electric field history saved for gradient calculation.- Shape:
(nt_saved, nstep, nx, ny, nz)(wherent_saveddepends onntandmodel_gradient_sampling_interval).
- Shape:
(Ex, Ey, Ez): The 3D electric field state at the final time step.(Hx, Hy, Hz): The 3D magnetic field state at the final time step.(PML_Tuple): A tuple of 24 Tensors recording the final time step state of the PML auxiliary $\Phi$ variables.receiver_amplitudes: The core output. The waveform signals recorded by the receivers over the entire simulation time.- Shape:
(nstep, nt, nrx) - Meaning:
[Shot Index, Time Step, Receiver Index]. Note that this output is already sliced to extract only the component specified byreciever_direction.
- Shape:
Cite information
If you find our codes useful, please kindly cite this article. Thanks.
@article{liu2026fast,
title={Fast ground penetrating radar dual-parameter full waveform inversion method accelerated by hybrid compilation of CUDA kernel function and PyTorch},
author={Liu, Lei and Song, Chao and He, Liangsheng and Wang, Silin and Feng, Xuan and Liu, Cai}, journal={Computers & Geosciences},
pages={106101},
year={2026},
publisher={Elsevier}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file deepgpr-0.0.9.tar.gz.
File metadata
- Download URL: deepgpr-0.0.9.tar.gz
- Upload date:
- Size: 352.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cea93dc5701981c502f3367181c405bcd2c6bc00238190d9a771a586e122b62b
|
|
| MD5 |
8a54fb6d8b30cd57a9f7cadee670ac3f
|
|
| BLAKE2b-256 |
2f72336e21aa78f7ea07e1fb077014a14575f865438e10c1221b575d6a0eb80f
|
File details
Details for the file deepgpr-0.0.9-py3-none-any.whl.
File metadata
- Download URL: deepgpr-0.0.9-py3-none-any.whl
- Upload date:
- Size: 350.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61cd39cc1161371b8321d6b422f6f3c27de0620267c864ca6d781269fab39c08
|
|
| MD5 |
903525e458a642962823751617f99ee9
|
|
| BLAKE2b-256 |
2b6b963baa1a22da642dcc2232c1dbb216f8c2d9bc9e949d843a833ac5333584
|