This PR is mainly aimed at improving the memory efficiency of the Kirchhoff operator.
In the current implementation, we create an overall trav table (similar for amp in dynamic=True mode) of size nynxnz x nsnr. Assuming ns=nr this scales quadratically with the ns.
In the new implementation, we handle source and receiver tables independently (trav_srcs and trav_recs) and not merge them into a unique table. Assuming ns=nr this scales linearly with the ns.
Changes
The following changes are introduced:
4 new methods are created: _travsrcrec_kirch_matvec, _travsrcrec_kirch_rmatvec, _amp_kirch_matvec, and _amp_kirch_rmatvec, which are the counterparts of _trav_kirch_matvec, _trav_kirch_rmatvec, _ampsrcrec_kirch_matvec, and _ampsrcrec_kirch_rmatvec which used full tables
trav and amp can now be provided as nd.arrays or tuples of 2 nd.arrays. In the second case, these Arte the src and rec tables. Internally the __init__ operator handles both cases to ensure backward compatibility.
the order and number of outputs in _traveltime_table is changed. However, being this a private method we should not expect users to use it (aka users should not expect us not to make changes), so I believe this is fine.
Motivation
This PR is mainly aimed at improving the memory efficiency of the
Kirchhoff
operator.In the current implementation, we create an overall
trav
table (similar foramp
indynamic=True
mode) of sizenynxnz x nsnr
. Assumingns=nr
this scales quadratically with thens
.In the new implementation, we handle source and receiver tables independently (
trav_srcs
andtrav_recs
) and not merge them into a unique table. Assumingns=nr
this scales linearly with thens
.Changes
The following changes are introduced:
_travsrcrec_kirch_matvec
,_travsrcrec_kirch_rmatvec
,_amp_kirch_matvec
, and_amp_kirch_rmatvec
, which are the counterparts of_trav_kirch_matvec
,_trav_kirch_rmatvec
,_ampsrcrec_kirch_matvec
, and_ampsrcrec_kirch_rmatvec
which used full tablestrav
andamp
can now be provided as nd.arrays or tuples of 2 nd.arrays. In the second case, these Arte the src and rec tables. Internally the__init__
operator handles both cases to ensure backward compatibility._traveltime_table
is changed. However, being this a private method we should not expect users to use it (aka users should not expect us not to make changes), so I believe this is fine.Performance tests
I run the following two performance tests using this code:
and equivalent code with old version of Kirchoff.
dynamic=False
dynamic=True