Skip to content

Fix bugs, add tests, and improve performance#127

Closed
pierpal wants to merge 9 commits into
mainfrom
optimize
Closed

Fix bugs, add tests, and improve performance#127
pierpal wants to merge 9 commits into
mainfrom
optimize

Conversation

@pierpal
Copy link
Copy Markdown
Contributor

@pierpal pierpal commented Mar 16, 2026

Bug fixes:

  • Fix incorrect error message in ThreadsLowMem constructor
  • Replace 20x exit(1) with throw for proper exception handling
  • Fix memory leak: raw HMM* → unique_ptr
  • Fix sign-extension in pair_key (int → uint32_t cast)
  • Fix sign bug in rho computation (visible at scale)

Performance:

  • Replace unordered_map traceback storage with std::deque arena
  • Replace std::set neighbor search with boolean array scan in Matcher
  • Add periodic pruning every 500 sites (bounds memory, improves cache)
  • Replace hash maps with flat vectors in ThreadsLowMem/ViterbiState
  • Add NumPy batch API for Matcher, Viterbi, and hets phases
  • Use const int* in process_site to avoid bounds-check overhead
  • Improve move semantics and reference passing

Testing:

  • Add 69 C++ unit tests (444 assertions) via Catch2

Bug fixes:
- Fix incorrect error message in ThreadsLowMem constructor
- Replace 20x exit(1) with throw for proper exception handling
- Fix memory leak: raw HMM* → unique_ptr
- Fix sign-extension in pair_key (int → uint32_t cast)
- Fix sign bug in rho computation (visible at scale)

Performance:
- Replace unordered_map traceback storage with std::deque arena
- Replace std::set neighbor search with boolean array scan in Matcher
- Add periodic pruning every 500 sites (bounds memory, improves cache)
- Replace hash maps with flat vectors in ThreadsLowMem/ViterbiState
- Add NumPy batch API for Matcher, Viterbi, and hets phases
- Use const int* in process_site to avoid bounds-check overhead
- Improve move semantics and reference passing

Testing:
- Add 69 C++ unit tests (444 assertions) via Catch2
pierpal added 8 commits March 17, 2026 17:26
  C++ bug fixes:
  - AlleleAges.cpp: fix infinite loops from self-ref in carrier chain
    and trace path, add target<0 guard for out-of-bounds crash
  - DataConsistency.cpp: fix infinite loop in carrier traversal, fix
    silent mismatch skipping from self-ref targets (replaced with sample 0)

  Optimizations:
  - Vectorized emission probabilities in fwbw.py
  - Optimized sparse posterior construction and VCF writing in impute.py

  Tests:
  - 152 new unit/property/integration tests covering infer, convert, map,
    impute, vcf, normalization, and allele ages
  - Benchmarks for imputation scaling and compression

  Cleanup:
  - Removed dead phase.py (broken imports, no CLI registration)
  - allele_ages: remove unnecessary np.array() conversion in per-site loop,
    replace multiprocessing.Manager().dict() with pool.imap() return values
  - map: lazy-import ray (~1s startup saving when single-threaded),
    remove per-variant time.time() instrumentation from hot loop
  - convert: lazy-import tszip (~0.7s saving when writing .argn only),
    skip guaranteed-fail noise=0.0 retry, narrow bare except to RuntimeError
  - Add bulk C++ functions for estimate_ages and run_consistency,
    eliminating per-site Python/C++ round-trips
  - Replace click with argparse (saves ~224ms import time)
  - Replace h5py with C++ HDF5 reader/writer (saves ~235ms import time)
  - Move h5py from core to dev dependency
  - Port forward/backward LS algorithm from numba to C++
  - Add VariantMetadata lightweight class replacing pandas DataFrame
@ArniFreyrG ArniFreyrG mentioned this pull request Mar 25, 2026
@pierpal pierpal closed this May 26, 2026
@pierpal pierpal deleted the optimize branch May 26, 2026 14:07
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