API Reference
Data Structure
ADSeismic.AcousticPropagator — TypeAcousticPropagatorA structure holding all the information for acoustic simulation
ADSeismic.ElasticSource — Typemutable struct ElasticSource
srci::Union{Array{Int64, 1},PyObject}
srcj::Union{Array{Int64, 1},PyObject}
srctype::Union{Array{Int64, 1},PyObject}
srcv::Union{Array{Float64, 2},PyObject}
endAdd source terms to different components according to srctype
- 0:
vx - 1:
vy - 2:
σxx - 3:
σyy - 4:
σxy
Simulation
ADSeismic.AcousticPropagatorSolver — MethodAcousticPropagatorSolver(param::AcousticPropagatorParams, src::AcousticSource, c::Union{PyObject, Array{Float64, 2}})
Arguments
- 'param::AcousticPropagatorParams': model configuration parameters, such as NX, NT
- 'src::AcousticSource': source locations
- 'c::Union{PyObject, Array{Float64, 2}}': velocity model
Return
- 'AcousticPropagator': forward calculation results, like displacement u
ADSeismic.SimulatedObservation! — MethodSimulatedObservation!(ap::AcousticPropagator, rcv::AcousticReceiver)Extract and save simulated displacement u into rcv::AcousticReceiver.
ADSeismic.pml_helper — Methodpml_helper(x::Float64, y::Float64, param::AcousticPropagatorParams)Computing the PML profile.
I/O
ADSeismic.load_acoustic_model — Methodloadacousticmodel(filename::String; inv_vp::Bool = false, kwargs...)
Load acoustic model from a MAT file.
Arguments
- 'filename::String': MAT filename
- 'inv_vp::Bool': inversion of velocity (default: false)
Return
- AcousticPropagatorSolver(src::AcousticSource)
Utilities
ADSeismic.Ricker — FunctionRicker(epp::Union{ElasticPropagatorParams, AcousticPropagatorParams},
a::Union{PyObject, <:Real},
shift::Union{PyObject, <:Real},
amp::Union{PyObject, <:Real}=1.0)Returns a Ricker wavelet (a tensor).
epp: aElasticPropagatorParamsor anAcousticPropagatorParamsa: Width parametershift: Center of the Ricker waveletamp: Amplitude of the Ricker wavelet
\[f(x) = \mathrm{amp}A (1 - x^2/a^2) exp(-x^2/2 a^2)\]
where
\[A = 2/sqrt(3a)pi^1/4\]
ADSeismic.compute_loss_and_grads_GPU — Methodcompute_loss_and_grads_GPU(model::Function, src::Union{Array{AcousticSource},Array{ElasticSource}},
rcv_sim::Union{Array{AcousticReceiver}, Array{ElasticReceiver}}, Rs::Array{Array{Float64}}, vs::Union{PyObject, Array{PyObject}})Computes the loss and the gradients of the model on all available GPUs.
model,src,rcv_sim: Model, Source and Receiver returned byload_acoustic_source,load_acoustic_model,load_acoustic_receiverorload_elastic_source,load_elastic_model,load_elastic_receiverRs: True receiver datavs: Variables to be optimized. It or its elements must havereftype.
ADSeismic.sampling_compute_loss_and_grads_GPU_v2 — Methodmodels: nsrc * batch_sizesrc: nsrcrcv_sim: nsrc * batch_sizeRs: nsrc * sample_size
ADSeismic.sampling_compute_loss_and_grads_GPU_v3 — MethodMathcing statistics.
models: nsrc * batch_sizesrc: nsrcrcv_sim: nsrc * batch_sizeRs: nsrc * sample_size
ADSeismic.visualize_wavefield — Methodvisualize_wavefield(val::Array{Float64, 3},
param::Union{ElasticPropagatorParams,AcousticPropagatorParams})
visualize_wavefield(val::Array{Array{Float64, 3}, 1},
param::Union{MPIAcousticPropagatorParams, MPIElasticPropagatorParams})Visualizes the wavefield and returns the handle of the animation. You can save the animation to gif via
p = visualize_wavefield(...)
saveanim(p, "myfigure.gif")Optimization
ADSeismic.LBFGS! — FunctionLBFGS!(sess::PyObject, loss::PyObject, max_iter::Int64=15000;
vars::Array{PyObject}=PyObject[], callback::Union{Function, Nothing}=nothing, kwargs...)BFGS! is a simplified interface for BFGS optimizer. See also ScipyOptimizerInterface. callback is a callback function with signature
callback(vs::Array, iter::Int64, loss::Float64)vars is an array consisting of tensors and its values will be the input to vs.
Example 1
a = Variable(1.0)
loss = (a - 10.0)^2
sess = Session(); init(sess)
BFGS!(sess, loss)Example 2
θ1 = Variable(1.0)
θ2 = Variable(1.0)
loss = (θ1-1)^2 + (θ2-2)^2
cb = (vs, iter, loss)->begin
printstyled("[#iter $iter] θ1=$(vs[1]), θ2=$(vs[2]), loss=$loss\n", color=:green)
end
sess = Session(); init(sess)
cb(run(sess, [θ1, θ2]), 0, run(sess, loss))
BFGS!(sess, loss, 100; vars=[θ1, θ2], callback=cb)Example 3
Use bounds to specify upper and lower bound of a variable.
x = Variable(2.0)
loss = x^2
sess = Session(); init(sess)
BFGS!(sess, loss, bounds=Dict(x=>[1.0,3.0]))ADSeismic.LBFGS! — FunctionLBFGS!(value_and_gradients_function::Function, initial_position::Union{PyObject, Array{Float64}}, max_iter::Int64=50, args...;kwargs...)Applies the BFGS optimizer to value_and_gradients_function
ADSeismic.LBFGS! — MethodLBFGS!(sess::PyObject, loss::PyObject, grads::Union{Array{T},Nothing,PyObject},
vars::Union{Array{PyObject},PyObject}; kwargs...) where T<:Union{Nothing, PyObject}Running BFGS algorithm $\min_{\texttt{vars}} \texttt{loss}(\texttt{vars})$ The gradients grads must be provided. Typically, grads[i] = gradients(loss, vars[i]). grads[i] can exist on different devices (GPU or CPU).
Example 1
import Optim # required
a = Variable(0.0)
loss = (a-1)^2
g = gradients(loss, a)
sess = Session(); init(sess)
BFGS!(sess, loss, g, a)Example 2
import Optim # required
a = Variable(0.0)
loss = (a^2+a-1)^2
g = gradients(loss, a)
sess = Session(); init(sess)
cb = (vs, iter, loss)->begin
printstyled("[#iter $iter] a = $vs, loss=$loss\n", color=:green)
end
BFGS!(sess, loss, g, a; callback = cb)