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.
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
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,
    ),
    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()
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]):
    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.list(),
        site_name=SALVUS_FLOW_SITE_NAME,
        ranks_per_job=1,
    )
[2024-07-05 10:16:57,586] INFO: Creating mesh. Hang on.
[2024-07-05 10:16:57,637] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407051016740097_7a296883b4@local
[2024-07-05 10:16:57,822] INFO: Creating mesh. Hang on.
[2024-07-05 10:16:57,851] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407051016855159_3890ee80c1@local
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")
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",
    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,
    )
[2024-07-05 10:16:58,853] INFO: Adding new iteration #0.
[2024-07-05 10:16:58,860] INFO: Resuming iteration #0.

[2024-07-05 10:16:58,861] INFO: 1 new tasks have been issued.
[2024-07-05 10:16:58,861] INFO: Processing task `misfit_and_gradient`
[2024-07-05 10:16:58,880] 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']
[2024-07-05 10:16:58,890] INFO: Submitting job ...
[2024-07-05 10:16:58,939] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-05 10:16:58,939] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-05 10:16:59,940] INFO: Processing task `misfit_and_gradient`
[2024-07-05 10:17:00,175] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407051017177000_a60913a9b1@local
[2024-07-05 10:17:00,221] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-07-05 10:17:00,221] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-05 10:17:01,223] INFO: Processing task `misfit_and_gradient`
[2024-07-05 10:17:01,304] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-07-05 10:17:01,435] INFO: 
Iteration 0: Number of events: 1	 chi = 3.7156536966723097e-10	 ||g|| = 3.3910359372571976e-12
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2024-07-05 10:17:01,439] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:01,439] INFO: Processing task `misfit`
[2024-07-05 10:17:01,467] INFO: Submitting job ...
[2024-07-05 10:17:01,520] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-05 10:17:01,521] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-05 10:17:02,534] INFO: Processing task `misfit`
[2024-07-05 10:17:02,641] INFO: 
old misfit control group: 3.7156536966723097e-10
new misfit control group: 1.073889989952079e-10
predicted reduction control group: -2.1653942143243586e-10
actual reduction control group: -2.6417637067202306e-10
1 out of 1 event(s) improved the misfit.
[2024-07-05 10:17:02,641] INFO: 
Model update accepted.
[2024-07-05 10:17:02,641] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:02,642] INFO: Processing task `finalize_iteration`
[2024-07-05 10:17:02,653] INFO: Succesfully completed iteration #0.
[2024-07-05 10:17:02,654] INFO: Adding new iteration #1.
[2024-07-05 10:17:02,658] INFO: Resuming iteration #1.

[2024-07-05 10:17:02,659] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:02,659] INFO: Processing task `gradient`
[2024-07-05 10:17:02,729] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407051017731188_8c9c718e09@local
[2024-07-05 10:17:02,773] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-07-05 10:17:02,773] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2024-07-05 10:17:03,775] INFO: Processing task `gradient`
[2024-07-05 10:17:03,822] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-07-05 10:17:03,950] INFO: 
Iteration 1: Number of events: 1	 chi = 1.073889989952079e-10	 ||g|| = 1.037229670389857e-12
pred = -2.1653942143243586e-10	ared = -2.6417637067202306e-10	norm_update = 127.71284376748982	tr_radius = 127.71284376748997
[2024-07-05 10:17:03,958] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:03,959] INFO: Processing task `misfit`
[2024-07-05 10:17:03,986] INFO: Submitting job ...
[2024-07-05 10:17:04,032] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-05 10:17:04,032] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2024-07-05 10:17:05,044] INFO: Processing task `misfit`
[2024-07-05 10:17:05,148] INFO: 
old misfit control group: 1.073889989952079e-10
new misfit control group: 7.296709075757565e-11
predicted reduction control group: -1.886436638060351e-11
actual reduction control group: -3.442190823763225e-11
1 out of 1 event(s) improved the misfit.
[2024-07-05 10:17:05,148] INFO: 
Model update accepted.
[2024-07-05 10:17:05,148] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:05,149] INFO: Processing task `finalize_iteration`
[2024-07-05 10:17:05,161] INFO: Succesfully completed iteration #1.
[2024-07-05 10:17:05,163] INFO: Adding new iteration #2.
[2024-07-05 10:17:05,168] INFO: Resuming iteration #2.

