Skip to main content

DevitoHorizon Documentation

Composable tools for wave-equation imaging

DevitoHorizon is a lightweight collection of building blocks for seismic Full Waveform Inversion (FWI) and imaging. Everything is explicit: you wire together first-class objects (Dataset, DevitoPhysics, Optimizer) with no hidden state or monolithic drivers.

Quick Start

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

# 1) Load model and data
model0 = load_model("models/overthrust_initial.h5", nbl=40, space_order=16)
dataset = Dataset.from_segy("data/overthrust_shots.segy")

# 2) Create physics engine
physics = DevitoPhysics(
    nbl=40,
    space_order=16,
    parameters=('m',),
    misfit='l2',
)

# 3) Compute a diagnostic gradient (optional)
shot = dataset[0]
result = physics.compute_shot_gradient(shot)
print(f"Misfit={result['misfit']:.3e}, |grad|={np.linalg.norm(result['gradients']['m']):.3e}")

# 4) Run FWI with optimizer
optimizer = SPG(maxiter=10, ftol=1e-6, gtol=1e-8, verbose=True)
model_opt, f_opt, result = optimizer.fwi(
    physics=physics,
    dataset=dataset,
    model0=model0,
    bounds={'vp': (1.5, 5.0)},
)

print(f"Optimization converged: {result.success}")
print(f"Final misfit: {f_opt:.6e}")

With Parallel Execution (Dask)

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

# Start Dask client
client = Client(n_workers=4, threads_per_worker=2)
scheduler = create_scheduler(client)

# Run FWI in parallel
model_opt, f_opt, result = optimizer.fwi(
    physics=physics,
    dataset=dataset,
    model0=model0,
    bounds={'vp': (1.5, 5.0)},
    scheduler=scheduler,  # Enable parallelization
)

Core Building Blocks

  1. Dataset (devitohorizon.data) Clean interface for seismic data with Dataset.from_segy() and Dataset.from_zarr(). Iterates over SeismicData containers with lazy loading.

  2. DevitoPhysics (devitohorizon.physics) Handles wave-equation solves, adjoint gradients, source estimation, illumination preconditioning, and gradient muting. Composable with any optimizer.

  3. Optimizer (devitohorizon.optimization) Pure optimization algorithms (SPG, PQN, Bregman). Call optimizer.fwi(physics, dataset, model0) or optimizer.minimize(objective, x0) for custom workflows.

  4. Scheduler (devitohorizon.scheduler) Pluggable parallelization via SerialScheduler (default) or DaskScheduler for distributed computing.

  5. Gradient Processing (devitohorizon.processing) Water-bottom masks, datum surfaces, cone muting, illumination preconditioning—all configurable via GradientProcessingConfig.

  6. Source Estimation (devitohorizon.processing.source) One complex scalar per frequency, fitted by least squares over every trace of the shot (Pratt, 1999).

  7. Model I/O (devitohorizon.model) Load models from HDF5, SEG-Y, or Zarr with load_model(). Handles resampling, boundary padding, and optional SDF inputs for immersed-boundary topography workflows.

Architecture

flowchart TB
    subgraph storage["Storage"]
        SEGY["SEGY Files"]
        ZARR["Zarr Store"]
        HDF5["HDF5 Model"]
    end

    subgraph data["Data Layer"]
        DM["DataManager<br/><i>SEGYDataManager | ZarrDataManager</i>"]
        DS["Dataset"]
        SHOT["SeismicData"]
    end

    subgraph model["Model Layer"]
        LOAD["load_model()"]
        MDL["Model<br/><i>(vp, rho, etc.)</i>"]
    end

    subgraph physics["Physics Layer"]
        DP["DevitoPhysics"]
        FWD["Forward Modeling"]
        ADJ["Adjoint / Gradient"]
        SRC["Source Estimation"]
        MIS["Misfit Functions<br/><i>L2 | Envelope | Custom</i>"]
    end

    subgraph processing["Processing Layer"]
        GP["GradientProcessor"]
        MASK["Water Mask"]
        MUTE["Cone Mute"]
        TAPER["Boundary Taper"]
        ILLUM["Illumination"]
    end

    subgraph optimization["Optimization Layer"]
        OPT["Optimizer<br/><i>SPG | PQN | Bregman</i>"]
        BOUNDS["Bounds Projection"]
        LINESEARCH["Line Search"]
    end

    subgraph scheduler["Execution"]
        SCHED["Scheduler<br/><i>Serial | Dask</i>"]
        DASK["Dask Client"]
    end

    subgraph output["Outputs"]
        MOPT["Optimized Model"]
        IMG["RTM Image"]
        GRAD["Gradient"]
    end

    %% Data flow
    SEGY --> DM
    ZARR --> DM
    DM --> DS
    DS --> SHOT

    HDF5 --> LOAD
    LOAD --> MDL

    SHOT --> DP
    MDL --> DP

    DP --> FWD
    DP --> ADJ
    DP --> SRC
    FWD --> MIS
    MIS --> ADJ

    ADJ --> GP
    GP --> MASK
    GP --> MUTE
    GP --> TAPER
    GP --> ILLUM

    GP --> OPT
    MDL --> OPT
    OPT --> BOUNDS
    OPT --> LINESEARCH
    OPT --> SCHED

    SCHED -.-> DASK

    OPT --> MOPT
    ADJ --> GRAD
    FWD --> IMG

    %% Styling
    style storage fill:#f5f5f5
    style data fill:#e3f2fd
    style model fill:#e8f5e9
    style physics fill:#fff3e0
    style processing fill:#fce4ec
    style optimization fill:#f3e5f5
    style scheduler fill:#e0f2f1
    style output fill:#fffde7

