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-11-15 13:45:40,369] INFO: Creating mesh. Hang on.
[2024-11-15 13:45:40,418] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2411151345525359_b287899ae0@local
[2024-11-15 13:45:40,600] INFO: Creating mesh. Hang on.
[2024-11-15 13:45:40,627] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2411151345633930_3a930449fd@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-11-15 13:45:41,695] INFO: Adding new iteration #0.
[2024-11-15 13:45:41,707] INFO: Resuming iteration #0.

[2024-11-15 13:45:41,708] INFO: 1 new tasks have been issued.
[2024-11-15 13:45:41,708] INFO: Processing task `misfit_and_gradient`
[2024-11-15 13:45:41,728] 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-11-15 13:45:41,742] INFO: Submitting job ...
[2024-11-15 13:45:41,790] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-11-15 13:45:41,790] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-11-15 13:45:42,792] INFO: Processing task `misfit_and_gradient`
[2024-11-15 13:45:43,019] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2411151345021156_f85a47736b@local
[2024-11-15 13:45:43,066] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-11-15 13:45:43,067] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-11-15 13:45:44,068] INFO: Processing task `misfit_and_gradient`
[2024-11-15 13:45:44,147] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-11-15 13:45:44,296] INFO: 
Iteration 0: Number of events: 1	 chi = 3.7156536966723097e-10	 ||g|| = 3.3910359372571976e-12
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2024-11-15 13:45:44,301] INFO: 1 new tasks have been issued.
[2024-11-15 13:45:44,301] INFO: Processing task `misfit`
[2024-11-15 13:45:44,332] INFO: Submitting job ...
[2024-11-15 13:45:44,380] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-11-15 13:45:44,380] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-11-15 13:45:45,394] INFO: Processing task `misfit`
[2024-11-15 13:45:45,520] 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-11-15 13:45:45,521] INFO: 
Model update accepted.
[2024-11-15 13:45:45,522] INFO: 1 new tasks have been issued.
[2024-11-15 13:45:45,522] INFO: Processing task `finalize_iteration`
[2024-11-15 13:45:45,556] INFO: Succesfully completed iteration #0.
[2024-11-15 13:45:45,558] INFO: Adding new iteration #1.
[2024-11-15 13:45:45,564] INFO: Resuming iteration #1.

[2024-11-15 13:45:45,565] INFO: 1 new tasks have been issued.
[2024-11-15 13:45:45,565] INFO: Processing task `gradient`
[2024-11-15 13:45:45,648] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2411151345651018_ac8de8e7ce@local
[2024-11-15 13:45:45,714] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-11-15 13:45:45,715] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2024-11-15 13:45:46,717] INFO: Processing task `gradient`
[2024-11-15 13:45:46,758] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-11-15 13:45:46,802] INFO: Some simulations are still running. Please check again to see if they are finished.
[2024-11-15 13:45:46,803] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2024-11-15 13:45:47,805] INFO: Processing task `gradient`
[2024-11-15 13:45:47,835] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-11-15 13:45:47,870] INFO: Some simulations are still running. Please check again to see if they are finished.
[2024-11-15 13:45:47,871] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2024-11-15 13:45:48,873] INFO: Processing task `gradient`
[2024-11-15 13:45:48,904] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-11-15 13:45:49,047] 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-11-15 13:45:49,060] INFO: 1 new tasks have been issued.
[2024-11-15 13:45:49,061] INFO: Processing task `misfit`
[2024-11-15 13:45:49,094] INFO: Submitting job ...
[2024-11-15 13:45:49,160] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-11-15 13:45:49,161] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2024-11-15 13:45:50,175] INFO: Processing task `misfit`
[2024-11-15 13:45:50,307] 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-11-15 13:45:50,308] INFO: 
Model update accepted.
[2024-11-15 13:45:50,309] INFO: 1 new tasks have been issued.
[2024-11-15 13:45:50,309] INFO: Processing task `finalize_iteration`
[2024-11-15 13:45:50,345] INFO: Succesfully completed iteration #1.
[2024-11-15 13:45:50,348] INFO: Adding new iteration #2.
[2024-11-15 13:45:50,354] INFO: Resuming iteration #2.

