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",
    wavefield_compression=sn.WavefieldCompression(
        forward_wavefield_sampling_interval=10
    ),
    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,
)
[2023-05-29 19:56:37,048] INFO: Adding new iteration #0.
[2023-05-29 19:56:37,061] INFO: Resuming iteration #0.

[2023-05-29 19:56:37,063] INFO: 1 new tasks have been issued.
[2023-05-29 19:56:37,064] INFO: Processing task `misfit_and_gradient`
[2023-05-29 19:56:37,629] INFO: 
Iteration 0: Number of events: 5	 chi = 0.017689821546673756	 ||g|| = 0.0162614694176267
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2023-05-29 19:56:37,631] INFO: 1 new tasks have been issued.
[2023-05-29 19:56:37,631] INFO: Processing task `preconditioner`

[2023-05-29 19:56:37,860] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2023-05-29 19:56:47,882] INFO: Processing task `preconditioner`
[2023-05-29 19:56:48,112] INFO: 1 new tasks have been issued.
[2023-05-29 19:56:48,113] INFO: Processing task `misfit`
[2023-05-29 19:56:48,202] INFO: Submitting job array with 5 jobs ...

[2023-05-29 19:56:48,528] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2023-05-29 19:56:48,529] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2023-05-29 19:56:58,573] INFO: Processing task `misfit`
[2023-05-29 19:56:59,680] INFO: 
old misfit control group: 0.017689821546673756
new misfit control group: 0.0066457093447483545
predicted reduction control group: -0.005735006306668265
actual reduction control group: -0.011044112201925402
5 out of 5 event(s) improved the misfit.
[2023-05-29 19:56:59,681] INFO: 
Model update accepted.
[2023-05-29 19:56:59,682] INFO: 1 new tasks have been issued.
[2023-05-29 19:56:59,683] INFO: Processing task `finalize_iteration`
[2023-05-29 19:56:59,742] INFO: Succesfully completed iteration #0.
[2023-05-29 19:56:59,745] 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.inversions.delete_disposable_files(
        inverse_problem_configuration="my_second_inversion",
        data_to_remove=["auxiliary", "gradients", "waveforms"],
    )
p.viz.nb.inversion(inverse_problem_configuration="my_second_inversion")
[2023-05-29 19:57:01,782] INFO: Resuming iteration #1.

[2023-05-29 19:57:01,783] INFO: 1 new tasks have been issued.
[2023-05-29 19:57:01,783] INFO: Processing task `gradient`
[2023-05-29 19:57:02,246] INFO: Submitting job array with 5 jobs ...

[2023-05-29 19:57:02,370] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2023-05-29 19:57:02,372] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2023-05-29 19:57:12,386] INFO: Processing task `gradient`
[2023-05-29 19:57:12,681] INFO: 5 events have already been submitted. They will not be submitted again.
[2023-05-29 19:57:13,425] INFO: 
Iteration 1: Number of events: 5	 chi = 0.0066457093447483545	 ||g|| = 0.008122033347238987
pred = -0.005735006306668265	ared = -0.011044112201925402	norm_update = 0.7265201743080936	tr_radius = 0.7265201888920712
[2023-05-29 19:57:13,441] INFO: 1 new tasks have been issued.
[2023-05-29 19:57:13,442] INFO: Processing task `preconditioner`

[2023-05-29 19:57:13,596] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2023-05-29 19:57:23,635] INFO: Processing task `preconditioner`
[2023-05-29 19:57:23,859] INFO: 1 new tasks have been issued.
[2023-05-29 19:57:23,860] INFO: Processing task `misfit`
[2023-05-29 19:57:23,955] INFO: Submitting job array with 5 jobs ...

[2023-05-29 19:57:24,139] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2023-05-29 19:57:24,141] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2023-05-29 19:57:34,201] INFO: Processing task `misfit`
[2023-05-29 19:57:35,174] INFO: 
old misfit control group: 0.0066457093447483545
new misfit control group: 0.0028967694956960307
predicted reduction control group: -0.0027947378751068505
actual reduction control group: -0.003748939849052324
5 out of 5 event(s) improved the misfit.
[2023-05-29 19:57:35,175] INFO: 
Model update accepted.
[2023-05-29 19:57:35,176] INFO: 1 new tasks have been issued.
[2023-05-29 19:57:35,176] INFO: Processing task `finalize_iteration`
[2023-05-29 19:57:35,271] INFO: Succesfully completed iteration #1.
[2023-05-29 19:57:35,275] INFO: Adding new iteration #2.
[2023-05-29 19:57:35,285] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00000
[2023-05-29 19:57:35,288] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00001
[2023-05-29 19:57:35,401] INFO: Freed up 4.4 MB of space.
[2023-05-29 19:57:35,407] INFO: Resuming iteration #2.

[2023-05-29 19:57:35,407] INFO: 1 new tasks have been issued.
[2023-05-29 19:57:35,408] INFO: Processing task `gradient`
[2023-05-29 19:57:35,852] INFO: Submitting job array with 5 jobs ...

[2023-05-29 19:57:35,963] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2023-05-29 19:57:35,964] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2023-05-29 19:57:45,978] INFO: Processing task `gradient`
[2023-05-29 19:57:46,270] INFO: 5 events have already been submitted. They will not be submitted again.
[2023-05-29 19:57:47,184] INFO: 
Iteration 2: Number of events: 5	 chi = 0.0028967694956960307	 ||g|| = 0.0033621126637955632
pred = -0.0027947378751068505	ared = -0.003748939849052324	norm_update = 0.7176637300170433	tr_radius = 1.4530403777841423
[2023-05-29 19:57:47,214] INFO: 1 new tasks have been issued.
[2023-05-29 19:57:47,215] INFO: Processing task `preconditioner`

[2023-05-29 19:57:47,383] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2023-05-29 19:57:57,441] INFO: Processing task `preconditioner`
[2023-05-29 19:57:57,669] INFO: 1 new tasks have been issued.
[2023-05-29 19:57:57,670] INFO: Processing task `misfit`
[2023-05-29 19:57:57,765] INFO: Submitting job array with 5 jobs ...

[2023-05-29 19:57:57,953] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2023-05-29 19:57:57,955] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2023-05-29 19:58:08,038] INFO: Processing task `misfit`
[2023-05-29 19:58:09,011] INFO: 
old misfit control group: 0.0028967694956960307
new misfit control group: 0.002407850346859309
predicted reduction control group: -0.0002203629212521284
actual reduction control group: -0.0004889191488367216
5 out of 5 event(s) improved the misfit.
[2023-05-29 19:58:09,012] INFO: 
Model update accepted.
[2023-05-29 19:58:09,013] INFO: 1 new tasks have been issued.
[2023-05-29 19:58:09,014] INFO: Processing task `finalize_iteration`
[2023-05-29 19:58:09,145] INFO: Succesfully completed iteration #2.
[2023-05-29 19:58:09,150] INFO: Adding new iteration #3.
[2023-05-29 19:58:09,161] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00000
[2023-05-29 19:58:09,165] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00001
[2023-05-29 19:58:09,281] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00002
[2023-05-29 19:58:09,393] INFO: Freed up 4.4 MB of space.