Version:

This documentation is not for the latest stable Salvus version.

This tutorial is presented as Python code running inside a Jupyter Notebook, the recommended way to use Salvus. To run it yourself you can copy/type each individual cell or directly download the full notebook, including all required files.
Copy
%matplotlib inline
%config Completer.use_jedi = False

import os

SALVUS_FLOW_SITE_NAME = os.environ.get("SITE_NAME", "local")

# Inverting for homogeneous material

In this mini-tutorial, we demonstrate how the mapping function can be used to invert for homogeneous material parameters. Here, the adjoint operation of the mapping class maps the space-dependent physical gradient into the subspace of homogeneous model parameters.

## Take-home message

Selecting scaling="homogeneous" in the mapping function of an InverseProblemConfiguration enables inversion for homogeneous model parameters with full-waveform inversion.
.css-fd3q3g{border-width:0px!important;padding:0px!important;font-size:85%!important;box-shadow:1px 1px 3px 1px rgba(0,0,0,0.48)!important;}Copysn.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

## Aperture

We consider a simplistic setup with a 2D elastic box domain with a single source-receiver pair.
Check out the full FWI tutorial for more details on the individual steps.
p = sn.Project.from_domain(
path="project",
domain=sn.domain.dim2.BoxDomain(
x0=0.0,
x1=1.0,
y0=0.0,
y1=1.5,
),
)
src = sn.simple_config.source.cartesian.VectorPoint2D(
x=0.33, y=0.0, fx=0.0, fy=1.0e9
)

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()

## Simulations

We consider two different homogeneous isotropic media. The "true" model we seek to reconstruct varies from the initial model in 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]):

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,
)
[2022-10-26 00:29:08,002] INFO: Creating mesh. Hang on.
[2022-10-26 00:29:08,804] INFO: Submitting job ...

ðŸš€  Submitted [email protected]local_cuda
[2022-10-26 00:29:09,270] INFO: Creating mesh. Hang on.
[2022-10-26 00:29:09,333] INFO: Submitting job ...

ðŸš€  Submitted [email protected]local_cuda

p.simulations.query(block=True)
True
This is of course not a realistic setup, but the waveforms differ in both components.
p.viz.nb.waveforms(data=["true", "init"], receiver_field="displacement")

## Inversion

Next, we setup the inverse problem. We are using 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",
)
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,
)
[2022-10-26 00:29:11,598] INFO: Adding new iteration #0.
[2022-10-26 00:29:11,612] INFO: Resuming iteration #0.

[2022-10-26 00:29:11,613] INFO: 1 new tasks have been issued.
[2022-10-26 00:29:11,613] INFO: Processing task misfit_and_gradient
[2022-10-26 00:29:11,649] 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']
[2022-10-26 00:29:11,670] INFO: Submitting job ...
[2022-10-26 00:29:11,753] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2022-10-26 00:29:11,755] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2022-10-26 00:29:12,758] INFO: Processing task misfit_and_gradient
[2022-10-26 00:29:12,885] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2022-10-26 00:29:13,889] INFO: Processing task misfit_and_gradient
[2022-10-26 00:29:13,984] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2022-10-26 00:29:14,989] INFO: Processing task misfit_and_gradient
[2022-10-26 00:29:15,117] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2022-10-26 00:29:16,121] INFO: Processing task misfit_and_gradient
[2022-10-26 00:29:16,684] INFO: Submitting job ...
[2022-10-26 00:29:16,782] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2022-10-26 00:29:16,784] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2022-10-26 00:29:17,788] INFO: Processing task misfit_and_gradient
[2022-10-26 00:29:17,975] INFO: 1 events have already been submitted. They will not be submitted again.
[2022-10-26 00:29:18,182] INFO:
Iteration 0: Number of events: 1	 chi = 3.715653972810587e-10	 ||g|| = 3.3910354800766238e-12
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2022-10-26 00:29:18,190] INFO: 1 new tasks have been issued.
[2022-10-26 00:29:18,191] INFO: Processing task misfit
[2022-10-26 00:29:18,246] INFO: Submitting job ...
[2022-10-26 00:29:18,332] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2022-10-26 00:29:18,334] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2022-10-26 00:29:19,366] INFO: Processing task misfit
[2022-10-26 00:29:19,465] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2022-10-26 00:29:20,490] INFO: Processing task misfit
[2022-10-26 00:29:20,591] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2022-10-26 00:29:21,613] INFO: Processing task misfit
[2022-10-26 00:29:21,715] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2022-10-26 00:29:22,733] INFO: Processing task misfit
[2022-10-26 00:29:22,901] INFO:
old misfit control group: 3.715653972810587e-10
new misfit control group: 1.0738900396722105e-10
predicted reduction control group: -2.1653939841251705e-10
actual reduction control group: -2.6417639331383764e-10
1 out of 1 event(s) improved the misfit.
[2022-10-26 00:29:22,902] INFO:
Model update accepted.
[2022-10-26 00:29:22,904] INFO: 1 new tasks have been issued.
[2022-10-26 00:29:22,904] INFO: Processing task finalize_iteration
[2022-10-26 00:29:22,933] INFO: Succesfully completed iteration #0.
[2022-10-26 00:29:22,936] INFO: Adding new iteration #1.
[2022-10-26 00:29:22,945] INFO: Resuming iteration #1.

