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-04-30 20:17:02,733] INFO: Adding new iteration #0.
[2022-04-30 20:17:02,748] INFO: Resuming iteration #0.

[2022-04-30 20:17:02,749] INFO: 1 new tasks have been issued.
[2022-04-30 20:17:02,750] INFO: Processing task `misfit_and_gradient`
[2022-04-30 20:17:13,341] INFO: Processing task `misfit_and_gradient`
[2022-04-30 20:17:13,953] INFO: 
Iteration 0: Number of events: 5	 chi = 0.017689823928743624	 ||g|| = 0.016261472594252594
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2022-04-30 20:17:14,014] INFO: 1 new tasks have been issued.
[2022-04-30 20:17:14,015] INFO: Processing task `preconditioner`

[2022-04-30 20:17:24,383] INFO: Processing task `preconditioner`
[2022-04-30 20:17:24,729] INFO: 1 new tasks have been issued.
[2022-04-30 20:17:24,731] INFO: Processing task `misfit`
[2022-04-30 20:17:25,012] INFO: Submitting job array with 5 jobs ...

[2022-04-30 20:17:25,250] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2022-04-30 20:17:35,359] INFO: Processing task `misfit`
[2022-04-30 20:17:35,553] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2022-04-30 20:17:45,665] INFO: Processing task `misfit`
[2022-04-30 20:17:47,236] INFO: 
old misfit control group: 0.017689823928743624
new misfit control group: 0.006645703381637208
predicted reduction control group: -0.005735012737836711
actual reduction control group: -0.011044120547106417
5 out of 5 event(s) improved the misfit.
[2022-04-30 20:17:47,238] INFO: 
Model update accepted.
[2022-04-30 20:17:47,336] INFO: 1 new tasks have been issued.
[2022-04-30 20:17:47,337] INFO: Processing task `finalize_iteration`
[2022-04-30 20:17:47,443] INFO: Succesfully completed iteration #0.
[2022-04-30 20:17:47,446] 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-04-30 20:17:50,180] INFO: Resuming iteration #1.

[2022-04-30 20:17:50,181] INFO: 1 new tasks have been issued.
[2022-04-30 20:17:50,182] INFO: Processing task `gradient`
[2022-04-30 20:17:50,809] INFO: Submitting job array with 5 jobs ...
[2022-04-30 20:17:50,952] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2022-04-30 20:18:00,965] INFO: Processing task `gradient`
[2022-04-30 20:18:01,552] INFO: 5 events have already been submitted. They will not be submitted again.
[2022-04-30 20:18:01,781] INFO: Some simulations are still running. Please check again to see if they are finished.
[2022-04-30 20:18:01,782] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2022-04-30 20:18:11,797] INFO: Processing task `gradient`
[2022-04-30 20:18:12,242] INFO: 5 events have already been submitted. They will not be submitted again.
[2022-04-30 20:18:13,143] INFO: 
Iteration 1: Number of events: 5	 chi = 0.006645703381637208	 ||g|| = 0.00812202639963039
pred = -0.005735012737836711	ared = -0.011044120547106417	norm_update = 0.7265208462438065	tr_radius = 0.7265209528514627
[2022-04-30 20:18:13,224] INFO: 1 new tasks have been issued.
[2022-04-30 20:18:13,225] INFO: Processing task `preconditioner`

[2022-04-30 20:18:23,559] INFO: Processing task `preconditioner`
[2022-04-30 20:18:23,897] INFO: 1 new tasks have been issued.
[2022-04-30 20:18:23,899] INFO: Processing task `misfit`
[2022-04-30 20:18:24,046] INFO: Submitting job array with 5 jobs ...

[2022-04-30 20:18:24,310] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2022-04-30 20:18:34,456] INFO: Processing task `misfit`
[2022-04-30 20:18:34,700] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2022-04-30 20:18:44,828] INFO: Processing task `misfit`
[2022-04-30 20:18:46,151] INFO: 
old misfit control group: 0.006645703381637208
new misfit control group: 0.0028967676360953315
predicted reduction control group: -0.0027947347225040216
actual reduction control group: -0.0037489357455418766
5 out of 5 event(s) improved the misfit.
[2022-04-30 20:18:46,152] INFO: 
Model update accepted.
[2022-04-30 20:18:46,279] INFO: 1 new tasks have been issued.
[2022-04-30 20:18:46,280] INFO: Processing task `finalize_iteration`
[2022-04-30 20:18:46,418] INFO: Succesfully completed iteration #1.
[2022-04-30 20:18:46,421] INFO: Adding new iteration #2.
[2022-04-30 20:18:46,432] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00000
[2022-04-30 20:18:46,436] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00001
[2022-04-30 20:18:46,586] INFO: Freed up 4.4 MB of space.
[2022-04-30 20:18:46,591] INFO: Resuming iteration #2.

[2022-04-30 20:18:46,591] INFO: 1 new tasks have been issued.
[2022-04-30 20:18:46,592] INFO: Processing task `gradient`
[2022-04-30 20:18:47,212] INFO: Submitting job array with 5 jobs ...
[2022-04-30 20:18:47,354] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2022-04-30 20:18:57,368] INFO: Processing task `gradient`
[2022-04-30 20:18:57,918] INFO: 5 events have already been submitted. They will not be submitted again.
[2022-04-30 20:18:58,141] INFO: Some simulations are still running. Please check again to see if they are finished.
[2022-04-30 20:18:58,144] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2022-04-30 20:19:08,163] INFO: Processing task `gradient`
[2022-04-30 20:19:08,766] INFO: 5 events have already been submitted. They will not be submitted again.
[2022-04-30 20:19:09,505] INFO: 
Iteration 2: Number of events: 5	 chi = 0.002896767636095332	 ||g|| = 0.00336211927619281
pred = -0.0027947347225040216	ared = -0.0037489357455418766	norm_update = 0.7176632824822352	tr_radius = 1.4530419057029254
[2022-04-30 20:19:09,599] INFO: 1 new tasks have been issued.
[2022-04-30 20:19:09,600] INFO: Processing task `preconditioner`

[2022-04-30 20:19:19,981] INFO: Processing task `preconditioner`
[2022-04-30 20:19:20,339] INFO: 1 new tasks have been issued.
[2022-04-30 20:19:20,340] INFO: Processing task `misfit`
[2022-04-30 20:19:20,486] INFO: Submitting job array with 5 jobs ...

[2022-04-30 20:19:20,743] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2022-04-30 20:19:30,900] INFO: Processing task `misfit`
[2022-04-30 20:19:31,148] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2022-04-30 20:19:41,325] INFO: Processing task `misfit`
[2022-04-30 20:19:42,642] INFO: 
old misfit control group: 0.0028967676360953315
new misfit control group: 0.002407844655095448
predicted reduction control group: -0.0002203646621262934
actual reduction control group: -0.0004889229809998835
5 out of 5 event(s) improved the misfit.
[2022-04-30 20:19:42,644] INFO: 
Model update accepted.
[2022-04-30 20:19:42,802] INFO: 1 new tasks have been issued.
[2022-04-30 20:19:42,803] INFO: Processing task `finalize_iteration`
[2022-04-30 20:19:42,970] INFO: Succesfully completed iteration #2.
[2022-04-30 20:19:42,974] INFO: Adding new iteration #3.
[2022-04-30 20:19:42,986] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00000
[2022-04-30 20:19:42,991] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00001
[2022-04-30 20:19:43,140] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00002
[2022-04-30 20:19:43,289] INFO: Freed up 4.4 MB of space.