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=p.events.list(),
    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,
)
[2024-05-15 12:57:23,617] INFO: Adding new iteration #0.
[2024-05-15 12:57:23,644] INFO: Resuming iteration #0.

[2024-05-15 12:57:23,646] INFO: 1 new tasks have been issued.
[2024-05-15 12:57:23,646] INFO: Processing task `misfit_and_gradient`
[2024-05-15 12:57:24,160] INFO: 
Iteration 0: Number of events: 5	 chi = 0.017690076157774178	 ||g|| = 0.01626160085513182
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2024-05-15 12:57:24,161] INFO: 1 new tasks have been issued.
[2024-05-15 12:57:24,162] INFO: Processing task `preconditioner`

[2024-05-15 12:57:24,408] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-05-15 12:57:34,417] INFO: Processing task `preconditioner`
[2024-05-15 12:57:34,578] INFO: 1 new tasks have been issued.
[2024-05-15 12:57:34,578] INFO: Processing task `misfit`
[2024-05-15 12:57:34,666] INFO: Submitting job array with 5 jobs ...

[2024-05-15 12:57:34,807] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2024-05-15 12:57:34,809] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-05-15 12:57:44,834] INFO: Processing task `misfit`
[2024-05-15 12:57:46,228] INFO: 
old misfit control group: 0.017690076157774175
new misfit control group: 0.00664570902045414
predicted reduction control group: -0.00573506534931896
actual reduction control group: -0.011044367137320035
5 out of 5 event(s) improved the misfit.
[2024-05-15 12:57:46,229] INFO: 
Model update accepted.
[2024-05-15 12:57:46,230] INFO: 1 new tasks have been issued.
[2024-05-15 12:57:46,231] INFO: Processing task `finalize_iteration`
[2024-05-15 12:57:46,312] INFO: Succesfully completed iteration #0.
[2024-05-15 12:57:46,315] 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")
[2024-05-15 12:57:48,898] INFO: Resuming iteration #1.

[2024-05-15 12:57:48,901] INFO: 1 new tasks have been issued.
[2024-05-15 12:57:48,902] INFO: Processing task `gradient`
[2024-05-15 12:57:49,606] INFO: Submitting job array with 5 jobs ...
Uploading 1 files...
Uploading 1 files...
Uploading 1 files...
Uploading 1 files...
Uploading 1 files...

[2024-05-15 12:57:49,800] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2024-05-15 12:57:49,805] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2024-05-15 12:57:59,811] INFO: Processing task `gradient`
[2024-05-15 12:58:00,827] INFO: 5 events have already been submitted. They will not be submitted again.
[2024-05-15 12:58:01,792] INFO: 
Iteration 1: Number of events: 5	 chi = 0.00664570902045414	 ||g|| = 0.008122022119893406
pred = -0.00573506534931896	ared = -0.011044367137320035	norm_update = 0.7265219524034239	tr_radius = 0.7265221051484864
[2024-05-15 12:58:01,813] INFO: 1 new tasks have been issued.
[2024-05-15 12:58:01,815] INFO: Processing task `preconditioner`

[2024-05-15 12:58:02,019] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2024-05-15 12:58:12,088] INFO: Processing task `preconditioner`
[2024-05-15 12:58:12,353] INFO: 1 new tasks have been issued.
[2024-05-15 12:58:12,362] INFO: Processing task `misfit`
[2024-05-15 12:58:12,547] INFO: Submitting job array with 5 jobs ...

[2024-05-15 12:58:12,877] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2024-05-15 12:58:12,881] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2024-05-15 12:58:23,013] INFO: Processing task `misfit`
[2024-05-15 12:58:24,288] INFO: 
old misfit control group: 0.00664570902045414
new misfit control group: 0.0028967886883502314
predicted reduction control group: -0.0027946883746031
actual reduction control group: -0.0037489203321039084
5 out of 5 event(s) improved the misfit.
[2024-05-15 12:58:24,294] INFO: 
Model update accepted.
[2024-05-15 12:58:24,297] INFO: 1 new tasks have been issued.
[2024-05-15 12:58:24,298] INFO: Processing task `finalize_iteration`
[2024-05-15 12:58:24,441] INFO: Succesfully completed iteration #1.
[2024-05-15 12:58:24,451] INFO: Adding new iteration #2.
[2024-05-15 12:58:24,469] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00000
[2024-05-15 12:58:24,477] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00001
[2024-05-15 12:58:24,810] INFO: Freed up 6.0 MB of space.
[2024-05-15 12:58:24,823] INFO: Resuming iteration #2.

[2024-05-15 12:58:24,837] INFO: 1 new tasks have been issued.
[2024-05-15 12:58:24,840] INFO: Processing task `gradient`
[2024-05-15 12:58:25,576] INFO: Submitting job array with 5 jobs ...
Uploading 1 files...
Uploading 1 files...
Uploading 1 files...
Uploading 1 files...
Uploading 1 files...

[2024-05-15 12:58:25,819] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2024-05-15 12:58:25,822] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2024-05-15 12:58:35,827] INFO: Processing task `gradient`
[2024-05-15 12:58:36,221] INFO: 5 events have already been submitted. They will not be submitted again.
[2024-05-15 12:58:37,165] INFO: 
Iteration 2: Number of events: 5	 chi = 0.002896788688350232	 ||g|| = 0.003362105420798052
pred = -0.0027946883746031	ared = -0.0037489203321039084	norm_update = 0.7176520315062779	tr_radius = 1.4530442102969727
[2024-05-15 12:58:37,315] INFO: 1 new tasks have been issued.
[2024-05-15 12:58:37,322] INFO: Processing task `preconditioner`

[2024-05-15 12:58:37,650] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2024-05-15 12:58:47,701] INFO: Processing task `preconditioner`
[2024-05-15 12:58:48,059] INFO: 1 new tasks have been issued.
[2024-05-15 12:58:48,061] INFO: Processing task `misfit`
[2024-05-15 12:58:48,183] INFO: Submitting job array with 5 jobs ...

[2024-05-15 12:58:48,501] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2024-05-15 12:58:48,515] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2024-05-15 12:58:58,881] INFO: Processing task `misfit`
[2024-05-15 12:59:00,683] INFO: 
old misfit control group: 0.0028967886883502314
new misfit control group: 0.0024078604607760306
predicted reduction control group: -0.0002203679362801023
actual reduction control group: -0.0004889282275742008
5 out of 5 event(s) improved the misfit.
[2024-05-15 12:59:00,686] INFO: 
Model update accepted.
[2024-05-15 12:59:00,694] INFO: 1 new tasks have been issued.
[2024-05-15 12:59:00,701] INFO: Processing task `finalize_iteration`
[2024-05-15 12:59:00,867] INFO: Succesfully completed iteration #2.
[2024-05-15 12:59:00,874] INFO: Adding new iteration #3.
[2024-05-15 12:59:00,889] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00000
[2024-05-15 12:59:00,895] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00001
[2024-05-15 12:59:01,093] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00002
[2024-05-15 12:59:01,465] INFO: Freed up 6.0 MB of space.