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-06-22 12:00:53,944] INFO: Adding new iteration #0.
[2021-06-22 12:00:53,957] INFO: Resuming iteration #0.

[2021-06-22 12:00:53,958] INFO: 1 new tasks have been issued.
[2021-06-22 12:00:53,958] INFO: Processing task `misfit_and_gradient`
[2021-06-22 12:01:04,533] INFO: Processing task `misfit_and_gradient`
[2021-06-22 12:01:05,005] INFO: 
Iteration 0: Number of events: 5	 chi = 0.017689821546673756	 ||g|| = 0.019869962634243732
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2021-06-22 12:01:05,059] INFO: 1 new tasks have been issued.
[2021-06-22 12:01:05,059] INFO: Processing task `preconditioner`

[2021-06-22 12:01:15,378] INFO: Processing task `preconditioner`
[2021-06-22 12:01:15,682] INFO: 1 new tasks have been issued.
[2021-06-22 12:01:15,683] INFO: Processing task `misfit`
[2021-06-22 12:01:15,783] INFO: Submitting job array with 5 jobs ...

[2021-06-22 12:01:15,995] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2021-06-22 12:01:26,095] INFO: Processing task `misfit`
[2021-06-22 12:01:26,387] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2021-06-22 12:01:36,479] INFO: Processing task `misfit`
[2021-06-22 12:01:37,606] INFO: 
old misfit control group: 0.017689821546673756
new misfit control group: 0.006625547195780521
predicted reduction control group: -0.007025970811433349
actual reduction control group: -0.011064274350893235
5 out of 5 event(s) improved the misfit.
[2021-06-22 12:01:37,607] INFO: 
Model update accepted.
[2021-06-22 12:01:37,771] INFO: Succesfully completed iteration #0.
[2021-06-22 12:01:37,773] 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-06-22 12:01:40,131] INFO: Resuming iteration #1.

[2021-06-22 12:01:40,132] INFO: 1 new tasks have been issued.
[2021-06-22 12:01:40,132] INFO: Processing task `gradient`
[2021-06-22 12:01:40,530] INFO: Submitting job array with 5 jobs ...
[2021-06-22 12:01:40,645] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2021-06-22 12:01:50,660] INFO: Processing task `gradient`
[2021-06-22 12:01:50,990] INFO: 5 events have already been submitted. They will not be submitted again.
[2021-06-22 12:01:51,169] INFO: Some simulations are still running. Please check again to see if they are finished.
[2021-06-22 12:01:51,171] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2021-06-22 12:02:01,184] INFO: Processing task `gradient`
[2021-06-22 12:02:01,492] INFO: 5 events have already been submitted. They will not be submitted again.
[2021-06-22 12:02:02,344] INFO: 
Iteration 1: Number of events: 5	 chi = 0.006625547195780521	 ||g|| = 0.009912885418757011
pred = -0.007025970811433349	ared = -0.011064274350893235	norm_update = 0.7274949011310814	tr_radius = 0.7274949020416265
[2021-06-22 12:02:02,416] INFO: 1 new tasks have been issued.
[2021-06-22 12:02:02,417] INFO: Processing task `preconditioner`

[2021-06-22 12:02:12,699] INFO: Processing task `preconditioner`
[2021-06-22 12:02:12,972] INFO: 1 new tasks have been issued.
[2021-06-22 12:02:12,973] INFO: Processing task `misfit`
[2021-06-22 12:02:13,241] INFO: Submitting job array with 5 jobs ...

[2021-06-22 12:02:13,461] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2021-06-22 12:02:23,578] INFO: Processing task `misfit`
[2021-06-22 12:02:23,756] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2021-06-22 12:02:33,875] INFO: Processing task `misfit`
[2021-06-22 12:02:34,879] INFO: 
old misfit control group: 0.006625547195780521
new misfit control group: 0.0029010297986212553
predicted reduction control group: -0.0034226086963365754
actual reduction control group: -0.0037245173971592656
5 out of 5 event(s) improved the misfit.
[2021-06-22 12:02:34,880] INFO: 
Model update accepted.
[2021-06-22 12:02:35,072] INFO: Succesfully completed iteration #1.
[2021-06-22 12:02:35,075] INFO: Adding new iteration #2.
[2021-06-22 12:02:35,089] INFO: Resuming iteration #2.

[2021-06-22 12:02:35,090] INFO: 1 new tasks have been issued.
[2021-06-22 12:02:35,091] INFO: Processing task `gradient`
[2021-06-22 12:02:35,467] INFO: Submitting job array with 5 jobs ...
[2021-06-22 12:02:35,585] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2021-06-22 12:02:45,597] INFO: Processing task `gradient`
[2021-06-22 12:02:45,929] INFO: 5 events have already been submitted. They will not be submitted again.
[2021-06-22 12:02:46,722] INFO: 
Iteration 2: Number of events: 5	 chi = 0.0029010297986212553	 ||g|| = 0.003963964186459496
pred = -0.0034226086963365754	ared = -0.0037245173971592656	norm_update = 0.7178719073373632	tr_radius = 1.454989804083253
[2021-06-22 12:02:46,809] INFO: 1 new tasks have been issued.
[2021-06-22 12:02:46,810] INFO: Processing task `preconditioner`

[2021-06-22 12:02:57,120] INFO: Processing task `preconditioner`
[2021-06-22 12:02:57,405] INFO: 1 new tasks have been issued.
[2021-06-22 12:02:57,406] INFO: Processing task `misfit`
[2021-06-22 12:02:57,502] INFO: Submitting job array with 5 jobs ...

[2021-06-22 12:02:57,716] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2021-06-22 12:03:07,844] INFO: Processing task `misfit`
[2021-06-22 12:03:08,847] INFO: 
old misfit control group: 0.0029010297986212553
new misfit control group: 0.0024151320182221785
predicted reduction control group: -0.00026266992116930624
actual reduction control group: -0.00048589778039907685
5 out of 5 event(s) improved the misfit.
[2021-06-22 12:03:08,848] INFO: 
Model update accepted.
[2021-06-22 12:03:09,076] INFO: Succesfully completed iteration #2.
[2021-06-22 12:03:09,080] INFO: Adding new iteration #3.