DevitoHorizon

Composable tools for seismic modelling, migration & FWI

What is Full-Waveform Inversion?

Recover the subsurface velocity model m by minimising the data misfit:

\[\min_{\mathbf{m}} \; \phi\!\left(\mathbf{d}_\text{syn}(\mathbf{m}),\, \mathbf{d}_\text{obs}\right)\]

Each iteration requires:

  • Forward solve — simulate seismic data with the current model
  • Adjoint solve — backpropagate the data residual to get a gradient
  • Optimization step — update the model

The challenge — computationally expensive, many moving parts: preprocessing, misfit choice, gradient muting, parallelism.

DevitoHorizon makes every piece explicit and swappable, with no hidden state.

Design Philosophy

“Everything is explicit—you wire together first-class objects (Dataset, DevitoPhysics, Optimizer) with no hidden state or monolithic drivers.”

Lightweight Small, focused modules. Easy to read, extend, and debug.

Composable Pick your misfit, optimizer, and scheduler independently.

Hackable Swap any component — custom misfit, batch sampler, or gradient processing in a few lines.

Architecture

%%{init: {'theme': 'base', 'themeVariables': {'fontSize': '16px'}}}%%
flowchart LR
    subgraph Data
        S["SEGY / Zarr"] --> DS["Dataset<br/>(SeismicData)"]
        H["HDF5"] --> M["Model<br/>(vp, m0…)"]
    end
    subgraph Physics
        DS & M --> DP["DevitoPhysics<br/>forward + adjoint"]
        DP --> GP["GradientProcessor<br/>muting · illumination"]
    end
    subgraph Optimization
        GP --> OPT["Optimizer<br/>SPG | PQN | Bregman"]
        OPT --> SCH["Scheduler<br/>Serial | Dask"]
        OPT --> OUT["Optimized Model"]
    end
    style Data fill:#e3f2fd
    style Physics fill:#fff3e0
    style Optimization fill:#f3e5f5

Core building blocks

Class Role
Data Dataset SEGY/Zarr, lazy SeismicData loading
Physics DevitoPhysics Wave-equation solves, adjoint gradients
Misfits L2, L1, Envelope, … Pluggable objective + adjoint source
Optimizers SPG, PQN, BREGMAN, SciPy Box-constrained minimisation
Scheduler SerialScheduler / DaskScheduler Transparent shot parallelism

Core API — Full-Batch FWI

from devitohorizon.data import Dataset
from devitohorizon.physics import DevitoPhysics
from devitohorizon.optimization import SPG

dataset = Dataset.from_segy("data/marmousi_shots.segy")

physics = DevitoPhysics(
    model={"m0": "models/marmousi_initial.h5"},
    nbl=40, space_order=8, misfit="l2",
    gradient={"mute": {"type": "datum", "cone_angle": 65.0}},
)

# QC a single shot first
result = physics.compute_shot_gradient(dataset[0])
misfit_val = result['misfit']

# Run FWI
optimizer = SPG(maxiter=10, ftol=1e-6, verbose=True)
model_opt, f_opt, result = optimizer.fwi(
    physics=physics, dataset=dataset,
    model0=physics.model, bounds={"vp": (1.4, 5.0)},
)

Misfits & Preprocessing

Built-in misfits — pass by name to DevitoPhysics(misfit=…):

Name Description
"l2" Half L2-squared — standard least-squares
"l1" L1 norm — robust to outliers
"students_t" Student’s-t — heavy-tailed robust objective
"envelope" Envelope (Hilbert-based) — cycle-skip robust
"phase" Phase-only inversion

Custom misfit — provide a (phi, dphi) pair:

physics = DevitoPhysics(..., misfit=(phi, dphi))

Preprocessing — per-shot pipeline passed to DevitoPhysics:

pre_cfg = {
    "filter": {"type": "bandpass", "fmin": 0.005, "fmax": 0.020},
    "mute":   {"type": "top", "v": 1500.0, "taper": 10},
}
physics = DevitoPhysics(..., preprocess=pre_cfg)

Stochastic Batches & Frequency Continuation

Mini-batch FWI

def make_sampler(batch_size):
    def sampler(ds, *, _c=[0]):
        seed = _c[0]; _c[0] += 1
        idx = np.random.default_rng(seed).choice(
            len(ds), batch_size, replace=False
        )
        return ds.subset(idx.tolist())
    return sampler

model_opt, f_opt, _ = optimizer.fwi(
    physics=physics, dataset=dataset,
    model0=physics.model,
    bounds={"vp": (1.4, 5.5)},
    batch_sampler=make_sampler(8),
)

Frequency continuation

bands = [
    {"fmin": 0.003, "fmax": 0.006, "iters": 4},
    {"fmin": 0.003, "fmax": 0.010, "iters": 5},
    {"fmin": 0.003, "fmax": 0.020, "iters": 8},
]

model = physics.model
for b in bands:
    pre = {"filter": {
        "type": "bandpass",
        "fmin": b["fmin"],
        "fmax": b["fmax"],
    }}
    physics = DevitoPhysics(
        model={"m0": model},
        nbl=40, preprocess=pre,
    )
    opt = SPG(maxiter=b["iters"], ftol=1e-6)
    model, _, _ = opt.fwi(
        physics=physics,
        dataset=dataset,
        model0=physics.model,
        bounds={"vp": (1.4, 5.0)},
    )

Scaling: Serial → Dask

from dask.distributed import Client, LocalCluster
from devitohorizon.scheduler import create_scheduler

# Serial (default — zero setup)
model_opt, f_opt, _ = optimizer.fwi(physics=physics, dataset=dataset, model0=model0)

# Local multi-worker Dask
cluster   = LocalCluster(n_workers=4, threads_per_worker=1)
client    = Client(cluster)
scheduler = create_scheduler(client)   # returns DaskScheduler

model_opt, f_opt, _ = optimizer.fwi(
    physics=physics, dataset=dataset,
    model0=model0, bounds={"vp": (1.4, 5.0)},
    scheduler=scheduler,
)
client.close(); cluster.close()

The Scheduler interface is fully pluggable — SerialScheduler by default, DaskScheduler for local or cloud distributed runs.

Example: Overthrust FWI — Initial vs Optimized

SPG, L2 misfit, full-batch — smooth 1D starting model → resolved structure

Initial model

Optimized model

Example: Immersed Boundary (BP1994)

FWI gradient — 5 shots, BP1994 benchmark

  • Irregular topography handled via a signed-distance field (SDF): no mesh deformation or manual padding required
  • DevitoPhysics accepts SDF-aware models directly; the gradient correctly honours the rugged free surface
  • Same composable API as any flat-surface problem — swap the model, everything else is unchanged