Skip to content

feat(corrfunc): leaf-only KD-tree backend (exact pair coverage)#38

Merged
TobiBu merged 7 commits into
paper/differentiable-applicationsfrom
feat/corrfunc-kdtree
Jul 16, 2026
Merged

feat(corrfunc): leaf-only KD-tree backend (exact pair coverage)#38
TobiBu merged 7 commits into
paper/differentiable-applicationsfrom
feat/corrfunc-kdtree

Conversation

@TobiBu

@TobiBu TobiBu commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Summary

Enables the kdtree backend for the corrfunc pair-counting estimator, targeting paper/differentiable-applications (where the corrfunc application lives).

Because the paper branch does not yet contain the leaf-only KD-tree work, this branch stacks that change onto paper (cherry-pick of the distributed/leaf-kd commit) and then adds the corrfunc-specific enablement:

  • applications/corrfunc/estimator.py: build_pair_topology no longer rejects backend="kdtree". The leaf-only bucket KD-tree stores every point in a leaf, so the near-list tiles all pairs — the heap KD-tree could not (its internal-node pivots were absent from the near-list).
  • tests/applications/test_corrfunc_vs_baseline.py: parametrize the vs-baseline tests over kdtree, and replace the rejection test with a near-field-exact check.

Validation

corrfunc vs brute-force baseline: 8 passed — including kdtree near-field exact vs brute force (rel < 1e-10 at theta=0) and the far-field-error-shrinks-with-theta test.

Relationship to the core change

The leaf-only KD-tree + distributed backend selector is proposed standalone against main in the companion PR #37. This PR carries the same change (re-applied onto the paper line, which lacks it) plus the corrfunc enablement, so the paper branch can use backend="kdtree" directly.

🤖 Generated with Claude Code

TobiBu and others added 7 commits July 16, 2026 14:01
…traversal

Multi-GPU tree build and cross-walk now support all three backends.

Distributed backend selector (radix + octree):
- local_tree: DISTRIBUTED_TREE_TYPES + _validate_distributed_tree_type +
  shard_map-safe _build_local_tree dispatch; distributed_tree_moments /
  build_local_moments gain tree_type (root via argmin(parent)).
- let: tree_type threaded to the local build in build_distributed_coarse_tree /
  classify_against_remote / distributed_let_import. Coarse tree stays radix
  (internal remote-COM representation; robust at coarse leaf_size=1).

Leaf-only (bucket) median-split KD-tree (build_leaf_kdtree, LeafKDTree):
- All points in leaves; internal nodes are pure split planes; compact
  contiguous node_ranges tiling [0,N) + nodes_by_level -> satisfies the same
  topology contract as radix/octree, giving complete pair coverage. The heap
  KD-tree (build_kdtree) used by the KNN kernels is untouched; the generic
  pipeline / tree_type="kdtree" / distributed now use the leaf-only build.

Validated: 46 kd unit tests (heap KNN preserved + leaf-kd interactions parity
vs radix); distributed CPU 9 passed incl. kd cross-walk complete disjoint
source partition (the invariant the heap KD-tree violated). GPU validation in
progress.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
(cherry picked from commit 3b1138f)
build_pair_topology no longer rejects backend="kdtree": the leaf-only bucket
KD-tree (yggdrax.kdtree.build_leaf_kdtree, via tree_type="kdtree") stores every
point in a leaf, so the near-list tiles all pairs. Parametrize the vs-baseline
tests over kdtree and replace the rejection test with a near-field-exact check
(kdtree soft counts == brute force to <1e-10 at theta=0).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…pydoclint)

Same pydoclint fix as on feat/distributed-tree-backends; pre-commit.ci already
auto-fixed black.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…dep)

The core type gate installs `.[dev]`, not `.[paper]`, so basedpyright cannot
resolve optax in applications/corrfunc/inference_demo.py (a paper illustration).
Exclude just that demo file; estimator/baselines/binning and svgd stay
type-checked. No test imports optax, so pytest is unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…d/tested

The differentiable-applications code (yggdrax/applications/corrfunc/inference_demo.py)
and the corrfunc bench smoke tests import optax, which lives in the `paper`
optional-deps extra. The CI job installed only `.[dev]`, so basedpyright could not
resolve optax and `test_corrfunc_bench_smoke[recovery]` failed (its subprocess
imports inference_demo -> optax). Install `.[dev,paper]` instead; this fixes both
and lets basedpyright type-check inference_demo again (so the earlier targeted
exclude is reverted). Verified locally: basedpyright 0 errors; tests/bench corrfunc
(4) + differentiability (3) smoke tests pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@TobiBu
TobiBu merged commit 6bd3805 into paper/differentiable-applications Jul 16, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant