`waveeqprocessing.Kirchhoff`: opt-in `paired=True` for zero-offset / common-offset data (one trace per source-receiver pair)
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 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 分钟
- 30 天内合并 PR
- 19
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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
维护者通常 2 天内回复
-
CI
难度 3/5 1-2 天 新手友好度 52/100
维护者通常 2 天内回复
-
enhancement
难度 5/5 一周以上 新手友好度 25/100
维护者通常 2 天内回复
相似的 Issue
-
binding:python bug
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
The Browser tab fails with a Wayland error when Open Terminal runs from a Wayland desktop session未关闭
难度 2/5 1-3 小时 新手友好度 78/100
open-webui/open-terminal#210 ·
-
triage/confirmed
难度 2/5 1-3 小时 新手友好度 78/100
agentscope-ai/agentscope#3807 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
NousResearch/hermes-agent#150542 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 91/100
triton-inference-server/server#9069 ·
维护者通常 1 天内回复