GETTING STARTED
Your first FWI in five steps.
From a fresh terminal to running gradient descent on a toy velocity model. By the end you'll be ready to open any of the notebooks.
01
Install
PyTorch is always installed — it is a required dependency. The
[jax] extra adds JAX on top, for the JAX backend.
PyTorch backend
recommended
$ pip install sweepx
JAX backend
$ pip install "sweep-solver[jax]"
tip The wheel ships a prebuilt CUDA core, so the compiled backend (
impl="c") works right after install — nothing compiles. For a dev clone, see
Installation.
02
Build a velocity model
A simple 2-layer model: 1500 m/s in the top half, 2000 m/s below. 10 m grid spacing.
quickstart.py
import torch, numpy as np
from sweep.propagator.torch import PropTorch
from sweep.equations import Acoustic
from sweep.signal import ricker
# A 2-layer 100×100 model.
vp = np.ones((100, 100), dtype=np.float32) * 1500
vp[50:, :] = 2000
vp · 100 × 100 · 10 m grid
03
Run a forward shot
Construct the equation, wrap it in a propagator, and call forward().
propagator
eq = Acoustic(spatial_order=8, device="cuda", backend="torch")
prop = PropTorch(eq, shape=(100, 100), device="cuda", dh=10., dt=2e-3,
source_type=["h1"], receiver_type=["h1"])
wave = ricker(np.arange(0, 1.5, 2e-3) - 0.1, f=8)
sources = np.array([[50, 2]])
receivers = np.array([[[ix, 2] for ix in range(10, 90)]])
obs = prop.forward(wave, sources, receivers, models=[torch.from_numpy(vp).to("cuda")])
shot record · 1 src · 80 rec · 750 samples
04
Get the gradient
Tag vp with requires_grad_, run forward, and backward(). That's it.
vp_t = torch.from_numpy(vp).to("cuda").requires_grad_(True)
obs = prop.forward(wave, sources, receivers, models=[vp_t])
obs.pow(2).sum().backward()
# vp_t.grad now holds the sensitivity kernel.
∂L/∂vp · 100 × 100
05