Skip to main content

Custom Gradient Processing

DevitoHorizon post-processes FWI gradients through an ordered pipeline of steps, mirroring the data-preprocessing pipeline. Each step is a dict {"kind": name, ...params}; steps run in order, and you can pick, reorder, and add your own steps without subclassing anything.

This tutorial builds a custom Laplacian (diffusion) smoother, registers it as a gradient step, and runs it through the real DevitoPhysics.objective flow (forward + adjoint + gradient finalization) alongside the built-in steps. Finally it reuses the same idea as a custom between-band model smoother in a real frequency-continuation run.

The built-in steps are:

Step Stage What it does
cone_mute shot Attenuate gradients outside the per-shot illumination cone
surface_mute reduced Zero gradients in the water column / above the datum
global_smoothing reduced Gaussian-smooth the reduced gradient

shot-stage steps run per shot inside compute_shot_gradient; reduced-stage steps run once on the summed gradient inside objective/finalize_reduced_gradient.

Laplacian smoothing

Gaussian smoothing convolves with a fixed kernel. Laplacian smoothing instead runs a few steps of the heat (diffusion) equation,

\[ g \leftarrow g + r\,\nabla^2 g, \]

repeated for \(N\) iterations. Each iteration averages a cell with its neighbours; more iterations means more smoothing. It is cheap and a natural drop-in alternative to the built-in Gaussian. For the standard 5-point Laplacian the update is stable when the rate \(r < 0.25\).

import tempfile

import numpy as np
import matplotlib.pyplot as plt
from scipy.ndimage import laplace
from recipes import WaveModel, layered_model

from devitohorizon.config import SeismicData
from devitohorizon.physics import DevitoPhysics
from devitohorizon.optimization import SPG
from devitohorizon.processing import gradient_step, available_gradient_steps
from devitohorizon.inversion.fwi import (
    model_smoother,
    resolve_model_smoother,
    run_frequency_continuation,
)
from devitohorizon.model.grid import get_interior_vp

plt.style.use("default")
plt.rcParams["figure.dpi"] = 70
run_dir = tempfile.mkdtemp(prefix="grad_tutorial_")
%matplotlib inline


def show(arrays, titles, cmap="seismic"):
    '''Plot a row of interior-grid arrays (transposed so depth points down).'''
    n = len(arrays)
    fig, axes = plt.subplots(1, n, figsize=(3.1 * n, 2.7))
    axes = np.atleast_1d(axes)
    for ax, arr, title in zip(axes, arrays, titles, strict=False):
        lim = np.max(np.abs(arr)) or 1.0
        im = ax.imshow(arr.T, aspect="auto", cmap=cmap, vmin=-lim, vmax=lim)
        ax.set_title(title)
        ax.set_xlabel("x [grid]")
        ax.set_ylabel("z [grid]")
        plt.colorbar(im, ax=ax, fraction=0.046)
    plt.tight_layout()
    plt.show()

1. Set up a tiny FWI problem

We build a small two-/three-layer acoustic model as the true model, a smooth initial model, an acquisition geometry, and synthetic “observed” data by forward modeling on the true model — all in memory, no data files.

shape = (151, 101)            # (nx, nz)
spacing = (10.0, 10.0)       # metres
nbl, so, tn, f0 = 10, 4, 0.5, 12.0

true_model = layered_model(
    "iso-acoustic", nlayers=3, shape=shape, spacing=spacing,
    nbl=nbl, space_order=so,
)
init_model = layered_model(
    "iso-acoustic", nlayers=1, shape=shape, spacing=spacing,
    nbl=nbl, space_order=so,
)

# Acquisition: one central source, a line of receivers along the surface.
src_pos = np.array([[shape[0] * spacing[0] / 2, 0.0]], dtype=np.float32)
rec_pos = np.array([[i * spacing[0], 0.0] for i in range(shape[0])],
                   dtype=np.float32)

# Synthetic observed data: forward-model on the TRUE model.
true_physics = DevitoPhysics(
    nbl=nbl, space_order=so, tn=tn, parameters=("m",),
    wavelet={"type": "ricker", "f0": f0}, run_name=f"{run_dir}/true",
)
true_physics.model = true_model
seed = SeismicData(
    shot_id=0, data=np.zeros((90, rec_pos.shape[0]), dtype=np.float32),
    src_pos=src_pos, rec_pos=rec_pos, dt=4.0,
)
observed = true_physics.simulate_shot(seed)["synthetic"]
shot = SeismicData(shot_id=0, data=observed, src_pos=src_pos, rec_pos=rec_pos,
                   dt=4.0)

