Version:

This documentation is not for the latest stable Salvus 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")
--> Server: 'https://data.mondaic.com/license_server/licensing_server', User: '_MONDAIC_INTERNAL_', Group: '_MONDAIC_INTERNAL_'.
--> Negotiating 1 license instance(s) for 'SalvusMesh' [license version 1.0.0] for 1 seconds ...
--> Success! [Total duration: 0.79 seconds]
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-10-11 12:09:52,105] INFO: Adding new iteration #0.
[2021-10-11 12:09:52,124] INFO: Resuming iteration #0.

[2021-10-11 12:09:52,125] INFO: 1 new tasks have been issued.
[2021-10-11 12:09:52,126] INFO: Processing task `misfit_and_gradient`
[2021-10-11 12:10:02,888] INFO: Processing task `misfit_and_gradient`
[2021-10-11 12:10:03,703] INFO: 
Iteration 0: Number of events: 5	 chi = 0.01768982330119291	 ||g|| = 0.019869965069024092
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2021-10-11 12:10:03,773] INFO: 1 new tasks have been issued.
[2021-10-11 12:10:03,774] INFO: Processing task `preconditioner`

[2021-10-11 12:10:14,164] INFO: Processing task `preconditioner`
[2021-10-11 12:10:14,495] INFO: 1 new tasks have been issued.
[2021-10-11 12:10:14,496] INFO: Processing task `misfit`
[2021-10-11 12:10:14,781] INFO: Submitting job array with 5 jobs ...

[2021-10-11 12:10:15,097] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2021-10-11 12:10:25,236] INFO: Processing task `misfit`
[2021-10-11 12:10:25,505] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2021-10-11 12:10:35,664] INFO: Processing task `misfit`
[2021-10-11 12:10:35,879] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2021-10-11 12:10:46,048] INFO: Processing task `misfit`
[2021-10-11 12:10:47,606] INFO: 
old misfit control group: 0.01768982330119291
new misfit control group: 0.006625547156448269
predicted reduction control group: -0.007025970888992128
actual reduction control group: -0.011064276144744641
5 out of 5 event(s) improved the misfit.
[2021-10-11 12:10:47,607] INFO: 
Model update accepted.
[2021-10-11 12:10:47,750] INFO: 1 new tasks have been issued.
[2021-10-11 12:10:47,751] INFO: Processing task `finalize_iteration`
[2021-10-11 12:10:47,839] INFO: Succesfully completed iteration #0.
[2021-10-11 12:10:47,842] 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-10-11 12:10:51,391] INFO: Resuming iteration #1.

[2021-10-11 12:10:51,391] INFO: 1 new tasks have been issued.
[2021-10-11 12:10:51,392] INFO: Processing task `gradient`
[2021-10-11 12:10:51,989] INFO: Submitting job array with 5 jobs ...
[2021-10-11 12:10:52,147] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2021-10-11 12:11:02,160] INFO: Processing task `gradient`
[2021-10-11 12:11:02,858] INFO: 5 events have already been submitted. They will not be submitted again.
[2021-10-11 12:11:03,167] INFO: Some simulations are still running. Please check again to see if they are finished.
[2021-10-11 12:11:03,169] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2021-10-11 12:11:13,180] INFO: Processing task `gradient`
[2021-10-11 12:11:14,043] INFO: 5 events have already been submitted. They will not be submitted again.
[2021-10-11 12:11:15,012] INFO: 
Iteration 1: Number of events: 5	 chi = 0.00662554715644827	 ||g|| = 0.009912886529112474
pred = -0.007025970888992128	ared = -0.011064276144744641	norm_update = 0.7274948271387309	tr_radius = 0.7274947818794892
[2021-10-11 12:11:15,104] INFO: 1 new tasks have been issued.
[2021-10-11 12:11:15,105] INFO: Processing task `preconditioner`