[2022-10-26 00:29:22,946] INFO: 1 new tasks have been issued.
[2022-10-26 00:29:22,946] INFO: Processing task gradient
[2022-10-26 00:29:23,081] INFO: Submitting job ...
[2022-10-26 00:29:23,176] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2022-10-26 00:29:23,178] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2022-10-26 00:29:24,183] INFO: Processing task gradient
[2022-10-26 00:29:24,270] INFO: 1 events have already been submitted. They will not be submitted again.
[2022-10-26 00:29:24,318] INFO: Some simulations are still running. Please check again to see if they are finished.
[2022-10-26 00:29:24,319] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2022-10-26 00:29:25,324] INFO: Processing task gradient
[2022-10-26 00:29:25,416] INFO: 1 events have already been submitted. They will not be submitted again.
[2022-10-26 00:29:25,521] INFO: Some simulations are still running. Please check again to see if they are finished.
[2022-10-26 00:29:25,523] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2022-10-26 00:29:26,528] INFO: Processing task gradient
[2022-10-26 00:29:26,634] INFO: 1 events have already been submitted. They will not be submitted again.
[2022-10-26 00:29:26,835] INFO:
Iteration 1: Number of events: 1	 chi = 1.0738900396722105e-10	 ||g|| = 1.0372299139557054e-12
pred = -2.1653939841251705e-10	ared = -2.6417639331383764e-10	norm_update = 127.71284740885349	tr_radius = 127.71284740885348
[2022-10-26 00:29:26,861] INFO: 1 new tasks have been issued.
[2022-10-26 00:29:26,862] INFO: Processing task misfit
[2022-10-26 00:29:26,910] INFO: Submitting job ...
[2022-10-26 00:29:27,003] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2022-10-26 00:29:27,005] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2022-10-26 00:29:28,036] INFO: Processing task misfit
[2022-10-26 00:29:28,205] INFO:
old misfit control group: 1.0738900396722105e-10
new misfit control group: 7.296714501260376e-11
predicted reduction control group: -1.8864376331100885e-11
actual reduction control group: -3.4421858954617294e-11
1 out of 1 event(s) improved the misfit.
[2022-10-26 00:29:28,206] INFO:
Model update accepted.
[2022-10-26 00:29:28,208] INFO: 1 new tasks have been issued.
[2022-10-26 00:29:28,209] INFO: Processing task finalize_iteration
[2022-10-26 00:29:28,234] INFO: Succesfully completed iteration #1.
[2022-10-26 00:29:28,237] INFO: Adding new iteration #2.
[2022-10-26 00:29:28,248] INFO: Resuming iteration #2.

