feat(neighbors): support global mode-2 sparse batches - #112
Conversation
Add validated canonical global indexing for padded sparse neighbor batches across calculation, periodic, and derivative paths. Signed-off-by: Roman Zubatyuk <rzubatiuk@nvidia.com>
|
Reviewed the full diff with empirical verification on an L40S (torch 2.9.1+cu128). The design direction is right — validation-first, clean kernel generalization, good CUDA-subprocess assert testing, and the CUDA compiled mode-2 forward is clean (0 graph breaks, eager parity ~1e-5). Legacy B>1 local-index inputs are rejected loudly on every entry path; no silent-wrong path through the calculator. But one measured physics bug and several majors need fixing before merge. Blocker — Ewald/PME energies depend on the padding width. Major — shared Major — ConvSV einsum fallback can leak features across systems. The masked gather index is 0 — system 0's first real atom in the flattened layout — so the CPU/float64 branch is only correct because Major — non-finite dummy coordinates poison Ewald (NaN energy; PME/DSF unaffected). Mode 2 keeps every dummy row in the backend call, unlike mode 1 which strips them. Major — Major — validation is triplicated and measurably expensive. The identical 6-line gate is copy-pasted in Major — the parity tests cannot see the blocker. Every periodic parity test compares mode-2 against mode-2 (B=2 vs B=1); the only genuine cross-mode check is non-periodic DSF, which is immune because its parameters are explicit. Please add: mode-1 vs mode-2 Ewald/PME energy/force parity (would have caught the blocker immediately), a padding-width-invariance test (same system, N_real+1 vs N_real+8 padding), a CPU mixed-size periodic case, and a compiled mode-2 forward test asserting zero graph breaks plus eager parity. Major — breaking-change bookkeeping. The semver-breaking input contract gets a single CHANGELOG line under Also: the branch now conflicts with main ( Suggested order: fix the Ewald/PME parameter estimation first (with the parity + padding-invariance tests pinning it), then the cell expand and the compile-safe check; consolidate validation while touching those lines; rebase; relabel the changelog. |
AIMNetCentral Pull Request
Description
This change adds canonical global-indexed mode-2 sparse neighbor matrices for batches containing molecules of different sizes. It lets callers supply padded batched neighbor lists while preserving correct short-range, long-range, periodic, derivative, and Hessian-vector-product behavior.
Mode-2 inputs are now validated before computation, including padded-center sentinels, per-system ownership, shift alignment, and neighbor-matrix suffix layout. This prevents invalid global indices from reaching CUDA kernels or periodic backends, where failures otherwise can be difficult to diagnose.
Type of Change
Changes Made
convert_mode2_local_to_globalfor callers migrating legacy local-index 3D matrices to the canonical global representation.Compatibility
aimnet.nbops.convert_mode2_local_to_globalbefore use.Testing
Checklist