[2024-11-15 13:45:50,355] INFO: 1 new tasks have been issued.
[2024-11-15 13:45:50,355] INFO: Processing task `gradient`
[2024-11-15 13:45:50,423] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2411151345425997_ff798d9ea1@local
[2024-11-15 13:45:50,481] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-11-15 13:45:50,482] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2024-11-15 13:45:51,484] INFO: Processing task `gradient`
[2024-11-15 13:45:51,530] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-11-15 13:45:51,696] 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-11-15 13:45:51,717] INFO: 1 new tasks have been issued.
[2024-11-15 13:45:51,718] INFO: Processing task `misfit`
[2024-11-15 13:45:51,756] INFO: Submitting job ...
[2024-11-15 13:45:51,844] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-11-15 13:45:51,845] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2024-11-15 13:45:52,858] INFO: Processing task `misfit`
[2024-11-15 13:45:52,976] 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-11-15 13:45:52,977] INFO: 
Model update accepted.
[2024-11-15 13:45:52,978] INFO: 1 new tasks have been issued.
[2024-11-15 13:45:52,978] INFO: Processing task `finalize_iteration`
[2024-11-15 13:45:53,007] INFO: Succesfully completed iteration #2.
[2024-11-15 13:45:53,010] INFO: Adding new iteration #3.
[2024-11-15 13:45:53,024] INFO: Resuming iteration #3.

[2024-11-15 13:45:53,025] INFO: 1 new tasks have been issued.
[2024-11-15 13:45:53,025] INFO: Processing task `gradient`
[2024-11-15 13:45:53,097] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2411151345106793_bbde83abbf@local
[2024-11-15 13:45:53,164] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-11-15 13:45:53,164] INFO: Some tasks of iteration #3 are still running. Please check again later.
[2024-11-15 13:45:54,168] INFO: Processing task `gradient`
[2024-11-15 13:45:54,222] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-11-15 13:45:54,394] 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-11-15 13:45:54,426] INFO: 1 new tasks have been issued.
[2024-11-15 13:45:54,432] INFO: Processing task `misfit`
[2024-11-15 13:45:54,471] INFO: Submitting job ...
[2024-11-15 13:45:54,539] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-11-15 13:45:54,539] INFO: Some tasks of iteration #3 are still running. Please check again later.
[2024-11-15 13:45:55,552] INFO: Processing task `misfit`
[2024-11-15 13:45:55,846] 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-11-15 13:45:55,846] INFO: 
Model update accepted.
[2024-11-15 13:45:55,847] INFO: 1 new tasks have been issued.
[2024-11-15 13:45:55,847] INFO: Processing task `finalize_iteration`
[2024-11-15 13:45:55,872] INFO: Succesfully completed iteration #3.
[2024-11-15 13:45:55,875] INFO: Adding new iteration #4.
[2024-11-15 13:45:55,884] INFO: Resuming iteration #4.

[2024-11-15 13:45:55,884] INFO: 1 new tasks have been issued.
[2024-11-15 13:45:55,885] INFO: Processing task `gradient`
[2024-11-15 13:45:55,940] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2411151345942222_a925efa864@local
[2024-11-15 13:45:55,986] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-11-15 13:45:55,986] INFO: Some tasks of iteration #4 are still running. Please check again later.
[2024-11-15 13:45:56,988] INFO: Processing task `gradient`
[2024-11-15 13:45:57,039] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-11-15 13:45:57,191] 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-11-15 13:45:57,239] INFO: 1 new tasks have been issued.
[2024-11-15 13:45:57,240] INFO: Processing task `misfit`
[2024-11-15 13:45:57,280] INFO: Submitting job ...
[2024-11-15 13:45:57,341] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-11-15 13:45:57,341] INFO: Some tasks of iteration #4 are still running. Please check again later.
[2024-11-15 13:45:58,361] INFO: Processing task `misfit`
[2024-11-15 13:45:58,478] 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-11-15 13:45:58,479] INFO: 
Model update accepted.
[2024-11-15 13:45:58,479] INFO: 1 new tasks have been issued.
[2024-11-15 13:45:58,479] INFO: Processing task `finalize_iteration`
[2024-11-15 13:45:58,516] INFO: Succesfully completed iteration #4.
[2024-11-15 13:45:58,520] INFO: Adding new iteration #5.
[2024-11-15 13:45:58,534] INFO: Resuming iteration #5.

