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",
    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,
)
[2022-05-16 20:10:47,054] INFO: Adding new iteration #0.
[2022-05-16 20:10:47,082] INFO: Resuming iteration #0.

[2022-05-16 20:10:47,084] INFO: 1 new tasks have been issued.
[2022-05-16 20:10:47,085] INFO: Processing task `misfit_and_gradient`
[2022-05-16 20:10:57,820] INFO: Processing task `misfit_and_gradient`
[2022-05-16 20:10:58,612] INFO: 
Iteration 0: Number of events: 5	 chi = 0.017689824028311374	 ||g|| = 0.01626147120818199
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2022-05-16 20:10:58,625] INFO: 1 new tasks have been issued.
[2022-05-16 20:10:58,626] INFO: Processing task `preconditioner`

[2022-05-16 20:11:08,877] INFO: Processing task `preconditioner`
[2022-05-16 20:11:09,170] INFO: 1 new tasks have been issued.
[2022-05-16 20:11:09,171] INFO: Processing task `misfit`
[2022-05-16 20:11:09,323] INFO: Submitting job array with 5 jobs ...

[2022-05-16 20:11:09,710] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2022-05-16 20:11:19,763] INFO: Processing task `misfit`
[2022-05-16 20:11:20,036] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2022-05-16 20:11:30,088] INFO: Processing task `misfit`
[2022-05-16 20:11:31,732] INFO: 
old misfit control group: 0.017689824028311374
new misfit control group: 0.006645708360067172
predicted reduction control group: -0.005735005404390085
actual reduction control group: -0.011044115668244201
5 out of 5 event(s) improved the misfit.
[2022-05-16 20:11:31,734] INFO: 
Model update accepted.
[2022-05-16 20:11:31,771] INFO: 1 new tasks have been issued.
[2022-05-16 20:11:31,772] INFO: Processing task `finalize_iteration`
[2022-05-16 20:11:31,839] INFO: Succesfully completed iteration #0.
[2022-05-16 20:11:31,843] 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")
[2022-05-16 20:11:34,638] INFO: Resuming iteration #1.

[2022-05-16 20:11:34,639] INFO: 1 new tasks have been issued.
[2022-05-16 20:11:34,639] INFO: Processing task `gradient`
[2022-05-16 20:11:35,391] INFO: Submitting job array with 5 jobs ...
[2022-05-16 20:11:35,556] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2022-05-16 20:11:45,571] INFO: Processing task `gradient`
[2022-05-16 20:11:46,169] INFO: 5 events have already been submitted. They will not be submitted again.
[2022-05-16 20:11:46,429] INFO: Some simulations are still running. Please check again to see if they are finished.
[2022-05-16 20:11:46,431] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2022-05-16 20:11:56,446] INFO: Processing task `gradient`
[2022-05-16 20:11:56,954] INFO: 5 events have already been submitted. They will not be submitted again.
[2022-05-16 20:11:57,843] INFO: 
Iteration 1: Number of events: 5	 chi = 0.006645708360067172	 ||g|| = 0.008122036085025817
pred = -0.005735005404390085	ared = -0.011044115668244201	norm_update = 0.7265199479808775	tr_radius = 0.7265200184595049
[2022-05-16 20:11:57,875] INFO: 1 new tasks have been issued.
[2022-05-16 20:11:57,877] INFO: Processing task `preconditioner`

[2022-05-16 20:12:08,109] INFO: Processing task `preconditioner`
[2022-05-16 20:12:08,385] INFO: 1 new tasks have been issued.
[2022-05-16 20:12:08,386] INFO: Processing task `misfit`
[2022-05-16 20:12:08,528] INFO: Submitting job array with 5 jobs ...

[2022-05-16 20:12:08,808] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2022-05-16 20:12:18,891] INFO: Processing task `misfit`
[2022-05-16 20:12:19,171] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2022-05-16 20:12:29,252] INFO: Processing task `misfit`
[2022-05-16 20:12:30,783] INFO: 
old misfit control group: 0.006645708360067172
new misfit control group: 0.0028967666570828684
predicted reduction control group: -0.002794740183717997
actual reduction control group: -0.003748941702984304
5 out of 5 event(s) improved the misfit.
[2022-05-16 20:12:30,785] INFO: 
Model update accepted.
[2022-05-16 20:12:30,852] INFO: 1 new tasks have been issued.
[2022-05-16 20:12:30,853] INFO: Processing task `finalize_iteration`
[2022-05-16 20:12:30,963] INFO: Succesfully completed iteration #1.
[2022-05-16 20:12:30,968] INFO: Adding new iteration #2.
[2022-05-16 20:12:30,986] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00000
[2022-05-16 20:12:30,993] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00001
[2022-05-16 20:12:31,171] INFO: Freed up 4.4 MB of space.
[2022-05-16 20:12:31,178] INFO: Resuming iteration #2.

[2022-05-16 20:12:31,179] INFO: 1 new tasks have been issued.
[2022-05-16 20:12:31,180] INFO: Processing task `gradient`
[2022-05-16 20:12:31,883] INFO: Submitting job array with 5 jobs ...
[2022-05-16 20:12:32,025] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2022-05-16 20:12:42,044] INFO: Processing task `gradient`
[2022-05-16 20:12:42,712] INFO: 5 events have already been submitted. They will not be submitted again.
[2022-05-16 20:12:42,978] INFO: Some simulations are still running. Please check again to see if they are finished.
[2022-05-16 20:12:42,979] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2022-05-16 20:12:52,994] INFO: Processing task `gradient`
[2022-05-16 20:12:53,514] INFO: 5 events have already been submitted. They will not be submitted again.
[2022-05-16 20:12:54,406] INFO: 
Iteration 2: Number of events: 5	 chi = 0.0028967666570828684	 ||g|| = 0.0033621155211880816
pred = -0.002794740183717997	ared = -0.003748941702984304	norm_update = 0.7176638788034376	tr_radius = 1.4530400369190097
[2022-05-16 20:12:54,460] INFO: 1 new tasks have been issued.
[2022-05-16 20:12:54,461] INFO: Processing task `preconditioner`

[2022-05-16 20:13:04,724] INFO: Processing task `preconditioner`
[2022-05-16 20:13:05,015] INFO: 1 new tasks have been issued.
[2022-05-16 20:13:05,016] INFO: Processing task `misfit`
[2022-05-16 20:13:05,157] INFO: Submitting job array with 5 jobs ...

[2022-05-16 20:13:05,422] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2022-05-16 20:13:15,515] INFO: Processing task `misfit`
[2022-05-16 20:13:15,754] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2022-05-16 20:13:25,857] INFO: Processing task `misfit`
[2022-05-16 20:13:27,471] INFO: 
old misfit control group: 0.0028967666570828684
new misfit control group: 0.002407844389404629
predicted reduction control group: -0.00022036448329393056
actual reduction control group: -0.0004889222676782395
5 out of 5 event(s) improved the misfit.
[2022-05-16 20:13:27,473] INFO: 
Model update accepted.
[2022-05-16 20:13:27,560] INFO: 1 new tasks have been issued.
[2022-05-16 20:13:27,561] INFO: Processing task `finalize_iteration`
[2022-05-16 20:13:27,720] INFO: Succesfully completed iteration #2.
[2022-05-16 20:13:27,730] INFO: Adding new iteration #3.
[2022-05-16 20:13:27,750] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00000
[2022-05-16 20:13:27,755] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00001
[2022-05-16 20:13:27,931] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00002
[2022-05-16 20:13:28,115] INFO: Freed up 4.4 MB of space.