Mondaic

salvus.flow.executors.direct.simulations

salvus.flow.executors.direct.simulations salvus flow executors direct simulations

Run simulations.

Functions

run_adjoint()

def run_adjoint(
    w: simple_config.simulation.Waveform,
    mesh: Mesh | UnstructuredMesh,
    event_block: EventBlock,
    source_time_functions: list[BaseSourceTimeFunction],
    adjoint_source_callback: typing.Callable[[EventData], EventMisfit],
    wavefield_compression: WavefieldCompression | None = None,
    gradient_parameters: set[str] | None = None,
    skip_gradient_assembly: bool = False,
    event_name: str | None = None,
    cores_per_simulation: int,
    threads_per_core: int,
    _force_in_process_run: bool = False,
    _force_subprocess_run: bool = False,
    run_directory: pathlib.Path | None = None,
    mpirun_binary: pathlib.Path | None = None,
    salvus_binary: pathlib.Path | None = None,
    use_gpus: bool = False,
    environment_variables: dict[str, str] | None = None,
    keep_intermediate_data_on_disk: bool = False,
    timer: Timer | None = None,
    reentrant_timer: bool = False,
) -> tuple[float, Mesh]: ...

Run a forward simulation followed by an adjoint simulation to compute the gradient.

This function first runs a forward simulation, then calls the provided callback function with the resulting EventData to compute the misfit and adjoint sources. Finally, it runs an adjoint simulation to compute the gradient.

Parameters
  • w simple_config.simulation.Waveform — The waveform configuration.
  • mesh Mesh | UnstructuredMesh — The mesh to run the simulation on.
  • event_block EventBlock — The event block defining sources and receivers.
  • source_time_functions list[BaseSourceTimeFunction] — The source time functions to use.
  • adjoint_source_callback typing.Callable[[EventData], EventMisfit] — A callback function that takes the EventData from the forward simulation and returns an EventMisfit object containing the adjoint sources. The misfit value will be retrieved from the EventMisfit.misfit_value property.
  • wavefield_compression WavefieldCompression | None — Wavefield compression settings.
  • gradient_parameters set[str] | None — Model parameters to compute the gradients for. Must be a subset of the model parameters. If not given, gradients will be computed for all model fields.
  • skip_gradient_assembly bool — Setting for skipping the pre-assembly after gradient computation. If True, the sensitivity kernels won’t be mapped to nodal fields and scaled with the mass matrix, which will have to be done manually.
  • event_name str | None — An optional name for the event.
  • cores_per_simulation int — Number of MPI ranks to use.
  • threads_per_core int — Number of threads per MPI rank.
  • _force_in_process_run bool — Force using the in-process direct executor.
  • _force_subprocess_run bool — Force using the subprocess executor.
  • run_directory pathlib.Path | None — The directory to run the simulation in (for subprocess runs).
  • mpirun_binary pathlib.Path | None — The path to the mpirun binary (for subprocess runs).
  • salvus_binary pathlib.Path | None — The path to the Salvus binary (for subprocess runs).
  • use_gpus bool — Whether to use GPUs for the simulation. By default it will grab all available GPUs, otherwise please specify with the environment_variables.
  • environment_variables dict[str, str] | None — Optional environment variables to set for the subprocess run.
  • keep_intermediate_data_on_disk bool — Whether to keep intermediate data on disk.
  • timer Timer | None — Execution timer.
  • reentrant_timer bool — Whether the child timers should be reentrant.
Returns tuple[float, Mesh] — A tuple of (misfit, gradient) where misfit is a float and the gradient is a Mesh object.

run_diffusion()

def run_diffusion(
    diffusion_sim: simple_config.simulation.Diffusion,
    run_directory: pathlib.Path,
    cores_per_simulation: int,
    threads_per_simulation: int,
    mpirun_binary: pathlib.Path,
    salvus_binary: pathlib.Path,
    use_gpus: bool = False,
    environment_variables: dict[str, str] | None = None,
    timer: Timer | None = None,
    log_to_logger: bool = True,
    reentrant_timer: bool = False,
) -> pathlib.Path: ...

Run a diffusion simulation in a subprocess.

Parameters
  • diffusion_sim simple_config.simulation.Diffusion — The diffusion simulation configuration.
  • run_directory pathlib.Path — The directory to run the simulation in.
  • cores_per_simulation int — Number of MPI ranks to use.
  • threads_per_simulation int — Number of threads per MPI rank.
  • mpirun_binary pathlib.Path — The path to the mpirun binary.
  • salvus_binary pathlib.Path — The path to the Salvus binary.
  • use_gpus bool — Whether to use GPUs for the simulation.
  • environment_variables dict[str, str] | None — Optional environment variables to set for the subprocess.
  • timer Timer | None — Execution timer.
  • log_to_logger bool — Whether to log the subprocess output to the logger.
  • reentrant_timer bool — Whether the child timers should be reentrant.
Returns pathlib.Path — The path to the smoothed final values HDF5 file.

run_simulation()

def run_simulation(
    w: simple_config.simulation.Waveform,
    mesh: Mesh | UnstructuredMesh,
    event_block: EventBlock,
    source_time_functions: list[BaseSourceTimeFunction],
    event_name: str | None = None,
    keep_intermediate_data_on_disk: bool = False,
    cores_per_simulation: int,
    threads_per_core: int,
    _force_in_process_run: bool = False,
    _force_subprocess_run: bool = False,
    run_directory: pathlib.Path | None = None,
    mpirun_binary: pathlib.Path | None = None,
    salvus_binary: pathlib.Path | None = None,
    use_gpus: bool = False,
    environment_variables: dict[str, str] | None = None,
    timer: Timer | None = None,
    reentrant_timer: bool = False,
) -> EventData: ...

Run a simulation.

Parameters
  • w simple_config.simulation.Waveform — The waveform configuration.
  • mesh Mesh | UnstructuredMesh — The mesh to run the simulation on.
  • event_block EventBlock — The event block defining sources and receivers.
  • source_time_functions list[BaseSourceTimeFunction] — The source time functions to use.
  • event_name str | None — An optional name for the event.
  • keep_intermediate_data_on_disk bool — Whether to keep intermediate data on disk after the run. This includes the data specified in the run_directory argument.
  • cores_per_simulation int — Number of MPI ranks to use.
  • threads_per_core int — Number of threads per core.
  • _force_in_process_run bool — Force using the in-process direct executor.
  • _force_subprocess_run bool — Force using the subprocess executor.
  • run_directory pathlib.Path | None — The directory to run the simulation in (for subprocess runs).
  • mpirun_binary pathlib.Path | None — The path to the mpirun binary (for subprocess runs).
  • salvus_binary pathlib.Path | None — The path to the Salvus binary (for subprocess runs).
  • use_gpus bool — Whether to use GPUs for the simulation. By default it will grab all available GPUs, otherwise please specify with the environment_variables.
  • environment_variables dict[str, str] | None — Optional environment variables to set for the subprocess run.
  • timer Timer | None — Execution timer.
  • reentrant_timer bool — Whether the child timers should be reentrant.
Returns EventData