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-09 22:34:32,541] INFO: Adding new iteration #0.
[2021-07-09 22:34:32,556] INFO: Resuming iteration #0.

[2021-07-09 22:34:32,557] INFO: 1 new tasks have been issued.
[2021-07-09 22:34:32,558] INFO: Processing task `misfit_and_gradient`
[2021-07-09 22:34:43,184] INFO: Processing task `misfit_and_gradient`
[2021-07-09 22:34:43,810] INFO: 
Iteration 0: Number of events: 5	 chi = 0.017689824583734397	 ||g|| = 0.01986996466901018
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2021-07-09 22:34:43,877] INFO: 1 new tasks have been issued.
[2021-07-09 22:34:43,877] INFO: Processing task `preconditioner`

[2021-07-09 22:34:54,244] INFO: Processing task `preconditioner`
[2021-07-09 22:34:54,582] INFO: 1 new tasks have been issued.
[2021-07-09 22:34:54,583] INFO: Processing task `misfit`
[2021-07-09 22:34:54,728] INFO: Submitting job array with 5 jobs ...

[2021-07-09 22:34:55,137] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2021-07-09 22:35:05,248] INFO: Processing task `misfit`
[2021-07-09 22:35:05,444] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2021-07-09 22:35:15,559] INFO: Processing task `misfit`
[2021-07-09 22:35:16,967] INFO: 
old misfit control group: 0.017689824583734397
new misfit control group: 0.006625548128398252
predicted reduction control group: -0.00702597187219768
actual reduction control group: -0.011064276455336145
5 out of 5 event(s) improved the misfit.
[2021-07-09 22:35:16,969] INFO: 
Model update accepted.
[2021-07-09 22:35:17,158] INFO: Succesfully completed iteration #0.
[2021-07-09 22:35:17,161] 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-09 22:35:19,872] INFO: Resuming iteration #1.

[2021-07-09 22:35:19,873] INFO: 1 new tasks have been issued.
[2021-07-09 22:35:19,873] INFO: Processing task `gradient`
[2021-07-09 22:35:20,425] INFO: Submitting job array with 5 jobs ...
[2021-07-09 22:35:20,573] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2021-07-09 22:35:30,589] INFO: Processing task `gradient`
[2021-07-09 22:35:31,134] INFO: 5 events have already been submitted. They will not be submitted again.
[2021-07-09 22:35:31,362] INFO: Some simulations are still running. Please check again to see if they are finished.
[2021-07-09 22:35:31,363] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2021-07-09 22:35:41,377] INFO: Processing task `gradient`
[2021-07-09 22:35:41,817] INFO: 5 events have already been submitted. They will not be submitted again.
[2021-07-09 22:35:42,741] INFO: 
Iteration 1: Number of events: 5	 chi = 0.006625548128398252	 ||g|| = 0.009912886749973178
pred = -0.00702597187219768	ared = -0.011064276455336145	norm_update = 0.7274949419996374	tr_radius = 0.7274949075740297
[2021-07-09 22:35:42,829] INFO: 1 new tasks have been issued.
[2021-07-09 22:35:42,829] INFO: Processing task `preconditioner`

[2021-07-09 22:35:53,159] INFO: Processing task `preconditioner`
[2021-07-09 22:35:53,464] INFO: 1 new tasks have been issued.
[2021-07-09 22:35:53,465] INFO: Processing task `misfit`
[2021-07-09 22:35:53,616] INFO: Submitting job array with 5 jobs ...

[2021-07-09 22:35:53,914] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2021-07-09 22:36:04,040] INFO: Processing task `misfit`
[2021-07-09 22:36:04,247] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2021-07-09 22:36:14,378] INFO: Processing task `misfit`
[2021-07-09 22:36:15,694] INFO: 
old misfit control group: 0.006625548128398252
new misfit control group: 0.002901029932515478
predicted reduction control group: -0.0034226100712540035
actual reduction control group: -0.0037245181958827744
5 out of 5 event(s) improved the misfit.
[2021-07-09 22:36:15,696] INFO: 
Model update accepted.
[2021-07-09 22:36:15,940] INFO: Succesfully completed iteration #1.
[2021-07-09 22:36:15,944] INFO: Adding new iteration #2.
[2021-07-09 22:36:15,961] INFO: Resuming iteration #2.

[2021-07-09 22:36:15,962] INFO: 1 new tasks have been issued.
[2021-07-09 22:36:15,962] INFO: Processing task `gradient`
[2021-07-09 22:36:16,497] INFO: Submitting job array with 5 jobs ...
[2021-07-09 22:36:16,641] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2021-07-09 22:36:26,662] INFO: Processing task `gradient`
[2021-07-09 22:36:27,371] INFO: 5 events have already been submitted. They will not be submitted again.
[2021-07-09 22:36:27,573] INFO: Some simulations are still running. Please check again to see if they are finished.
[2021-07-09 22:36:27,574] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2021-07-09 22:36:37,590] INFO: Processing task `gradient`
[2021-07-09 22:36:38,031] INFO: 5 events have already been submitted. They will not be submitted again.
[2021-07-09 22:36:38,793] INFO: 
Iteration 2: Number of events: 5	 chi = 0.002901029932515478	 ||g|| = 0.0039639637200966716
pred = -0.0034226100712540035	ared = -0.0037245181958827744	norm_update = 0.7178720948615558	tr_radius = 1.4549898151480594
[2021-07-09 22:36:38,901] INFO: 1 new tasks have been issued.
[2021-07-09 22:36:38,902] INFO: Processing task `preconditioner`

[2021-07-09 22:36:49,273] INFO: Processing task `preconditioner`
[2021-07-09 22:36:49,599] INFO: 1 new tasks have been issued.
[2021-07-09 22:36:49,600] INFO: Processing task `misfit`
[2021-07-09 22:36:49,742] INFO: Submitting job array with 5 jobs ...

[2021-07-09 22:36:50,040] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2021-07-09 22:37:00,200] INFO: Processing task `misfit`
[2021-07-09 22:37:00,402] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2021-07-09 22:37:10,587] INFO: Processing task `misfit`
[2021-07-09 22:37:12,014] INFO: 
old misfit control group: 0.002901029932515478
new misfit control group: 0.002415132053698662
predicted reduction control group: -0.0002626700331247045
actual reduction control group: -0.0004858978788168161
5 out of 5 event(s) improved the misfit.
[2021-07-09 22:37:12,015] INFO: 
Model update accepted.
[2021-07-09 22:37:12,289] INFO: Succesfully completed iteration #2.
[2021-07-09 22:37:12,294] INFO: Adding new iteration #3.