[2022-10-26 00:29:28,249] INFO: 1 new tasks have been issued.
[2022-10-26 00:29:28,250] INFO: Processing task gradient
[2022-10-26 00:29:28,386] INFO: Submitting job ...
[2022-10-26 00:29:28,479] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2022-10-26 00:29:28,481] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2022-10-26 00:29:29,489] INFO: Processing task gradient
[2022-10-26 00:29:29,615] INFO: 1 events have already been submitted. They will not be submitted again.
[2022-10-26 00:29:29,724] INFO: Some simulations are still running. Please check again to see if they are finished.
[2022-10-26 00:29:29,726] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2022-10-26 00:29:30,736] INFO: Processing task gradient
[2022-10-26 00:29:30,827] INFO: 1 events have already been submitted. They will not be submitted again.

[2022-10-26 00:29:30,929] INFO: Some simulations are still running. Please check again to see if they are finished.
[2022-10-26 00:29:30,931] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2022-10-26 00:29:31,937] INFO: Processing task gradient
[2022-10-26 00:29:32,164] INFO: 1 events have already been submitted. They will not be submitted again.
[2022-10-26 00:29:32,364] INFO:
Iteration 2: Number of events: 1	 chi = 7.296714501260376e-11	 ||g|| = 8.841259606909132e-13
pred = -1.8864376331100885e-11	ared = -3.4421858954617294e-11	norm_update = 38.05516791279771	tr_radius = 255.42569481770695
[2022-10-26 00:29:32,401] INFO: 1 new tasks have been issued.
[2022-10-26 00:29:32,402] INFO: Processing task misfit
[2022-10-26 00:29:32,448] INFO: Submitting job ...
[2022-10-26 00:29:32,544] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2022-10-26 00:29:32,545] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2022-10-26 00:29:33,575] INFO: Processing task misfit
[2022-10-26 00:29:33,742] INFO:
old misfit control group: 7.296714501260376e-11
new misfit control group: 7.299242285354682e-12
predicted reduction control group: -5.3947856816300656e-11
actual reduction control group: -6.566790272724907e-11
1 out of 1 event(s) improved the misfit.
[2022-10-26 00:29:33,743] INFO:
Model update accepted.
[2022-10-26 00:29:33,743] INFO: 1 new tasks have been issued.
[2022-10-26 00:29:33,744] INFO: Processing task finalize_iteration
[2022-10-26 00:29:33,782] INFO: Succesfully completed iteration #2.
[2022-10-26 00:29:33,787] INFO: Adding new iteration #3.
[2022-10-26 00:29:33,801] INFO: Resuming iteration #3.

[2022-10-26 00:29:33,802] INFO: 1 new tasks have been issued.
[2022-10-26 00:29:33,803] INFO: Processing task gradient
[2022-10-26 00:29:33,938] INFO: Submitting job ...
[2022-10-26 00:29:34,033] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2022-10-26 00:29:34,034] INFO: Some tasks of iteration #3 are still running. Please check again later.
[2022-10-26 00:29:35,041] INFO: Processing task gradient
[2022-10-26 00:29:35,149] INFO: 1 events have already been submitted. They will not be submitted again.
[2022-10-26 00:29:35,193] INFO: Some simulations are still running. Please check again to see if they are finished.
[2022-10-26 00:29:35,194] INFO: Some tasks of iteration #3 are still running. Please check again later.
[2022-10-26 00:29:36,199] INFO: Processing task gradient
[2022-10-26 00:29:36,290] INFO: 1 events have already been submitted. They will not be submitted again.
[2022-10-26 00:29:36,388] INFO: Some simulations are still running. Please check again to see if they are finished.
[2022-10-26 00:29:36,390] INFO: Some tasks of iteration #3 are still running. Please check again later.
[2022-10-26 00:29:37,397] INFO: Processing task gradient
[2022-10-26 00:29:37,485] INFO: 1 events have already been submitted. They will not be submitted again.
[2022-10-26 00:29:37,701] INFO:
Iteration 3: Number of events: 1	 chi = 7.299242285354682e-12	 ||g|| = 2.1081340879152915e-13
pred = -5.3947856816300656e-11	ared = -6.566790272724907e-11	norm_update = 127.71284740885332	tr_radius = 127.71284740885348
[2022-10-26 00:29:37,744] INFO: 1 new tasks have been issued.
[2022-10-26 00:29:37,745] INFO: Processing task misfit
[2022-10-26 00:29:37,800] INFO: Submitting job ...
[2022-10-26 00:29:37,897] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2022-10-26 00:29:37,899] INFO: Some tasks of iteration #3 are still running. Please check again later.
[2022-10-26 00:29:38,934] INFO: Processing task misfit
[2022-10-26 00:29:39,087] INFO:
old misfit control group: 7.299242285354682e-12
new misfit control group: 3.854002481304582e-12
predicted reduction control group: -3.625594188942009e-12
actual reduction control group: -3.4452398040501003e-12
1 out of 1 event(s) improved the misfit.
[2022-10-26 00:29:39,088] INFO:
Model update accepted.
[2022-10-26 00:29:39,089] INFO: 1 new tasks have been issued.
[2022-10-26 00:29:39,090] INFO: Processing task finalize_iteration
[2022-10-26 00:29:39,128] INFO: Succesfully completed iteration #3.
[2022-10-26 00:29:39,133] INFO: Adding new iteration #4.
[2022-10-26 00:29:39,150] INFO: Resuming iteration #4.