[2024-07-05 10:17:05,169] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:05,170] INFO: Processing task `gradient`
[2024-07-05 10:17:05,238] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407051017239961_a7dfe3c4b2@local
[2024-07-05 10:17:05,284] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-07-05 10:17:05,285] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2024-07-05 10:17:06,287] INFO: Processing task `gradient`
[2024-07-05 10:17:06,334] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-07-05 10:17:06,458] INFO: 
Iteration 2: Number of events: 1	 chi = 7.296709075757565e-11	 ||g|| = 8.841255720378636e-13
pred = -1.886436638060351e-11	ared = -3.442190823763225e-11	norm_update = 38.055155588990125	tr_radius = 255.42568753497994
[2024-07-05 10:17:06,471] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:06,472] INFO: Processing task `misfit`
[2024-07-05 10:17:06,504] INFO: Submitting job ...
[2024-07-05 10:17:06,550] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-05 10:17:06,551] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2024-07-05 10:17:07,563] INFO: Processing task `misfit`
[2024-07-05 10:17:07,667] INFO: 
old misfit control group: 7.296709075757565e-11
new misfit control group: 7.29921706188182e-12
predicted reduction control group: -5.3947833613705984e-11
actual reduction control group: -6.566787369569383e-11
1 out of 1 event(s) improved the misfit.
[2024-07-05 10:17:07,667] INFO: 
Model update accepted.
[2024-07-05 10:17:07,667] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:07,668] INFO: Processing task `finalize_iteration`
[2024-07-05 10:17:07,680] INFO: Succesfully completed iteration #2.
[2024-07-05 10:17:07,681] INFO: Adding new iteration #3.
[2024-07-05 10:17:07,687] INFO: Resuming iteration #3.

[2024-07-05 10:17:07,687] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:07,688] INFO: Processing task `gradient`
[2024-07-05 10:17:07,755] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407051017757468_1e5c731415@local
[2024-07-05 10:17:07,801] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-07-05 10:17:07,802] INFO: Some tasks of iteration #3 are still running. Please check again later.
[2024-07-05 10:17:08,804] INFO: Processing task `gradient`
[2024-07-05 10:17:08,851] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-07-05 10:17:08,974] INFO: 
Iteration 3: Number of events: 1	 chi = 7.29921706188182e-12	 ||g|| = 2.1080709923504721e-13
pred = -5.3947833613705984e-11	ared = -6.566787369569383e-11	norm_update = 127.71284376748984	tr_radius = 127.71284376748997
[2024-07-05 10:17:08,994] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:08,994] INFO: Processing task `misfit`
[2024-07-05 10:17:09,021] INFO: Submitting job ...
[2024-07-05 10:17:09,068] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-05 10:17:09,068] INFO: Some tasks of iteration #3 are still running. Please check again later.
[2024-07-05 10:17:10,080] INFO: Processing task `misfit`
[2024-07-05 10:17:10,180] INFO: 
old misfit control group: 7.29921706188182e-12
new misfit control group: 3.853990185690102e-12
predicted reduction control group: -3.625527296947774e-12
actual reduction control group: -3.4452268761917177e-12
1 out of 1 event(s) improved the misfit.
[2024-07-05 10:17:10,180] INFO: 
Model update accepted.
[2024-07-05 10:17:10,181] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:10,181] INFO: Processing task `finalize_iteration`
[2024-07-05 10:17:10,193] INFO: Succesfully completed iteration #3.
[2024-07-05 10:17:10,195] INFO: Adding new iteration #4.
[2024-07-05 10:17:10,203] INFO: Resuming iteration #4.

