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-07-03 17:38:33,335] INFO: Adding new iteration #0.
[2022-07-03 17:38:33,360] INFO: Resuming iteration #0.

[2022-07-03 17:38:33,361] INFO: 1 new tasks have been issued.
[2022-07-03 17:38:33,362] INFO: Processing task `misfit_and_gradient`
[2022-07-03 17:38:44,144] INFO: Processing task `misfit_and_gradient`
[2022-07-03 17:38:44,957] INFO: 
Iteration 0: Number of events: 5	 chi = 0.017689825110885782	 ||g|| = 0.016261472269729016
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2022-07-03 17:38:44,971] INFO: 1 new tasks have been issued.
[2022-07-03 17:38:44,972] INFO: Processing task `preconditioner`

[2022-07-03 17:38:55,248] INFO: Processing task `preconditioner`
[2022-07-03 17:38:55,507] INFO: 1 new tasks have been issued.
[2022-07-03 17:38:55,508] INFO: Processing task `misfit`
[2022-07-03 17:38:55,651] INFO: Submitting job array with 5 jobs ...

[2022-07-03 17:38:56,021] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2022-07-03 17:39:06,068] INFO: Processing task `misfit`
[2022-07-03 17:39:06,278] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2022-07-03 17:39:16,324] INFO: Processing task `misfit`
[2022-07-03 17:39:17,900] INFO: 
old misfit control group: 0.017689825110885782
new misfit control group: 0.006645702005669973
predicted reduction control group: -0.005735011349324115
actual reduction control group: -0.01104412310521581
5 out of 5 event(s) improved the misfit.
[2022-07-03 17:39:17,902] INFO: 
Model update accepted.
[2022-07-03 17:39:17,936] INFO: 1 new tasks have been issued.
[2022-07-03 17:39:17,937] INFO: Processing task `finalize_iteration`
[2022-07-03 17:39:18,003] INFO: Succesfully completed iteration #0.
[2022-07-03 17:39:18,006] 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-07-03 17:39:20,845] INFO: Resuming iteration #1.

[2022-07-03 17:39:20,846] INFO: 1 new tasks have been issued.
[2022-07-03 17:39:20,847] INFO: Processing task `gradient`
[2022-07-03 17:39:21,612] INFO: Submitting job array with 5 jobs ...
[2022-07-03 17:39:21,770] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2022-07-03 17:39:31,784] INFO: Processing task `gradient`
[2022-07-03 17:39:32,320] INFO: 5 events have already been submitted. They will not be submitted again.
[2022-07-03 17:39:32,628] INFO: Some simulations are still running. Please check again to see if they are finished.
[2022-07-03 17:39:32,630] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2022-07-03 17:39:42,645] INFO: Processing task `gradient`
[2022-07-03 17:39:43,169] INFO: 5 events have already been submitted. They will not be submitted again.
[2022-07-03 17:39:44,066] INFO: 
Iteration 1: Number of events: 5	 chi = 0.006645702005669974	 ||g|| = 0.008122032059910345
pred = -0.005735011349324115	ared = -0.01104412310521581	norm_update = 0.7265207407877287	tr_radius = 0.7265209299976106
[2022-07-03 17:39:44,100] INFO: 1 new tasks have been issued.
[2022-07-03 17:39:44,101] INFO: Processing task `preconditioner`

[2022-07-03 17:39:54,312] INFO: Processing task `preconditioner`
[2022-07-03 17:39:54,547] INFO: 1 new tasks have been issued.
[2022-07-03 17:39:54,548] INFO: Processing task `misfit`
[2022-07-03 17:39:54,697] INFO: Submitting job array with 5 jobs ...

[2022-07-03 17:39:54,938] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2022-07-03 17:40:05,004] INFO: Processing task `misfit`
[2022-07-03 17:40:05,242] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2022-07-03 17:40:15,321] INFO: Processing task `misfit`
[2022-07-03 17:40:17,004] INFO: 
old misfit control group: 0.006645702005669973
new misfit control group: 0.002896766117081185
predicted reduction control group: -0.002794735112684646
actual reduction control group: -0.003748935888588788
5 out of 5 event(s) improved the misfit.
[2022-07-03 17:40:17,006] INFO: 
Model update accepted.
[2022-07-03 17:40:17,070] INFO: 1 new tasks have been issued.
[2022-07-03 17:40:17,071] INFO: Processing task `finalize_iteration`
[2022-07-03 17:40:17,203] INFO: Succesfully completed iteration #1.
[2022-07-03 17:40:17,209] INFO: Adding new iteration #2.
[2022-07-03 17:40:17,222] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00000
[2022-07-03 17:40:17,227] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00001
[2022-07-03 17:40:17,433] INFO: Freed up 4.4 MB of space.
[2022-07-03 17:40:17,440] INFO: Resuming iteration #2.

[2022-07-03 17:40:17,441] INFO: 1 new tasks have been issued.
[2022-07-03 17:40:17,441] INFO: Processing task `gradient`
[2022-07-03 17:40:18,239] INFO: Submitting job array with 5 jobs ...
[2022-07-03 17:40:18,394] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2022-07-03 17:40:28,408] INFO: Processing task `gradient`
[2022-07-03 17:40:29,149] INFO: 5 events have already been submitted. They will not be submitted again.
[2022-07-03 17:40:29,442] INFO: Some simulations are still running. Please check again to see if they are finished.
[2022-07-03 17:40:29,444] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2022-07-03 17:40:39,460] INFO: Processing task `gradient`
[2022-07-03 17:40:39,988] INFO: 5 events have already been submitted. They will not be submitted again.
[2022-07-03 17:40:40,913] INFO: 
Iteration 2: Number of events: 5	 chi = 0.0028967661170811853	 ||g|| = 0.003362117439052218
pred = -0.002794735112684646	ared = -0.003748935888588788	norm_update = 0.7176632483583003	tr_radius = 1.4530418599952213
[2022-07-03 17:40:40,970] INFO: 1 new tasks have been issued.
[2022-07-03 17:40:40,971] INFO: Processing task `preconditioner`

[2022-07-03 17:40:51,216] INFO: Processing task `preconditioner`
[2022-07-03 17:40:51,466] INFO: 1 new tasks have been issued.
[2022-07-03 17:40:51,467] INFO: Processing task `misfit`
[2022-07-03 17:40:51,621] INFO: Submitting job array with 5 jobs ...

[2022-07-03 17:40:51,875] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2022-07-03 17:41:01,964] INFO: Processing task `misfit`
[2022-07-03 17:41:02,406] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2022-07-03 17:41:12,504] INFO: Processing task `misfit`
[2022-07-03 17:41:13,886] INFO: 
old misfit control group: 0.002896766117081185
new misfit control group: 0.0024078430291397434
predicted reduction control group: -0.00022036546736047168
actual reduction control group: -0.0004889230879414415
5 out of 5 event(s) improved the misfit.
[2022-07-03 17:41:13,887] INFO: 
Model update accepted.
[2022-07-03 17:41:13,967] INFO: 1 new tasks have been issued.
[2022-07-03 17:41:13,968] INFO: Processing task `finalize_iteration`
[2022-07-03 17:41:14,122] INFO: Succesfully completed iteration #2.
[2022-07-03 17:41:14,129] INFO: Adding new iteration #3.
[2022-07-03 17:41:14,144] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00000
[2022-07-03 17:41:14,150] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00001
[2022-07-03 17:41:14,342] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00002
[2022-07-03 17:41:14,529] INFO: Freed up 4.4 MB of space.