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-02 14:21:13,144] INFO: Creating mesh. Hang on.
[2024-07-02 14:21:13,213] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407021421328322_0281c56c3c@local
[2024-07-02 14:21:13,433] INFO: Creating mesh. Hang on.
[2024-07-02 14:21:13,476] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407021421487879_4931599aaf@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-02 14:21:14,484] INFO: Adding new iteration #0.
[2024-07-02 14:21:14,495] INFO: Resuming iteration #0.

[2024-07-02 14:21:14,495] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:14,495] INFO: Processing task `misfit_and_gradient`
[2024-07-02 14:21:14,520] 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-02 14:21:14,532] INFO: Submitting job ...
[2024-07-02 14:21:14,578] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-02 14:21:14,579] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:21:15,580] INFO: Processing task `misfit_and_gradient`
[2024-07-02 14:21:15,822] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407021421823991_62493ce27c@local
[2024-07-02 14:21:15,866] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-07-02 14:21:15,866] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:21:16,868] INFO: Processing task `misfit_and_gradient`
[2024-07-02 14:21:16,952] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-07-02 14:21:17,086] INFO: 
Iteration 0: Number of events: 1	 chi = 3.7156536966723097e-10	 ||g|| = 3.3910359372571976e-12
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2024-07-02 14:21:17,090] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:17,091] INFO: Processing task `misfit`
[2024-07-02 14:21:17,121] INFO: Submitting job ...
[2024-07-02 14:21:17,182] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-02 14:21:17,183] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:21:18,200] INFO: Processing task `misfit`
[2024-07-02 14:21:18,321] 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-02 14:21:18,322] INFO: 
Model update accepted.
[2024-07-02 14:21:18,322] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:18,323] INFO: Processing task `finalize_iteration`
[2024-07-02 14:21:18,345] INFO: Succesfully completed iteration #0.
[2024-07-02 14:21:18,347] INFO: Adding new iteration #1.
[2024-07-02 14:21:18,354] INFO: Resuming iteration #1.

[2024-07-02 14:21:18,355] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:18,355] INFO: Processing task `gradient`
[2024-07-02 14:21:18,439] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407021421442004_2110fc56c0@local
[2024-07-02 14:21:18,495] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-07-02 14:21:18,496] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2024-07-02 14:21:19,498] INFO: Processing task `gradient`
[2024-07-02 14:21:19,544] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-07-02 14:21:19,672] 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-02 14:21:19,681] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:19,681] INFO: Processing task `misfit`
[2024-07-02 14:21:19,709] INFO: Submitting job ...
[2024-07-02 14:21:19,761] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-02 14:21:19,761] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2024-07-02 14:21:20,774] INFO: Processing task `misfit`
[2024-07-02 14:21:20,878] 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-02 14:21:20,878] INFO: 
Model update accepted.
[2024-07-02 14:21:20,879] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:20,879] INFO: Processing task `finalize_iteration`
[2024-07-02 14:21:20,895] INFO: Succesfully completed iteration #1.
[2024-07-02 14:21:20,898] INFO: Adding new iteration #2.
[2024-07-02 14:21:20,906] INFO: Resuming iteration #2.

[2024-07-02 14:21:20,907] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:20,907] INFO: Processing task `gradient`
[2024-07-02 14:21:21,005] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407021421007879_c675870f8b@local
[2024-07-02 14:21:21,058] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-07-02 14:21:21,058] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2024-07-02 14:21:22,061] INFO: Processing task `gradient`
[2024-07-02 14:21:22,111] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-07-02 14:21:22,241] 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-02 14:21:22,256] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:22,257] INFO: Processing task `misfit`
[2024-07-02 14:21:22,292] INFO: Submitting job ...
[2024-07-02 14:21:22,348] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-02 14:21:22,349] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2024-07-02 14:21:23,362] INFO: Processing task `misfit`
[2024-07-02 14:21:23,478] 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-02 14:21:23,478] INFO: 
Model update accepted.
[2024-07-02 14:21:23,479] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:23,479] INFO: Processing task `finalize_iteration`
[2024-07-02 14:21:23,497] INFO: Succesfully completed iteration #2.
[2024-07-02 14:21:23,500] INFO: Adding new iteration #3.
[2024-07-02 14:21:23,507] INFO: Resuming iteration #3.