[2024-11-15 13:45:58,535] INFO: 1 new tasks have been issued.
[2024-11-15 13:45:58,535] INFO: Processing task `gradient`
[2024-11-15 13:45:58,623] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2411151345626349_88ede30f4b@local
[2024-11-15 13:45:58,689] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-11-15 13:45:58,689] INFO: Some tasks of iteration #5 are still running. Please check again later.
[2024-11-15 13:45:59,693] INFO: Processing task `gradient`
[2024-11-15 13:45:59,742] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-11-15 13:45:59,904] 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-11-15 13:45:59,952] INFO: 1 new tasks have been issued.
[2024-11-15 13:45:59,952] INFO: Processing task `misfit`
[2024-11-15 13:45:59,989] INFO: Submitting job ...
[2024-11-15 13:46:00,053] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-11-15 13:46:00,053] INFO: Some tasks of iteration #5 are still running. Please check again later.
[2024-11-15 13:46:01,071] INFO: Processing task `misfit`
[2024-11-15 13:46:01,198] 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-11-15 13:46:01,199] INFO: 
Model update accepted.
[2024-11-15 13:46:01,199] INFO: 1 new tasks have been issued.
[2024-11-15 13:46:01,199] INFO: Processing task `finalize_iteration`
[2024-11-15 13:46:01,237] INFO: Succesfully completed iteration #5.
[2024-11-15 13:46:01,242] INFO: Adding new iteration #6.
[2024-11-15 13:46:01,258] INFO: Resuming iteration #6.

[2024-11-15 13:46:01,259] INFO: 1 new tasks have been issued.
[2024-11-15 13:46:01,259] INFO: Processing task `gradient`
[2024-11-15 13:46:01,340] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2411151346342645_2327e91691@local
[2024-11-15 13:46:01,412] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-11-15 13:46:01,413] INFO: Some tasks of iteration #6 are still running. Please check again later.
[2024-11-15 13:46:02,417] INFO: Processing task `gradient`
[2024-11-15 13:46:02,461] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-11-15 13:46:02,621] 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-11-15 13:46:02,677] INFO: 1 new tasks have been issued.
[2024-11-15 13:46:02,677] INFO: Processing task `misfit`
[2024-11-15 13:46:02,714] INFO: Submitting job ...
[2024-11-15 13:46:02,780] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-11-15 13:46:02,780] INFO: Some tasks of iteration #6 are still running. Please check again later.
[2024-11-15 13:46:03,800] INFO: Processing task `misfit`
[2024-11-15 13:46:03,846] INFO: Some tasks of iteration #6 are still running. Please check again later.
[2024-11-15 13:46:04,869] INFO: Processing task `misfit`
[2024-11-15 13:46:05,005] 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-11-15 13:46:05,006] INFO: 
Model update accepted.
[2024-11-15 13:46:05,006] INFO: 1 new tasks have been issued.
[2024-11-15 13:46:05,007] INFO: Processing task `finalize_iteration`
[2024-11-15 13:46:05,037] INFO: Succesfully completed iteration #6.
[2024-11-15 13:46:05,041] INFO: Adding new iteration #7.
[2024-11-15 13:46:05,053] INFO: Resuming iteration #7.

[2024-11-15 13:46:05,053] INFO: 1 new tasks have been issued.
[2024-11-15 13:46:05,054] INFO: Processing task `gradient`
[2024-11-15 13:46:05,138] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2411151346141383_c9ae864694@local
[2024-11-15 13:46:05,201] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-11-15 13:46:05,202] INFO: Some tasks of iteration #7 are still running. Please check again later.
[2024-11-15 13:46:06,208] INFO: Processing task `gradient`
[2024-11-15 13:46:06,259] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-11-15 13:46:06,414] 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-11-15 13:46:06,464] INFO: 1 new tasks have been issued.
[2024-11-15 13:46:06,465] INFO: Processing task `misfit`
[2024-11-15 13:46:06,495] INFO: Submitting job ...
[2024-11-15 13:46:06,564] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-11-15 13:46:06,564] INFO: Some tasks of iteration #7 are still running. Please check again later.
[2024-11-15 13:46:07,584] INFO: Processing task `misfit`
[2024-11-15 13:46:07,705] 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-11-15 13:46:07,706] INFO: 
Model update accepted.
[2024-11-15 13:46:07,706] INFO: 1 new tasks have been issued.
[2024-11-15 13:46:07,706] INFO: Processing task `finalize_iteration`
[2024-11-15 13:46:07,749] INFO: Succesfully completed iteration #7.
[2024-11-15 13:46:07,755] INFO: Adding new iteration #8.
[2024-11-15 13:46:07,778] INFO: Resuming iteration #8.

