feat: fuse annotated+spliced haplotype reconstruction (Phase 5 W3)#258
Merged
Conversation
…sized plan) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…FFI crossing (Phase 5 W3) Add reconstruct_annotated_haplotypes_spliced_fused — the annotated counterpart of reconstruct_haplotypes_spliced_fused. Folds RC in-kernel (bytes RC'd, annotation rows reversed) so the Python _FlatAnnotatedHaps.reverse_masked post-pass is dropped on the rust backend. Byte-identical to the composed numba oracle (new parity backstop). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…combos now single-FFI (Phase 5 W3) Also applies ruff formatting to _haps.py (post-Task-1 residual). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 5 W3 — fuse the deferred annotated+spliced reconstruction path
Closes the last un-fused FFI seam in haplotype reconstruction. Three of the four annotated×spliced combinations were already single-FFI-crossing fused kernels; the fourth — annotated AND spliced — was deferred to Phase 5. On the rust backend it ran the un-fused dispatched core plus a Python RC post-pass (
_FlatAnnotatedHaps.reverse_masked).What changed
reconstruct_annotated_haplotypes_spliced_fused(src/ffi/mod.rs) — a faithful merge of the two existing parity-proven kernels: the spliced scaffolding (reconstruct_haplotypes_spliced_fused: precomputedout_offsets, permuted ploidy-1 inputs, noget_diffs_sparse) + the annotation buffers and RC triple (reconstruct_annotated_haplotypes_fused). Registered insrc/lib.rs, imported in_haps.py._dataset/_haps.py): the splice branch of_reconstruct_annotated_haplotypesnow calls the fused kernel on the rust backend (RC folded in-kernel) and drops the Pythonreverse_maskedpost-pass; the numba branch is retained unchanged as the oracle.RC invariant (the parity-critical detail)
For the spliced path RC is per permuted element. Rust folds RC in-kernel:
rc_flat_rows_inplaceon the sequence bytes (reverse+complement) andreverse_flat_rows_inplaceon both annotation arrays (reverse only, no complement) — byte-identical to_FlatAnnotatedHaps.reverse_masked(mask, _COMP). Numba RCs externally in_query.py::_getitem_spliced(numba-only guard);_query.pyis untouched. No double-RC, no missed-RC.Parity gate
New
tests/parity/test_annotated_spliced_haplotypes_parity.py: spy proves the fused entry fires on rust only; all three arrays (haps,var_idxs,ref_coords) + offsets compared byte-identically to the composed numba oracle; a negative-strand transcript with anrc_negTrue-vs-False difference check exercises the in-kernel RC path. Full parity suite green on both backends (78p/1s each); dataset+unit 632p; ruff/format/typecheck/clippy clean; 17 cargo reconstruct tests pass.numba remains the oracle (deletion is W5/W6). Phase 5 stays 🚧 (W4–W9 remain).
Plan:
docs/superpowers/plans/2026-06-26-rust-migration-phase-5-w3.md🤖 Generated with Claude Code