[2024-07-02 14:21:23,507] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:23,508] INFO: Processing task `gradient`
[2024-07-02 14:21:23,589] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407021421592020_88f8187fc1@local
[2024-07-02 14:21:23,845] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-07-02 14:21:23,845] INFO: Some tasks of iteration #3 are still running. Please check again later.
[2024-07-02 14:21:24,848] INFO: Processing task `gradient`
[2024-07-02 14:21:24,895] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-07-02 14:21:25,020] 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-02 14:21:25,044] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:25,045] INFO: Processing task `misfit`
[2024-07-02 14:21:25,071] INFO: Submitting job ...
[2024-07-02 14:21:25,119] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-02 14:21:25,120] INFO: Some tasks of iteration #3 are still running. Please check again later.
[2024-07-02 14:21:26,134] INFO: Processing task `misfit`
[2024-07-02 14:21:26,234] 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-02 14:21:26,234] INFO: 
Model update accepted.
[2024-07-02 14:21:26,235] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:26,235] INFO: Processing task `finalize_iteration`
[2024-07-02 14:21:26,252] INFO: Succesfully completed iteration #3.
[2024-07-02 14:21:26,257] INFO: Adding new iteration #4.
[2024-07-02 14:21:26,269] INFO: Resuming iteration #4.

[2024-07-02 14:21:26,270] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:26,270] INFO: Processing task `gradient`
[2024-07-02 14:21:26,367] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407021421370302_bc76a53381@local
[2024-07-02 14:21:26,414] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-07-02 14:21:26,415] INFO: Some tasks of iteration #4 are still running. Please check again later.
[2024-07-02 14:21:27,419] INFO: Processing task `gradient`
[2024-07-02 14:21:27,481] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-07-02 14:21:27,643] 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-02 14:21:27,675] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:27,676] INFO: Processing task `misfit`
[2024-07-02 14:21:27,705] INFO: Submitting job ...
[2024-07-02 14:21:27,758] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-02 14:21:27,758] INFO: Some tasks of iteration #4 are still running. Please check again later.
[2024-07-02 14:21:28,773] INFO: Processing task `misfit`
[2024-07-02 14:21:28,883] 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-02 14:21:28,883] INFO: 
Model update accepted.
[2024-07-02 14:21:28,883] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:28,884] INFO: Processing task `finalize_iteration`
[2024-07-02 14:21:28,905] INFO: Succesfully completed iteration #4.
[2024-07-02 14:21:28,910] INFO: Adding new iteration #5.
[2024-07-02 14:21:28,923] INFO: Resuming iteration #5.

[2024-07-02 14:21:28,924] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:28,929] INFO: Processing task `gradient`
[2024-07-02 14:21:29,013] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407021421015747_4a8781bd1f@local
[2024-07-02 14:21:29,058] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-07-02 14:21:29,059] INFO: Some tasks of iteration #5 are still running. Please check again later.
[2024-07-02 14:21:30,062] INFO: Processing task `gradient`
[2024-07-02 14:21:30,109] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-07-02 14:21:30,233] 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-02 14:21:30,276] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:30,277] INFO: Processing task `misfit`
[2024-07-02 14:21:30,310] INFO: Submitting job ...
[2024-07-02 14:21:30,354] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-02 14:21:30,355] INFO: Some tasks of iteration #5 are still running. Please check again later.
[2024-07-02 14:21:31,373] INFO: Processing task `misfit`
[2024-07-02 14:21:31,477] 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-02 14:21:31,478] INFO: 
Model update accepted.
[2024-07-02 14:21:31,478] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:31,479] INFO: Processing task `finalize_iteration`
[2024-07-02 14:21:31,498] INFO: Succesfully completed iteration #5.
[2024-07-02 14:21:31,502] INFO: Adding new iteration #6.
[2024-07-02 14:21:31,516] INFO: Resuming iteration #6.

[2024-07-02 14:21:31,518] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:31,518] INFO: Processing task `gradient`
[2024-07-02 14:21:31,592] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407021421594905_abe729016e@local
[2024-07-02 14:21:31,641] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-07-02 14:21:31,642] INFO: Some tasks of iteration #6 are still running. Please check again later.
[2024-07-02 14:21:32,645] INFO: Processing task `gradient`
[2024-07-02 14:21:32,694] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-07-02 14:21:32,855] 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-02 14:21:32,909] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:32,910] INFO: Processing task `misfit`
[2024-07-02 14:21:32,936] INFO: Submitting job ...
[2024-07-02 14:21:32,986] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-02 14:21:32,987] INFO: Some tasks of iteration #6 are still running. Please check again later.
[2024-07-02 14:21:34,001] INFO: Processing task `misfit`
[2024-07-02 14:21:34,111] 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-02 14:21:34,112] INFO: 
Model update accepted.
[2024-07-02 14:21:34,112] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:34,113] INFO: Processing task `finalize_iteration`
[2024-07-02 14:21:34,136] INFO: Succesfully completed iteration #6.
[2024-07-02 14:21:34,143] INFO: Adding new iteration #7.
[2024-07-02 14:21:34,162] INFO: Resuming iteration #7.

