This documentation is not for the latest stable Salvus version.
import os
MIN_PERIOD = 70.0
MAX_PERIOD = 120.0
SIMULATION_TIME_IN_SECONDS = 1200.0
SALVUS_FLOW_SITE_NAME = os.environ.get("SITE_NAME", "local")
RANKS_PER_JOB = 4
PROJECT_DIR = "project_dir_central_europe"
period_band_name = f"{int(MIN_PERIOD)}_{int(MAX_PERIOD)}_seconds"
SELECTED_EVENTS = [
"event_CRETE_GREECE_Mag_6.15_2015-04-16-18-07",
"event_ICELAND_REGION_Mag_5.75_2020-06-20-19-26",
"event_STRAIT_OF_GIBRALTAR_Mag_6.38_2016-01-25-04-22",
]
# Load the project with the data from the previous parts.
from salvus import namespace as sn
p = sn.Project(path=PROJECT_DIR)
events
)misfit_configuration
)prior_model
)mapping
)method
)preconditioner
)job_submission
)InverseProblemConfiguration
collects these parameters to setup the inverse problem.
Often enough, it is hard to choose the best setting a-prior, which is why the inverse problem is constructed as a tree that allows to branch off an ongoing inversion with changed parameters, or to run several scenarios concurrently.p += sn.InverseProblemConfiguration(
name=f"inv_{period_band_name}",
events=SELECTED_EVENTS[:2],
misfit_configuration=f"tf_phase_misfit_{period_band_name}",
wavefield_compression=sn.WavefieldCompression(
forward_wavefield_sampling_interval=10
),
prior_model=f"initial_model_{period_band_name}",
mapping=sn.Mapping(
scaling="relative_deviation_from_prior",
inversion_parameters=["VSH", "VSV", "VP"],
map_to_physical_parameters={
"VPV": "VP",
"VPH": "VP",
},
source_cutout_radius_in_meters=300000,
receiver_cutout_radius_in_meters=50000,
),
method=sn.TrustRegion(initial_trust_region_linf=0.02),
preconditioner=sn.ModelDependentSmoothing(
smoothing_lengths_in_wavelengths={
"VSH": [0.2, 0.5, 0.5],
"VSV": [0.2, 0.5, 0.5],
"VP": [0.2, 0.5, 0.5],
},
reference_frequency_in_hertz=1.0 / MIN_PERIOD,
reference_model="prior",
reference_velocities={"VSH": "VSH", "VSV": "VSH", "VP": "VSH"},
),
job_submission={
"forward": sn.SiteConfig(
site_name=SALVUS_FLOW_SITE_NAME, ranks_per_job=RANKS_PER_JOB
),
"adjoint": sn.SiteConfig(
site_name=SALVUS_FLOW_SITE_NAME, ranks_per_job=RANKS_PER_JOB
),
"preconditioner": sn.SiteConfig(
site_name="local", ranks_per_job=RANKS_PER_JOB
),
},
)
p.inversions.add_iteration(
inverse_problem_configuration=f"inv_{period_band_name}"
)
[2024-03-15 09:41:25,543] INFO: Adding new iteration #0.
True
p.viz.nb.inversion(inverse_problem_configuration=f"inv_{period_band_name}")
Salvus
operates a task-based workflow.SalvusOpt
steps through an iteration, and automatically dispatches simulations whenever necessary. The function resume
will return whenever SalvusOpt
is waiting for other tasks to finish first. Calling it several time, will step through the iteration in sequence. The log messages inform about the current status and tasks.p.inversions.resume(
inverse_problem_configuration=f"inv_{period_band_name}",
)
[2024-03-15 09:41:26,309] INFO: Resuming iteration #0. Current stage: initialize [2024-03-15 09:41:26,309] INFO: 1 new tasks have been issued. [2024-03-15 09:41:26,309] INFO: Processing task `misfit_and_gradient` [2024-03-15 09:41:27,319] INFO: Submitting job array with 2 jobs ...
Uploading 1 files... Uploading 1 files... [2024-03-15 09:41:27,371] INFO: Launched adjoint simulations for 2 events. Please check again to see if they are finished. [2024-03-15 09:41:27,371] INFO: Some tasks of iteration #0 are still running. Please check again later.
p.inversions.resume(
inverse_problem_configuration=f"inv_{period_band_name}",
)
[2024-03-15 09:41:27,378] INFO: Resuming iteration #0. Current stage: check_convergence [2024-03-15 09:41:27,378] INFO: Processing task `misfit_and_gradient` [2024-03-15 09:41:27,503] INFO: 2 events have already been submitted. They will not be submitted again. [2024-03-15 09:41:27,549] INFO: Some simulations are still running. Please check again to see if they are finished. [2024-03-15 09:41:27,550] INFO: Some tasks of iteration #0 are still running. Please check again later.
p.inversions.resume(
inverse_problem_configuration=f"inv_{period_band_name}",
)
[2024-03-15 09:41:27,556] INFO: Resuming iteration #0. Current stage: check_convergence [2024-03-15 09:41:27,557] INFO: Processing task `misfit_and_gradient` [2024-03-15 09:41:27,685] INFO: 2 events have already been submitted. They will not be submitted again. [2024-03-15 09:41:27,723] INFO: Some simulations are still running. Please check again to see if they are finished. [2024-03-15 09:41:27,724] INFO: Some tasks of iteration #0 are still running. Please check again later.
p.viz.nb.inversion(
inverse_problem_configuration=f"inv_{period_band_name}",
)
Salvus
to run an entire iteration at once. Note the parameter timeout_in_seconds
, which will force the cell to return even if the iteration has not been completed yet, and there might still be a few simulations running in the back.
Again, you can execute the cell several times or mix it with calls to the previous one until the iteration is complete.p.inversions.iterate(
inverse_problem_configuration=f"inv_{period_band_name}",
timeout_in_seconds=1800,
ping_interval_in_seconds=100,
)
[2024-03-15 09:41:28,187] INFO: Resuming iteration #0. [2024-03-15 09:41:28,188] INFO: Processing task `misfit_and_gradient` [2024-03-15 09:41:28,318] INFO: 2 events have already been submitted. They will not be submitted again. [2024-03-15 09:41:28,354] INFO: Some simulations are still running. Please check again to see if they are finished. [2024-03-15 09:41:28,355] INFO: Some tasks of iteration #0 are still running. Please check again later. [2024-03-15 09:43:08,357] INFO: Processing task `misfit_and_gradient` [2024-03-15 09:43:08,507] INFO: 2 events have already been submitted. They will not be submitted again. [2024-03-15 09:43:08,562] INFO: Some simulations are still running. Please check again to see if they are finished. [2024-03-15 09:43:08,564] INFO: Some tasks of iteration #0 are still running. Please check again later. [2024-03-15 09:44:48,567] INFO: Processing task `misfit_and_gradient` [2024-03-15 09:44:48,710] INFO: 2 events have already been submitted. They will not be submitted again. [2024-03-15 09:44:48,770] INFO: Some simulations are still running. Please check again to see if they are finished. [2024-03-15 09:44:48,771] INFO: Some tasks of iteration #0 are still running. Please check again later. [2024-03-15 09:46:28,773] INFO: Processing task `misfit_and_gradient` [2024-03-15 09:46:28,902] INFO: 2 events have already been submitted. They will not be submitted again. [2024-03-15 09:46:29,394] INFO: Iteration 0: Number of events: 2 chi = 308.4717891328537 ||g|| = 1.222967280451441e-05 pred = --- ared = --- norm_update = --- tr_radius = --- [2024-03-15 09:46:29,395] INFO: 1 new tasks have been issued. [2024-03-15 09:46:29,396] INFO: Processing task `preconditioner` [2024-03-15 09:46:29,667] INFO: Some tasks of iteration #0 are still running. Please check again later. [2024-03-15 09:48:09,698] INFO: Processing task `preconditioner` [2024-03-15 09:48:09,983] INFO: 1 new tasks have been issued. [2024-03-15 09:48:09,984] INFO: Processing task `misfit` [2024-03-15 09:48:10,166] INFO: Submitting job array with 2 jobs ... [2024-03-15 09:48:10,241] INFO: Launched simulations for 2 events. Please check again to see if they are finished. [2024-03-15 09:48:10,241] INFO: Some tasks of iteration #0 are still running. Please check again later. [2024-03-15 09:49:50,342] INFO: Processing task `misfit` [2024-03-15 09:49:51,087] INFO: old misfit control group: 308.4717891328537 new misfit control group: 220.000211222491 predicted reduction control group: -44.11213423327639 actual reduction control group: -88.4715779103627 2 out of 2 event(s) improved the misfit. [2024-03-15 09:49:51,088] INFO: Model update accepted. [2024-03-15 09:49:51,088] INFO: 1 new tasks have been issued. [2024-03-15 09:49:51,088] INFO: Processing task `finalize_iteration` [2024-03-15 09:49:51,258] INFO: Succesfully completed iteration #0. [2024-03-15 09:49:51,259] INFO: Adding new iteration #1.
p.viz.nb.inversion(
inverse_problem_configuration=f"inv_{period_band_name}",
)
p.viz.nb.gradients(
simulation_configuration=f"initial_model_{period_band_name}",
misfit_configuration=f"tf_phase_misfit_{period_band_name}",
wavefield_compression=sn.WavefieldCompression(
forward_wavefield_sampling_interval=10
),
events=SELECTED_EVENTS[:2],
)