[2024-07-05 10:17:10,205] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:10,205] INFO: Processing task `gradient`
[2024-07-05 10:17:10,272] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407051017421006_46ea270b95@local
[2024-07-05 10:17:10,465] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-07-05 10:17:10,465] INFO: Some tasks of iteration #4 are still running. Please check again later.
[2024-07-05 10:17:11,469] INFO: Processing task `gradient`
[2024-07-05 10:17:11,514] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-07-05 10:17:11,642] INFO: 
Iteration 4: Number of events: 1	 chi = 3.853990185690102e-12	 ||g|| = 5.491251362114438e-14
pred = -3.625527296947774e-12	ared = -3.4452268761917177e-12	norm_update = 37.634593986576924	tr_radius = 255.42568753497994
[2024-07-05 10:17:11,668] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:11,669] INFO: Processing task `misfit`
[2024-07-05 10:17:11,696] INFO: Submitting job ...
[2024-07-05 10:17:11,743] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-05 10:17:11,744] INFO: Some tasks of iteration #4 are still running. Please check again later.
[2024-07-05 10:17:12,756] INFO: Processing task `misfit`
[2024-07-05 10:17:12,859] INFO: 
old misfit control group: 3.853990185690102e-12
new misfit control group: 3.660798440136839e-12
predicted reduction control group: -1.1394903979292904e-13
actual reduction control group: -1.9319174555326333e-13
1 out of 1 event(s) improved the misfit.
[2024-07-05 10:17:12,859] INFO: 
Model update accepted.
[2024-07-05 10:17:12,860] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:12,860] INFO: Processing task `finalize_iteration`
[2024-07-05 10:17:12,873] INFO: Succesfully completed iteration #4.
[2024-07-05 10:17:12,876] INFO: Adding new iteration #5.
[2024-07-05 10:17:12,886] INFO: Resuming iteration #5.

[2024-07-05 10:17:12,886] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:12,887] INFO: Processing task `gradient`
[2024-07-05 10:17:12,955] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407051017957338_f4429bb899@local
[2024-07-05 10:17:13,000] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-07-05 10:17:13,000] INFO: Some tasks of iteration #5 are still running. Please check again later.
[2024-07-05 10:17:14,003] INFO: Processing task `gradient`
[2024-07-05 10:17:14,048] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-07-05 10:17:14,170] INFO: 
Iteration 5: Number of events: 1	 chi = 3.660798440136839e-12	 ||g|| = 3.682525298193585e-14
pred = -1.1394903979292904e-13	ared = -1.9319174555326333e-13	norm_update = 4.998974676234866	tr_radius = 127.71284376748997
[2024-07-05 10:17:14,200] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:14,201] INFO: Processing task `misfit`
[2024-07-05 10:17:14,225] INFO: Submitting job ...
[2024-07-05 10:17:14,272] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-05 10:17:14,272] INFO: Some tasks of iteration #5 are still running. Please check again later.
[2024-07-05 10:17:15,284] INFO: Processing task `misfit`
[2024-07-05 10:17:15,384] INFO: 
old misfit control group: 3.660798440136839e-12
new misfit control group: 2.9810284223434555e-12
predicted reduction control group: -4.4323683818356934e-13
actual reduction control group: -6.797700177933832e-13
1 out of 1 event(s) improved the misfit.
[2024-07-05 10:17:15,385] INFO: 
Model update accepted.
[2024-07-05 10:17:15,385] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:15,385] INFO: Processing task `finalize_iteration`
[2024-07-05 10:17:15,399] INFO: Succesfully completed iteration #5.
[2024-07-05 10:17:15,402] INFO: Adding new iteration #6.
[2024-07-05 10:17:15,414] INFO: Resuming iteration #6.

