This documentation is not for the latest stable Salvus version.
%matplotlib inline
import numpy as np
import os
import salvus.namespace as sn
SALVUS_FLOW_SITE_NAME = os.environ.get("SITE_NAME", "local")
p = sn.Project(path="project")
SalvusProject
takes care of data management and book keeping.SimulationConfiguration
object of the initial model we created above. Furthermore, we need to specify all possible events that we might consider during the inversion. This could be a subset of events defined in the project, and we could add more events later on.
Together with the events, we need to pass the observed data. Because we created it synthetically, this is also just a SimulationConfiguration
object. The remaining parameters specify which parameters to invert for (VP
and RHO
), what misfit functional to use, preconditioner and descent method, and where to run the simulations.p += sn.InverseProblemConfiguration(
name="my_inversion",
prior_model="initial_model",
events=p.events.list(),
mapping=sn.Mapping(scaling="absolute", inversion_parameters=["VP", "RHO"]),
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
),
)
SalvusOpt
uses a tree-based framework of iteration. At any point during the inversion, you can branch off, modify the settings, and run one or more streams simultaneously.p.inversions.add_iteration(inverse_problem_configuration="my_inversion")
[2024-03-15 09:25:32,698] INFO: Adding new iteration #0.
True
SalvusOpt
steps through an iteration, and automatically dispatches simulations whenever necessary. The function resume
will return whenever SalvusOpt
is waiting for other tasks to finish first. Calling it several time, will step through the iteration in sequence.p.inversions.resume(
inverse_problem_configuration="my_inversion",
)
[2024-03-15 09:25:32,710] INFO: Resuming iteration #0. Current stage: initialize [2024-03-15 09:25:32,711] INFO: 1 new tasks have been issued. [2024-03-15 09:25:32,711] INFO: Processing task `misfit_and_gradient` [2024-03-15 09:25:33,234] INFO: Iteration 0: Number of events: 5 chi = 0.017690077140191465 ||g|| = 0.02256501255377387 pred = --- ared = --- norm_update = --- tr_radius = --- [2024-03-15 09:25:33,235] INFO: 1 new tasks have been issued. [2024-03-15 09:25:33,235] INFO: Processing task `preconditioner` [2024-03-15 09:25:33,410] INFO: Some tasks of iteration #0 are still running. Please check again later.
p.inversions.resume(
inverse_problem_configuration="my_inversion",
)
[2024-03-15 09:25:33,426] INFO: Resuming iteration #0. Current stage: compute_trial_model [2024-03-15 09:25:33,427] INFO: Processing task `preconditioner` [2024-03-15 09:25:33,458] INFO: Some tasks of iteration #0 are still running. Please check again later.
p.viz.nb.iteration(
inverse_problem_configuration="my_inversion", iteration_id=0
)
SalvusOpt
to run an entire iteration at once. Note the parameter timeout_in_seconds
, which will force the cell to return even if the iteration has not been completed yet, and there might still be a few simulations running in the back.p.inversions.iterate(
inverse_problem_configuration="my_inversion",
timeout_in_seconds=360,
ping_interval_in_seconds=10,
)
p.viz.nb.inversion(inverse_problem_configuration="my_inversion")
[2024-03-15 09:25:33,938] INFO: Resuming iteration #0. [2024-03-15 09:25:33,938] INFO: Processing task `preconditioner` [2024-03-15 09:25:33,958] INFO: Some tasks of iteration #0 are still running. Please check again later. [2024-03-15 09:25:43,959] INFO: Processing task `preconditioner` [2024-03-15 09:25:44,090] INFO: 1 new tasks have been issued. [2024-03-15 09:25:44,090] INFO: Processing task `misfit` [2024-03-15 09:25:44,159] INFO: Submitting job array with 5 jobs ... [2024-03-15 09:25:44,270] INFO: Launched simulations for 5 events. Please check again to see if they are finished. [2024-03-15 09:25:44,271] INFO: Some tasks of iteration #0 are still running. Please check again later. [2024-03-15 09:25:54,285] INFO: Processing task `misfit` [2024-03-15 09:25:54,982] INFO: old misfit control group: 0.01769007714019146 new misfit control group: 0.006215537864641849 predicted reduction control group: -0.009679726576114392 actual reduction control group: -0.011474539275549613 5 out of 5 event(s) improved the misfit. [2024-03-15 09:25:54,982] INFO: Model update accepted. [2024-03-15 09:25:54,983] INFO: 1 new tasks have been issued. [2024-03-15 09:25:54,983] INFO: Processing task `finalize_iteration` [2024-03-15 09:25:55,010] INFO: Succesfully completed iteration #0. [2024-03-15 09:25:55,011] INFO: Adding new iteration #1.