`waveeqprocessing.Kirchhoff`: opt-in `paired=True` for zero-offset / common-offset data (one trace per source-receiver pair)
Los mantenedores suelen responder en 2 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- python
- Área
- backend, performance
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Python
- Estrellas
- 539
- Forks
- 126
- Merge medio
- 3 d 17 min
- PR fusionados (30 d)
- 19
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de PyLops/pylops
-
Dificultad 3/5 1-2 días Aptitud para principiantes 56/100
Los mantenedores suelen responder en 2 días
-
Lipschitz methodPosiblemente ocupada @Megumi1773 la tomó hace 29 días. Abiertoenhancement good first issue
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
Los mantenedores suelen responder en 2 días
-
enhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
PyLops/pylops#786 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
Uv setup for intel environmentAbiertoCI
Dificultad 3/5 1-2 días Aptitud para principiantes 52/100
Los mantenedores suelen responder en 2 días
-
enhancement
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
Los mantenedores suelen responder en 2 días
Todos los issues de PyLops/pylops
Issues similares
-
docs size:S
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
strawberry-graphql/strawberry#4794 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
dataforgoodfr/cetolog#21 ·
-
security_citations_test fails against ecc 2026.11.6: SECURITY.md quotes ecc v2026.11.2's linesAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
btclib-org/btclib#2932 ·
Los mantenedores suelen responder en 1 día