This documentation is not for the latest stable Salvus version.
%matplotlib inline
%config Completer.use_jedi = False
import os
SALVUS_FLOW_SITE_NAME = os.environ.get("SITE_NAME", "local")
scaling="homogeneous"
in the mapping
function of an InverseProblemConfiguration
enables inversion for homogeneous model parameters with full-waveform inversion.sn.Mapping( scaling="homogeneous", inversion_parameters=[...], ... )
import matplotlib.pyplot as plt
import numpy as np
import pathlib
import time
import xarray as xr
import salvus.namespace as sn
p = sn.Project.from_domain(
path="project",
domain=sn.domain.dim2.BoxDomain(
x0=0.0,
x1=1.0,
y0=0.0,
y1=1.5,
),
load_if_exists=True,
)
src = sn.simple_config.source.cartesian.VectorPoint2D(
x=0.33, y=0.0, fx=0.0, fy=1.0e9
)
rec = sn.simple_config.receiver.cartesian.Point2D(
x=0.67,
y=1.5,
fields=["displacement"],
network_code="REC",
station_code="000",
)
p += sn.Event(event_name="event", sources=src, receivers=rec)
ec = sn.EventConfiguration(
waveform_simulation_configuration=sn.WaveformSimulationConfiguration(
end_time_in_seconds=0.0006
),
wavelet=sn.simple_config.stf.Ricker(center_frequency=10000.0),
)
p.viz.nb.domain()
vp
, vs
and rho
. Note that the deviations in the parameters have opposite signs and different magnitudes.true_model = sn.model.background.homogeneous.IsotropicElastic(
vp=5800.0, vs=3200.0, rho=2600.0
)
initial_model = sn.model.background.homogeneous.IsotropicElastic(
vp=5600.0, vs=3300.0, rho=2400.0
)
for name, model in zip(["true", "init"], [true_model, initial_model]):
p.add_to_project(
sn.SimulationConfiguration(
name=name,
elements_per_wavelength=2,
tensor_order=1,
max_frequency_in_hertz=20000.0,
model_configuration=sn.ModelConfiguration(background_model=model),
event_configuration=ec,
),
overwrite=True,
)
p.simulations.launch(
simulation_configuration=name,
events=p.events.get_all(),
site_name=SALVUS_FLOW_SITE_NAME,
ranks_per_job=1,
)
[2023-07-03 12:25:24,689] INFO: Creating mesh. Hang on. <class 'salvus.project.configuration.model.background.homogeneous.IsotropicElastic'> [2023-07-03 12:25:25,245] INFO: Submitting job ... Uploading 1 files... 🚀 Submitted job_2307031225374430_8fec9fe3dd@local [2023-07-03 12:25:25,562] INFO: Creating mesh. Hang on. <class 'salvus.project.configuration.model.background.homogeneous.IsotropicElastic'> [2023-07-03 12:25:25,852] INFO: Submitting job ... Uploading 1 files... 🚀 Submitted job_2307031225857573_f31e70ad6e@local
p.simulations.query(block=True)
True
p.viz.nb.waveforms(data=["true", "init"], receiver_field="displacement")
scaling="homogeneous"
in the mapping function, which enforces a homogeneous medium in every iteration. Note that a smoothing preconditioner is not necessary here, because the mapped gradient is already homogeneous.p += sn.MisfitConfiguration(
name="L2",
observed_data="true",
misfit_function="L2",
receiver_field="displacement",
)
p += sn.InverseProblemConfiguration(
name="inversion",
prior_model="init",
events=p.events.list(),
mapping=sn.Mapping(
scaling="homogeneous",
inversion_parameters=["VP", "VS", "RHO"],
),
method=sn.TrustRegion(initial_trust_region_linf=100.0),
misfit_configuration="L2",
job_submission=sn.SiteConfig(
site_name=SALVUS_FLOW_SITE_NAME, ranks_per_job=1
),
)
for i in range(10):
p.inversions.iterate(
inverse_problem_configuration="inversion",
timeout_in_seconds=360,
ping_interval_in_seconds=1,
)
[2023-07-03 12:25:27,000] INFO: Adding new iteration #0. [2023-07-03 12:25:27,022] INFO: Resuming iteration #0. [2023-07-03 12:25:27,029] INFO: 1 new tasks have been issued. [2023-07-03 12:25:27,030] INFO: Processing task `misfit_and_gradient` [2023-07-03 12:25:27,056] INFO: The following events have been simulated before, but checkpoints are not available for this combination of `site_name` and `ranks_per_job` and wavefield compression settings. They will be run again: ['event'] [2023-07-03 12:25:27,073] INFO: Submitting job ... [2023-07-03 12:25:27,144] INFO: Launched simulations for 1 events. Please check again to see if they are finished. [2023-07-03 12:25:27,145] INFO: Some tasks of iteration #0 are still running. Please check again later. [2023-07-03 12:25:28,148] INFO: Processing task `misfit_and_gradient` [2023-07-03 12:25:28,550] INFO: Submitting job ... [2023-07-03 12:25:28,615] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished. [2023-07-03 12:25:28,616] INFO: Some tasks of iteration #0 are still running. Please check again later. [2023-07-03 12:25:29,620] INFO: Processing task `misfit_and_gradient` [2023-07-03 12:25:29,755] INFO: 1 events have already been submitted. They will not be submitted again. [2023-07-03 12:25:29,921] INFO: Iteration 0: Number of events: 1 chi = 3.7156536966723097e-10 ||g|| = 3.3910356819472767e-12 pred = --- ared = --- norm_update = --- tr_radius = --- [2023-07-03 12:25:29,926] INFO: 1 new tasks have been issued. [2023-07-03 12:25:29,927] INFO: Processing task `misfit` [2023-07-03 12:25:29,970] INFO: Submitting job ... [2023-07-03 12:25:30,037] INFO: Launched simulations for 1 events. Please check again to see if they are finished. [2023-07-03 12:25:30,038] INFO: Some tasks of iteration #0 are still running. Please check again later. [2023-07-03 12:25:31,066] INFO: Processing task `misfit` [2023-07-03 12:25:31,228] INFO: old misfit control group: 3.7156536966723097e-10 new misfit control group: 1.073889989952079e-10 predicted reduction control group: -2.1653940651003643e-10 actual reduction control group: -2.6417637067202306e-10 1 out of 1 event(s) improved the misfit. [2023-07-03 12:25:31,229] INFO: Model update accepted. [2023-07-03 12:25:31,230] INFO: 1 new tasks have been issued. [2023-07-03 12:25:31,230] INFO: Processing task `finalize_iteration` [2023-07-03 12:25:31,255] INFO: Succesfully completed iteration #0. [2023-07-03 12:25:31,257] INFO: Adding new iteration #1. [2023-07-03 12:25:31,274] INFO: Resuming iteration #1. [2023-07-03 12:25:31,275] INFO: 1 new tasks have been issued. [2023-07-03 12:25:31,276] INFO: Processing task `gradient` [2023-07-03 12:25:31,373] INFO: Submitting job ... [2023-07-03 12:25:31,436] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished. [2023-07-03 12:25:31,437] INFO: Some tasks of iteration #1 are still running. Please check again later. [2023-07-03 12:25:32,441] INFO: Processing task `gradient` [2023-07-03 12:25:32,542] INFO: 1 events have already been submitted. They will not be submitted again. [2023-07-03 12:25:32,706] INFO: Iteration 1: Number of events: 1 chi = 1.073889989952079e-10 ||g|| = 1.0372296701805176e-12 pred = -2.1653940651003643e-10 ared = -2.6417637067202306e-10 norm_update = 127.71284458185958 tr_radius = 127.71284458185946 [2023-07-03 12:25:32,720] INFO: 1 new tasks have been issued. [2023-07-03 12:25:32,725] INFO: Processing task `misfit` [2023-07-03 12:25:32,762] INFO: Submitting job ... [2023-07-03 12:25:32,830] INFO: Launched simulations for 1 events. Please check again to see if they are finished. [2023-07-03 12:25:32,831] INFO: Some tasks of iteration #1 are still running. Please check again later. [2023-07-03 12:25:33,854] INFO: Processing task `misfit` [2023-07-03 12:25:33,998] INFO: old misfit control group: 1.073889989952079e-10 new misfit control group: 7.296709075757565e-11 predicted reduction control group: -1.8864368053734403e-11 actual reduction control group: -3.442190823763225e-11 1 out of 1 event(s) improved the misfit. [2023-07-03 12:25:33,999] INFO: Model update accepted. [2023-07-03 12:25:33,999] INFO: 1 new tasks have been issued. [2023-07-03 12:25:34,000] INFO: Processing task `finalize_iteration` [2023-07-03 12:25:34,019] INFO: Succesfully completed iteration #1. [2023-07-03 12:25:34,021] INFO: Adding new iteration #2. [2023-07-03 12:25:34,032] INFO: Resuming iteration #2. [2023-07-03 12:25:34,033] INFO: 1 new tasks have been issued. [2023-07-03 12:25:34,033] INFO: Processing task `gradient` [2023-07-03 12:25:34,124] INFO: Submitting job ... [2023-07-03 12:25:34,186] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished. [2023-07-03 12:25:34,187] INFO: Some tasks of iteration #2 are still running. Please check again later. [2023-07-03 12:25:35,193] INFO: Processing task `gradient` [2023-07-03 12:25:35,257] INFO: 1 events have already been submitted. They will not be submitted again. [2023-07-03 12:25:35,407] INFO: Iteration 2: Number of events: 1 chi = 7.296709075757565e-11 ||g|| = 8.841255606549503e-13 pred = -1.8864368053734403e-11 ared = -3.442190823763225e-11 norm_update = 38.055159234364226 tr_radius = 255.4256891637189 [2023-07-03 12:25:35,427] INFO: 1 new tasks have been issued. [2023-07-03 12:25:35,428] INFO: Processing task `misfit` [2023-07-03 12:25:35,467] INFO: Submitting job ... [2023-07-03 12:25:35,540] INFO: Launched simulations for 1 events. Please check again to see if they are finished. [2023-07-03 12:25:35,542] INFO: Some tasks of iteration #2 are still running. Please check again later. [2023-07-03 12:25:36,564] INFO: Processing task `misfit` [2023-07-03 12:25:36,692] INFO: old misfit control group: 7.296709075757565e-11 new misfit control group: 7.29921706188182e-12 predicted reduction control group: -5.394783288127456e-11 actual reduction control group: -6.566787369569383e-11 1 out of 1 event(s) improved the misfit. [2023-07-03 12:25:36,692] INFO: Model update accepted. [2023-07-03 12:25:36,693] INFO: 1 new tasks have been issued. [2023-07-03 12:25:36,693] INFO: Processing task `finalize_iteration` [2023-07-03 12:25:36,719] INFO: Succesfully completed iteration #2. [2023-07-03 12:25:36,723] INFO: Adding new iteration #3. [2023-07-03 12:25:36,736] INFO: Resuming iteration #3. [2023-07-03 12:25:36,736] INFO: 1 new tasks have been issued. [2023-07-03 12:25:36,737] INFO: Processing task `gradient` [2023-07-03 12:25:36,840] INFO: Submitting job ... [2023-07-03 12:25:36,910] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished. [2023-07-03 12:25:36,912] INFO: Some tasks of iteration #3 are still running. Please check again later. [2023-07-03 12:25:37,918] INFO: Processing task `gradient` [2023-07-03 12:25:37,977] INFO: 1 events have already been submitted. They will not be submitted again. [2023-07-03 12:25:38,155] INFO: Iteration 3: Number of events: 1 chi = 7.29921706188182e-12 ||g|| = 2.1080712308528524e-13 pred = -5.394783288127456e-11 ared = -6.566787369569383e-11 norm_update = 127.71284458185963 tr_radius = 127.71284458185946
[2023-07-03 12:25:38,183] INFO: 1 new tasks have been issued. [2023-07-03 12:25:38,183] INFO: Processing task `misfit` [2023-07-03 12:25:38,219] INFO: Submitting job ... [2023-07-03 12:25:38,287] INFO: Launched simulations for 1 events. Please check again to see if they are finished. [2023-07-03 12:25:38,288] INFO: Some tasks of iteration #3 are still running. Please check again later. [2023-07-03 12:25:39,311] INFO: Processing task `misfit` [2023-07-03 12:25:39,468] INFO: old misfit control group: 7.29921706188182e-12 new misfit control group: 3.853990185690102e-12 predicted reduction control group: -3.6255290993512647e-12 actual reduction control group: -3.4452268761917177e-12 1 out of 1 event(s) improved the misfit. [2023-07-03 12:25:39,469] INFO: Model update accepted. [2023-07-03 12:25:39,469] INFO: 1 new tasks have been issued. [2023-07-03 12:25:39,470] INFO: Processing task `finalize_iteration` [2023-07-03 12:25:39,501] INFO: Succesfully completed iteration #3. [2023-07-03 12:25:39,505] INFO: Adding new iteration #4. [2023-07-03 12:25:39,521] INFO: Resuming iteration #4. [2023-07-03 12:25:39,527] INFO: 1 new tasks have been issued. [2023-07-03 12:25:39,528] INFO: Processing task `gradient` [2023-07-03 12:25:39,616] INFO: Submitting job ... [2023-07-03 12:25:39,681] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished. [2023-07-03 12:25:39,682] INFO: Some tasks of iteration #4 are still running. Please check again later. [2023-07-03 12:25:40,687] INFO: Processing task `gradient` [2023-07-03 12:25:40,782] INFO: 1 events have already been submitted. They will not be submitted again. [2023-07-03 12:25:40,943] INFO: Iteration 4: Number of events: 1 chi = 3.853990185690102e-12 ||g|| = 5.491251396381121e-14 pred = -3.6255290993512647e-12 ared = -3.4452268761917177e-12 norm_update = 37.63460606490359 tr_radius = 255.4256891637189 [2023-07-03 12:25:40,986] INFO: 1 new tasks have been issued. [2023-07-03 12:25:40,986] INFO: Processing task `misfit` [2023-07-03 12:25:41,025] INFO: Submitting job ... [2023-07-03 12:25:41,108] INFO: Launched simulations for 1 events. Please check again to see if they are finished. [2023-07-03 12:25:41,109] INFO: Some tasks of iteration #4 are still running. Please check again later. [2023-07-03 12:25:42,140] INFO: Processing task `misfit` [2023-07-03 12:25:42,273] INFO: old misfit control group: 3.853990185690102e-12 new misfit control group: 3.660798440136839e-12 predicted reduction control group: -1.1394905736794103e-13 actual reduction control group: -1.9319174555326333e-13 1 out of 1 event(s) improved the misfit. [2023-07-03 12:25:42,274] INFO: Model update accepted. [2023-07-03 12:25:42,275] INFO: 1 new tasks have been issued. [2023-07-03 12:25:42,275] INFO: Processing task `finalize_iteration` [2023-07-03 12:25:42,307] INFO: Succesfully completed iteration #4. [2023-07-03 12:25:42,311] INFO: Adding new iteration #5. [2023-07-03 12:25:42,329] INFO: Resuming iteration #5. [2023-07-03 12:25:42,330] INFO: 1 new tasks have been issued. [2023-07-03 12:25:42,330] INFO: Processing task `gradient` [2023-07-03 12:25:42,434] INFO: Submitting job ... [2023-07-03 12:25:42,499] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished. [2023-07-03 12:25:42,500] INFO: Some tasks of iteration #5 are still running. Please check again later. [2023-07-03 12:25:43,505] INFO: Processing task `gradient` [2023-07-03 12:25:43,577] INFO: 1 events have already been submitted. They will not be submitted again. [2023-07-03 12:25:43,749] INFO: Iteration 5: Number of events: 1 chi = 3.660798440136839e-12 ||g|| = 3.6825252782816895e-14 pred = -1.1394905736794103e-13 ared = -1.9319174555326333e-13 norm_update = 4.99897566392313 tr_radius = 127.71284458185946 [2023-07-03 12:25:43,795] INFO: 1 new tasks have been issued. [2023-07-03 12:25:43,795] INFO: Processing task `misfit` [2023-07-03 12:25:43,830] INFO: Submitting job ... [2023-07-03 12:25:43,903] INFO: Launched simulations for 1 events. Please check again to see if they are finished. [2023-07-03 12:25:43,904] INFO: Some tasks of iteration #5 are still running. Please check again later. [2023-07-03 12:25:44,926] INFO: Processing task `misfit` [2023-07-03 12:25:45,043] INFO: old misfit control group: 3.660798440136839e-12 new misfit control group: 2.980987500487273e-12 predicted reduction control group: -4.432370370761637e-13 actual reduction control group: -6.798109396495656e-13 1 out of 1 event(s) improved the misfit. [2023-07-03 12:25:45,043] INFO: Model update accepted. [2023-07-03 12:25:45,044] INFO: 1 new tasks have been issued. [2023-07-03 12:25:45,044] INFO: Processing task `finalize_iteration` [2023-07-03 12:25:45,068] INFO: Succesfully completed iteration #5. [2023-07-03 12:25:45,073] INFO: Adding new iteration #6. [2023-07-03 12:25:45,092] INFO: Resuming iteration #6. [2023-07-03 12:25:45,093] INFO: 1 new tasks have been issued. [2023-07-03 12:25:45,093] INFO: Processing task `gradient` [2023-07-03 12:25:45,185] INFO: Submitting job ... [2023-07-03 12:25:45,251] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished. [2023-07-03 12:25:45,252] INFO: Some tasks of iteration #6 are still running. Please check again later. [2023-07-03 12:25:46,259] INFO: Processing task `gradient` [2023-07-03 12:25:46,338] INFO: 1 events have already been submitted. They will not be submitted again. [2023-07-03 12:25:46,501] INFO: Iteration 6: Number of events: 1 chi = 2.980987500487273e-12 ||g|| = 1.1332571299671699e-13 pred = -4.432370370761637e-13 ared = -6.798109396495656e-13 norm_update = 25.94562134433939 tr_radius = 63.85642229092973 [2023-07-03 12:25:46,569] INFO: 1 new tasks have been issued. [2023-07-03 12:25:46,570] INFO: Processing task `misfit` [2023-07-03 12:25:46,608] INFO: Submitting job ... [2023-07-03 12:25:46,685] INFO: Launched simulations for 1 events. Please check again to see if they are finished. [2023-07-03 12:25:46,687] INFO: Some tasks of iteration #6 are still running. Please check again later. [2023-07-03 12:25:47,712] INFO: Processing task `misfit` [2023-07-03 12:25:47,873] INFO: old misfit control group: 2.980987500487273e-12 new misfit control group: 1.9556121150259184e-12 predicted reduction control group: -6.673018157289353e-13 actual reduction control group: -1.0253753854613548e-12 1 out of 1 event(s) improved the misfit. [2023-07-03 12:25:47,874] INFO: Model update accepted. [2023-07-03 12:25:47,874] INFO: 1 new tasks have been issued. [2023-07-03 12:25:47,875] INFO: Processing task `finalize_iteration` [2023-07-03 12:25:47,901] INFO: Succesfully completed iteration #6. [2023-07-03 12:25:47,907] INFO: Adding new iteration #7. [2023-07-03 12:25:47,927] INFO: Resuming iteration #7. [2023-07-03 12:25:47,928] INFO: 1 new tasks have been issued. [2023-07-03 12:25:47,928] INFO: Processing task `gradient` [2023-07-03 12:25:48,033] INFO: Submitting job ... [2023-07-03 12:25:48,099] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2023-07-03 12:25:48,100] INFO: Some tasks of iteration #7 are still running. Please check again later. [2023-07-03 12:25:49,108] INFO: Processing task `gradient` [2023-07-03 12:25:49,182] INFO: 1 events have already been submitted. They will not be submitted again. [2023-07-03 12:25:49,378] INFO: Iteration 7: Number of events: 1 chi = 1.9556121150259184e-12 ||g|| = 1.808294297046996e-13 pred = -6.673018157289353e-13 ared = -1.0253753854613548e-12 norm_update = 51.89124268867883 tr_radius = 51.89124268867878 [2023-07-03 12:25:49,442] INFO: 1 new tasks have been issued. [2023-07-03 12:25:49,443] INFO: Processing task `misfit` [2023-07-03 12:25:49,483] INFO: Submitting job ... [2023-07-03 12:25:49,547] INFO: Launched simulations for 1 events. Please check again to see if they are finished. [2023-07-03 12:25:49,548] INFO: Some tasks of iteration #7 are still running. Please check again later. [2023-07-03 12:25:50,576] INFO: Processing task `misfit` [2023-07-03 12:25:50,706] INFO: old misfit control group: 1.9556121150259184e-12 new misfit control group: 7.197023936523717e-13 predicted reduction control group: -8.886065486350005e-13 actual reduction control group: -1.2359097213735467e-12 1 out of 1 event(s) improved the misfit. [2023-07-03 12:25:50,707] INFO: Model update accepted. [2023-07-03 12:25:50,707] INFO: 1 new tasks have been issued. [2023-07-03 12:25:50,707] INFO: Processing task `finalize_iteration` [2023-07-03 12:25:50,735] INFO: Succesfully completed iteration #7. [2023-07-03 12:25:50,743] INFO: Adding new iteration #8. [2023-07-03 12:25:50,768] INFO: Resuming iteration #8. [2023-07-03 12:25:50,768] INFO: 1 new tasks have been issued. [2023-07-03 12:25:50,769] INFO: Processing task `gradient` [2023-07-03 12:25:50,861] INFO: Submitting job ... [2023-07-03 12:25:50,927] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished. [2023-07-03 12:25:50,928] INFO: Some tasks of iteration #8 are still running. Please check again later. [2023-07-03 12:25:51,935] INFO: Processing task `gradient` [2023-07-03 12:25:52,019] INFO: 1 events have already been submitted. They will not be submitted again. [2023-07-03 12:25:52,207] INFO: Iteration 8: Number of events: 1 chi = 7.197023936523717e-13 ||g|| = 1.668480968557139e-13 pred = -8.886065486350005e-13 ared = -1.2359097213735467e-12 norm_update = 83.03738112594749 tr_radius = 103.78248537735756 [2023-07-03 12:25:52,275] INFO: 1 new tasks have been issued. [2023-07-03 12:25:52,276] INFO: Processing task `misfit` [2023-07-03 12:25:52,318] INFO: Submitting job ... [2023-07-03 12:25:52,397] INFO: Launched simulations for 1 events. Please check again to see if they are finished. [2023-07-03 12:25:52,398] INFO: Some tasks of iteration #8 are still running. Please check again later. [2023-07-03 12:25:53,426] INFO: Processing task `misfit` [2023-07-03 12:25:53,559] INFO: old misfit control group: 7.197023936523717e-13 new misfit control group: 3.4243745597393776e-14 predicted reduction control group: -5.162831995936662e-13 actual reduction control group: -6.854586480549779e-13 1 out of 1 event(s) improved the misfit. [2023-07-03 12:25:53,560] INFO: Model update accepted. [2023-07-03 12:25:53,561] INFO: 1 new tasks have been issued. [2023-07-03 12:25:53,561] INFO: Processing task `finalize_iteration` [2023-07-03 12:25:53,594] INFO: Succesfully completed iteration #8. [2023-07-03 12:25:53,602] INFO: Adding new iteration #9. [2023-07-03 12:25:53,633] INFO: Resuming iteration #9. [2023-07-03 12:25:53,634] INFO: The total number of iterations in this inversion tree has been reached and no new iteration will be added. If you want to continue with this inversion, you need to adjust `max_iterations_global` using `set_stopping_criteria`.
p.viz.nb.inversion(inverse_problem_configuration="inversion")