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.

Full-Waveform Inversion

Part 5 - Extensions

Copy
%matplotlib inline
# This notebook will use this variable to determine which
# remote site to run on.
import os
import numpy as np
import salvus.namespace as sn

SALVUS_FLOW_SITE_NAME = os.environ.get("SITE_NAME", "local")
p = sn.Project(path="project")
In a typical USCT setup, there is always enough space between the ultrasound transducers and the phantom. What if we include that information as prior knowledge into our problem formulation?
An easy way of doing this, is to define a region of interest and restrict the reconstruction to this area.
To keep it simple, we just define a sphere with a radius of 6.5 cm as the target region.
mesh = p.simulations.get_mesh(simulation_configuration="initial_model")
# define the region of interest
roi = np.zeros_like(mesh.connectivity)
mask = np.linalg.norm(mesh.points[mesh.connectivity], axis=2) < 0.065
roi[mask] = 1.0
mesh.attach_field("region_of_interest", roi)
Let's see if this helps with the iterations. To be able to compare the results, we just create a new inverse problem within the same project, initialize the region of interest, and start iterating.
p += sn.InverseProblemConfiguration(
    name="my_second_inversion",
    prior_model="initial_model",
    events=p.events.list(),
    mapping=sn.Mapping(
        scaling="absolute",
        inversion_parameters=["VP", "RHO"],
        region_of_interest=mesh,
    ),
    preconditioner=sn.ConstantSmoothing({"VP": 0.01, "RHO": 0.01}),
    method=sn.TrustRegion(initial_trust_region_linf=10.0),
    misfit_configuration="L2",
    wavefield_compression=sn.WavefieldCompression(
        forward_wavefield_sampling_interval=10
    ),
    job_submission=sn.SiteConfig(
        site_name=SALVUS_FLOW_SITE_NAME, ranks_per_job=4
    ),
)
p.inversions.iterate(
    inverse_problem_configuration="my_second_inversion",
    timeout_in_seconds=360,
    ping_interval_in_seconds=10,
)
[2024-07-02 14:16:58,018] INFO: Adding new iteration #0.
[2024-07-02 14:16:58,053] INFO: Resuming iteration #0.

[2024-07-02 14:16:58,056] INFO: 1 new tasks have been issued.
[2024-07-02 14:16:58,057] INFO: Processing task `misfit_and_gradient`
[2024-07-02 14:16:58,840] INFO: 
Iteration 0: Number of events: 5	 chi = 0.017690076157774178	 ||g|| = 0.01626160085513182
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2024-07-02 14:16:58,842] INFO: 1 new tasks have been issued.
[2024-07-02 14:16:58,846] INFO: Processing task `preconditioner`

[2024-07-02 14:16:59,244] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:17:09,288] INFO: Processing task `preconditioner`
[2024-07-02 14:17:09,601] INFO: 1 new tasks have been issued.
[2024-07-02 14:17:09,604] INFO: Processing task `misfit`
[2024-07-02 14:17:09,724] INFO: Submitting job array with 5 jobs ...

[2024-07-02 14:17:10,165] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2024-07-02 14:17:10,169] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:17:20,287] INFO: Processing task `misfit`
[2024-07-02 14:17:21,561] INFO: 
old misfit control group: 0.017690076157774175
new misfit control group: 0.00664570902045414
predicted reduction control group: -0.00573506534931896
actual reduction control group: -0.011044367137320035
5 out of 5 event(s) improved the misfit.
[2024-07-02 14:17:21,562] INFO: 
Model update accepted.
[2024-07-02 14:17:21,562] INFO: 1 new tasks have been issued.
[2024-07-02 14:17:21,563] INFO: Processing task `finalize_iteration`
[2024-07-02 14:17:21,611] INFO: Succesfully completed iteration #0.
[2024-07-02 14:17:21,614] INFO: Adding new iteration #1.
Let's see if the region of interest was considered when the model was updated.
p.viz.nb.inversion(inverse_problem_configuration="my_second_inversion")
Indeed, outside of the pre-defined sphere, the model is still constant and has the same values as the initial model.
Let's do a few more iterations and see what the reconstruction will be.
for i in range(2):
    p.inversions.iterate(
        inverse_problem_configuration="my_second_inversion",
        timeout_in_seconds=360,
        ping_interval_in_seconds=10,
    )
    p.inversions.delete_disposable_files(
        inverse_problem_configuration="my_second_inversion",
        data_to_remove=["auxiliary", "gradients", "waveforms"],
    )
p.viz.nb.inversion(inverse_problem_configuration="my_second_inversion")
[2024-07-02 14:17:23,385] INFO: Resuming iteration #1.

