Version:

salvus.project.components.inversion_component

salvus.project.components.inversion_component salvus project components inversion_component
The inversion component.

Classes

InversionComponent

Project subclass handling inverse problems.
SIGNATURE
class InversionComponent(builtins.object):
    def __init__(self, project: Project): ...
ARGUMENTS
Required
project
Type:Project
Description:
The project for the component.

Methods

InversionComponent.add_events()
Add events to an inverse problem. The events have to exist in the project already.
SIGNATURE
def add_events(
    self,
    inverse_problem_configuration: str,
    events: str | typing.Sequence[str],
) -> None: ...
ARGUMENTS
Required
inverse_problem_configuration
Type:str
Description:
The inverse problem.
Required
events
Type:str | typing.Sequence[str]
Description:
Event name or list of event names.
InversionComponent.add_iteration()
Add a new iteration to an inverse problem. All components that are not specified directly are either inherited from the parent iteration (if provided) or from the inverse problem.
SIGNATURE
def add_iteration(
    self,
    inverse_problem_configuration: str,
    model: str | None = None,
    events: typing.Sequence[str] | None = None,
    control_group_events: typing.Sequence[str] | None = None,
    misfit_configuration: str | None = None,
    parent_id: int | None = None,
    comm: int | None = None,
    timer: Timer | None = None,
    log_to_logger: bool = False,
) -> bool: ...
ARGUMENTS
Required
inverse_problem_configuration
Type:str
Description:
The inverse problem.
Optional
model
Type:str | None
Default value:None
Description:
The model of the iteration. If not provided either the final model from the parent iteration or the prior model of the inverse problem is used.
Optional
events
Type:typing.Sequence[str] | None
Default value:None
Description:
Iteration-specific event selection.
Optional
control_group_events
Type:typing.Sequence[str] | None
Default value:None
Description:
Iteration-specific control group.
Optional
misfit_configuration
Type:str | None
Default value:None
Description:
Name of the misfit configuration.
Optional
parent_id
Type:int | None
Default value:None
Description:
Id of the parent iteration that this iteration should be derived from.
Optional
comm
Type:int | None
Default value:None
Description:
MPI communicator for distributed operations, if applicable.
Optional
timer
Type:Timer | None
Default value:None
Description:
Execution timer.
Optional
log_to_logger
Type:bool
Default value:False
Description:
Log timings to logger.
InversionComponent.delete()
Delete an inverse problem. Attention: This will remove all associated models and can lead to significant data loss.
SIGNATURE
def delete(self, inverse_problem_name: str) -> None: ...
ARGUMENTS
Required
inverse_problem_name
Type:str
Description:
The inverse problem to be deleted.
InversionComponent.delete_disposable_files()
Delete files such as waveforms, gradients or auxiliary files that are not strictly required to continue the inversion, or can be recomputed if needed.
SIGNATURE
def delete_disposable_files(
    self,
    inverse_problem_configuration: str | InverseProblemConfiguration,
    iteration_id: int | None = None,
    data_to_remove: str | typing.Sequence[str] = "auxiliary",
    keep_data_from_first_iteration: bool = True,
    keep_data_from_unfinished_iterations: bool = True,
    comm: int | None = None,
) -> None: ...
ARGUMENTS
Required
inverse_problem_configuration
Type:str | InverseProblemConfiguration
Description:
The inverse problem.
Optional
iteration_id
Type:int | None
Default value:None
Description:
Optional iteration ID. If not specified, disposable files from all finished iterations except the initial model will be deleted.
Optional
data_to_remove
Type:str | typing.Sequence[str]
Default value:'auxiliary'
Description:
Specify which data to delete. Can be either all for all that can be recomputed, or any combination of auxiliary, waveforms, and gradients. Note that waveforms are cheaper to recompute than gradients and should be deleted second after auxiliary files.
Optional
keep_data_from_first_iteration
Type:bool
Default value:True
Description:
Option to also remove data from iterations without a parent id. If True, the files of the initial iteration will be kept.
Optional
keep_data_from_unfinished_iterations
Type:bool
Default value:True
Description:
Option to also remove data from unfinished iterations, including the current one. Running this function with False is recommended when finishing an inversion.
Optional
comm
Type:int | None
Default value:None
Description:
MPI communicator, if any.
InversionComponent.delete_iteration()
Delete an iteration.
SIGNATURE
def delete_iteration(
    self, inverse_problem_configuration: str, id: int
) -> None: ...
ARGUMENTS
Required
inverse_problem_configuration
Type:str
Description:
The inverse problem.
Required
id
Type:int
Description:
Id of the iteration to be deleted.
InversionComponent.get_iteration()
Get the iteration object from an inverse problem configuration and index.
SIGNATURE
def get_iteration(
    self, inverse_problem_configuration: str, iteration_id: int
) -> Iteration: ...
ARGUMENTS
Required
inverse_problem_configuration
Type:str
Description:
The inverse problem.
Required
iteration_id
Type:int
Description:
Iteration ID.
InversionComponent.get_iteration_directory()
Get the directory containing all the models of an iteration.
SIGNATURE
def get_iteration_directory(
    self,
    inverse_problem_configuration: str | InverseProblemConfiguration,
    iteration_id: int,
) -> pathlib.Path: ...
ARGUMENTS
Required
inverse_problem_configuration
Type:str | InverseProblemConfiguration
Description:
The inverse problem.
Required
iteration_id
Type:int
Description:
Iteration ID.
InversionComponent.get_misfits()
Retrieves aggregated misfit values for specified inverse problems and events.
This function aggregates misfit values across different events for each inversion problem. The aggregation can be either a sum or a mean, based on the misfit_type. It supports filtering by specific inversions and events.
If combine_event_misfits is True and no events are found for an inversion, and empty list is returned as the misfit array for that inversion. If combine_event_misfits is False, empty dictionaries will be returned per inversion for which no events are found.
SIGNATURE
def get_misfits(
    self,
    inversions: typing.Sequence[str] | None = None,
    combine_event_misfits: bool = False,
    events: typing.Sequence[str] | None = None,
    misfit_type: typing.Literal[
        "absolute", "relative", "iteration_relative"
    ] = "absolute",
) -> dict[str, npt.NDArray] | dict[str, dict[str, npt.NDArray]]: ...
ARGUMENTS
Optional
inversions
Type:typing.Sequence[str] | None
Default value:None
Description:
An optional sequence of inversion problem identifiers. If None, misfits for all inversions are retrieved.
Optional
combine_event_misfits
Type:bool
Default value:False
Description:
A flag indicating whether to aggregate misfits across events. If True, misfits for each inversion are combined into a single value per inversion; otherwise, misfits are returned per event per inversion. This will raise a ValueError if used in conjuction with iteration-dependent event selections.
Optional
events
Type:typing.Sequence[str] | None
Default value:None
Description:
An optional sequence of event identifiers. If None, misfits for all events are retrieved.
Optional
misfit_type
Type:typing.Literal['absolute', 'relative', 'iteration_relative']
Default value:'absolute'
Description:
Specifies the type of misfit calculation. Can be 'absolute', 'relative', or 'iteration_relative'.
InversionComponent.get_model()
Obtain the model of an iteration as unstructured mesh.
SIGNATURE
def get_model(
    self,
    inverse_problem_configuration: str | InverseProblemConfiguration,
    iteration_id: int,
) -> UnstructuredMesh: ...
ARGUMENTS
Required
inverse_problem_configuration
Type:str | InverseProblemConfiguration
Description:
The inverse problem.
Required
iteration_id
Type:int
Description:
Iteration ID.
InversionComponent.get_simulation_name()
Get the name of the simulation configuration that belongs to an iteration.
SIGNATURE
def get_simulation_name(
    self,
    inverse_problem_configuration: str | InverseProblemConfiguration,
    iteration_id: int,
) -> str: ...
ARGUMENTS
Required
inverse_problem_configuration
Type:str | InverseProblemConfiguration
Description:
The inverse problem.
Required
iteration_id
Type:int
Description:
Iteration ID.
InversionComponent.iterate()
Run or continue an iteration until a model update has been computed successfully. The function can be called on any state of the iteration. In particular, if the previous attempt reached the time limit, repeated calls to this function will continue with the iteration where it stopped the last time.
SIGNATURE
def iterate(
    self,
    inverse_problem_configuration: str | InverseProblemConfiguration,
    timeout_in_seconds: salvus._core.types.float_,
    ping_interval_in_seconds: salvus._core.types.float_ | None = None,
    iteration_ids: str | int | builtins.list[int] = "latest",
    delete_disposable_files: str | builtins.list[str] | None = None,
    timer: Timer | None = None,
    verbosity: int = 1,
    comm: int | None = None,
    log_to_logger: bool = False,
) -> None: ...
ARGUMENTS
Required
inverse_problem_configuration
Type:str | InverseProblemConfiguration
Description:
The inverse problem.
Required
timeout_in_seconds
Type:salvus._core.types.float_
Description:
Maximum time spent after which the function returns even if the iteration has not been completed yet.
Optional
ping_interval_in_seconds
Type:salvus._core.types.float_ | None
Default value:None
Description:
Ping interval to check for updated on the simulations.
Optional
iteration_ids
Type:str | int | builtins.list[int]
Default value:'latest'
Description:
List of iteration IDs to be processed. Alternatively, the key words latest (default, use only the latest iteration) or all (use all running iterations) can be provided.
Optional
delete_disposable_files
Type:str | builtins.list[str] | None
Default value:None
Description:
Optional cleanup stage when finalizing the iteration. Possible choices are all, or any combination of auxiliary, checkpoints, waveforms, and gradients.
Optional
timer
Type:Timer | None
Default value:None
Description:
Execution timer.
Optional
verbosity
Type:int
Default value:1
Description:
Verbosity level.
Optional
comm
Type:int | None
Default value:None
Description:
MPI communicator, if any.
Optional
log_to_logger
Type:bool
Default value:False
Description:
Whether to log timing information to the logger.
InversionComponent.list()
Get a list of all inverse problem configurations.
SIGNATURE
def list(self) -> list[str]: ...
InversionComponent.resume()
Resume with the inversion. This function steps through the optimization algorithm in sequences and returns whenever a new task that potentially requires longer compute time has been issued.
Repeated calls to this function will advance an iteration until a model update has been successfully computed.
If no iterations are specified, this function will advance all unfinished iterations of the inverse problem.
SIGNATURE
def resume(
    self,
    inverse_problem_configuration: str | InverseProblemConfiguration,
    iteration_ids: str | int | builtins.list[int] = "latest",
    verbosity: int = 2,
    timer: Timer | None = None,
    comm: int | None = None,
    log_to_logger: bool = False,
) -> bool: ...
ARGUMENTS
Required
inverse_problem_configuration
Type:str | InverseProblemConfiguration
Description:
The inverse problem.
Optional
iteration_ids
Type:str | int | builtins.list[int]
Default value:'latest'
Description:
List of iteration IDs to be processed. If not provided, all running iterations will be considered.
Optional
verbosity
Type:int
Default value:2
Description:
Verbosity level.
Optional
timer
Type:Timer | None
Default value:None
Description:
Execution timer.
Optional
comm
Type:int | None
Default value:None
Description:
MPI communicator, if any.
Optional
log_to_logger
Type:bool
Default value:False
Description:
Whether to log timing information to the logger.
InversionComponent.set_constraints()
Set or modify the stopping criteria for the inverse problem.
SIGNATURE
def set_constraints(
    self, inverse_problem_configuration: str, constraints: dict
) -> None: ...
ARGUMENTS
Required
inverse_problem_configuration
Type:str
Description:
The inverse problem.
Required
constraints
Type:dict
Description:
Dictionary of constraints. Currently supported are pointwise lower and/or upper bounds on the inversion parameters.
InversionComponent.set_job_submission_configuration()
Set or modify the job submission configuration of an inverse problem. for asynchronous tasks.
SIGNATURE
def set_job_submission_configuration(
    self,
    inverse_problem_configuration: str,
    job_submission: (
        SiteConfig
        | TaskChainSiteConfig
        | dict[str, SiteConfig | bool | dict[str, TaskChainSiteConfig]]
        | MPIExecutionConfiguration
    ),
    comm: int | None = None,
) -> None: ...
ARGUMENTS
Required
inverse_problem_configuration
Type:str
Description:
The inverse problem.
Required
job_submission
Type:SiteConfig | TaskChainSiteConfig | dict[str, SiteConfig | bool | dict[str, TaskChainSiteConfig]] | MPIExecutionConfiguration
Description:
Either a SiteConfig or a dictionary of SiteConfigs with keys forward, adjoint, and preconditioner. Alternatively it could be a TaskChainSiteConfig object or a dictionary of dictionaries with many task chain configurations on remote sites.
Optional
comm
Type:int | None
Default value:None
Description:
MPI communicator, if any.
InversionComponent.set_stopping_criteria()
Set or modify the stopping criteria for the inverse problem.
SIGNATURE
def set_stopping_criteria(
    self, inverse_problem_configuration: str, criteria: dict
) -> None: ...
ARGUMENTS
Required
inverse_problem_configuration
Type:str
Description:
The inverse problem.
Required
criteria
Type:dict
Description:
Dictionary of stopping criteria. If any of them is true, no further iterations will be added. Currently supported are max_iterations for the maximum number of iterations per branch and max_iterations_global for the maximum number of iterations in the entire inversion tree.
InversionComponent.set_wavefield_compression()
Set or modify the wavefield compression settings for computing gradients.
SIGNATURE
def set_wavefield_compression(
    self,
    inverse_problem_configuration: str,
    wavefield_compression: WavefieldCompression,
) -> None: ...
ARGUMENTS
Required
inverse_problem_configuration
Type:str
Description:
The inverse problem.
Required
wavefield_compression
Type:WavefieldCompression
Description:
Wavefield compression settings.
PAGE CONTENTS