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,
)
[2023-07-03 12:21:58,920] INFO: Adding new iteration #0.
[2023-07-03 12:21:58,936] INFO: Resuming iteration #0.

[2023-07-03 12:21:58,942] INFO: 1 new tasks have been issued.
[2023-07-03 12:21:58,943] INFO: Processing task `misfit_and_gradient`
[2023-07-03 12:21:59,480] INFO: 
Iteration 0: Number of events: 5	 chi = 0.017689825271254428	 ||g|| = 0.016261474262368125
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2023-07-03 12:21:59,481] INFO: 1 new tasks have been issued.
[2023-07-03 12:21:59,482] INFO: Processing task `preconditioner`

[2023-07-03 12:21:59,739] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2023-07-03 12:22:09,757] INFO: Processing task `preconditioner`
[2023-07-03 12:22:10,017] INFO: 1 new tasks have been issued.
[2023-07-03 12:22:10,018] INFO: Processing task `misfit`
[2023-07-03 12:22:10,114] INFO: Submitting job array with 5 jobs ...

[2023-07-03 12:22:10,274] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2023-07-03 12:22:10,275] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2023-07-03 12:22:20,323] INFO: Processing task `misfit`
[2023-07-03 12:22:21,491] INFO: 
old misfit control group: 0.017689825271254428
new misfit control group: 0.006645706564992383
predicted reduction control group: -0.00573500841424071
actual reduction control group: -0.011044118706262044
5 out of 5 event(s) improved the misfit.
[2023-07-03 12:22:21,492] INFO: 
Model update accepted.
[2023-07-03 12:22:21,493] INFO: 1 new tasks have been issued.
[2023-07-03 12:22:21,493] INFO: Processing task `finalize_iteration`
[2023-07-03 12:22:21,552] INFO: Succesfully completed iteration #0.
[2023-07-03 12:22:21,554] 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-07-03 12:22:23,565] INFO: Resuming iteration #1.

[2023-07-03 12:22:23,565] INFO: 1 new tasks have been issued.
[2023-07-03 12:22:23,566] INFO: Processing task `gradient`
[2023-07-03 12:22:24,052] INFO: Submitting job array with 5 jobs ...

[2023-07-03 12:22:24,167] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2023-07-03 12:22:24,169] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2023-07-03 12:22:34,178] INFO: Processing task `gradient`
[2023-07-03 12:22:34,479] INFO: 5 events have already been submitted. They will not be submitted again.
[2023-07-03 12:22:35,183] INFO: 
Iteration 1: Number of events: 5	 chi = 0.006645706564992384	 ||g|| = 0.008122033047540137
pred = -0.00573500841424071	ared = -0.011044118706262044	norm_update = 0.7265203644041015	tr_radius = 0.7265203854287905
[2023-07-03 12:22:35,206] INFO: 1 new tasks have been issued.
[2023-07-03 12:22:35,207] INFO: Processing task `preconditioner`

[2023-07-03 12:22:35,363] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2023-07-03 12:22:45,412] INFO: Processing task `preconditioner`
[2023-07-03 12:22:45,611] INFO: 1 new tasks have been issued.
[2023-07-03 12:22:45,612] INFO: Processing task `misfit`
[2023-07-03 12:22:45,711] INFO: Submitting job array with 5 jobs ...

[2023-07-03 12:22:45,878] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2023-07-03 12:22:45,880] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2023-07-03 12:22:55,951] INFO: Processing task `misfit`
[2023-07-03 12:22:56,854] INFO: 
old misfit control group: 0.006645706564992383
new misfit control group: 0.0028967663828196677
predicted reduction control group: -0.00279473808584682
actual reduction control group: -0.0037489401821727154
5 out of 5 event(s) improved the misfit.
[2023-07-03 12:22:56,855] INFO: 
Model update accepted.
[2023-07-03 12:22:56,856] INFO: 1 new tasks have been issued.
[2023-07-03 12:22:56,856] INFO: Processing task `finalize_iteration`
[2023-07-03 12:22:56,958] INFO: Succesfully completed iteration #1.
[2023-07-03 12:22:56,961] INFO: Adding new iteration #2.
[2023-07-03 12:22:56,974] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00000
[2023-07-03 12:22:56,979] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00001
[2023-07-03 12:22:57,093] INFO: Freed up 4.4 MB of space.
[2023-07-03 12:22:57,098] INFO: Resuming iteration #2.

[2023-07-03 12:22:57,099] INFO: 1 new tasks have been issued.
[2023-07-03 12:22:57,099] INFO: Processing task `gradient`
[2023-07-03 12:22:57,547] INFO: Submitting job array with 5 jobs ...

[2023-07-03 12:22:57,657] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2023-07-03 12:22:57,659] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2023-07-03 12:23:07,673] INFO: Processing task `gradient`
[2023-07-03 12:23:07,973] INFO: 5 events have already been submitted. They will not be submitted again.
[2023-07-03 12:23:08,811] INFO: 
Iteration 2: Number of events: 5	 chi = 0.0028967663828196677	 ||g|| = 0.003362121794535246
pred = -0.00279473808584682	ared = -0.0037489401821727154	norm_update = 0.7176637218434795	tr_radius = 1.453040770857581
[2023-07-03 12:23:08,848] INFO: 1 new tasks have been issued.
[2023-07-03 12:23:08,849] INFO: Processing task `preconditioner`

[2023-07-03 12:23:09,022] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2023-07-03 12:23:19,089] INFO: Processing task `preconditioner`
[2023-07-03 12:23:19,313] INFO: 1 new tasks have been issued.
[2023-07-03 12:23:19,314] INFO: Processing task `misfit`
[2023-07-03 12:23:19,409] INFO: Submitting job array with 5 jobs ...

[2023-07-03 12:23:19,574] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2023-07-03 12:23:19,576] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2023-07-03 12:23:29,672] INFO: Processing task `misfit`
[2023-07-03 12:23:30,571] INFO: 
old misfit control group: 0.0028967663828196677
new misfit control group: 0.0024078467050186606
predicted reduction control group: -0.00022036385947312755
actual reduction control group: -0.0004889196778010071
5 out of 5 event(s) improved the misfit.
[2023-07-03 12:23:30,571] INFO: 
Model update accepted.
[2023-07-03 12:23:30,572] INFO: 1 new tasks have been issued.
[2023-07-03 12:23:30,573] INFO: Processing task `finalize_iteration`
[2023-07-03 12:23:30,715] INFO: Succesfully completed iteration #2.
[2023-07-03 12:23:30,720] INFO: Adding new iteration #3.
[2023-07-03 12:23:30,735] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00000
[2023-07-03 12:23:30,740] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00001
[2023-07-03 12:23:30,863] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00002
[2023-07-03 12:23:30,980] INFO: Freed up 4.4 MB of space.