`waveeqprocessing.Kirchhoff`: opt-in `paired=True` for zero-offset / common-offset data (one trace per source-receiver pair)
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 25/100
- issue の種類
- 機能追加
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- python
- 領域
- backend, performance
調査の方向性
The proposal names Kirchhoff and the kernels _travsrcrec_kirch_[r]matvec and _ampsrcrec_kirch_[r]matvec; the draft implementation and tests are in linked PR #840, including pytests/test_kirchhoff.py and pytests/test_lsm.py. Read the draft PR and these tests first, then check how LSM forwards arguments to Kirchhoff. Done means paired source-receiver data work across the described modes and dimensions, existing unpaired behavior stays bit-identical, and the stated checks pass.
索引モデルが issue の本文から書いたものです。
説明
Edited 2026-11-06: Proposal points 3-4 and question 2 now describe the paired argument on the existing
kernels that the draft PR uses; the first version copied the kernels.
Motivation
Kirchhoff models every source with every receiver (ns * nr traces). Zero-offset and common-offset data
have one trace per source-receiver pair, for example ground-penetrating radar profiles. We migrate glacier GPR profiles (500–5000 traces per line) with your
operator, and today there are three ways to do zero offset:
- (A) all pairs +
Restrictionto the diagonal. Modelsn²traces to keepn: cost ∝n² · ni,
memory ∝n² · nt. A 515-trace × 3963-sample profile ran for more than 45 min and used 27 GB before we
stopped it. - (B)
VStackof one single-pairKirchhoffper trace (your suggestion in #755). Correct for
dynamic=False, but each sub-operator compiles its own numba kernels (0.2–0.4 s per trace on the
first call), and withdynamic=Truethe result changes: each sub-operator sets its own
maxdist = 1e-2 (max dist_srcs + max dist_recs), so the amplitudes depend on how the survey is split
(5–25 % max difference below; identical once all sub-operators use the same epsilon). - (C)
mode='byot'with one two-way table and a single dummy receiver (nr = 1,
trav = 2 * t_src). This already works and is fast, but only kinematically:dynamic=Trueneeds
separate tables, so it raises. You also have to build the tables yourself, which means calling the
privateKirchhoff._traveltime_table.
Adjoint timings (2-D, constant velocity, analytic tables, engine='numba' serial as pylops' default, image
n x 200, nt = 400, after JIT; (D) is the proposal below). Every route gives the same result as (A),
except where noted:
| traces | (A) all pairs + Restriction | (B) VStack (first call incl. JIT) | (C) byot, nr = 1 | (D) paired=True |
|---|---|---|---|---|
dynamic=False, 50 |
0.13 s | 0.006 s (8.8 s) | 0.002 s | 0.003 s |
dynamic=False, 100 |
1.05 s | 0.016 s (18.3 s) | 0.007 s | 0.009 s |
dynamic=False, 200 |
6.06 s | 0.045 s (36.1 s) | 0.022 s | 0.029 s |
dynamic=True, 50 |
0.43 s | 0.063 s (19.0 s), differs by 5 % | not possible | 0.014 s |
dynamic=True, 100 |
3.91 s | 0.25 s (38.2 s), differs by 14 % | not possible | 0.051 s |
dynamic=True, 200 |
30.2 s | 0.97 s (77.0 s), differs by 25 % | not possible | 0.203 s |
With NUMBA_NUM_THREADS=8, dynamic=True, 200 traces: (A) 6.1 s, (B) 0.087 s (203 s first call),
(D) 0.043 s. Dependencies as in your uv.lock (uv sync --locked, as in build.yaml), Python 3.12.
(D) is the current version of the draft PR; its adjoint is about 40 % slower than with the copied kernels
of the first version (dynamic, 200 traces: 0.20 s against 0.14 s serial, 0.042 s against 0.030 s with 8
threads, timed alternately in one process); the forward is equally fast.
Proposal
Add a new keyword argument paired: bool = False, placed last so that positional calls are unaffected.
With paired=True, source i is paired with receiver i: srcs and recs must have the same size, and
the data have shape (ns, nt) instead of (ns, nr, nt). Everything else stays the same: modes
(analytic, eikonal, byot with a tuple or a single (ni, ns) table), dynamic, wavfilter,
aperture, angleaperture, numpy/numba, 2-D and 3-D, and LSM (which forwards its keyword arguments
to Kirchhoff).
In the current code the change touches only:
__init__:nsnr = ns if paired else ns * nr. This value replacesns * nrin theConvolve1D
size, inself.nsnrand in the 3-Dsix/rixzeros. Alsodimsd = (ns, nt)when paired, and
six/rixget one entry per pair (2-D). That is 6 modified lines. Withpaired=Falseeach one
computes exactly what it computes now.- Input checks, raised only when
paired=True:ValueErrorifns != nr, or if a single table does not
havenscolumns. _register_multiplications:NotImplementedErrorforengine='cuda'whenpaired=True; with
paired=True, the selected kernels are bound withfunctools.partial(kernel, paired=True). The CUDA
helper is not modified. With a singlebyottable, the existing_trav_kirch_*kernels already loop
over pairs, so they are used unchanged.- The four kernels
_travsrcrec_kirch_[r]matvecand_ampsrcrec_kirch_[r]matvecget a last argument
paired: bool = False(here the forward kinematic kernel; the other three change in the same way):
trav_recs: NDArray,
+ paired: bool = False,
) -> NDArray:
+ # paired=True: only receiver isrc for source isrc (one trace per pair)
+ nrs, ipair = (1, 1) if paired else (nr, 0)
for isrc in prange(ns):
travisrc = trav_srcs[:, isrc]
- for irec in range(nr):
- travirec = trav_recs[:, irec]
+ for irec in range(nrs):
+ travirec = trav_recs[:, irec + ipair * isrc]
...
- y[isrc * nr + irec, itravii] += x[ii] * (1 - travdii)
- y[isrc * nr + irec, itravii + 1] += x[ii] * travdii
+ y[isrc * nrs + irec, itravii] += x[ii] * (1 - travdii)
+ y[isrc * nrs + irec, itravii + 1] += x[ii] * travdii
With paired=False the kernels are called with the same arguments as now, and the indices reduce to the
current ones (nrs = nr, ipair = 0).
In the operator the diff is +83 / −33 lines (20 of the added lines are docstring). The first
version of the draft PR added four copies of the kernels instead (276 lines). Codacy flagged them (8 new
Lizard issues: parameter count, cyclomatic complexity, length), so the PR now uses the argument.
Verification (on dev 06dc276)
We checked 112 configurations: 2-D and 3-D × analytic / eikonal / byot (tuple) / byot
(single table) × dynamic on and off × numpy / numba × (no apertures, no wavelet filter) and
(aperture=2, angleaperture=30, wavfilter=True in 2-D) × offset 0 and 2. The grid has dx != dz.
Each configuration was run serial and with NUMBA_NUM_THREADS=8:
paired=Falsegives forward and adjoint bit-identical to unpatched pylops (np.array_equal), with the
samedimsd.paired=Trueis bit-identical toRestriction(diagonal) @ Kirchhoff(all pairs), both forward and
adjoint, for zero offset and common offset.paired=Truepassesdottest(rtol 1e-10).- The three new errors are raised as intended.
Not tested: engine='cuda' (no GPU here). With paired=False the CUDA path receives the same arguments as
before.
The first version of the patch (copied kernels) was also bit-identical to the paired copy of your operator
that we run in production (zero offset, analytic and eikonal, dynamic on and off, both engines). The
current version gives bit-identical forward and adjoint to the first version in all 112 configurations.
Out of scope
- When
srcs == recs, the source and receiver tables are computed twice. Sharing them would halve the
eikonal time and the table memory. This is a possible follow-up and is not part of this change. - Grid-spacing issues in
byot+dynamicgradients and in the offset aperture: reported in #838. Thepairedoption keeps pylops' current conventions, so the results stay identical to
(A).
Questions
- Is
paireda good name, or would you prefer something likegeometry="pairs"? - Is the
pairedargument on the existing kernels fine, or would you prefer separate kernels (they
would need restructuring to stay within Codacy's Lizard limits)? - Should the kinematic-only route (C) also go into the docs?
A draft PR with the patch, tests in pytests/test_kirchhoff.py and pytests/test_lsm.py, a docstring note,
a CHANGELOG entry and a zero-offset section in the LSM tutorial is open: #840. We will adapt it to your
answers before marking it ready.
How AI was used
The analysis of the existing routes, the patch, the checks and the benchmark were done with Claude Code
(Anthropic) in a pair-programming setup: I chose the design (keyword instead of a new class, no CUDA
kernels in a first step), reviewed the diff and the results, and own them.
- 主要言語
- Python
- スター
- 539
- フォーク
- 126
- 平均マージ
- 3日 17分
- マージ済み PR(30日)
- 19
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
PyLops/pylops のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 56/100
メンテナーはふだん 2 日以内に返信
-
Lipschitz method対応中かも @Megumi1773 が 29 日前に担当しました。 オープンenhancement good first issue
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
メンテナーはふだん 2 日以内に返信
-
enhancement
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
PyLops/pylops#786 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
CI
難易度 3/5 1〜2日 初心者へのやさしさ 52/100
メンテナーはふだん 2 日以内に返信
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
メンテナーはふだん 2 日以内に返信
似ている issue
-
docs size:S
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
strawberry-graphql/strawberry#4794 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
dataforgoodfr/cetolog#21 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
btclib-org/btclib#2932 ·
メンテナーはふだん 1 日以内に返信