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.
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.
- 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.
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 DeepGPRimport 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.
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 |
|---|---|---|
![]() |
![]() |
![]() |
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 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.
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):| 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., |
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). |
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 ( |
se |
Tensor (float) |
(nx, ny, nz) or (nx, ny)
|
Electrical conductivity ( |
mr |
Tensor (float) |
(nx, ny, nz) or (nx, ny)
|
Relative permeability (er. |
Dimension Key:
nx,ny, andnzrepresent the number of grid cells along the X, Y, and Z axes, respectively.
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 |
reciever_direction |
int |
Scalar | The component direction recorded by the receivers. (Note: typo in variable name is kept as-is to match code).0 = 1 = 2 = |
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.
| 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. |
For starting a forward simulation from scratch (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 ( |
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:
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}
}