show([get_interior_vp(true_model), get_interior_vp(init_model)],
     ["True vp [km/s]", "Initial vp [km/s]"], cmap="viridis")
Solver FWISolverImpl_HorizonSolver_AcousticIsotropic building operator: ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.02 s

2. Define and register a custom Laplacian step

A gradient step is a callable

def my_step(gradients, model, **params) -> dict:
    ...

where gradients is the {parameter_name: array} dict on the interior grid and model is the working WaveModel — the same model argument passed to misfit and model-smoother callables (use get_interior_vp(model), model.spacing, etc.). The remaining keys of the step dict arrive as **params.

Decorating it with @gradient_step(name, stage=...) registers it under a string name so it can be referenced from a config — the form that stays serialisable and survives pickling to Dask workers.

def _laplacian_diffuse(arr, iterations, rate):
    '''Apply `iterations` steps of g += rate * laplacian(g).'''
    out = arr.astype(np.float64, copy=True)
    for _ in range(iterations):
        out += rate * laplace(out, mode="nearest")
    return out.astype(arr.dtype, copy=False)


@gradient_step("laplacian_smoothing", stage="reduced")
def laplacian_smoothing(gradients, model, *, iterations=40, rate=0.2):
    '''Diffusion smoother for reduced gradients.'''
    return {name: _laplacian_diffuse(g, iterations, rate)
            for name, g in gradients.items()}


# It now shows up next to the built-ins.
available_gradient_steps()
{'cone_mute': 'shot',
 'surface_mute': 'reduced',
 'global_smoothing': 'reduced',
 'laplacian_smoothing': 'reduced'}

3. Run it through DevitoPhysics.objective

Pass an explicit steps tuple to the physics gradient= argument. The reduced step then runs every time objective finalizes the summed gradient. We compute the initial-model gradient three ways on the same shot — no smoothing, the built-in Gaussian, and our custom Laplacian — and compare.

def gradient_with(gradient_cfg, tag):
    physics = DevitoPhysics(
        nbl=nbl, space_order=so, tn=tn, parameters=("m",),
        wavelet={"type": "ricker", "f0": f0},
        run_name=f"{run_dir}/{tag}", gradient=gradient_cfg,
    )
    physics.model = init_model
    misfit, gradients = physics.objective(shot)
    return misfit, gradients["m"]


f_raw, g_raw = gradient_with({"global_smoothing": False}, "raw")
f_gauss, g_gauss = gradient_with(
    {"steps": ({"kind": "global_smoothing", "sigma": 2},)}, "gauss")
f_lap, g_lap = gradient_with(
    {"steps": ({"kind": "laplacian_smoothing", "iterations": 60},)}, "lap")

print("misfit (shared init model):", round(float(f_raw), 3))
print("gradient std  raw / gaussian / laplacian:",
      round(float(g_raw.std()), 5),
      round(float(g_gauss.std()), 5),
      round(float(g_lap.std()), 5))

show([g_raw, g_gauss, g_lap],
     ["Raw gradient", "Built-in Gaussian", "Custom Laplacian"])
