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],
)
p.actions.inversion.sum_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],
)
<salvus.mesh.unstructured_mesh.UnstructuredMesh at 0x7fec8825ad90>
scp
to transfer the data to your local machine.print(
p.inversions.get_iteration_directory(
inverse_problem_configuration=f"inv_{period_band_name}", iteration_id=0
).absolute()
)
/tmp/tmpzmy1cfxt/project_dir_central_europe/INVERSIONS/inv_70_120_seconds/00000
p.inversions.add_events(
f"inv_{period_band_name}",
SELECTED_EVENTS[-1],
)
previous_events = p.inversions.get_iteration(
f"inv_{period_band_name}", 0
).events
new_events = [
SELECTED_EVENTS[-1],
]
p.inversions.add_iteration(
inverse_problem_configuration=f"inv_{period_band_name}",
parent_id=0,
events=previous_events + new_events,
)
[2024-03-15 09:49:53,071] INFO: Adding new iteration #2.
True
p.inversion.iterate
will always continue on the last added iteration marked by the green edge in the inversion tree.SalvusOpt
will automatically trigger the simulation once we continue with the inversion.p.viz.nb.inversion(
inverse_problem_configuration=f"inv_{period_band_name}",
)
iterate
function and create a few more model updates.for i in range(2):
p.inversions.iterate(
inverse_problem_configuration=f"inv_{period_band_name}",
timeout_in_seconds=3600,
ping_interval_in_seconds=120,
)
[2024-03-15 09:49:53,806] INFO: Resuming iteration #2. [2024-03-15 09:49:53,806] INFO: 2 new tasks have been issued. [2024-03-15 09:49:53,807] INFO: Processing task `misfit_and_gradient` [2024-03-15 09:49:53,903] INFO: Submitting job ... [2024-03-15 09:49:53,960] INFO: Launched simulations for 1 events. Please check again to see if they are finished. [2024-03-15 09:49:53,960] INFO: Processing task `gradient` [2024-03-15 09:49:54,121] INFO: Submitting job array with 2 jobs ...
Uploading 1 files... Uploading 1 files... [2024-03-15 09:49:54,165] INFO: Launched adjoint simulations for 2 events. Please check again to see if they are finished. [2024-03-15 09:49:54,165] INFO: Some tasks of iteration #2 are still running. Please check again later. [2024-03-15 09:51:54,168] INFO: Processing task `misfit_and_gradient` [2024-03-15 09:51:54,809] INFO: Submitting job ... Uploading 1 files... 🚀 Submitted job_2403150951812639_17c0863822@local [2024-03-15 09:51:54,870] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished. [2024-03-15 09:51:54,872] INFO: Processing task `gradient` [2024-03-15 09:51:54,976] INFO: 2 events have already been submitted. They will not be submitted again. [2024-03-15 09:51:55,035] INFO: Some simulations are still running. Please check again to see if they are finished. [2024-03-15 09:51:55,036] INFO: Some tasks of iteration #2 are still running. Please check again later. [2024-03-15 09:53:55,039] INFO: Processing task `misfit_and_gradient` [2024-03-15 09:53:55,214] INFO: 1 events have already been submitted. They will not be submitted again. [2024-03-15 09:53:55,273] INFO: Some simulations are still running. Please check again to see if they are finished. [2024-03-15 09:53:55,275] INFO: Processing task `gradient` [2024-03-15 09:53:55,449] INFO: 2 events have already been submitted. They will not be submitted again. [2024-03-15 09:53:55,528] INFO: Some simulations are still running. Please check again to see if they are finished. [2024-03-15 09:53:55,530] INFO: Some tasks of iteration #2 are still running. Please check again later. [2024-03-15 09:55:55,536] INFO: Processing task `misfit_and_gradient` [2024-03-15 09:55:55,611] INFO: 1 events have already been submitted. They will not be submitted again. [2024-03-15 09:55:55,851] INFO: Processing task `gradient` [2024-03-15 09:55:55,915] INFO: 2 events have already been submitted. They will not be submitted again. [2024-03-15 09:55:56,418] INFO: Iteration 2: Number of events: 3 chi = 256.81835553496404 ||g|| = 1.1361320832462406e-05 pred = -44.11213423327639 ared = -88.4715779103627 norm_update = 9517195.57521609 tr_radius = 9517195.57521609 [2024-03-15 09:55:56,549] INFO: 1 new tasks have been issued. [2024-03-15 09:55:56,550] INFO: Processing task `preconditioner` [2024-03-15 09:55:56,857] INFO: Some tasks of iteration #2 are still running. Please check again later. [2024-03-15 09:57:56,940] INFO: Processing task `preconditioner` [2024-03-15 09:57:57,244] INFO: 1 new tasks have been issued. [2024-03-15 09:57:57,244] INFO: Processing task `misfit` [2024-03-15 09:57:57,434] INFO: Submitting job array with 3 jobs ... [2024-03-15 09:57:57,514] INFO: Launched simulations for 3 events. Please check again to see if they are finished. [2024-03-15 09:57:57,515] INFO: Some tasks of iteration #2 are still running. Please check again later. [2024-03-15 09:59:57,651] INFO: Processing task `misfit` [2024-03-15 09:59:57,728] INFO: Some tasks of iteration #2 are still running. Please check again later. [2024-03-15 10:01:57,942] INFO: Processing task `misfit` [2024-03-15 10:01:59,149] INFO: old misfit control group: 256.81835553496404 new misfit control group: 163.90660343068012 predicted reduction control group: -67.50845076105418 actual reduction control group: -92.91175210428392 3 out of 3 event(s) improved the misfit. [2024-03-15 10:01:59,149] INFO: Model update accepted. [2024-03-15 10:01:59,149] INFO: 1 new tasks have been issued. [2024-03-15 10:01:59,150] INFO: Processing task `finalize_iteration` [2024-03-15 10:01:59,447] INFO: Succesfully completed iteration #2. [2024-03-15 10:01:59,450] INFO: Adding new iteration #3. [2024-03-15 10:01:59,473] INFO: Resuming iteration #3. [2024-03-15 10:01:59,473] INFO: 1 new tasks have been issued. [2024-03-15 10:01:59,473] INFO: Processing task `gradient` [2024-03-15 10:01:59,692] INFO: Submitting job array with 3 jobs ...
Uploading 1 files... Uploading 1 files... Uploading 1 files... [2024-03-15 10:01:59,749] INFO: Launched adjoint simulations for 3 events. Please check again to see if they are finished. [2024-03-15 10:01:59,749] INFO: Some tasks of iteration #3 are still running. Please check again later. [2024-03-15 10:03:59,752] INFO: Processing task `gradient` [2024-03-15 10:03:59,876] INFO: 3 events have already been submitted. They will not be submitted again. [2024-03-15 10:03:59,947] INFO: Some simulations are still running. Please check again to see if they are finished. [2024-03-15 10:03:59,947] INFO: Some tasks of iteration #3 are still running. Please check again later. [2024-03-15 10:05:59,951] INFO: Processing task `gradient` [2024-03-15 10:06:00,136] INFO: 3 events have already been submitted. They will not be submitted again. [2024-03-15 10:06:00,228] INFO: Some simulations are still running. Please check again to see if they are finished. [2024-03-15 10:06:00,229] INFO: Some tasks of iteration #3 are still running. Please check again later. [2024-03-15 10:08:00,238] INFO: Processing task `gradient` [2024-03-15 10:08:00,525] INFO: 3 events have already been submitted. They will not be submitted again. [2024-03-15 10:08:00,673] INFO: Some simulations are still running. Please check again to see if they are finished. [2024-03-15 10:08:00,692] INFO: Some tasks of iteration #3 are still running. Please check again later. [2024-03-15 10:10:00,706] INFO: Processing task `gradient` [2024-03-15 10:10:00,820] INFO: 3 events have already been submitted. They will not be submitted again. [2024-03-15 10:10:01,536] INFO: Iteration 3: Number of events: 3 chi = 163.9066034306801 ||g|| = 1.03417046189998e-05 pred = -67.50845076105418 ared = -92.91175210428392 norm_update = 19034391.514349777 tr_radius = 19034391.15043218 [2024-03-15 10:10:01,778] INFO: 1 new tasks have been issued. [2024-03-15 10:10:01,779] INFO: Processing task `preconditioner` [2024-03-15 10:10:02,218] INFO: Some tasks of iteration #3 are still running. Please check again later. [2024-03-15 10:12:02,379] INFO: Processing task `preconditioner` [2024-03-15 10:12:02,858] INFO: 1 new tasks have been issued. [2024-03-15 10:12:02,858] INFO: Processing task `misfit` [2024-03-15 10:12:03,143] INFO: Submitting job array with 3 jobs ... [2024-03-15 10:12:03,240] INFO: Launched simulations for 3 events. Please check again to see if they are finished. [2024-03-15 10:12:03,241] INFO: Some tasks of iteration #3 are still running. Please check again later. [2024-03-15 10:14:03,563] INFO: Processing task `misfit` [2024-03-15 10:14:03,708] INFO: Some tasks of iteration #3 are still running. Please check again later. [2024-03-15 10:16:04,246] INFO: Processing task `misfit` [2024-03-15 10:16:05,560] INFO: old misfit control group: 163.90660343068012 new misfit control group: 141.75768151181185 predicted reduction control group: -17.024869272432838 actual reduction control group: -22.148921918868268 3 out of 3 event(s) improved the misfit. [2024-03-15 10:16:05,561] INFO: Model update accepted. [2024-03-15 10:16:05,561] INFO: 1 new tasks have been issued. [2024-03-15 10:16:05,561] INFO: Processing task `finalize_iteration` [2024-03-15 10:16:06,069] INFO: Succesfully completed iteration #3. [2024-03-15 10:16:06,073] INFO: Adding new iteration #4.
p.viz.nb.inversion(inverse_problem_configuration=f"inv_{period_band_name}")
p.viz.nb.misfit_comparison(
reference_data=f"initial_model_{period_band_name}",
other_data=[
p.inversions.get_simulation_name(
inverse_problem_configuration=f"inv_{period_band_name}",
iteration_id=4,
)
],
misfit_configuration=f"tf_phase_misfit_{period_band_name}",
event=SELECTED_EVENTS[-1],
)
ini... (reference) | inv... | Reduction inv... | |
---|---|---|---|
II.BORG.00 | 5.7530e+01 | 5.3255e+01 | 4.2743e+00 |
II.ESK.00 | 6.3279e+01 | 2.9680e+01 | 3.3599e+01 |
II.LVZ.00 | 3.7027e+01 | 2.1928e+01 | 1.5099e+01 |
II.OBN.00 | 3.9500e+00 | 3.1830e+00 | 7.6700e-01 |
IU.GRFO. | 5.9321e+01 | 2.0406e+01 | 3.8915e+01 |
IU.KEV.00 | 6.0323e+01 | 1.6189e+01 | 4.4134e+01 |
IU.KONO.00 | 3.6185e+01 | 2.4987e+01 | 1.1199e+01 |
IU.MACI. | 5.2442e+01 | 3.8249e+01 | 1.4193e+01 |
IU.PAB.00 | 2.5385e+00 | 1.8415e+00 | 6.9702e-01 |
<pandas.io.formats.style.Styler at 0x7fec86adeb10>
p.viz.misfit_histogram(
simulation_configuration_a=f"initial_model_{period_band_name}",
simulation_configuration_b=p.inversions.get_simulation_name(
inverse_problem_configuration=f"inv_{period_band_name}", iteration_id=4
),
misfit_configuration=f"tf_phase_misfit_{period_band_name}",
events=SELECTED_EVENTS[-1],
merge_all_components=False,
)
STRAIT_OF_GIBRALTAR
and station GB.GAL1
for a good example.
Note that only the parts of the waveforms within the shaded windows informed the inverse problem about the model space.
Interestingly, however, as we approach better models some wiggles that were not selected also match the data better now then they did initially; see station RO.BUR31
for an example.
We could make use of this, re-pick windows and then continue with more iterations and a modified MisfitConfiguration
.p.viz.nb.waveforms(
[
f"PROCESSED_DATA:{period_band_name}",
f"initial_model_{period_band_name}",
p.inversions.get_simulation_name(
inverse_problem_configuration=f"inv_{period_band_name}",
iteration_id=4,
),
],
receiver_field="displacement",
data_selection_configuration=f"initial_selection_{period_band_name}",
)