[2022-10-26 00:29:39,151] INFO: 1 new tasks have been issued.
[2022-10-26 00:29:39,151] INFO: Processing task gradient
[2022-10-26 00:29:39,316] INFO: Submitting job ...
[2022-10-26 00:29:39,445] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2022-10-26 00:29:39,450] INFO: Some tasks of iteration #4 are still running. Please check again later.
[2022-10-26 00:29:40,457] INFO: Processing task gradient
[2022-10-26 00:29:40,578] INFO: 1 events have already been submitted. They will not be submitted again.
[2022-10-26 00:29:40,653] INFO: Some simulations are still running. Please check again to see if they are finished.
[2022-10-26 00:29:40,655] INFO: Some tasks of iteration #4 are still running. Please check again later.
[2022-10-26 00:29:41,664] INFO: Processing task gradient
[2022-10-26 00:29:41,777] INFO: 1 events have already been submitted. They will not be submitted again.
[2022-10-26 00:29:41,905] INFO: Some simulations are still running. Please check again to see if they are finished.
[2022-10-26 00:29:41,906] INFO: Some tasks of iteration #4 are still running. Please check again later.
[2022-10-26 00:29:42,920] INFO: Processing task gradient
[2022-10-26 00:29:43,037] INFO: 1 events have already been submitted. They will not be submitted again.
[2022-10-26 00:29:43,257] INFO:
Iteration 4: Number of events: 1	 chi = 3.854002481304582e-12	 ||g|| = 5.492643832641963e-14
pred = -3.625594188942009e-12	ared = -3.4452398040501003e-12	norm_update = 37.634812443934806	tr_radius = 255.42569481770695
[2022-10-26 00:29:43,306] INFO: 1 new tasks have been issued.
[2022-10-26 00:29:43,306] INFO: Processing task misfit
[2022-10-26 00:29:43,353] INFO: Submitting job ...
[2022-10-26 00:29:43,453] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2022-10-26 00:29:43,454] INFO: Some tasks of iteration #4 are still running. Please check again later.
[2022-10-26 00:29:44,489] INFO: Processing task misfit
[2022-10-26 00:29:44,603] INFO: Some tasks of iteration #4 are still running. Please check again later.
[2022-10-26 00:29:45,624] INFO: Processing task misfit
[2022-10-26 00:29:45,723] INFO: Some tasks of iteration #4 are still running. Please check again later.
[2022-10-26 00:29:46,741] INFO: Processing task misfit
[2022-10-26 00:29:46,842] INFO: Some tasks of iteration #4 are still running. Please check again later.
[2022-10-26 00:29:47,865] INFO: Processing task misfit
[2022-10-26 00:29:48,053] INFO:
old misfit control group: 3.854002481304582e-12
new misfit control group: 3.660822844892237e-12
predicted reduction control group: -1.1395979122188652e-13
actual reduction control group: -1.9317963641234512e-13
1 out of 1 event(s) improved the misfit.

