Version:
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,599] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407051017601263_a270ef0903@local
[2024-07-05 10:17:20,644] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-07-05 10:17:20,645] INFO: Some tasks of iteration #8 are still running. Please check again later.
[2024-07-05 10:17:21,648] INFO: Processing task `gradient`
[2024-07-05 10:17:21,693] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-07-05 10:17:21,820] 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-05 10:17:21,865] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:21,866] INFO: Processing task `misfit`
[2024-07-05 10:17:21,892] INFO: Submitting job ...
[2024-07-05 10:17:21,939] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-05 10:17:21,939] INFO: Some tasks of iteration #8 are still running. Please check again later.
[2024-07-05 10:17:22,952] INFO: Processing task `misfit`
[2024-07-05 10:17:23,058] 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-05 10:17:23,058] INFO: 
Model update accepted.
[2024-07-05 10:17:23,058] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:23,059] INFO: Processing task `finalize_iteration`
[2024-07-05 10:17:23,074] INFO: Succesfully completed iteration #8.
[2024-07-05 10:17:23,079] INFO: Adding new iteration #9.
[2024-07-05 10:17:23,094] INFO: Resuming iteration #9.

[2024-07-05 10:17:23,095] 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 0x7fda7f446fd0>
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-05 10:17:24,420] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407051017423565_d56d25e52b@local
[2024-07-05 10:17:25,022] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407051017025145_500f25f96a@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-05 10:17:25,766] INFO: Adding new iteration #0.
[2024-07-05 10:17:25,773] INFO: Resuming iteration #0.

[2024-07-05 10:17:25,773] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:25,773] INFO: Processing task `misfit_and_gradient`
[2024-07-05 10:17:25,789] 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:17:25,798] INFO: Submitting job ...
[2024-07-05 10:17:25,847] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-05 10:17:25,848] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-05 10:17:30,850] INFO: Processing task `misfit_and_gradient`
[2024-07-05 10:17:31,023] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2407051017025051_23ecb1c90b@local
[2024-07-05 10:17:31,070] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-07-05 10:17:31,071] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-05 10:17:36,073] INFO: Processing task `misfit_and_gradient`
[2024-07-05 10:17:36,141] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-07-05 10:17:36,261] INFO: 
Iteration 0: Number of events: 1	 chi = 1.8063817169917176e-11	 ||g|| = 3.4633490526471955e-13
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2024-07-05 10:17:36,264] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:36,264] INFO: Processing task `misfit`
[2024-07-05 10:17:36,290] INFO: Submitting job ...
[2024-07-05 10:17:36,336] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-07-05 10:17:36,336] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-05 10:17:41,347] INFO: Processing task `misfit`
[2024-07-05 10:17:41,450] 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-05 10:17:41,451] INFO: 
Model update accepted.
[2024-07-05 10:17:41,451] INFO: 1 new tasks have been issued.
[2024-07-05 10:17:41,451] INFO: Processing task `finalize_iteration`
[2024-07-05 10:17:41,462] INFO: Succesfully completed iteration #0.
[2024-07-05 10:17:41,463] 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 0x7fda7f379ed0>
PAGE CONTENTS