Repository navigation
fix(search): make the out-of-core candidate backing retrieve the same set as in-RAM (#65) - #66
Conversation
… RAM (#65) `--candidate-index mmap` and `ram` returned different PIN row sets (77,526 vs 77,097 on the E. coli fixture) despite being documented and tested as copy-for-copy identical. Two independent defects, both in the out-of-core path only; the RAM path is unchanged. 1. `base_record_multiplicity` subtracted EVERY mod delta to recover the base-peptide mass, including FIXED mods. The on-disk index is built by `base_peptide_records`, which zeroes only `max_variable_mods_per_peptide` and keeps fixed mods folded into residue mass. So for any peptide bearing a fixed mod the lookup mass was off by the fixed total (57.02 Da for a single Cys), the mass window matched no record, and the multiplicity collapsed to the `max(1)` floor -- dropping every duplicate copy the RAM enumeration keeps. Only variable deltas are removed now. 2. The replicated copies were pushed back to back and ordered by `(protein_index, start_offset)`. RAM's global order inside a protein is `[whole seq_offset=0 walk] ++ [whole seq_offset=1 Met-cleaved walk]`, so the copies are separated by the rest of the protein's spans. The interleaving left the multiset right but the ORDER wrong, which moved the order-dependent per-spectrum float accumulator behind the PIN `RawScoreCal` column. Copies are now tagged with their pass index and sorted `(protein, pass, start_offset, length)`; a span at offset 1 carrying `is_protein_n_term` is pass 1 by construction (the flag is set iff the span starts at `seq_offset`). Base records are also sorted with `length` in the key so equal-start spans keep the enumeration's end-ascending order. Verified byte-identical (`cmp` exit 0) for default mods, `NumMods=0` fixed-only, and one variable mod. New `#[ignore]`d gate `crates/andes/tests/mmap_ram_pin_equivalence.rs` drives the real fixtures and fails on the unfixed code for all three configurations.
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe change aligns mmap candidate ordering and multiplicity lookup with RAM behavior. It adds ignored integration tests that compare generated PIN files across RAM and mmap searches using real E. coli fixtures and multiple modification configurations. ChangesMmap/RAM candidate equivalence
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This change makes mmap candidate generation match in-memory results for ordering and fixed-modification multiplicity. The documented regression coverage supports expected equivalent search output, with no remaining merge-blocking risk identified. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…r spectrum
The out-of-core candidate path was 3-15x slower than in-RAM, and the whole gap sat
inside the search loop: on the ecoli fixture `[PHASE stream_search]` was 30.9s
out-of-core against 8.0s in-RAM, with index load negligible.
The in-RAM path enumerates candidates ONCE for the run and each spectrum reads a
bucket range. The out-of-core path re-did the base-record fetch, mod expansion,
multiplicity replication, decoy relabel and sort for EVERY (spectrum, charge) unit.
Measured on that fixture: 49,066 search units cover only 1,657 distinct nominal
windows, a 29.6x mean reuse, and every unit shares its window with another. So ~97%
of that work was repeated.
Each chunk now collects the distinct windows of its units, expands each exactly once
(in parallel), and the scoring loop reads the prepared slice. The hot path takes no
lock and memory is bounded to one chunk's distinct windows, with a cap beyond which
expansion falls back to the direct path.
The window key is the nominal bounds only: the calibration shift is
`params.precursor_mass_shift_ppm`, a run-level constant, so it cannot vary between
units of a chunk and does not belong in the key.
stream_search, 3 runs each, same host/command:
no cache 30.58 / 30.12 / 32.03 s mean 30.9
cached 13.82 / 16.63 / 18.31 s mean 16.3 -> ~1.9x, ranges disjoint
in-RAM reference 8.0
Pure caching: the out-of-core PIN stays byte-identical to the in-RAM PIN in all three
modification configurations (default 77,097 rows; fixed-only 75,739; one variable mod
77,129), which is the equivalence PR #66 established.
…r spectrum (#67) The out-of-core candidate path was 3-15x slower than in-RAM, and the whole gap sat inside the search loop: on the ecoli fixture `[PHASE stream_search]` was 30.9s out-of-core against 8.0s in-RAM, with index load negligible. The in-RAM path enumerates candidates ONCE for the run and each spectrum reads a bucket range. The out-of-core path re-did the base-record fetch, mod expansion, multiplicity replication, decoy relabel and sort for EVERY (spectrum, charge) unit. Measured on that fixture: 49,066 search units cover only 1,657 distinct nominal windows, a 29.6x mean reuse, and every unit shares its window with another. So ~97% of that work was repeated. Each chunk now collects the distinct windows of its units, expands each exactly once (in parallel), and the scoring loop reads the prepared slice. The hot path takes no lock and memory is bounded to one chunk's distinct windows, with a cap beyond which expansion falls back to the direct path. The window key is the nominal bounds only: the calibration shift is `params.precursor_mass_shift_ppm`, a run-level constant, so it cannot vary between units of a chunk and does not belong in the key. stream_search, 3 runs each, same host/command: no cache 30.58 / 30.12 / 32.03 s mean 30.9 cached 13.82 / 16.63 / 18.31 s mean 16.3 -> ~1.9x, ranges disjoint in-RAM reference 8.0 Pure caching: the out-of-core PIN stays byte-identical to the in-RAM PIN in all three modification configurations (default 77,097 rows; fixed-only 75,739; one variable mod 77,129), which is the equivalence PR #66 established.
Fixes #65. Two independent defects, both confined to the
Mmaparm; the in-RAM path is untouched and its output is byte-identical before and after (verified on three modification configurations).Fixed modifications were subtracted from the base-mass lookup.
base_record_multiplicityrecovered a base peptide's mass by subtracting every modification delta, but the on-disk index stores masses with fixed modifications still folded in — it zeroes onlymax_variable_mods_per_peptide. So any peptide carrying Carbamidomethyl was looked up 57.021 Da too light, matched no record, andcount.max(1)silently returned 1, dropping the duplicate copies the RAM enumeration keeps. Now only non-fixed deltas are subtracted. The evidence is clean: on the instrumented divergent scan, all 18 differing rows were RAM-only and every one contained a cysteine.Copy ordering did not match the enumeration.
enumerate_proteinwalks a protein twice, at offset 0 and again at offset 1 for N-terminal-Met cleavage, so RAM's order is all pass-0 spans followed by all pass-1 spans, with copies separated. The disk path pushed copies back to back and sorted on(protein, start_offset)only, which cannot distinguish the passes. That perturbed an order-dependent per-spectrum float accumulator and changedRawScoreCal. Copies now carry their pass index and sort(protein, pass, start_offset, length).Acceptance
Before the fix these were 77,097/77,526, 75,739/76,290 and 77,129/77,425. The in-RAM column is unchanged in all three.
Regression test
crates/andes/tests/mmap_ram_pin_equivalence.rs, three tests over the real fixtures,#[ignore]d because they take ~246 s in release:They were checked to be non-vacuous by re-running against the unfixed code, where all three fail. The four pre-existing equivalence tests pass while the bug is live, which is why a fixture-scale test was needed.
Not addressed here, and still open:
--candidate-index mmapis silently downgraded to in-RAM when precursor-calibration reuse is active, which is why the reproduction needs--precursor-cal off. The new test documents that so the gate cannot pass vacuously.Summary by CodeRabbit
Bug Fixes
Tests