[2024-07-05 10:17:15,414] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:15,415] INFO: Processing task `gradient`
[2024-07-05 10:17:15,482] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407051017484407_f28b50d9c5@local
[2024-07-05 10:17:15,528] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-07-05 10:17:15,528] INFO: Some tasks of iteration #6 are still running. Please check again later.
[2024-07-05 10:17:16,532] INFO: Processing task `gradient`
[2024-07-05 10:17:16,578] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-07-05 10:17:16,705] INFO: 
Iteration 6: Number of events: 1	 chi = 2.9810284223434555e-12	 ||g|| = 1.1334072418867954e-13
pred = -4.4323683818356934e-13	ared = -6.797700177933832e-13	norm_update = 25.945609247270596	tr_radius = 63.856421883744986
[2024-07-05 10:17:16,740] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:16,741] INFO: Processing task `misfit`
[2024-07-05 10:17:16,764] INFO: Submitting job ...
[2024-07-05 10:17:16,812] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-05 10:17:16,812] INFO: Some tasks of iteration #6 are still running. Please check again later.
[2024-07-05 10:17:17,825] INFO: Processing task `misfit`
[2024-07-05 10:17:17,931] INFO: 
old misfit control group: 2.9810284223434555e-12
new misfit control group: 1.9555860418200896e-12
predicted reduction control group: -6.673080610254194e-13
actual reduction control group: -1.025442380523366e-12
1 out of 1 event(s) improved the misfit.
[2024-07-05 10:17:17,932] INFO: 
Model update accepted.
[2024-07-05 10:17:17,932] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:17,933] INFO: Processing task `finalize_iteration`
[2024-07-05 10:17:17,947] INFO: Succesfully completed iteration #6.
[2024-07-05 10:17:17,951] INFO: Adding new iteration #7.
[2024-07-05 10:17:17,963] INFO: Resuming iteration #7.

[2024-07-05 10:17:17,964] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:17,964] INFO: Processing task `gradient`
[2024-07-05 10:17:18,030] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407051017032706_1e9906ddfa@local
[2024-07-05 10:17:18,076] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-07-05 10:17:18,077] INFO: Some tasks of iteration #7 are still running. Please check again later.
[2024-07-05 10:17:19,082] INFO: Processing task `gradient`
[2024-07-05 10:17:19,129] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-07-05 10:17:19,254] INFO: 
Iteration 7: Number of events: 1	 chi = 1.9555860418200896e-12	 ||g|| = 1.8082278362551017e-13
pred = -6.673080610254194e-13	ared = -1.025442380523366e-12	norm_update = 51.891218494541064	tr_radius = 51.89121849454119
[2024-07-05 10:17:19,295] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:19,296] INFO: Processing task `misfit`
[2024-07-05 10:17:19,321] INFO: Submitting job ...
[2024-07-05 10:17:19,368] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-05 10:17:19,369] INFO: Some tasks of iteration #7 are still running. Please check again later.
[2024-07-05 10:17:20,384] INFO: Processing task `misfit`
[2024-07-05 10:17:20,495] INFO: 
old misfit control group: 1.9555860418200896e-12
new misfit control group: 7.195492692978477e-13
predicted reduction control group: -8.887018361461577e-13
actual reduction control group: -1.2360367725222419e-12
1 out of 1 event(s) improved the misfit.
[2024-07-05 10:17:20,496] INFO: 
Model update accepted.
[2024-07-05 10:17:20,496] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:20,496] INFO: Processing task `finalize_iteration`
[2024-07-05 10:17:20,513] INFO: Succesfully completed iteration #7.
[2024-07-05 10:17:20,517] INFO: Adding new iteration #8.
[2024-07-05 10:17:20,531] INFO: Resuming iteration #8.

[2024-07-05 10:17:20,531] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:20,532] INFO: Processing task `gradient`
[2024-07-05 10:17:20