Skip to main content

Physics & Optimization API

DevitoPhysics, GradientProcessor, and SPG

DevitoPhysics

from devitohorizon.physics import DevitoPhysics

Constructor

DevitoPhysics(
    model: dict | str,
    *,
    nbl: int = 40,
    space_order: int = 8,
    t0: float | str | None = None,
    tn: float | str | None = None,
    freesurface: bool = False,
    parameters: tuple[str, ...] = ('m',),
    illumination: bool = True,
    wavelet: dict | None = None,
    gradient: dict | None = None,
    preprocess: dict | None = None,
    source_estimation: bool | str = False,
    output_dir: str | None = None,
)

All keyword meanings are documented in the Physics API.

Methods

Method Description
compute_shot_gradient(shot) Runs a forward+adjoint pair for a single SeismicData. Returns (misfit, gradients_dict, illumination) where gradients_dict contains arrays for each requested parameter.
objective(dataset_or_list, model=None) Computes the average misfit and stacked gradients over an iterable of shots (or a Dataset).
preprocess_data(data, dt) Applies the configured preprocessing dictionary to a numpy array.

Attributes

Attribute Description
model The current WaveModel.
gradient_processor Instance of GradientProcessor used internally; you can call it manually if needed.
cone_weight Last cone weight applied (per shot).

GradientProcessor

from devitohorizon.processing.gradient import GradientProcessor

DevitoPhysics uses this class under the hood. Advanced users can instantiate it directly:

processor = GradientProcessor(template=model, config=gradient_cfg)
shot_grad = processor.process(gradients, geometry=geometry_dict)
muted = processor.apply_surface_mute(shot_grad, dataset.surface)

Configuration keys match the gradient dictionary accepted by DevitoPhysics. Useful methods:

  • process(gradients, geometry=None) — apply per-shot muting (e.g., cones).
  • apply_surface_mute(gradients, surface) — project Dataset.surface onto the grid and apply the datum cutoff once.
  • project_to_grid(...) — copy gradients from a cropped grid to the global grid (used in some Dask demos).

SPG Optimizer

from devitohorizon.optimization import SPG

Constructor Arguments

Argument Description
maxiter Maximum number of iterations (default 10).
ftol, gtol Misfit and gradient tolerances.
step0 Initial step length.
verbose If True, prints progress information.
callback Optional hook callback(iteration, model, misfit, gradients).

fwi Method

model_opt, f_opt, info = optimizer.fwi(
    physics,
    dataset,
    model0,
    *,
    bounds=None,
    batch_sampler=None,
)
Parameter Description
physics DevitoPhysics instance.
dataset Dataset or list of SeismicData.
model0 Starting WaveModel. A deep copy is stored internally.
bounds Dict mapping parameter names to (lower, upper) floats. Missing names remain unbounded.
batch_sampler Callable batch_sampler(dataset) returning a subset. If None, the entire dataset is used each iteration.

info matches scipy.optimize conventions (nit, message, etc.).

Back to top