Version:

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")

Only update within a region of interest

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,
    delete_disposable_files="all",
)
[2024-10-30 23:45:02,450] INFO: Adding new iteration #0.
[2024-10-30 23:45:02,462] INFO: Resuming iteration #0.

[2024-10-30 23:45:02,462] INFO: 1 new tasks have been issued.
[2024-10-30 23:45:02,463] INFO: Processing task `misfit_and_gradient`
[2024-10-30 23:45:02,711] INFO: 
Iteration 0: Number of events: 5	 chi = 0.018681064754203797	 ||g|| = 0.016366358801050206
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2024-10-30 23:45:02,712] INFO: 1 new tasks have been issued.
[2024-10-30 23:45:02,712] INFO: Processing task `preconditioner`

[2024-10-30 23:45:02,865] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-10-30 23:45:12,876] INFO: Processing task `preconditioner`
[2024-10-30 23:45:13,009] INFO: 1 new tasks have been issued.
[2024-10-30 23:45:13,009] INFO: Processing task `misfit`
[2024-10-30 23:45:13,047] INFO: Submitting job array with 5 jobs ...

[2024-10-30 23:45:13,130] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2024-10-30 23:45:13,131] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2024-10-30 23:45:23,154] INFO: Processing task `misfit`
[2024-10-30 23:45:24,701] INFO: 
old misfit control group: 0.018681064754203797
new misfit control group: 0.007802509365775308
predicted reduction control group: -0.005675405778715309
actual reduction control group: -0.010878555388428489
5 out of 5 event(s) improved the misfit.
[2024-10-30 23:45:24,702] INFO: 
Model update accepted.
[2024-10-30 23:45:24,702] INFO: 1 new tasks have been issued.
[2024-10-30 23:45:24,702] INFO: Processing task `finalize_iteration`
[2024-10-30 23:45:24,743] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00000
[2024-10-30 23:45:24,754] INFO: Freed up 1.2 MB of space.
[2024-10-30 23:45:24,754] INFO: Succesfully completed iteration #0.
[2024-10-30 23:45:24,756] 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,
        delete_disposable_files="all",
    )
p.viz.nb.inversion(inverse_problem_configuration="my_second_inversion")
[2024-10-30 23:45:25,676] INFO: Resuming iteration #1.

[2024-10-30 23:45:25,676] INFO: 1 new tasks have been issued.
[2024-10-30 23:45:25,676] INFO: Processing task `gradient`
[2024-10-30 23:45:25,859] INFO: Submitting job array with 5 jobs ...
Uploading 1 files...
Uploading 1 files...
Uploading 1 files...
Uploading 1 files...
Uploading 1 files...

[2024-10-30 23:45:25,909] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2024-10-30 23:45:25,910] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2024-10-30 23:45:35,911] INFO: Processing task `gradient`
[2024-10-30 23:45:36,213] INFO: 5 events have already been submitted. They will not be submitted again.
[2024-10-30 23:45:36,607] INFO: 
Iteration 1: Number of events: 5	 chi = 0.0078025093657753085	 ||g|| = 0.008438424180558228
pred = -0.005675405778715309	ared = -0.010878555388428489	norm_update = 0.7166324367619695	tr_radius = 0.7166322852767166
[2024-10-30 23:45:36,617] INFO: 1 new tasks have been issued.
[2024-10-30 23:45:36,617] INFO: Processing task `preconditioner`

[2024-10-30 23:45:36,701] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2024-10-30 23:45:46,722] INFO: Processing task `preconditioner`
[2024-10-30 23:45:46,851] INFO: 1 new tasks have been issued.
[2024-10-30 23:45:46,852] INFO: Processing task `misfit`
[2024-10-30 23:45:46,889] INFO: Submitting job array with 5 jobs ...

[2024-10-30 23:45:46,975] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2024-10-30 23:45:46,976] INFO: Some tasks of iteration #1 are still running. Please check again later.
[2024-10-30 23:45:57,010] INFO: Processing task `misfit`
[2024-10-30 23:45:58,464] INFO: 
old misfit control group: 0.007802509365775308
new misfit control group: 0.0038977169133135496
predicted reduction control group: -0.0029460718526640095
actual reduction control group: -0.003904792452461758
5 out of 5 event(s) improved the misfit.
[2024-10-30 23:45:58,465] INFO: 
Model update accepted.
[2024-10-30 23:45:58,465] INFO: 1 new tasks have been issued.
[2024-10-30 23:45:58,465] INFO: Processing task `finalize_iteration`
[2024-10-30 23:45:58,524] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00001
[2024-10-30 23:45:58,630] INFO: Freed up 4.8 MB of space.
[2024-10-30 23:45:58,630] INFO: Succesfully completed iteration #1.
[2024-10-30 23:45:58,632] INFO: Adding new iteration #2.
[2024-10-30 23:45:58,637] INFO: Resuming iteration #2.

[2024-10-30 23:45:58,637] INFO: 1 new tasks have been issued.
[2024-10-30 23:45:58,637] INFO: Processing task `gradient`
[2024-10-30 23:45:58,805] INFO: Submitting job array with 5 jobs ...
Uploading 1 files...
Uploading 1 files...
Uploading 1 files...
Uploading 1 files...
Uploading 1 files...

[2024-10-30 23:45:58,858] INFO: Launched adjoint simulations for 5 events. Please check again to see if they are finished.
[2024-10-30 23:45:58,859] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2024-10-30 23:46:08,862] INFO: Processing task `gradient`
[2024-10-30 23:46:09,006] INFO: 5 events have already been submitted. They will not be submitted again.
[2024-10-30 23:46:09,374] INFO: 
Iteration 2: Number of events: 5	 chi = 0.0038977169133135496	 ||g|| = 0.0038998099223934266
pred = -0.0029460718526640095	ared = -0.003904792452461758	norm_update = 0.7368817080094618	tr_radius = 1.4332645705534333
[2024-10-30 23:46:09,388] INFO: 1 new tasks have been issued.
[2024-10-30 23:46:09,389] INFO: Processing task `preconditioner`

[2024-10-30 23:46:09,474] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2024-10-30 23:46:19,510] INFO: Processing task `preconditioner`
[2024-10-30 23:46:19,650] INFO: 1 new tasks have been issued.
[2024-10-30 23:46:19,650] INFO: Processing task `misfit`
[2024-10-30 23:46:19,692] INFO: Submitting job array with 5 jobs ...

[2024-10-30 23:46:19,955] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2024-10-30 23:46:19,956] INFO: Some tasks of iteration #2 are still running. Please check again later.
[2024-10-30 23:46:29,999] INFO: Processing task `misfit`
[2024-10-30 23:46:31,423] INFO: 
old misfit control group: 0.0038977169133135496
new misfit control group: 0.003293527922292616
predicted reduction control group: -0.00027362868818550537
actual reduction control group: -0.0006041889910209336
5 out of 5 event(s) improved the misfit.
[2024-10-30 23:46:31,424] INFO: 
Model update accepted.
[2024-10-30 23:46:31,424] INFO: 1 new tasks have been issued.
[2024-10-30 23:46:31,424] INFO: Processing task `finalize_iteration`
[2024-10-30 23:46:31,504] INFO: ... searching for obsolete files in project/INVERSIONS/my_second_inversion/00002
[2024-10-30 23:46:31,614] INFO: Freed up 6.0 MB of space.
[2024-10-30 23:46:31,614] INFO: Succesfully completed iteration #2.
[2024-10-30 23:46:31,616] INFO: Adding new iteration #3.