[2021-10-11 12:11:25,508] INFO: Processing task `preconditioner`
[2021-10-11 12:11:25,850] INFO: 1 new tasks have been issued.
[2021-10-11 12:11:25,851] INFO: Processing task `misfit`
[2021-10-11 12:11:26,020] INFO: Submitting job array with 5 jobs ...

[2021-10-11 12:11:26,287] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2021-10-11 12:11:36,456] INFO: Processing task `misfit`
[2021-10-11 12:11:36,738] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2021-10-11 12:11:46,940] INFO: Processing task `misfit`
[2021-10-11 12:11:47,176] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2021-10-11 12:11:57,340] INFO: Processing task `misfit`
[2021-10-11 12:11:58,868] INFO: 
old misfit control group: 0.006625547156448269
new misfit control group: 0.0029010293171877932
predicted reduction control group: -0.0034226090821450226
actual reduction control group: -0.003724517839260476
5 out of 5 event(s) improved the misfit.
[2021-10-11 12:11:58,869] INFO: 
Model update accepted.
[2021-10-11 12:11:59,041] INFO: 1 new tasks have been issued.
[2021-10-11 12:11:59,041] INFO: Processing task `finalize_iteration`
[2021-10-11 12:11:59,233] INFO: Succesfully completed iteration #1.
[2021-10-11 12:11:59,238] INFO: Adding new iteration #2.
[2021-10-11 12:11:59,261] INFO: Resuming iteration #2.

[2021-10-11 12:11:59,261] INFO: 1 new tasks have been issued.
[2021-10-11 12:11:59,262] INFO: Processing task `gradient`
[2021-10-11 12:12:00,052] INFO: Submitting job array with 5 jobs ...
[2021-10-11 12:12:00,220] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2021-10-11 12:12:10,236] INFO: Processing task `gradient`
[2021-10-11 12:12:10,906] INFO: 5 events have already been submitted. They will not be submitted again.
[2021-10-11 12:12:11,157] INFO: Some simulations are still running. Please check again to see if they are finished.
[2021-10-11 12:12:11,159] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2021-10-11 12:12:21,175] INFO: Processing task `gradient`
[2021-10-11 12:12:21,799] INFO: 5 events have already been submitted. They will not be submitted again.
[2021-10-11 12:12:22,612] INFO: 
Iteration 2: Number of events: 5	 chi = 0.0029010293171877932	 ||g|| = 0.0039639643816744225
pred = -0.0034226090821450226	ared = -0.003724517839260476	norm_update = 0.7178719289992278	tr_radius = 1.4549895637589785
[2021-10-11 12:12:22,741] INFO: 1 new tasks have been issued.
[2021-10-11 12:12:22,742] INFO: Processing task `preconditioner`

[2021-10-11 12:12:33,172] INFO: Processing task `preconditioner`
[2021-10-11 12:12:33,485] INFO: 1 new tasks have been issued.
[2021-10-11 12:12:33,486] INFO: Processing task `misfit`
[2021-10-11 12:12:33,653] INFO: Submitting job array with 5 jobs ...

[2021-10-11 12:12:33,894] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2021-10-11 12:12:44,088] INFO: Processing task `misfit`
[2021-10-11 12:12:44,356] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2021-10-11 12:12:54,573] INFO: Processing task `misfit`
[2021-10-11 12:12:56,105] INFO: 
old misfit control group: 0.0029010293171877932
new misfit control group: 0.00241513136824724
predicted reduction control group: -0.00026267015338753694
actual reduction control group: -0.0004858979489405532
5 out of 5 event(s) improved the misfit.
[2021-10-11 12:12:56,105] INFO: 
Model update accepted.
[2021-10-11 12:12:56,246] INFO: 1 new tasks have been issued.
[2021-10-11 12:12:56,247] INFO: Processing task `finalize_iteration`
[2021-10-11 12:12:56,442] INFO: Succesfully completed iteration #2.
[2021-10-11 12:12:56,447] INFO: Adding new iteration #3.