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=[e.event_name for e in p.events.get_all()],
    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",
    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,
)
[2021-08-05 08:45:04,702] INFO: Adding new iteration #0.
[2021-08-05 08:45:04,717] INFO: Resuming iteration #0.

[2021-08-05 08:45:04,718] INFO: 1 new tasks have been issued.
[2021-08-05 08:45:04,719] INFO: Processing task `misfit_and_gradient`
[2021-08-05 08:45:15,357] INFO: Processing task `misfit_and_gradient`
[2021-08-05 08:45:15,972] INFO: 
Iteration 0: Number of events: 5	 chi = 0.01768982006512383	 ||g|| = 0.019869962732072092
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2021-08-05 08:45:16,036] INFO: 1 new tasks have been issued.
[2021-08-05 08:45:16,037] INFO: Processing task `preconditioner`

[2021-08-05 08:45:26,407] INFO: Processing task `preconditioner`
[2021-08-05 08:45:26,727] INFO: 1 new tasks have been issued.
[2021-08-05 08:45:26,728] INFO: Processing task `misfit`
[2021-08-05 08:45:26,883] INFO: Submitting job array with 5 jobs ...

[2021-08-05 08:45:27,293] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2021-08-05 08:45:37,408] INFO: Processing task `misfit`
[2021-08-05 08:45:37,604] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2021-08-05 08:45:47,721] INFO: Processing task `misfit`
[2021-08-05 08:45:49,155] INFO: 
old misfit control group: 0.01768982006512383
new misfit control group: 0.0066255479088313364
predicted reduction control group: -0.007025970857825386
actual reduction control group: -0.011064272156292493
5 out of 5 event(s) improved the misfit.
[2021-08-05 08:45:49,156] INFO: 
Model update accepted.
[2021-08-05 08:45:49,357] INFO: Succesfully completed iteration #0.
[2021-08-05 08:45:49,360] 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.viz.nb.inversion(inverse_problem_configuration="my_second_inversion")
[2021-08-05 08:45:52,050] INFO: Resuming iteration #1.

[2021-08-05 08:45:52,051] INFO: 1 new tasks have been issued.
[2021-08-05 08:45:52,052] INFO: Processing task `gradient`
[2021-08-05 08:45:52,612] INFO: Submitting job array with 5 jobs ...
[2021-08-05 08:45:52,744] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2021-08-05 08:46:02,761] INFO: Processing task `gradient`
[2021-08-05 08:46:03,219] INFO: 5 events have already been submitted. They will not be submitted again.
[2021-08-05 08:46:03,422] INFO: Some simulations are still running. Please check again to see if they are finished.
[2021-08-05 08:46:03,423] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2021-08-05 08:46:13,438] INFO: Processing task `gradient`
[2021-08-05 08:46:13,900] INFO: 5 events have already been submitted. They will not be submitted again.
[2021-08-05 08:46:14,862] INFO: 
Iteration 1: Number of events: 5	 chi = 0.0066255479088313364	 ||g|| = 0.009912887164373097
pred = -0.007025970857825386	ared = -0.011064272156292493	norm_update = 0.7274949076682948	tr_radius = 0.7274949068329261
[2021-08-05 08:46:14,953] INFO: 1 new tasks have been issued.
[2021-08-05 08:46:14,954] INFO: Processing task `preconditioner`

[2021-08-05 08:46:25,290] INFO: Processing task `preconditioner`
[2021-08-05 08:46:25,588] INFO: 1 new tasks have been issued.
[2021-08-05 08:46:25,589] INFO: Processing task `misfit`
[2021-08-05 08:46:25,737] INFO: Submitting job array with 5 jobs ...

[2021-08-05 08:46:26,037] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2021-08-05 08:46:36,164] INFO: Processing task `misfit`
[2021-08-05 08:46:36,413] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2021-08-05 08:46:46,544] INFO: Processing task `misfit`
[2021-08-05 08:46:47,840] INFO: 
old misfit control group: 0.0066255479088313364
new misfit control group: 0.002901029875679453
predicted reduction control group: -0.003422610472083958
actual reduction control group: -0.0037245180331518836
5 out of 5 event(s) improved the misfit.
[2021-08-05 08:46:47,841] INFO: 
Model update accepted.
[2021-08-05 08:46:48,081] INFO: Succesfully completed iteration #1.
[2021-08-05 08:46:48,085] INFO: Adding new iteration #2.
[2021-08-05 08:46:48,104] INFO: Resuming iteration #2.

[2021-08-05 08:46:48,105] INFO: 1 new tasks have been issued.
[2021-08-05 08:46:48,106] INFO: Processing task `gradient`
[2021-08-05 08:46:48,649] INFO: Submitting job array with 5 jobs ...
[2021-08-05 08:46:48,794] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2021-08-05 08:46:58,808] INFO: Processing task `gradient`
[2021-08-05 08:46:59,270] INFO: 5 events have already been submitted. They will not be submitted again.
[2021-08-05 08:46:59,645] INFO: Some simulations are still running. Please check again to see if they are finished.
[2021-08-05 08:46:59,648] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2021-08-05 08:47:09,668] INFO: Processing task `gradient`
[2021-08-05 08:47:10,112] INFO: 5 events have already been submitted. They will not be submitted again.
[2021-08-05 08:47:10,882] INFO: 
Iteration 2: Number of events: 5	 chi = 0.0029010298756794533	 ||g|| = 0.0039639652834609785
pred = -0.003422610472083958	ared = -0.0037245180331518836	norm_update = 0.7178721778622843	tr_radius = 1.4549898136658521
[2021-08-05 08:47:10,990] INFO: 1 new tasks have been issued.
[2021-08-05 08:47:10,991] INFO: Processing task `preconditioner`

[2021-08-05 08:47:21,388] INFO: Processing task `preconditioner`
[2021-08-05 08:47:21,696] INFO: 1 new tasks have been issued.
[2021-08-05 08:47:21,697] INFO: Processing task `misfit`
[2021-08-05 08:47:21,840] INFO: Submitting job array with 5 jobs ...

[2021-08-05 08:47:22,124] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2021-08-05 08:47:32,277] INFO: Processing task `misfit`
[2021-08-05 08:47:32,465] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2021-08-05 08:47:42,648] INFO: Processing task `misfit`
[2021-08-05 08:47:43,947] INFO: 
old misfit control group: 0.002901029875679453
new misfit control group: 0.002415131491457637
predicted reduction control group: -0.00026266991574613603
actual reduction control group: -0.00048589838422181605
5 out of 5 event(s) improved the misfit.
[2021-08-05 08:47:43,948] INFO: 
Model update accepted.
[2021-08-05 08:47:44,226] INFO: Succesfully completed iteration #2.
[2021-08-05 08:47:44,232] INFO: Adding new iteration #3.