[2024-07-02 14:21:34,162] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:34,163] INFO: Processing task `gradient`
[2024-07-02 14:21:34,258] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407021421260589_454da9451d@local
[2024-07-02 14:21:34,302] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-07-02 14:21:34,302] INFO: Some tasks of iteration #7 are still running. Please check again later.
[2024-07-02 14:21:35,306] INFO: Processing task `gradient`
[2024-07-02 14:21:35,353] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-07-02 14:21:35,514] 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-02 14:21:35,570] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:35,570] INFO: Processing task `misfit`
[2024-07-02 14:21:35,603] INFO: Submitting job ...
[2024-07-02 14:21:35,665] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-02 14:21:35,666] INFO: Some tasks of iteration #7 are still running. Please check again later.
[2024-07-02 14:21:36,683] INFO: Processing task `misfit`
[2024-07-02 14:21:36,798] 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-02 14:21:36,799] INFO: 
Model update accepted.
[2024-07-02 14:21:36,799] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:36,800] INFO: Processing task `finalize_iteration`
[2024-07-02 14:21:36,827] INFO: Succesfully completed iteration #7.
[2024-07-02 14:21:36,833] INFO: Adding new iteration #8.
[2024-07-02 14:21:36,850] INFO: Resuming iteration #8.

[2024-07-02 14:21:36,850] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:36,851] INFO: Processing task `gradient`
[2024-07-02 14:21:36,933] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407021421935842_6e5e49d7f8@local
[2024-07-02 14:21:36,987] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-07-02 14:21:36,988] INFO: Some tasks of iteration #8 are still running. Please check again later.
[2024-07-02 14:21:37,994] INFO: Processing task `gradient`
[2024-07-02 14:21:38,050] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-07-02 14:21:38,209] INFO: 
Iteration 8: Number of events: 1	 chi = 7.195492692978477e-13	 ||g|| = 1.668305656509431e-13
pred = -8.887018361461577e-13	ared = -1.2360367725222419e-12	norm_update = 83.04605740553336	tr_radius = 103.78243698908238
[2024-07-02 14:21:38,263] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:38,264] INFO: Processing task `misfit`
[2024-07-02 14:21:38,293] INFO: Submitting job ...
[2024-07-02 14:21:38,344] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-02 14:21:38,344] INFO: Some tasks of iteration #8 are still running. Please check again later.
[2024-07-02 14:21:39,360] INFO: Processing task `misfit`
[2024-07-02 14:21:39,461] INFO: 
old misfit control group: 7.195492692978477e-13
new misfit control group: 3.428681080907987e-14
predicted reduction control group: -5.160693460554207e-13
actual reduction control group: -6.852624584887678e-13
1 out of 1 event(s) improved the misfit.
[2024-07-02 14:21:39,461] INFO: 
Model update accepted.
[2024-07-02 14:21:39,462] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:39,462] INFO: Processing task `finalize_iteration`
[2024-07-02 14:21:39,485] INFO: Succesfully completed iteration #8.
[2024-07-02 14:21:39,490] INFO: Adding new iteration #9.
[2024-07-02 14:21:39,509] INFO: Resuming iteration #9.