Prebuilding operators...
Solver FWISolverImpl_HorizonSolver_AcousticIsotropic building operator: ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic
Solver FWISolverImpl_HorizonSolver_AcousticIsotropic building operator: ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic
Solver FWISolverImpl_HorizonSolver_AcousticIsotropic building operator: JacobianAdjFWISolverImpl_HorizonSolver_AcousticIsotropic
Operators prebuilt and cached successfully
Cropping model in X to [0.000km, 1.500km]
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Operator `JacobianAdjFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Finalizing reduced gradient with 2 step(s). Surface mute type: None, Global smoothing: False
Prebuilding operators...
Solver FWISolverImpl_HorizonSolver_AcousticIsotropic building operator: ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic
Solver FWISolverImpl_HorizonSolver_AcousticIsotropic building operator: ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic
Solver FWISolverImpl_HorizonSolver_AcousticIsotropic building operator: JacobianAdjFWISolverImpl_HorizonSolver_AcousticIsotropic
Operators prebuilt and cached successfully
Cropping model in X to [0.000km, 1.500km]
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Operator `JacobianAdjFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Finalizing reduced gradient with 1 step(s). Surface mute type: None, Global smoothing: True
Applying Gaussian smoothing to gradient with sigma=2
Prebuilding operators...
Solver FWISolverImpl_HorizonSolver_AcousticIsotropic building operator: ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic
Solver FWISolverImpl_HorizonSolver_AcousticIsotropic building operator: ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic
Solver FWISolverImpl_HorizonSolver_AcousticIsotropic building operator: JacobianAdjFWISolverImpl_HorizonSolver_AcousticIsotropic
Operators prebuilt and cached successfully
Cropping model in X to [0.000km, 1.500km]
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Operator `JacobianAdjFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Finalizing reduced gradient with 1 step(s). Surface mute type: None, Global smoothing: True
misfit (shared init model): 463.451
gradient std  raw / gaussian / laplacian: 0.35051 0.2585 0.13919

Both smoothers suppress high-wavenumber noise in the reduced gradient. Everything is driven from the config — iterations/rate for the Laplacian, sigma for the Gaussian — without touching the step code or the physics.

4. Muting steps, order, and datum surfaces

Steps compose and run in the order you list them. Here we mute above a datum surface and then apply our Laplacian smoother. Datum muting needs the dataset surface samples (source/receiver-derived); attach them to the shot and objective picks them up automatically.

Order matters: smoothing after muting would diffuse live values back into the muted zone, so we mute last.

# Datum surface 80 m (8 cells) deep across the line.
horizontal = np.linspace(0.0, (shape[0] - 1) * spacing[0], shape[0])
surface = {
    "horizontal": horizontal.reshape(-1, 1).astype(np.float32),
    "depth": np.full(shape[0], 80.0, dtype=np.float32),
}
shot_with_surface = SeismicData(
    shot_id=0, data=observed, src_pos=src_pos, rec_pos=rec_pos, dt=4.0,
    surface=surface,
)

physics = DevitoPhysics(
    nbl=nbl, space_order=so, tn=tn, parameters=("m",),
    wavelet={"type": "ricker", "f0": f0}, run_name=f"{run_dir}/datum",
    gradient={"steps": (
        {"kind": "laplacian_smoothing", "iterations": 60},   # smooth first
        {"kind": "surface_mute", "mute_type": "datum"},      # then mute
    )},
)
physics.model = init_model
_, g_muted = physics.objective(shot_with_surface)
g_muted = g_muted["m"]
print("above-datum (top 8 rows) zeroed:", np.allclose(g_muted[:, :8], 0.0))

show([g_lap, g_muted], ["Laplacian only", "Laplacian + datum mute"])
Prebuilding operators...
Solver FWISolverImpl_HorizonSolver_AcousticIsotropic building operator: ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic
Solver FWISolverImpl_HorizonSolver_AcousticIsotropic building operator: ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic
Solver FWISolverImpl_HorizonSolver_AcousticIsotropic building operator: JacobianAdjFWISolverImpl_HorizonSolver_AcousticIsotropic
Operators prebuilt and cached successfully
Cropping model in X to [0.000km, 1.500km]
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Operator `JacobianAdjFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Finalizing reduced gradient with 2 step(s). Surface mute type: None, Global smoothing: True
above-datum (top 8 rows) zeroed: True

5. A custom model smoother for frequency continuation

Frequency continuation smooths the model between bands to drop wavenumbers the next band cannot resolve. That smoother is pluggable too: register one with @model_smoother. A model smoother has the signature fn(model, fmax, **params) -> WaveModel and receives smoothing_factor, mute_type, mute_threshold, plus any smoothing_params.

We reuse the diffusion idea, scaling iterations with the band frequency (lower fmax → more smoothing), and run a real two-band continuation.

@model_smoother("laplacian")
def laplacian_model_smoother(model, fmax, *, base_iterations=8, ref_freq=10.0,
                             rate=0.2, **_):
    iters = max(1, int(round(base_iterations * ref_freq / max(fmax, 1e-6))))
    vp_s = _laplacian_diffuse(get_interior_vp(model), iters, rate)
    return WaveModel(model.origin, model.spacing, model.shape, model.space_order,
                     nbl=model.nbl, fs=model.fs, bcs="damp", vp=vp_s)


smoother = resolve_model_smoother("laplacian")    # registry lookup by name


def band_physics(model, tag):
    physics = DevitoPhysics(
        nbl=nbl, space_order=so, tn=tn, parameters=("m",),
        wavelet={"type": "ricker", "f0": f0}, run_name=f"{run_dir}/{tag}",
    )
    physics.model = model
    return physics


