salvus.project.components.simulation_component
salvus.project.components.simulation_component salvus project components simulation_component SalvusProject simulation component.
Functions
get_simulation_input_file()
get_simulation_input_file()def get_simulation_input_file(
simulation_template: simple_config.simulation.Waveform,
event: Event,
event_configuration: EventConfiguration,
project_path: pathlib.Path,
event_dependent_mesh_masking: typing.Callable | None = None,
wavefield_compression: WavefieldCompression | None = None,
extra_output_configuration: dict[str, typing.Any] | None = None,
) -> simple_config.simulation.Waveform: ...Create Salvus input file for a single event from a template.
simulation_templatesimple_config.simulation.Waveform — Template for the simulation containing all non-event-dependent information, such as start/end time or a template for the boundary conditions.eventEvent — Event object to extract the source(s) and receivers from.event_configurationEventConfiguration — EventConfiguration object.project_pathpathlib.Path — Root path to the project.event_dependent_mesh_maskingtyping.Callable | None — Optional callback function for event- dependent mesh masking. The function signature must take the global mesh and the event as arguments. Boundary conditions will be applied automatically.wavefield_compressionWavefieldCompression | None — Options that have an effect on the output of subsequent simulations but must already be known now. Currently allows the specification of some techniques to compress wavefields for the purpose of gradient computations. Must be given for checkpoints to be generated during the forward simulation.extra_output_configurationdict[str, typing.Any] | None — Extra settings for the waveform simulations. Can only be used for settings that do not change the resulting waveforms.python extra_output_configuration={ "volume_data": { "sampling_interval_in_time_steps": 50, "fields": ["displacement"], }, "surface_data": { "sampling_interval_in_time_steps": 20, "fields": ["acceleration", "velocity"], "side_sets": ["x0", "x1"], }, "memory_per_rank_in_MB": 2000.0, }
Classes
SimulationComponent
SimulationComponentclass SimulationComponent(builtins.object):
def __init__(self, project: Project): ...Project subclass dealing with all things related to simulations. This explicitly includes meshes as for the project they largely exist for the purpose of simulations.
projectProject — The project to attach the components to.
cancel()
cancel()def cancel(
self,
simulation_configuration: str | None = None,
events: (
str
| typing.Sequence[str]
| Event
| typing.Sequence[Event]
| EventCollection
| None
) = None,
misfit_configuration: str | MisfitConfiguration | None = None,
wavefield_compression: WavefieldCompression | None = None,
gradient_parameters: set[str] | None = None,
) -> None: ...Cancel ongoing or pending simulations. Note that if simulations for
several events have been simultaneously submitted using
simulations.launch(), all jobs in this job array will be cancelled.
simulation_configurationstr | None — Name of the simulation configuration.eventsstr | typing.Sequence[str] | Event | typing.Sequence[Event] | EventCollection | None — One or more events.misfit_configurationstr | MisfitConfiguration | None — Optional misfit configuration to query adjoint simulationswavefield_compressionWavefieldCompression | None — Must be given for adjoint simulations.gradient_parametersset[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.
cancel_all()
cancel_all()def cancel_all(self) -> None: ...Cancel all running simulations.
All currently launched simulations that have not finished yet will be cancelled.
clear_simulation_store()
clear_simulation_store()def clear_simulation_store(self) -> None: ...Remove all items from the simulation store. Try to delete dangling jobs on remote sites.
delete_jobs()
delete_jobs()def delete_jobs(
self,
simulation_configuration: str | SimulationConfiguration,
events: (
str
| typing.Sequence[str]
| Event
| typing.Sequence[Event]
| EventCollection
),
verbosity: int = 0,
) -> None: ...Manually delete the jobs associated with a simulation configuration
and events. By default, this happens automatically, when all remote
output is downloaded with query() unless there still exists remote
data.
simulation_configurationstr | SimulationConfiguration — The simulation configuration.eventsstr | typing.Sequence[str] | Event | typing.Sequence[Event] | EventCollection — One or more events.verbosityint — Verbosity level.
delete_results()
delete_results()def delete_results(
self,
simulation_configuration: str,
events: (
str
| typing.Sequence[str]
| Event
| typing.Sequence[Event]
| EventCollection
),
misfit_configuration: str | None = None,
wavefield_compression: WavefieldCompression | None = None,
gradient_parameters: set[str] | None = None,
verbosity: int = 1,
) -> int: ...Delete simulation results (waveforms, gradients, …). The function does not delete the configuration, but only simulated data. Those data can be recomputed if necessary.
simulation_configurationstr — The name of the simulation configuration.eventsstr | typing.Sequence[str] | Event | typing.Sequence[Event] | EventCollection — One or more events.misfit_configurationstr | None — The name of the misfit configuration for deleting gradients.wavefield_compressionWavefieldCompression | None — The wavefield compression settings for deleting gradients.gradient_parametersset[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.verbosityint — Verbosity level.
get_adjoint_input_files()
get_adjoint_input_files()def get_adjoint_input_files(
self,
simulation_configuration: str,
misfit_configuration: str | MisfitConfiguration,
wavefield_compression: WavefieldCompression,
gradient_parameters: set[str] | None,
events: (
str
| typing.Sequence[str]
| Event
| typing.Sequence[Event]
| EventCollection
),
skip_gradient_assembly: bool = False,
skip_existing_simulations: bool = False,
verbose: bool = True,
site_name: str | None = None,
ranks_per_job: salvus._core.types.int_ | None = None,
) -> tuple[
list[simple_config.simulation.Waveform], list[Event], dict[str, str]
]: ...Create Salvus input files for adjoint simulations for one or more events.
This is largely useful for custom workflows - if you want to simulate
and remain fully inside SalvusProject, please use the
.launch_adjoint() method.
Returns a tuple of the list of input files and the list of events for
the input files. If skip_existing_simulations is True that list
might be a subset of the input list.
simulation_configurationstr — Name of the simulation configuration for the forward run.misfit_configurationstr | MisfitConfiguration — Name of the misfit configuration.wavefield_compressionWavefieldCompression — The wavefield compression settings. Used to check compatibility of potentially already existing checkpoints.gradient_parametersset[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.eventsstr | typing.Sequence[str] | Event | typing.Sequence[Event] | EventCollection — One or more events.skip_gradient_assemblybool — 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.skip_existing_simulationsbool — If True, do not return input files for simulations that already exist as part of the project.verbosebool — Verbosity.site_namestr | None — Optionally provide site name to check for remote files.ranks_per_jobsalvus._core.types.int_ | None — Optionally provide the number of ranks to check for consistent checkpoints.
get_input_files()
get_input_files()def get_input_files(
self,
simulation_configuration: str | _SimulationConfigurationBase,
events: (
str
| typing.Sequence[str]
| Event
| typing.Sequence[Event]
| EventCollection
),
skip_existing_simulations: bool = False,
derived_job_config: WavefieldCompression | None = None,
verbose: bool = True,
site_name: str | None = None,
ranks_per_job: salvus._core.types.int_ | None = None,
extra_output_configuration: dict[str, typing.Any] | None = None,
delete_conflicting_previous_results: bool = False,
allow_empty_output: bool = False,
) -> tuple[
list[simple_config.simulation.Waveform], list[Event], dict[str, str]
]: ...Create Salvus input files for one or more events.
This is largely useful for custom workflows - if you want to simulate
and remain fully inside SalvusProject, please use the .launch()
method.
Returns a tuple of the list of input files and the list of events for
the input files. If skip_existing_simulations is True that list
might be a subset of the input list.
simulation_configurationstr | _SimulationConfigurationBase — Name of the simulation configuration.eventsstr | typing.Sequence[str] | Event | typing.Sequence[Event] | EventCollection — One or more events. If not given, it will return a generic input file without any sources or receivers.skip_existing_simulationsbool — If True, do not return input files for simulations that already exist as part of the project.derived_job_configWavefieldCompression | None — Options that have an effect on the output of subsequent simulations but must already be known now. Currently allows the specification of some techniques to compress wavefields for the purpose of gradient computations. Must be given for checkpoints to be generated during the forward simulation.verbosebool — Verbosity.site_namestr | None — Optionally provide site name to check for remote files.ranks_per_jobsalvus._core.types.int_ | None — Optionally provide the number of ranks to check for consistent checkpoints.extra_output_configurationdict[str, typing.Any] | None — Extra settings for the waveform simulations. Can only be used for settings that do not change the resulting waveforms.python extra_output_configuration={ "volume_data": { "sampling_interval_in_time_steps": 50, "fields": ["displacement"], }, "surface_data": { "sampling_interval_in_time_steps": 20, "fields": ["acceleration", "velocity"], "side_sets": ["x0", "x1"], }, "memory_per_rank_in_MB": 2000.0, }delete_conflicting_previous_resultsbool — If skip_existing_simulations is True, simulations with existing results but different extra_output_configurations would cause an error. If this options is set to True, it will delete the potentially conflicting existing results.allow_empty_outputbool — By default, this method will raise a ValueError if one attempts to get an input file for an event that would have no output at all. This argument overwrites that which is useful for example for visualization purposes.
get_mesh()
get_mesh()def get_mesh(
self,
simulation_configuration: str,
event: Event | str | None = None,
verbosity: int = 1,
execution_policy: bindings.ExecutionPolicy = salvus._core.lib.salvus_core_python_bindings.ExecutionPolicy,
skip_validation: bool = True,
comm: int | None = None,
) -> UnstructuredMesh | DistributedMesh: ...Load the chosen mesh from disk or create if necessary.
simulation_configurationstr — Simulation for which to get the mesh.eventEvent | str | None — Optional event to retrieve an event-dependent mesh. If not given, the master mesh is returned.verbosityint — Verbosity level.execution_policybindings.ExecutionPolicy — Execution policy governing the maximum allowable parallelism of child routines.skip_validationbool — Whether to skip mesh quality control after mesh creation. Will only trigger if the mesh has not been created yet.commint | None — MPI communicator for distributed mesh loading.
get_mesh_filenames()
get_mesh_filenames()def get_mesh_filenames(
self,
simulation_configuration: str,
event: Event | str | None = None,
verbosity: int = 1,
execution_policy: bindings.ExecutionPolicy = salvus._core.lib.salvus_core_python_bindings.ExecutionPolicy,
skip_validation: bool = True,
) -> dict[str, pathlib.Path]: ...Get mesh and XDMF filenames for a chosen simulation.
This will create the mesh if it does not exist yet, for now in legacy
mode (i.e. as an UnstructuredMesh object).
The XDMF file will not exist for the minimal and minimal_fast mesh
file modes.
simulation_configurationstr — Simulation for which to create the mesh.eventEvent | str | None — Not active yet but serves as scaffolding for the future possibility to build event dependent meshes.verbosityint — Verbosity level.execution_policybindings.ExecutionPolicy — Execution policy governing the maximum allowable parallelism of child routines.skip_validationbool — Whether to skip mesh quality control after mesh creation. Will only trigger if the mesh has not been created yet.
get_remote_output_directory()
get_remote_output_directory()def get_remote_output_directory(
self, simulation_configuration: str, event: str | Event
) -> dict[str, typing.Any]: ...Get the remote output directory for a given simulation. The function does not check if the remote data still exist.
simulation_configurationstr — The name of the simulation configuration.eventstr | Event — The used event.
get_simulation_output_directories()
get_simulation_output_directories()def get_simulation_output_directories(
self,
simulation_configuration: str | _SimulationConfigurationBase,
events: (
str
| typing.Sequence[str]
| Event
| typing.Sequence[Event]
| EventCollection
),
) -> dict[str, pathlib.Path]: ...Get the output directories for a given simulation and a list of events.
simulation_configurationstr | _SimulationConfigurationBase — The name of the simulation configuration.eventsstr | typing.Sequence[str] | Event | typing.Sequence[Event] | EventCollection — One or several events.
get_simulation_output_directory()
get_simulation_output_directory()def get_simulation_output_directory(
self,
simulation_configuration: str | _SimulationConfigurationBase,
event: str | Event,
) -> pathlib.Path: ...Get the output directory for a given simulation.
simulation_configurationstr | _SimulationConfigurationBase — The name of the simulation configuration.eventstr | Event — The used event.
get_simulation_template()
get_simulation_template()def get_simulation_template(
self,
simulation_configuration: str | _SimulationConfigurationBase,
events: (
str
| typing.Sequence[str]
| Event
| typing.Sequence[Event]
| EventCollection
| None
) = None,
extra_output_configuration: dict[str, typing.Any] | None = None,
apply_waveform_simulation_configuration: bool = True,
execution_policy: bindings.ExecutionPolicy = salvus._core.lib.salvus_core_python_bindings.ExecutionPolicy,
) -> simple_config.simulation.Waveform: ...Get the Salvus simulation template for a given setup.
simulation_configurationstr | _SimulationConfigurationBase — Simulation configuration, or name thereof.eventsstr | typing.Sequence[str] | Event | typing.Sequence[Event] | EventCollection | None — Optionally pass a list of event to check for consistency regarding attenuation.extra_output_configurationdict[str, typing.Any] | None — Extra settings for the waveform simulations. Can only be used for settings that do not change the resulting waveforms.python extra_output_configuration={ "volume_data": { "sampling_interval_in_time_steps": 50, "fields": ["displacement"], }, "surface_data": { "sampling_interval_in_time_steps": 20, "fields": ["acceleration", "velocity"], "side_sets": ["x0", "x1"], }, "memory_per_rank_in_MB": 2000.0, }apply_waveform_simulation_configurationbool — Apply the waveform simulation configuration before returning the template. A ValueError will be raised in case the waveform simulation configuration is event-dependent.execution_policybindings.ExecutionPolicy — Execution policy governing the maximum allowable parallelism of child routines.
launch()
launch()def launch(
self,
simulation_configuration: str,
events: (
str
| typing.Sequence[str]
| Event
| typing.Sequence[Event]
| EventCollection
),
site_name: str,
ranks_per_job: salvus._core.types.int_,
wall_time_in_seconds_per_job: salvus._core.types.float_ | None = None,
derived_job_config: WavefieldCompression | None = None,
store_adjoint_checkpoints: bool | None = None,
verbosity: salvus._core.types.int_ = 2,
max_block_in_seconds: salvus._core.types.float_ = 0,
extra_output_configuration: dict[str, typing.Any] | None = None,
delete_conflicting_previous_results: bool = False,
) -> int: ...Generate synthetics for one or more events.
simulation_configurationstr — Name of the simulation configuration.eventsstr | typing.Sequence[str] | Event | typing.Sequence[Event] | EventCollection — One or more events.site_namestr — Site to use.ranks_per_jobsalvus._core.types.int_ — Ranks per job.wall_time_in_seconds_per_jobsalvus._core.types.float_ | None — Wall time per job.derived_job_configWavefieldCompression | None — Options that have an effect on the output of subsequent simulations but must already be known now. Currently allows the specification of some techniques to compress wavefields for the purpose of gradient computations.store_adjoint_checkpointsbool | None — Deprecated. Please use thederived_job_configparameter.verbositysalvus._core.types.int_ — Verbosity.max_block_in_secondssalvus._core.types.float_ — If set, the function will wait for the specified time for the simulations to finish.extra_output_configurationdict[str, typing.Any] | None — Extra settings for the waveform simulations. Can only be used for settings that do not change the resulting waveforms. Forvolume_dataandsurface_data, the output cadence can be given either as an explicitsampling_interval_in_time_stepsor as an approximatenumber_of_snapshots. In the latter case the sampling interval is computed automatically from the simulation’s time step and duration so that roughly that many snapshots are written.python extra_output_configuration={ "volume_data": { "sampling_interval_in_time_steps": 50, "fields": ["displacement"], }, "surface_data": { "number_of_snapshots": 200, "fields": ["acceleration", "velocity"], "side_sets": ["x0", "x1"], }, "memory_per_rank_in_MB": 2000.0, }delete_conflicting_previous_resultsbool — If data for an event but a different extra_output_configuration already exists, an error will be raised. If this option is set to True, it will delete pre-existing conflicting output. Use with caution, as this can delete expensive-to-compute outputs.
launch_adjoint()
launch_adjoint()def launch_adjoint(
self,
simulation_configuration: str,
misfit_configuration: str,
wavefield_compression: WavefieldCompression,
gradient_parameters: set[str] | None,
events: (
str
| typing.Sequence[str]
| Event
| typing.Sequence[Event]
| EventCollection
),
site_name: str,
ranks_per_job: int,
skip_gradient_assembly: bool = False,
wall_time_in_seconds_per_job: salvus._core.types.float_ | None = None,
verbosity: bool = True,
max_block_in_seconds: int = 0,
) -> int: ...Launch adjoint simulations for one or more events.
simulation_configurationstr — Name of the simulation configuration for the forward run.misfit_configurationstr — Name of the misfit configuration.wavefield_compressionWavefieldCompression — The gradient compression settings.gradient_parametersset[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.eventsstr | typing.Sequence[str] | Event | typing.Sequence[Event] | EventCollection — One or more events.site_namestr — Site to use.ranks_per_jobint — Ranks per job.skip_gradient_assemblybool — 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.wall_time_in_seconds_per_jobsalvus._core.types.float_ | None — Wall time per job.verbositybool — Verbosity.max_block_in_secondsint — If set, the function will wait for the specified time for the simulations to finish.
list()
list()def list(self) -> list[str]: ...Get a list of all simulation configurations.
list_events()
list_events()def list_events(
self, simulation_configuration: str, verbosity: int = 1
) -> dict[str, typing.Any]: ...Return all event names known for this simulation configuration.
simulation_configurationstr — Name of the simulation configuration.verbosityint — Verbosity level.
query()
query()def query(
self,
simulation_configuration: str | None = None,
events: (
str
| typing.Sequence[str]
| Event
| typing.Sequence[Event]
| EventCollection
| None
) = None,
misfit_configuration: str | MisfitConfiguration | None = None,
wavefield_compression: WavefieldCompression | None = None,
gradient_parameters: set[str] | None = None,
get_all_outputs: bool | None = None,
block: bool = False,
ping_interval_in_seconds: salvus._core.types.float_ | None = None,
raise_on_failed_jobs: bool = True,
verbosity: int = 1,
) -> bool: ...Query the status of currently ongoing simulations.
simulation_configurationstr | None — Name of the simulation configuration.eventsstr | typing.Sequence[str] | Event | typing.Sequence[Event] | EventCollection | None — One or more events.misfit_configurationstr | MisfitConfiguration | None — Optional misfit configuration to query adjoint simulationswavefield_compressionWavefieldCompression | None — Must be given for querying adjoint simulations.gradient_parametersset[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.get_all_outputsbool | None — Optional flag to skip the download of large output files. If not set, checkpoints will remain on the remote site, while all other outputs are downloaded. IfFalse, the data can manually be downloaded usingEventData.download_extra_outputs().blockbool — IfTrue, wait for all simulations to finish.ping_interval_in_secondssalvus._core.types.float_ | None — Update interval of the status of the jobs ifblock=True.raise_on_failed_jobsbool — IfTrue, querying failed or cancelled jobs will raise an error. When set to false, errors for the failed jobs will be retrieved and printed in the in the widget, but no error will be thrown.verbosityint — Verbosity level. Negative values hide the widget.
run()
run()def run(
self,
simulation_configuration: str,
events: (
str
| typing.Sequence[str]
| Event
| typing.Sequence[Event]
| EventCollection
),
site_config: (
SiteConfig
| TaskChainSiteConfig
| dict[str, TaskChainSiteConfig]
| MPIExecutionConfiguration
),
timer: Timer | None = None,
) -> None: ...Run simulations for a selection of events, wait for them to finish, and add the results to the project.
This function only returns after all simulations have been completed.
For an asynchronous options, use launch() instead.
simulation_configurationstr — Name of the simulation configuration.eventsstr | typing.Sequence[str] | Event | typing.Sequence[Event] | EventCollection — One or more events.site_configSiteConfig | TaskChainSiteConfig | dict[str, TaskChainSiteConfig] | MPIExecutionConfiguration — The site configuration and job submission settings.timerTimer | None — Execution timer.
Used in tutorials
- 2-D Global-scale simulations w/ heterogeneous models
- 3D-to-2D Conversion
- Acoustic simulations in isotropic and anisotropic media
- Attenuation
- Conical Pitting
- Continental Scale FWI - Part 2: Forward simulations
- Continental Scale FWI Tutorial - Part 3: Data selection and misfit definition
- Continental-scale Simulations
- Creating and plotting custom gathers from Salvus' receiver outputs
- Equivalence of Filtering STFs and Filtering Synthetics
- External 2D Meshes
- External 3D Meshes
- Full-Waveform Inversion
- Full-Waveform Inversion
- Full-Waveform Inversion