[2024-07-02 14:21:39,510] 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`.
Finally, we load the final model and check that it indeed converged to the true model. The reconstruction matches the true model with less than 0.1% error for compressional and shear wave speed and less than 0.2% for density.
p.viz.nb.inversion(inverse_problem_configuration="inversion")
solution = p.simulations.get_mesh(
    p.inversions.get_simulation_name("inversion", 9)
)
np.testing.assert_allclose(solution.elemental_fields["VP"], 5800.0, 1e-3)
np.testing.assert_allclose(solution.elemental_fields["VS"], 3200.0, 1e-3)
np.testing.assert_allclose(solution.elemental_fields["RHO"], 2600.0, 2e-3)
Another useful extension deals with piecewise constant material parameters. We assume that the the partition of the domain into two or more materials is known and captured by the mesh, but the exact material parameters are unknown.
Discontinuous material interfaces can be indicated using an elemental field block with integer IDs labeling the different parts of the model. For some meshing routines, this field is automatically added. In this example, we manually assign different IDs to distinguish a small square at [0.4, 0.6] x [0.5, 0.7] from the background media.
mesh = p.simulations.get_mesh("true")

blocks = np.zeros(mesh.nelem, dtype=int)
mask1 = mesh.get_element_centroid()[:, 0] > 0.4
mask2 = mesh.get_element_centroid()[:, 0] < 0.6
mask3 = mesh.get_element_centroid()[:, 1] > 0.5
mask4 = mesh.get_element_centroid()[:, 1] < 0.7
mask = mask1 & mask2 & mask3 & mask4
blocks[mask] = 1
mesh.attach_field("block", blocks)
mesh
<salvus.mesh.data_structures.unstructured_mesh.unstructured_mesh.UnstructuredMesh object at 0x7f9dea353a10>
To demonstrate inverting for piece-wise constant material, we add two simulation configurations, a homogeneous model with the block IDs as initial model, and the "true model" with different properties in the selected square.
p.add_to_project(
    sn.UnstructuredMeshSimulationConfiguration(
        name="two_blocks_initial",
        unstructured_mesh=mesh,
        event_configuration=ec,
    ),
)

mesh.elemental_fields["VP"][blocks == 1] *= 1.1
mesh.elemental_fields["VS"][blocks == 1] *= 1.1
mesh.elemental_fields["RHO"][blocks == 1] *= 1.1

p.add_to_project(
    sn.UnstructuredMeshSimulationConfiguration(
        name="two_blocks",
        unstructured_mesh=mesh,
        event_configuration=ec,
    ),
)
for name in ["two_blocks_initial", "two_blocks"]:
    p.simulations.launch(
        simulation_configuration=name,
        events=p.events.list(),
        site_name=SALVUS_FLOW_SITE_NAME,
        ranks_per_job=1,
    )
    p.simulations.query(block=True)
[2024-07-02 14:21:41,140] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407021421145349_cd95941a93@local
[2024-07-02 14:21:41,763] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407021421767044_febb28538d@local
A new misfit configuration is required to reference the data from te block model.
p += sn.MisfitConfiguration(
    name="L2-block",
    observed_data="two_blocks",
    misfit_function="L2",
    receiver_field="displacement",
)
The key element to bring in the discontinuous model parameterization into the inversion is in the mapping function. Here, we specify discontinuous_model_blocks, which refers to the values defined in the field block and indicates the piece-wise constant regions of the model. In this example, only the area with block = 1 will be updated. The background model is kept constant. Note that in this example no region of interest or preconditioner is required.
p += sn.InverseProblemConfiguration(
    name="inversion_two",
    prior_model="two_blocks_initial",
    events=p.events.list(),
    mapping=sn.Mapping(
        scaling="homogeneous",
        discontinuous_model_blocks=[[1]],
        inversion_parameters=["VP", "VS", "RHO"],
    ),
    method=sn.TrustRegion(initial_trust_region_linf=100.0),
    misfit_configuration="L2-block",
    job_submission=sn.SiteConfig(
        site_name=SALVUS_FLOW_SITE_NAME, ranks_per_job=1
    ),
)
We perform a single iteration to validate that the update only affects the block inclusion.
p.inversions.iterate(
    inverse_problem_configuration="inversion_two",
    timeout_in_seconds=360,
    ping_interval_in_seconds=5,
)
[2024-07-02 14:21:42,582] INFO: Adding new iteration #0.
[2024-07-02 14:21:42,600] INFO: Resuming iteration #0.

[2024-07-02 14:21:42,600] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:42,602] INFO: Processing task `misfit_and_gradient`
[2024-07-02 14:21:42,630] 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-02 14:21:42,648] INFO: Submitting job ...
[2024-07-02 14:21:42,701] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-02 14:21:42,702] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:21:47,703] INFO: Processing task `misfit_and_gradient`
[2024-07-02 14:21:48,005] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407021421008416_ddbbcdc676@local
[2024-07-02 14:21:48,059] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-07-02 14:21:48,059] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:21:53,061] INFO: Processing task `misfit_and_gradient`
[2024-07-02 14:21:53,135] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-07-02 14:21:53,264] INFO: 
Iteration 0: Number of events: 1	 chi = 1.8063817169917176e-11	 ||g|| = 3.4633490526471955e-13
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2024-07-02 14:21:53,268] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:53,268] INFO: Processing task `misfit`
[2024-07-02 14:21:53,296] INFO: Submitting job ...
[2024-07-02 14:21:53,342] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-02 14:21:53,343] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:21:58,357] INFO: Processing task `misfit`
[2024-07-02 14:21:58,462] INFO: 
old misfit control group: 1.8063817169917176e-11
new misfit control group: 1.0995271385440556e-11
predicted reduction control group: -4.165941036285124e-12
actual reduction control group: -7.06854578447662e-12
1 out of 1 event(s) improved the misfit.
[2024-07-02 14:21:58,463] INFO: 
Model update accepted.
[2024-07-02 14:21:58,463] INFO: 1 new tasks have been issued.
[2024-07-02 14:21:58,464] INFO: Processing task `finalize_iteration`
[2024-07-02 14:21:58,477] INFO: Succesfully completed iteration #0.
[2024-07-02 14:21:58,479] INFO: Adding new iteration #1.
p.simulations.get_mesh(p.inversions.get_simulation_name("inversion_two", 1))
<salvus.mesh.data_structures.unstructured_mesh.unstructured_mesh.UnstructuredMesh object at 0x7f9dea34f910>
PAGE CONTENTS