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")
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-07-02 16:30:05,795] INFO: Adding new iteration #0.
[2021-07-02 16:30:05,818] INFO: Resuming iteration #0.

[2021-07-02 16:30:05,820] INFO: 1 new tasks have been issued.
[2021-07-02 16:30:05,821] INFO: Processing task `misfit_and_gradient`
[2021-07-02 16:30:16,423] INFO: Processing task `misfit_and_gradient`
[2021-07-02 16:30:17,055] INFO: 
Iteration 0: Number of events: 5	 chi = 0.01768982359663406	 ||g|| = 0.019869964586989936
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2021-07-02 16:30:17,129] INFO: 1 new tasks have been issued.
[2021-07-02 16:30:17,130] INFO: Processing task `preconditioner`

[2021-07-02 16:30:27,515] INFO: Processing task `preconditioner`
[2021-07-02 16:30:27,865] INFO: 1 new tasks have been issued.
[2021-07-02 16:30:27,866] INFO: Processing task `misfit`
[2021-07-02 16:30:28,022] INFO: Submitting job array with 5 jobs ...

[2021-07-02 16:30:28,344] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2021-07-02 16:30:38,468] INFO: Processing task `misfit`
[2021-07-02 16:30:38,838] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2021-07-02 16:30:48,992] INFO: Processing task `misfit`
[2021-07-02 16:30:50,447] INFO: 
old misfit control group: 0.01768982359663406
new misfit control group: 0.006625548505856668
predicted reduction control group: -0.007025971919833207
actual reduction control group: -0.011064275090777391
5 out of 5 event(s) improved the misfit.
[2021-07-02 16:30:50,449] INFO: 
Model update accepted.
[2021-07-02 16:30:50,642] INFO: Succesfully completed iteration #0.
[2021-07-02 16:30:50,645] 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-07-02 16:30:53,327] INFO: Resuming iteration #1.

[2021-07-02 16:30:53,328] INFO: 1 new tasks have been issued.
[2021-07-02 16:30:53,329] INFO: Processing task `gradient`
[2021-07-02 16:30:53,859] INFO: Submitting job array with 5 jobs ...
[2021-07-02 16:30:54,012] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2021-07-02 16:31:04,027] INFO: Processing task `gradient`
[2021-07-02 16:31:04,590] INFO: 5 events have already been submitted. They will not be submitted again.
[2021-07-02 16:31:04,839] INFO: Some simulations are still running. Please check again to see if they are finished.
[2021-07-02 16:31:04,841] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2021-07-02 16:31:14,858] INFO: Processing task `gradient`
[2021-07-02 16:31:15,319] INFO: 5 events have already been submitted. They will not be submitted again.
[2021-07-02 16:31:16,228] INFO: 
Iteration 1: Number of events: 5	 chi = 0.006625548505856668	 ||g|| = 0.009912886732810157
pred = -0.007025971919833207	ared = -0.011064275090777391	norm_update = 0.7274949484904276	tr_radius = 0.7274949125402823
[2021-07-02 16:31:16,315] INFO: 1 new tasks have been issued.
[2021-07-02 16:31:16,316] INFO: Processing task `preconditioner`

[2021-07-02 16:31:26,660] INFO: Processing task `preconditioner`
[2021-07-02 16:31:27,016] INFO: 1 new tasks have been issued.
[2021-07-02 16:31:27,018] INFO: Processing task `misfit`
[2021-07-02 16:31:27,174] INFO: Submitting job array with 5 jobs ...

[2021-07-02 16:31:27,500] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2021-07-02 16:31:37,645] INFO: Processing task `misfit`
[2021-07-02 16:31:37,905] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2021-07-02 16:31:48,077] INFO: Processing task `misfit`
[2021-07-02 16:31:49,402] INFO: 
old misfit control group: 0.006625548505856668
new misfit control group: 0.0029010298889493797
predicted reduction control group: -0.0034226096385970577
actual reduction control group: -0.0037245186169072887
5 out of 5 event(s) improved the misfit.
[2021-07-02 16:31:49,404] INFO: 
Model update accepted.
[2021-07-02 16:31:49,650] INFO: Succesfully completed iteration #1.
[2021-07-02 16:31:49,654] INFO: Adding new iteration #2.
[2021-07-02 16:31:49,672] INFO: Resuming iteration #2.

[2021-07-02 16:31:49,673] INFO: 1 new tasks have been issued.
[2021-07-02 16:31:49,673] INFO: Processing task `gradient`
[2021-07-02 16:31:50,177] INFO: Submitting job array with 5 jobs ...
[2021-07-02 16:31:50,328] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2021-07-02 16:32:00,344] INFO: Processing task `gradient`
[2021-07-02 16:32:01,079] INFO: 5 events have already been submitted. They will not be submitted again.
[2021-07-02 16:32:01,294] INFO: Some simulations are still running. Please check again to see if they are finished.
[2021-07-02 16:32:01,295] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2021-07-02 16:32:11,313] INFO: Processing task `gradient`
[2021-07-02 16:32:11,766] INFO: 5 events have already been submitted. They will not be submitted again.
[2021-07-02 16:32:12,522] INFO: 
Iteration 2: Number of events: 5	 chi = 0.0029010298889493797	 ||g|| = 0.003963964729945908
pred = -0.0034226096385970577	ared = -0.0037245186169072887	norm_update = 0.7178720093457103	tr_radius = 1.4549898250805646
[2021-07-02 16:32:12,636] INFO: 1 new tasks have been issued.
[2021-07-02 16:32:12,636] INFO: Processing task `preconditioner`

[2021-07-02 16:32:23,030] INFO: Processing task `preconditioner`
[2021-07-02 16:32:23,377] INFO: 1 new tasks have been issued.
[2021-07-02 16:32:23,379] INFO: Processing task `misfit`
[2021-07-02 16:32:23,524] INFO: Submitting job array with 5 jobs ...

[2021-07-02 16:32:23,823] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2021-07-02 16:32:33,978] INFO: Processing task `misfit`
[2021-07-02 16:32:34,223] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2021-07-02 16:32:44,400] INFO: Processing task `misfit`
[2021-07-02 16:32:45,856] INFO: 
old misfit control group: 0.0029010298889493797
new misfit control group: 0.002415131378652226
predicted reduction control group: -0.00026266998732131215
actual reduction control group: -0.0004858985102971537
5 out of 5 event(s) improved the misfit.
[2021-07-02 16:32:45,857] INFO: 
Model update accepted.
[2021-07-02 16:32:46,135] INFO: Succesfully completed iteration #2.
[2021-07-02 16:32:46,142] INFO: Adding new iteration #3.