[2024-07-02 14:17:23,394] INFO: 1 new tasks have been issued.
[2024-07-02 14:17:23,395] INFO: Processing task `gradient`
[2024-07-02 14:17:23,944] INFO: Submitting job array with 5 jobs ...
Uploading 1 files...
Uploading 1 files...
Uploading 1 files...
Uploading 1 files...
Uploading 1 files...

[2024-07-02 14:17:24,092] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2024-07-02 14:17:24,095] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2024-07-02 14:17:34,098] INFO: Processing task `gradient`
[2024-07-02 14:17:34,763] INFO: 5 events have already been submitted. They will not be submitted again.
[2024-07-02 14:17:35,649] INFO: 
Iteration 1: Number of events: 5	 chi = 0.00664570902045414	 ||g|| = 0.008122022119893406
pred = -0.00573506534931896	ared = -0.011044367137320035	norm_update = 0.7265219524034239	tr_radius = 0.7265221051484864
[2024-07-02 14:17:35,663] INFO: 1 new tasks have been issued.
[2024-07-02 14:17:35,664] INFO: Processing task `preconditioner`

[2024-07-02 14:17:35,784] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2024-07-02 14:17:45,810] INFO: Processing task `preconditioner`
[2024-07-02 14:17:46,011] INFO: 1 new tasks have been issued.
[2024-07-02 14:17:46,012] INFO: Processing task `misfit`
[2024-07-02 14:17:46,177] INFO: Submitting job array with 5 jobs ...

[2024-07-02 14:17:46,621] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2024-07-02 14:17:46,643] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2024-07-02 14:17:56,827] INFO: Processing task `misfit`
[2024-07-02 14:17:57,870] INFO: 
old misfit control group: 0.00664570902045414
new misfit control group: 0.0028967886883502314
predicted reduction control group: -0.0027946883746031
actual reduction control group: -0.0037489203321039084
5 out of 5 event(s) improved the misfit.
[2024-07-02 14:17:57,872] INFO: 
Model update accepted.
[2024-07-02 14:17:57,872] INFO: 1 new tasks have been issued.
[2024-07-02 14:17:57,873] INFO: Processing task `finalize_iteration`
[2024-07-02 14:17:57,978] INFO: Succesfully completed iteration #1.
[2024-07-02 14:17:57,982] INFO: Adding new iteration #2.
[2024-07-02 14:17:57,993] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00000
[2024-07-02 14:17:57,997] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00001
[2024-07-02 14:17:58,259] INFO: Freed up 6.0 MB of space.
[2024-07-02 14:17:58,274] INFO: Resuming iteration #2.

[2024-07-02 14:17:58,276] INFO: 1 new tasks have been issued.
[2024-07-02 14:17:58,278] INFO: Processing task `gradient`
[2024-07-02 14:17:58,867] INFO: Submitting job array with 5 jobs ...
Uploading 1 files...
Uploading 1 files...
Uploading 1 files...
Uploading 1 files...
Uploading 1 files...

[2024-07-02 14:17:58,972] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2024-07-02 14:17:58,973] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2024-07-02 14:18:08,981] INFO: Processing task `gradient`
[2024-07-02 14:18:09,252] INFO: 5 events have already been submitted. They will not be submitted again.
[2024-07-02 14:18:09,889] INFO: 
Iteration 2: Number of events: 5	 chi = 0.002896788688350232	 ||g|| = 0.003362105420798052
pred = -0.0027946883746031	ared = -0.0037489203321039084	norm_update = 0.7176520315062779	tr_radius = 1.4530442102969727
[2024-07-02 14:18:09,911] INFO: 1 new tasks have been issued.
[2024-07-02 14:18:09,912] INFO: Processing task `preconditioner`

[2024-07-02 14:18:10,061] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2024-07-02 14:18:20,116] INFO: Processing task `preconditioner`
[2024-07-02 14:18:20,317] INFO: 1 new tasks have been issued.
[2024-07-02 14:18:20,318] INFO: Processing task `misfit`
[2024-07-02 14:18:20,444] INFO: Submitting job array with 5 jobs ...

