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-31 14:27:10,572] INFO: Adding new iteration #0.
[2022-05-31 14:27:10,601] INFO: Resuming iteration #0.

[2022-05-31 14:27:10,603] INFO: 1 new tasks have been issued.
[2022-05-31 14:27:10,605] INFO: Processing task `misfit_and_gradient`
[2022-05-31 14:27:21,349] INFO: Processing task `misfit_and_gradient`
[2022-05-31 14:27:22,139] INFO: 
Iteration 0: Number of events: 5	 chi = 0.01768982199519792	 ||g|| = 0.016261472605639975
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2022-05-31 14:27:22,152] INFO: 1 new tasks have been issued.
[2022-05-31 14:27:22,153] INFO: Processing task `preconditioner`

[2022-05-31 14:27:32,397] INFO: Processing task `preconditioner`
[2022-05-31 14:27:32,830] INFO: 1 new tasks have been issued.
[2022-05-31 14:27:32,831] INFO: Processing task `misfit`
[2022-05-31 14:27:32,967] INFO: Submitting job array with 5 jobs ...

[2022-05-31 14:27:33,213] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2022-05-31 14:27:43,257] INFO: Processing task `misfit`
[2022-05-31 14:27:43,521] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2022-05-31 14:27:53,571] INFO: Processing task `misfit`
[2022-05-31 14:27:55,177] INFO: 
old misfit control group: 0.01768982199519792
new misfit control group: 0.006645702149831084
predicted reduction control group: -0.005735010238752116
actual reduction control group: -0.011044119845366834
5 out of 5 event(s) improved the misfit.
[2022-05-31 14:27:55,179] INFO: 
Model update accepted.
[2022-05-31 14:27:55,218] INFO: 1 new tasks have been issued.
[2022-05-31 14:27:55,219] INFO: Processing task `finalize_iteration`
[2022-05-31 14:27:55,294] INFO: Succesfully completed iteration #0.
[2022-05-31 14:27:55,298] 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-31 14:27:58,092] INFO: Resuming iteration #1.

[2022-05-31 14:27:58,093] INFO: 1 new tasks have been issued.
[2022-05-31 14:27:58,094] INFO: Processing task `gradient`
[2022-05-31 14:27:58,827] INFO: Submitting job array with 5 jobs ...
[2022-05-31 14:27:58,977] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2022-05-31 14:28:08,993] INFO: Processing task `gradient`
[2022-05-31 14:28:09,677] INFO: 5 events have already been submitted. They will not be submitted again.
[2022-05-31 14:28:09,907] INFO: Some simulations are still running. Please check again to see if they are finished.
[2022-05-31 14:28:09,909] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2022-05-31 14:28:19,924] INFO: Processing task `gradient`
[2022-05-31 14:28:20,450] INFO: 5 events have already been submitted. They will not be submitted again.
[2022-05-31 14:28:21,328] INFO: 
Iteration 1: Number of events: 5	 chi = 0.006645702149831085	 ||g|| = 0.008122027008748487
pred = -0.005735010238752116	ared = -0.011044119845366834	norm_update = 0.7265206523262115	tr_radius = 0.7265207658505455
[2022-05-31 14:28:21,363] INFO: 1 new tasks have been issued.
[2022-05-31 14:28:21,365] INFO: Processing task `preconditioner`

[2022-05-31 14:28:31,565] INFO: Processing task `preconditioner`
[2022-05-31 14:28:31,840] INFO: 1 new tasks have been issued.
[2022-05-31 14:28:31,841] INFO: Processing task `misfit`
[2022-05-31 14:28:32,166] INFO: Submitting job array with 5 jobs ...

[2022-05-31 14:28:32,405] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2022-05-31 14:28:42,477] INFO: Processing task `misfit`
[2022-05-31 14:28:42,769] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2022-05-31 14:28:52,852] INFO: Processing task `misfit`
[2022-05-31 14:28:54,215] INFO: 
old misfit control group: 0.006645702149831084
new misfit control group: 0.0028967648087232963
predicted reduction control group: -0.0027947345172333275
actual reduction control group: -0.0037489373411077878
5 out of 5 event(s) improved the misfit.
[2022-05-31 14:28:54,217] INFO: 
Model update accepted.
[2022-05-31 14:28:54,286] INFO: 1 new tasks have been issued.
[2022-05-31 14:28:54,286] INFO: Processing task `finalize_iteration`
[2022-05-31 14:28:54,399] INFO: Succesfully completed iteration #1.
[2022-05-31 14:28:54,403] INFO: Adding new iteration #2.
[2022-05-31 14:28:54,416] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00000
[2022-05-31 14:28:54,422] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00001
[2022-05-31 14:28:54,619] INFO: Freed up 4.4 MB of space.
[2022-05-31 14:28:54,632] INFO: Resuming iteration #2.

[2022-05-31 14:28:54,632] INFO: 1 new tasks have been issued.
[2022-05-31 14:28:54,633] INFO: Processing task `gradient`
[2022-05-31 14:28:55,343] INFO: Submitting job array with 5 jobs ...
[2022-05-31 14:28:55,500] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2022-05-31 14:29:05,517] INFO: Processing task `gradient`
[2022-05-31 14:29:06,187] INFO: 5 events have already been submitted. They will not be submitted again.
[2022-05-31 14:29:06,434] INFO: Some simulations are still running. Please check again to see if they are finished.
[2022-05-31 14:29:06,437] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2022-05-31 14:29:16,457] INFO: Processing task `gradient`
[2022-05-31 14:29:16,972] INFO: 5 events have already been submitted. They will not be submitted again.
[2022-05-31 14:29:17,851] INFO: 
Iteration 2: Number of events: 5	 chi = 0.0028967648087232963	 ||g|| = 0.0033621127753446856
pred = -0.0027947345172333275	ared = -0.0037489373411077878	norm_update = 0.7176631484340629	tr_radius = 1.453041531701091
[2022-05-31 14:29:17,902] INFO: 1 new tasks have been issued.
[2022-05-31 14:29:17,903] INFO: Processing task `preconditioner`

[2022-05-31 14:29:28,162] INFO: Processing task `preconditioner`
[2022-05-31 14:29:28,446] INFO: 1 new tasks have been issued.
[2022-05-31 14:29:28,448] INFO: Processing task `misfit`
[2022-05-31 14:29:28,778] INFO: Submitting job array with 5 jobs ...

[2022-05-31 14:29:29,055] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2022-05-31 14:29:39,161] INFO: Processing task `misfit`
[2022-05-31 14:29:39,437] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2022-05-31 14:29:49,560] INFO: Processing task `misfit`
[2022-05-31 14:29:50,944] INFO: 
old misfit control group: 0.0028967648087232963
new misfit control group: 0.00240784355349764
predicted reduction control group: -0.00022036433291974328
actual reduction control group: -0.0004889212552256564
5 out of 5 event(s) improved the misfit.
[2022-05-31 14:29:50,946] INFO: 
Model update accepted.
[2022-05-31 14:29:51,026] INFO: 1 new tasks have been issued.
[2022-05-31 14:29:51,027] INFO: Processing task `finalize_iteration`
[2022-05-31 14:29:51,184] INFO: Succesfully completed iteration #2.
[2022-05-31 14:29:51,190] INFO: Adding new iteration #3.
[2022-05-31 14:29:51,206] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00000
[2022-05-31 14:29:51,211] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00001
[2022-05-31 14:29:51,397] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00002
[2022-05-31 14:29:51,575] INFO: Freed up 4.4 MB of space.