salvus.project.components.simulation_component
SalvusProject simulation component.
Functions
get_simulation_input_file()
get_simulation_input_file()def get_simulation_input_file(
simulation_template: salvus.flow.simple_config.simulation.waveform.Waveform,
event: salvus.flow.collections.event.Event,
event_configuration: salvus.project.configuration.event_configuration.EventConfiguration,
event_dependent_mesh_masking: Optional[Callable] = None,
wavefield_compression: Optional[
salvus.flow.collections.wavefield_compression.WavefieldCompression
] = None,
extra_output_configuration: Optional[Dict[str, Any]] = None,
) -> salvus.flow.simple_config.simulation.waveform.Waveform:
...Create Salvus input file for a single event from a template.
simulation_templatesalvus.flow.simple_config.simulation.waveform.Waveform — Template for the simulation containing all non-event-dependent information, such as start/end time or a template for the boundary conditions.eventsalvus.flow.collections.event.Event — Event object to extract the source(s) and receivers from.event_configurationsalvus.project.configuration.event_configuration.EventConfiguration — EventConfiguration object.event_dependent_mesh_maskingOptional[Callable] — 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_compressionOptional[salvus.flow.collections.wavefield_compression.WavefieldCompression] — 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_configurationOptional[Dict[str, Any]] — 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: salvus.project.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.
projectsalvus.project.project.Project — The project to attach the components to.
cancel()
cancel()def cancel(
self,
simulation_configuration: Optional[str] = None,
events: Optional[
str,
Sequence[str],
salvus.flow.collections.event.Event,
Sequence[salvus.flow.collections.event.Event],
salvus.flow.collections.event_collection.EventCollection,
] = None,
misfit_configuration: Optional[
str,
salvus.project.configuration.misfit_configuration.MisfitConfiguration,
] = None,
wavefield_compression: Optional[
salvus.flow.collections.wavefield_compression.WavefieldCompression
] = 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_configurationOptional[str] — Name of the simulation configuration.eventsOptional[str, Sequence[str], salvus.flow.collections.event.Event, Sequence[salvus.flow.collections.event.Event], salvus.flow.collections.event_collection.EventCollection] — One or more events.misfit_configurationOptional[str, salvus.project.configuration.misfit_configuration.MisfitConfiguration] — Optional misfit configuration to query adjoint simulationswavefield_compressionOptional[salvus.flow.collections.wavefield_compression.WavefieldCompression] — Must be given for adjoint simulations.
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: Union[
str,
salvus.project.configuration.simulation_configuration.SimulationConfiguration,
],
events: Union[
str,
Sequence[str],
salvus.flow.collections.event.Event,
Sequence[salvus.flow.collections.event.Event],
salvus.flow.collections.event_collection.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_configurationUnion[str, salvus.project.configuration.simulation_configuration.SimulationConfiguration] — The simulation configuration.eventsUnion[str, Sequence[str], salvus.flow.collections.event.Event, Sequence[salvus.flow.collections.event.Event], salvus.flow.collections.event_collection.EventCollection] — One or more events.verbosityint — Verbosity level.
delete_results()
delete_results()def delete_results(
self,
simulation_configuration: str,
events: Union[
str,
Sequence[str],
salvus.flow.collections.event.Event,
Sequence[salvus.flow.collections.event.Event],
salvus.flow.collections.event_collection.EventCollection,
],
misfit_configuration: Optional[str] = None,
wavefield_compression: Optional[
salvus.flow.collections.wavefield_compression.WavefieldCompression
] = 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.eventsUnion[str, Sequence[str], salvus.flow.collections.event.Event, Sequence[salvus.flow.collections.event.Event], salvus.flow.collections.event_collection.EventCollection] — One or more events.misfit_configurationOptional[str] — The name of the misfit configuration for deleting gradients.wavefield_compressionOptional[salvus.flow.collections.wavefield_compression.WavefieldCompression] — The wavefield compression settings for deleting gradients.verbosityint — Verbosity level.
get_adjoint_input_files()
get_adjoint_input_files()def get_adjoint_input_files(
self,
simulation_configuration: str,
misfit_configuration: Union[
str,
salvus.project.configuration.misfit_configuration.MisfitConfiguration,
],
wavefield_compression: salvus.flow.collections.wavefield_compression.WavefieldCompression,
events: Union[
str,
Sequence[str],
salvus.flow.collections.event.Event,
Sequence[salvus.flow.collections.event.Event],
salvus.flow.collections.event_collection.EventCollection,
],
skip_existing_simulations: bool = False,
verbose: bool = True,
site_name: Optional[str] = None,
ranks_per_job: Optional[int] = None,
) -> Tuple[
List[salvus.flow.simple_config.simulation.waveform.Waveform],
List[salvus.flow.collections.event.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_configurationUnion[str, salvus.project.configuration.misfit_configuration.MisfitConfiguration] — Name of the misfit configuration.wavefield_compressionsalvus.flow.collections.wavefield_compression.WavefieldCompression — The wavefield compression settings. Used to check compatibility of potentially already existing checkpoints.eventsUnion[str, Sequence[str], salvus.flow.collections.event.Event, Sequence[salvus.flow.collections.event.Event], salvus.flow.collections.event_collection.EventCollection] — One or more events.skip_existing_simulationsbool — If True, do not return input files for simulations that already exist as part of the project.verbosebool — Verbosity.site_nameOptional[str] — Optionally provide site name to check for remote files.ranks_per_jobOptional[int] — Optionally provide the number of ranks to check for consistent checkpoints.
get_input_files()
get_input_files()def get_input_files(
self,
simulation_configuration: Union[
str,
salvus.project.configuration.simulation_configuration.SimulationConfiguration,
salvus.project.configuration.simulation_configuration._UnstructuredMeshFileSimulationConfiguration,
],
events: Union[
str,
Sequence[str],
salvus.flow.collections.event.Event,
Sequence[salvus.flow.collections.event.Event],
salvus.flow.collections.event_collection.EventCollection,
],
skip_existing_simulations: bool = False,
derived_job_config: Optional[
salvus.flow.collections.wavefield_compression.WavefieldCompression
] = None,
verbose: bool = True,
site_name: Optional[str] = None,
ranks_per_job: Optional[int] = None,
extra_output_configuration: Optional[Dict[str, Any]] = None,
delete_conflicting_previous_results: bool = False,
allow_empty_output: bool = False,
) -> Tuple[
List[salvus.flow.simple_config.simulation.waveform.Waveform],
List[salvus.flow.collections.event.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_configurationUnion[str, salvus.project.configuration.simulation_configuration.SimulationConfiguration, salvus.project.configuration.simulation_configuration._UnstructuredMeshFileSimulationConfiguration] — Name of the simulation configuration.eventsUnion[str, Sequence[str], salvus.flow.collections.event.Event, Sequence[salvus.flow.collections.event.Event], salvus.flow.collections.event_collection.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_configOptional[salvus.flow.collections.wavefield_compression.WavefieldCompression] — 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_nameOptional[str] — Optionally provide site name to check for remote files.ranks_per_jobOptional[int] — Optionally provide the number of ranks to check for consistent checkpoints.extra_output_configurationOptional[Dict[str, Any]] — 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: Optional[salvus.flow.collections.event.Event, str] = None,
verbosity: int = 1,
) -> salvus.mesh.unstructured_mesh.UnstructuredMesh:
...Load the chosen mesh from disc or create if necessary.
simulation_configurationstr — Simulation for which to get the mesh.eventOptional[salvus.flow.collections.event.Event, str] — Optional event to retrieve an event-dependent mesh. If not given, the master mesh is returned.verbosityint — Verbosity level.
get_mesh_filenames()
get_mesh_filenames()def get_mesh_filenames(
self,
simulation_configuration: str,
event: Optional[salvus.flow.collections.event.Event, str] = None,
verbosity: int = 1,
) -> Dict[str, pathlib.Path]:
...Get mesh and XDMF filenames for a chosen simulation. Will create the mesh if it does not exist yet.
simulation_configurationstr — Simulation for which to create the mesh.eventOptional[salvus.flow.collections.event.Event, str] — Not active yet but serves as scaffolding for the future possibility to build event dependent meshes.verbosityint — Verbosity level.
get_remote_output_directory()
get_remote_output_directory()def get_remote_output_directory(
self,
simulation_configuration: str,
event: Union[str, salvus.flow.collections.event.Event],
) -> Dict[str, 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.eventUnion[str, salvus.flow.collections.event.Event] — The used event.
get_simulation_output_directory()
get_simulation_output_directory()def get_simulation_output_directory(
self,
simulation_configuration: Union[
str,
salvus.project.configuration.simulation_configuration.SimulationConfiguration,
],
event: Union[str, salvus.flow.collections.event.Event],
) -> pathlib.Path:
...Get the output directory for a given simulation.
simulation_configurationUnion[str, salvus.project.configuration.simulation_configuration.SimulationConfiguration] — The name of the simulation configuration.eventUnion[str, salvus.flow.collections.event.Event] — The used event.
get_simulation_template()
get_simulation_template()def get_simulation_template(
self,
simulation_configuration: Union[
str,
salvus.project.configuration.simulation_configuration.SimulationConfiguration,
salvus.project.configuration.simulation_configuration._UnstructuredMeshFileSimulationConfiguration,
],
events: Optional[
str,
Sequence[str],
salvus.flow.collections.event.Event,
Sequence[salvus.flow.collections.event.Event],
salvus.flow.collections.event_collection.EventCollection,
] = None,
extra_output_configuration: Optional[Dict[str, Any]] = None,
apply_waveform_simulation_configuration: bool = True,
) -> salvus.flow.simple_config.simulation.waveform.Waveform:
...Get the Salvus simulation template for a given setup.
simulation_configurationUnion[str, salvus.project.configuration.simulation_configuration.SimulationConfiguration, salvus.project.configuration.simulation_configuration._UnstructuredMeshFileSimulationConfiguration] — Simulation configuration, or name thereof.eventsOptional[str, Sequence[str], salvus.flow.collections.event.Event, Sequence[salvus.flow.collections.event.Event], salvus.flow.collections.event_collection.EventCollection] — Optionally pass a list of event to check for consistency regarding attenuation.extra_output_configurationOptional[Dict[str, Any]] — 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.
launch()
launch()def launch(
self,
simulation_configuration: str,
events: Union[
str,
Sequence[str],
salvus.flow.collections.event.Event,
Sequence[salvus.flow.collections.event.Event],
salvus.flow.collections.event_collection.EventCollection,
],
site_name: str,
ranks_per_job: int,
wall_time_in_seconds_per_job: Optional[int] = None,
derived_job_config: Optional[
salvus.flow.collections.wavefield_compression.WavefieldCompression
] = None,
store_adjoint_checkpoints: Optional[bool] = None,
verbosity: int = 2,
max_block_in_seconds: int = 0,
extra_output_configuration: Optional[Dict[str, Any]] = None,
delete_conflicting_previous_results: bool = False,
) -> int:
...Generate synthetics for one or more events.
simulation_configurationstr — Name of the simulation configuration.eventsUnion[str, Sequence[str], salvus.flow.collections.event.Event, Sequence[salvus.flow.collections.event.Event], salvus.flow.collections.event_collection.EventCollection] — One or more events.site_namestr — Site to use.ranks_per_jobint — Ranks per job.wall_time_in_seconds_per_jobOptional[int] — Wall time per job.derived_job_configOptional[salvus.flow.collections.wavefield_compression.WavefieldCompression] — 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_checkpointsOptional[bool] — Deprecated. Please use thederived_job_configparameter.verbosityint — Verbosity.max_block_in_secondsint — If set, the function will wait for the specified time for the simulations to finish.extra_output_configurationOptional[Dict[str, Any]] — 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 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: salvus.flow.collections.wavefield_compression.WavefieldCompression,
events: Union[
str,
Sequence[str],
salvus.flow.collections.event.Event,
Sequence[salvus.flow.collections.event.Event],
salvus.flow.collections.event_collection.EventCollection,
],
site_name: str,
ranks_per_job: int,
wall_time_in_seconds_per_job: Optional[int] = 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_compressionsalvus.flow.collections.wavefield_compression.WavefieldCompression — The gradient compression settings.eventsUnion[str, Sequence[str], salvus.flow.collections.event.Event, Sequence[salvus.flow.collections.event.Event], salvus.flow.collections.event_collection.EventCollection] — One or more events.site_namestr — Site to use.ranks_per_jobint — Ranks per job.wall_time_in_seconds_per_jobOptional[int] — 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, 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: Optional[str] = None,
events: Optional[
str,
Sequence[str],
salvus.flow.collections.event.Event,
Sequence[salvus.flow.collections.event.Event],
salvus.flow.collections.event_collection.EventCollection,
] = None,
misfit_configuration: Optional[
str,
salvus.project.configuration.misfit_configuration.MisfitConfiguration,
] = None,
wavefield_compression: Optional[
salvus.flow.collections.wavefield_compression.WavefieldCompression
] = None,
get_all_outputs: Optional[bool] = None,
block: bool = False,
ping_interval_in_seconds: Optional[
int, numpy.int32, numpy.int64, float, numpy.float32, numpy.float64
] = None,
raise_on_failed_jobs: bool = True,
verbosity: int = 1,
) -> bool:
...Query the status of currently ongoing simulations.
simulation_configurationOptional[str] — Name of the simulation configuration.eventsOptional[str, Sequence[str], salvus.flow.collections.event.Event, Sequence[salvus.flow.collections.event.Event], salvus.flow.collections.event_collection.EventCollection] — One or more events.misfit_configurationOptional[str, salvus.project.configuration.misfit_configuration.MisfitConfiguration] — Optional misfit configuration to query adjoint simulationswavefield_compressionOptional[salvus.flow.collections.wavefield_compression.WavefieldCompression] — Must be given for querying adjoint simulations.get_all_outputsOptional[bool] — 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_secondsOptional[int, numpy.int32, numpy.int64, float, numpy.float32, numpy.float64] — 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.