[2024-07-02 14:18:20,652] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2024-07-02 14:18:20,653] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2024-07-02 14:18:30,734] INFO: Processing task `misfit`
[2024-07-02 14:18:31,977] INFO: 
old misfit control group: 0.0028967886883502314
new misfit control group: 0.0024078604607760306
predicted reduction control group: -0.0002203679362801023
actual reduction control group: -0.0004889282275742008
5 out of 5 event(s) improved the misfit.
[2024-07-02 14:18:31,977] INFO: 
Model update accepted.
[2024-07-02 14:18:31,979] INFO: 1 new tasks have been issued.
[2024-07-02 14:18:31,980] INFO: Processing task `finalize_iteration`
[2024-07-02 14:18:32,105] INFO: Succesfully completed iteration #2.
[2024-07-02 14:18:32,109] INFO: Adding new iteration #3.
[2024-07-02 14:18:32,119] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00000
[2024-07-02 14:18:32,122] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00001
[2024-07-02 14:18:32,247] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00002
[2024-07-02 14:18:32,459] INFO: Freed up 6.0 MB of space.
This looks better, so the prior knowledge was indeed helpful.
Alternatively, we could specify point-wise lower and upper bounds on the model parameters In the example below, we allow deviations of +/- 20% in both VP and RHO, except for the previously selected region of interest, where we restrict VP updates to +/- 1 m/s.
Note that the mapping function does not contain a region of interest in this case.
p += sn.InverseProblemConfiguration(
    name="my_third_inversion",
    prior_model="initial_model",
    events=p.events.list(),
    mapping=sn.Mapping(
        scaling="absolute",
        inversion_parameters=["VP", "RHO"],
    ),
    preconditioner=sn.ConstantSmoothing({"VP": 0.01, "RHO": 0.01}),
    method=sn.TrustRegion(initial_trust_region_linf=10.0),
    misfit_configuration="L2",
    wavefield_compression=sn.WavefieldCompression(
        forward_wavefield_sampling_interval=10
    ),
    job_submission=sn.SiteConfig(
        site_name=SALVUS_FLOW_SITE_NAME, ranks_per_job=4
    ),
)
mesh = p.simulations.get_mesh("initial_model")
lb = mesh.copy()
ones = np.ones_like(lb.elemental_fields["VP"])
lb.elemental_fields["VP"] *= 0.8
lb.elemental_fields["RHO"] *= 0.8
lb.elemental_fields["VP"][roi < 0.5] = 1501.0

ub = mesh.copy()
ub.elemental_fields["VP"] *= 1.2
ub.elemental_fields["RHO"] *= 1.2
ub.elemental_fields["VP"][roi < 0.5] = 1502.0

p.inversions.set_constraints(
    inverse_problem_configuration="my_third_inversion",
    constraints={
        "lower_bounds": lb,
        "upper_bounds": ub,
    },
)
p.inversions.iterate("my_third_inversion", timeout_in_seconds=360)
p.viz.nb.inversion(inverse_problem_configuration="my_third_inversion")
[2024-07-02 14:18:33,900] INFO: Adding new iteration #0.
[2024-07-02 14:18:33,912] INFO: Resuming iteration #0.

[2024-07-02 14:18:33,912] INFO: 1 new tasks have been issued.
[2024-07-02 14:18:33,913] INFO: Processing task `misfit_and_gradient`
[2024-07-02 14:18:34,490] INFO: 
Iteration 0: Number of events: 5	 chi = 0.017690076157774178	 ||g|| = 0.02256501205974222
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2024-07-02 14:18:34,491] INFO: 1 new tasks have been issued.
[2024-07-02 14:18:34,492] INFO: Processing task `preconditioner`

[2024-07-02 14:18:34,601] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:34,611] INFO: Processing task `preconditioner`
[2024-07-02 14:18:34,652] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:34,685] INFO: Processing task `preconditioner`
[2024-07-02 14:18:34,741] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:34,768] INFO: Processing task `preconditioner`
[2024-07-02 14:18:34,854] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:34,870] INFO: Processing task `preconditioner`
[2024-07-02 14:18:34,915] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:34,927] INFO: Processing task `preconditioner`
[2024-07-02 14:18:35,047] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:35,059] INFO: Processing task `preconditioner`
[2024-07-02 14:18:35,206] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:35,236] INFO: Processing task `preconditioner`
[2024-07-02 14:18:35,337] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:35,381] INFO: Processing task `preconditioner`
[2024-07-02 14:18:35,482] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:35,511] INFO: Processing task `preconditioner`
[2024-07-02 14:18:35,616] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:35,631] INFO: Processing task `preconditioner`
[2024-07-02 14:18:35,685] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:35,697] INFO: Processing task `preconditioner`
[2024-07-02 14:18:35,754] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:35,775] INFO: Processing task `preconditioner`
[2024-07-02 14:18:35,851] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:35,862] INFO: Processing task `preconditioner`
[2024-07-02 14:18:35,937] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:35,950] INFO: Processing task `preconditioner`
[2024-07-02 14:18:36,057] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:36,074] INFO: Processing task `preconditioner`
[2024-07-02 14:18:36,147] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:36,158] INFO: Processing task `preconditioner`
[2024-07-02 14:18:36,228] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:36,240] INFO: Processing task `preconditioner`
[2024-07-02 14:18:36,290] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:36,305] INFO: Processing task `preconditioner`
[2024-07-02 14:18:36,376] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:36,389] INFO: Processing task `preconditioner`
[2024-07-02 14:18:36,446] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:36,459] INFO: Processing task `preconditioner`
[2024-07-02 14:18:36,524] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:36,538] INFO: Processing task `preconditioner`
[2024-07-02 14:18:36,604] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:36,618] INFO: Processing task `preconditioner`
[2024-07-02 14:18:36,693] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:36,705] INFO: Processing task `preconditioner`
[2024-07-02 14:18:36,757] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:36,778] INFO: Processing task `preconditioner`
[2024-07-02 14:18:36,849] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:36,877] INFO: Processing task `preconditioner`
[2024-07-02 14:18:36,965] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:36,979] INFO: Processing task `preconditioner`
[2024-07-02 14:18:37,168] INFO: 1 new tasks have been issued.
[2024-07-02 14:18:37,169] INFO: Processing task `misfit`
[2024-07-02 14:18:37,316] INFO: Submitting job array with 5 jobs ...