bands = [
    {"dataset": [shot], "model": init_model, "maxiter": 3, "label": "4 Hz",
     "physics_factory": lambda m: band_physics(m, "band0")},
    {"dataset": [shot], "model_transform": lambda m: smoother(m, 8.0),
     "maxiter": 3, "label": "8 Hz",
     "physics_factory": lambda m: band_physics(m, "band1")},
]

recovered, f_final, _, history = run_frequency_continuation(
    SPG(maxiter=3), bands, bounds={"vp": (1.4, 4.0)},
)
print("per-band objective:", [(h["label"], round(float(h["objective"]), 2))
                              for h in history])

show([get_interior_vp(init_model), get_interior_vp(recovered),
      get_interior_vp(true_model)],
     ["Initial", "Recovered (2 bands)", "True"], cmap="viridis")
Starting FWI optimization...
  Algorithm      : SPG
  Run name       : /var/folders/5k/328zp6912nd1h1bqnylt0wph0000gp/T/grad_tutorial_c6im5zcs/band0
  Max iterations : 3
  Shots          : 1 (all shots)
  Misfit         : l2
  Parameters     : m
  Output dir     : /var/folders/5k/328zp6912nd1h1bqnylt0wph0000gp/T/grad_tutorial_c6im5zcs/band0
  Save models    : every 1 iteration(s)
  Bounds [vp]    : (1.4, 4)
Prebuilding operators...
Solver FWISolverImpl_HorizonSolver_AcousticIsotropic building operator: ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic
Solver FWISolverImpl_HorizonSolver_AcousticIsotropic building operator: ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic
Solver FWISolverImpl_HorizonSolver_AcousticIsotropic building operator: JacobianAdjFWISolverImpl_HorizonSolver_AcousticIsotropic
Operators prebuilt and cached successfully
Cropping model in X to [0.000km, 1.500km]
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Operator `JacobianAdjFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Finalizing reduced gradient with 2 step(s). Surface mute type: None, Global smoothing: True
Applying Gaussian smoothing to gradient with sigma=(2, 1)
Cropping model in X to [0.000km, 1.500km]
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Prebuilding operators...
Operators prebuilt and cached successfully
Cropping model in X to [0.000km, 1.500km]
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Operator `JacobianAdjFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Finalizing reduced gradient with 2 step(s). Surface mute type: None, Global smoothing: True
Applying Gaussian smoothing to gradient with sigma=(2, 1)
SPG iter   1: f = 4.539609e+02  optCond = 3.816e-01  step = 1.00e+00  alpha = 1.00e+00  feval =     3  geval =     2  time = 8.33e-01s
Cropping model in X to [0.000km, 1.500km]
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Cropping model in X to [0.000km, 1.500km]
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Cropping model in X to [0.000km, 1.500km]
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Prebuilding operators...
Operators prebuilt and cached successfully
Cropping model in X to [0.000km, 1.500km]
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Operator `JacobianAdjFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Finalizing reduced gradient with 2 step(s). Surface mute type: None, Global smoothing: True
Applying Gaussian smoothing to gradient with sigma=(2, 1)
SPG iter   2: f = 3.513868e+02  optCond = 3.860e-01  step = 2.50e-01  alpha = 3.16e-02  feval =     7  geval =     3  time = 1.25e+00s
Cropping model in X to [0.000km, 1.500km]
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Prebuilding operators...
Operators prebuilt and cached successfully
Cropping model in X to [0.000km, 1.500km]
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Operator `JacobianAdjFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Finalizing reduced gradient with 2 step(s). Surface mute type: None, Global smoothing: True
Applying Gaussian smoothing to gradient with sigma=(2, 1)
SPG iter   3: f = 3.460482e+02  optCond = 3.961e-01  step = 1.00e+00  alpha = 9.35e-03  feval =     9  geval =     4  time = 7.12e-01s
SPG: Number of iterations reached maxiter
Starting FWI optimization...
  Algorithm      : SPG
  Run name       : /var/folders/5k/328zp6912nd1h1bqnylt0wph0000gp/T/grad_tutorial_c6im5zcs/band1
  Max iterations : 3
  Shots          : 1 (all shots)
  Misfit         : l2
  Parameters     : m
  Output dir     : /var/folders/5k/328zp6912nd1h1bqnylt0wph0000gp/T/grad_tutorial_c6im5zcs/band1
  Save models    : every 1 iteration(s)
  Bounds [vp]    : (1.4, 4)