[2022-10-26 00:29:48,054] INFO:
Model update accepted.
[2022-10-26 00:29:48,055] INFO: 1 new tasks have been issued.
[2022-10-26 00:29:48,055] INFO: Processing task finalize_iteration
[2022-10-26 00:29:48,095] INFO: Succesfully completed iteration #4.
[2022-10-26 00:29:48,103] INFO: Adding new iteration #5.
[2022-10-26 00:29:48,132] INFO: Resuming iteration #5.

[2022-10-26 00:29:48,133] INFO: 1 new tasks have been issued.
[2022-10-26 00:29:48,134] INFO: Processing task gradient
[2022-10-26 00:29:48,322] INFO: Submitting job ...
[2022-10-26 00:29:48,427] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2022-10-26 00:29:48,428] INFO: Some tasks of iteration #5 are still running. Please check again later.
[2022-10-26 00:29:49,439] INFO: Processing task gradient
[2022-10-26 00:29:49,530] INFO: 1 events have already been submitted. They will not be submitted again.
[2022-10-26 00:29:49,638] INFO: Some simulations are still running. Please check again to see if they are finished.
[2022-10-26 00:29:49,640] INFO: Some tasks of iteration #5 are still running. Please check again later.
[2022-10-26 00:29:50,649] INFO: Processing task gradient
[2022-10-26 00:29:50,758] INFO: 1 events have already been submitted. They will not be submitted again.
[2022-10-26 00:29:50,867] INFO: Some simulations are still running. Please check again to see if they are finished.
[2022-10-26 00:29:50,868] INFO: Some tasks of iteration #5 are still running. Please check again later.
[2022-10-26 00:29:51,876] INFO: Processing task gradient
[2022-10-26 00:29:51,987] INFO: 1 events have already been submitted. They will not be submitted again.
[2022-10-26 00:29:52,095] INFO: Some simulations are still running. Please check again to see if they are finished.
[2022-10-26 00:29:52,096] INFO: Some tasks of iteration #5 are still running. Please check again later.
[2022-10-26 00:29:53,104] INFO: Processing task gradient
[2022-10-26 00:29:53,226] INFO: 1 events have already been submitted. They will not be submitted again.
[2022-10-26 00:29:53,471] INFO:
Iteration 5: Number of events: 1	 chi = 3.660822844892237e-12	 ||g|| = 3.6825050144792296e-14
pred = -1.1395979122188652e-13	ared = -1.9317963641234512e-13	norm_update = 4.998494199106016	tr_radius = 127.71284740885348
[2022-10-26 00:29:53,531] INFO: 1 new tasks have been issued.
[2022-10-26 00:29:53,532] INFO: Processing task misfit
[2022-10-26 00:29:53,587] INFO: Submitting job ...
[2022-10-26 00:29:53,671] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2022-10-26 00:29:53,672] INFO: Some tasks of iteration #5 are still running. Please check again later.
[2022-10-26 00:29:54,703] INFO: Processing task misfit
[2022-10-26 00:29:54,751] INFO: Some tasks of iteration #5 are still running. Please check again later.
[2022-10-26 00:29:55,773] INFO: Processing task misfit
[2022-10-26 00:29:55,873] INFO: Some tasks of iteration #5 are still running. Please check again later.
[2022-10-26 00:29:56,896] INFO: Processing task misfit
[2022-10-26 00:29:56,995] INFO: Some tasks of iteration #5 are still running. Please check again later.
[2022-10-26 00:29:58,013] INFO: Processing task misfit
[2022-10-26 00:29:58,241] INFO:
old misfit control group: 3.660822844892237e-12
new misfit control group: 2.9816476404449344e-12
predicted reduction control group: -4.4283115796376097e-13
actual reduction control group: -6.791752044473022e-13
1 out of 1 event(s) improved the misfit.
[2022-10-26 00:29:58,242]