[2024-07-02 14:18:37,496] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2024-07-02 14:18:37,498] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:37,563] INFO: Processing task `misfit`
[2024-07-02 14:18:37,712] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:37,742] INFO: Processing task `misfit`
[2024-07-02 14:18:37,852] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:37,884] INFO: Processing task `misfit`
[2024-07-02 14:18:38,271] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:38,300] INFO: Processing task `misfit`
[2024-07-02 14:18:38,426] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:38,456] INFO: Processing task `misfit`
[2024-07-02 14:18:38,578] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:38,609] INFO: Processing task `misfit`
[2024-07-02 14:18:38,722] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:38,751] INFO: Processing task `misfit`
[2024-07-02 14:18:38,876] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:38,905] INFO: Processing task `misfit`
[2024-07-02 14:18:39,053] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:39,098] INFO: Processing task `misfit`
[2024-07-02 14:18:39,239] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:39,272] INFO: Processing task `misfit`
[2024-07-02 14:18:39,391] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:39,420] INFO: Processing task `misfit`
[2024-07-02 14:18:39,532] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:39,562] INFO: Processing task `misfit`
[2024-07-02 14:18:39,677] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:39,713] INFO: Processing task `misfit`
[2024-07-02 14:18:39,835] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:39,863] INFO: Processing task `misfit`
[2024-07-02 14:18:39,966] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:39,996] INFO: Processing task `misfit`
[2024-07-02 14:18:40,100] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:40,132] INFO: Processing task `misfit`
[2024-07-02 14:18:40,517] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:40,550] INFO: Processing task `misfit`
[2024-07-02 14:18:40,687] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:40,764] INFO: Processing task `misfit`
[2024-07-02 14:18:40,939] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:40,965] INFO: Processing task `misfit`
[2024-07-02 14:18:41,103] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:41,149] INFO: Processing task `misfit`
[2024-07-02 14:18:41,290] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:41,315] INFO: Processing task `misfit`
[2024-07-02 14:18:41,443] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:41,485] INFO: Processing task `misfit`
[2024-07-02 14:18:41,615] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:41,646] INFO: Processing task `misfit`
[2024-07-02 14:18:41,836] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:41,874] INFO: Processing task `misfit`
[2024-07-02 14:18:42,053] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:42,111] INFO: Processing task `misfit`
[2024-07-02 14:18:42,327] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:42,389] INFO: Processing task `misfit`
[2024-07-02 14:18:42,564] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:42,597] INFO: Processing task `misfit`
[2024-07-02 14:18:42,711] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-07-02 14:18:42,774] INFO: Processing task `misfit`
[2024-07-02 14:18:44,106] INFO: 
old misfit control group: 0.017690076157774175
new misfit control group: 0.008118346781190224
predicted reduction control group: -0.005352483018395816
actual reduction control group: -0.00957172937658395
5 out of 5 event(s) improved the misfit.
[2024-07-02 14:18:44,106] INFO: 
Model update accepted.
[2024-07-02 14:18:44,107] INFO: 1 new tasks have been issued.
[2024-07-02 14:18:44,107] INFO: Processing task `finalize_iteration`
[2024-07-02 14:18:44,181] INFO: Succesfully completed iteration #0.
[2024-07-02 14:18:44,184] INFO: Adding new iteration #1.
The example above is just meant to demonstrate the use of box constraints. For cases where lower and upper bounds are (almost) equal, we recommend using a region of interest instead.
Bonus question. The setup above is also a prime example of an "inverse crime", except for one small detail. Can you identify what it is?
PAGE CONTENTS