Prebuilding operators...
Solver FWISolverImpl_HorizonSolver_AcousticIsotropic building operator: ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic
Solver FWISolverImpl_HorizonSolver_AcousticIsotropic building operator: ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic
Solver FWISolverImpl_HorizonSolver_AcousticIsotropic building operator: JacobianAdjFWISolverImpl_HorizonSolver_AcousticIsotropic
Operators prebuilt and cached successfully
Cropping model in X to [0.000km, 1.500km]
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Operator `JacobianAdjFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Finalizing reduced gradient with 2 step(s). Surface mute type: None, Global smoothing: True
Applying Gaussian smoothing to gradient with sigma=(2, 1)
Cropping model in X to [0.000km, 1.500km]
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Prebuilding operators...
Operators prebuilt and cached successfully
Cropping model in X to [0.000km, 1.500km]
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Operator `JacobianAdjFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Finalizing reduced gradient with 2 step(s). Surface mute type: None, Global smoothing: True
Applying Gaussian smoothing to gradient with sigma=(2, 1)
SPG iter   1: f = 3.371304e+02  optCond = 3.800e-01  step = 1.00e+00  alpha = 1.00e+00  feval =     3  geval =     2  time = 9.48e-01s
Cropping model in X to [0.000km, 1.500km]
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Cropping model in X to [0.000km, 1.500km]
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Prebuilding operators...
Operators prebuilt and cached successfully
Cropping model in X to [0.000km, 1.500km]
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Operator `JacobianAdjFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Finalizing reduced gradient with 2 step(s). Surface mute type: None, Global smoothing: True
Applying Gaussian smoothing to gradient with sigma=(2, 1)
SPG iter   2: f = 3.286061e+02  optCond = 4.217e-01  step = 5.00e-01  alpha = 7.75e-02  feval =     6  geval =     3  time = 1.03e+00s
Cropping model in X to [0.000km, 1.500km]
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Cropping model in X to [0.000km, 1.500km]
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Cropping model in X to [0.000km, 1.500km]
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Prebuilding operators...
Operators prebuilt and cached successfully
Cropping model in X to [0.000km, 1.500km]
Operator `initdamp` ran in 0.01 s
Operator `dampvp` ran in 0.01 s
Operator `ForwardFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Operator `JacobianAdjFWISolverImpl_HorizonSolver_AcousticIsotropic` ran in 0.01 s
Finalizing reduced gradient with 2 step(s). Surface mute type: None, Global smoothing: True
Applying Gaussian smoothing to gradient with sigma=(2, 1)
SPG iter   3: f = 2.593381e+02  optCond = 4.249e-01  step = 2.50e-01  alpha = 4.55e-02  feval =    10  geval =     4  time = 1.51e+00s
SPG: Number of iterations reached maxiter
per-band objective: [('4 Hz', 346.05), ('8 Hz', 259.34)]

In production you would normally drive continuation declaratively through FWIObjective, selecting the smoother by name — True/"gaussian" is the built-in Gaussian, a string is a registered smoother, a callable is used directly:

from devitohorizon.inversion.fwi import FWIObjective

param = {
    "data_path": "data/shots.segy",
    "model": {"m0": "models/init.h5"},
    "nbl": 40, "space_order": 8,
    "wavelet": {"type": "ricker", "f0": 12.0},
    "gradient": {"steps": ({"kind": "laplacian_smoothing", "iterations": 60},)},
    "continuation": {
        "fmax": [4.0, 8.0, 16.0],
        "model_smoothing": "laplacian",            # our custom smoother
        "smoothing_params": {"base_iterations": 8, "rate": 0.2},
    },
}
model_opt, f_opt, result = FWIObjective(param=param).run()

smoothing_params is forwarded to the smoother as keyword arguments.

Summary

  • Gradient processing is an ordered step pipeline; each step is {"kind": name, ...params} and runs at the shot or reduced stage.
  • Add a custom step with @gradient_step(name, stage=...) and a step(gradients, model, **params) callable; reference it by name from the physics gradient= config.
  • Steps run inside the real DevitoPhysics.objective flow, compose with the built-ins, and order matters (mute last to keep muted regions clean). Datum muting reads the dataset surface attached to the shots.
  • The between-band continuation smoother is pluggable the same way via @model_smoother / model_smoothing + smoothing_params.

See the Gradient Processing guide and the Continuation tutorial for the full reference.

Back to top