Component Customization

Component Class Customization
Data Dataset Subclass DataManager for new formats
Physics DevitoPhysics Custom misfit_fn, misfit_grad_fn, space/time order
Processing GradientProcessor Configure via GradientProcessingConfig
Optimization SPG, PQN Bounds, tolerances, line search params
Execution Scheduler SerialScheduler or DaskScheduler
Source Est. estimate_source_and_fix_synthetic none: lags follow the data band

Key Features

Composable API

No monolithic FWI class—just first-class objects that interact:

# RTM/Migration (no optimization)
image = physics.image(dataset)

# Custom optimization loop
for iteration in range(20):
    batch = dataset.sample(8)  # Mini-batch
    f, g_dict = physics.objective(batch, model)
    # Apply custom update...

True Lazy Loading

Data is loaded fresh each time—no caching, no stale arrays:

dataset = Dataset.from_segy("data.segy")
for shot in dataset:
    # Shot loaded from disk every iteration
    sim = physics.simulate_shot(shot)

Extensibility

Swap components without touching core code:

# Custom misfit function
def my_misfit(synth, obs):
    return np.linalg.norm(synth - obs)

def my_misfit_grad(synth, obs):
    return synth - obs

physics = DevitoPhysics(
    nbl=40,
    space_order=16,
    misfit_fn=my_misfit,
    misfit_grad_fn=my_misfit_grad,
)

Immersed Boundary Topography

Topography-aware modeling is supported by attaching a signed-distance field (sdf) to the model description:

model = load_model({
    "model": {
        "vp": "models/bp94_velocity.sgy",
        "sdf": "models/bp94_surface_sdf.sgy",
    },
    "nbl": 40,
    "space_order": 8,
})

The loaded WaveModel carries the SDF through forward, adjoint, migration, and FWI workflows. See Immersed Boundary Support for the full setup and the BP1994 example.

Documentation Map

Examples

Step-by-step guides for: - Basic FWI workflow - Stochastic mini-batching - Multi-parameter inversion - Frequency continuation

Immersed Boundary Support

Guide for topography-aware runs with signed-distance fields: - Required model and SDF inputs - BP1994 immersed-boundary walkthrough - Notes on Schism availability and SDF conventions

Customization Guides

Extend the framework with custom components: - Configuring an FWI Run - Config reference: preprocessing, mutes, continuation, migration - Custom Misfits - Cross-correlation, optimal transport, adaptive objectives - Custom Optimizers - Adam, SGD, trust-region, SciPy wrappers - Custom Data I/O - HDF5, NetCDF, cloud storage, databases - Custom Gradient Processing - Muting, preconditioning, smoothing - Custom Schedulers - Ray, MPI, multiprocessing, GPU clusters

API Reference

Detailed API documentation for: - Data - Dataset, SeismicData, DataManager - Physics - DevitoPhysics, ForwardResult, GradientResult - Optimizers - SPG, PQN, Bregman - Misfits - Misfit, L2Misfit, Envelope1DMisfit, regularizers (Tikhonov, TV, GradientL2)

Architecture

System architecture, design decisions, and component interaction.

Installation & Environment

git clone https://github.com/devitocodes/devitohorizon.git
cd devitohorizon
python -m pip install -e .

Set Devito environment (Apple Silicon example):

export DEVITO_ARCH=clang
export DEVITO_LANGUAGE=openmp
export DEVITO_PLATFORM=m1
export OMP_NUM_THREADS=4
export PATH="/opt/homebrew/bin:/opt/homebrew/opt/llvm/bin:$PATH"
export LD_LIBRARY_PATH="/opt/homebrew/opt/llvm/lib:$LD_LIBRARY_PATH"

Need Help?

  • 📂 demos/ — Runnable examples (local, Dask, Azure)
  • 📚 Examples — Step-by-step guides
  • 🔍 API Reference — Full API documentation
  • 💬 GitHub Discussions — Workflow questions
  • 🐞 GitHub Issues — Bugs and feature requests
Back to top