[2024-11-15 13:46:07,778] INFO: 1 new tasks have been issued.
[2024-11-15 13:46:07,779] INFO: Processing task `gradient`
[2024-11-15 13:46:07,858] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2411151346860987_c23704b56f@local
[2024-11-15 13:46:07,916] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-11-15 13:46:07,916] INFO: Some tasks of iteration #8 are still running. Please check again later.
[2024-11-15 13:46:08,921] INFO: Processing task `gradient`
[2024-11-15 13:46:08,970] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-11-15 13:46:09,028] INFO: Some simulations are still running. Please check again to see if they are finished.
[2024-11-15 13:46:09,031] INFO: Some tasks of iteration #8 are still running. Please check again later.
[2024-11-15 13:46:10,037] INFO: Processing task `gradient`
[2024-11-15 13:46:10,090] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-11-15 13:46:10,147] INFO: Some simulations are still running. Please check again to see if they are finished.
[2024-11-15 13:46:10,148] INFO: Some tasks of iteration #8 are still running. Please check again later.
[2024-11-15 13:46:11,153] INFO: Processing task `gradient`
[2024-11-15 13:46:11,198] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-11-15 13:46:11,347] 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-11-15 13:46:11,411] INFO: 1 new tasks have been issued.
[2024-11-15 13:46:11,411] INFO: Processing task `misfit`
[2024-11-15 13:46:11,446] INFO: Submitting job ...
[2024-11-15 13:46:11,510] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-11-15 13:46:11,511] INFO: Some tasks of iteration #8 are still running. Please check again later.
[2024-11-15 13:46:12,531] INFO: Processing task `misfit`
[2024-11-15 13:46:12,567] INFO: Some tasks of iteration #8 are still running. Please check again later.
[2024-11-15 13:46:13,589] INFO: Processing task `misfit`
[2024-11-15 13:46:13,631] INFO: Some tasks of iteration #8 are still running. Please check again later.
[2024-11-15 13:46:14,648] INFO: Processing task `misfit`
[2024-11-15 13:46:14,808] 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-11-15 13:46:14,809] INFO: 
Model update accepted.
[2024-11-15 13:46:14,809] INFO: 1 new tasks have been issued.
[2024-11-15 13:46:14,810] INFO: Processing task `finalize_iteration`
[2024-11-15 13:46:14,867] INFO: Succesfully completed iteration #8.
[2024-11-15 13:46:14,873] INFO: Adding new iteration #9.
[2024-11-15 13:46:14,890] INFO: Resuming iteration #9.

[2024-11-15 13:46:14,890] 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, 4e-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 0x76a90af5da50>
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-11-15 13:46:16,710] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2411151346713953_ab18ac3e50@local
[2024-11-15 13:46:17,403] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2411151346406711_b511831812@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-11-15 13:46:18,276] INFO: Adding new iteration #0.
[2024-11-15 13:46:18,287] INFO: Resuming iteration #0.

[2024-11-15 13:46:18,287] INFO: 1 new tasks have been issued.
[2024-11-15 13:46:18,288] INFO: Processing task `misfit_and_gradient`
[2024-11-15 13:46:18,307] 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-11-15 13:46:18,321] INFO: Submitting job ...
[2024-11-15 13:46:18,415] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-11-15 13:46:18,419] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-11-15 13:46:23,421] INFO: Processing task `misfit_and_gradient`
[2024-11-15 13:46:23,653] INFO: Submitting job ...
Uploading 1 files...

🚀  Submitted job_2411151346656357_f90e0ec00e@local
[2024-11-15 13:46:23,725] INFO: Launched adjoint simulations for 1 events. Please check again to see if they are finished.
[2024-11-15 13:46:23,726] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-11-15 13:46:28,729] INFO: Processing task `misfit_and_gradient`
[2024-11-15 13:46:28,828] INFO: 1 events have already been submitted. They will not be submitted again.
[2024-11-15 13:46:29,016] INFO: 
Iteration 0: Number of events: 1	 chi = 1.8063817169917176e-11	 ||g|| = 3.4633490526471955e-13
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2024-11-15 13:46:29,026] INFO: 1 new tasks have been issued.
[2024-11-15 13:46:29,026] INFO: Processing task `misfit`
[2024-11-15 13:46:29,077] INFO: Submitting job ...
[2024-11-15 13:46:29,226] INFO: Launched simulations for 1 events. Please check again to see if they are finished.
[2024-11-15 13:46:29,227] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-11-15 13:46:34,293] INFO: Processing task `misfit`
[2024-11-15 13:46:34,494] 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-11-15 13:46:34,495] INFO: 
Model update accepted.
[2024-11-15 13:46:34,496] INFO: 1 new tasks have been issued.
[2024-11-15 13:46:34,496] INFO: Processing task `finalize_iteration`
[2024-11-15 13:46:34,532] INFO: Succesfully completed iteration #0.
[2024-11-15 13:46:34,535] 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 0x76a90b1f8fd0>
PAGE CONTENTS