Skip to content

Refactor LineageTree to SciPy CSR sparse array representation and array-level simulation (#1000) - #1002

Merged
aarmey merged 9 commits into
masterfrom
CSR
Aug 20, 2026
Merged

Refactor LineageTree to SciPy CSR sparse array representation and array-level simulation (#1000)#1002
aarmey merged 9 commits into
masterfrom
CSR

Conversation

@aarmey

@aarmey aarmey commented Aug 20, 2026

Copy link
Copy Markdown
Member

Resolves #1000

Overview

This PR refactors the core tree representation and algorithm recursions in tHMM:

  1. SciPy CSR Sparse Array Lineage Representation:

    • Replaced node-based pointer trees with a scipy.sparse.csr_array adjacency representation (lineage.tree) storing directed parent $\to$ daughter edges.
    • Vectorized parent-daughter edge indexing using CSR indptr and indices.
    • Vectorized transition likelihood scoring (log_T_score) in tHMM.py using flat edge tensors, yielding a ~60x speedup.
    • Vectorized M-step transition probability estimation in lineage/HMM/M_step.py via np.einsum.
  2. Array-Based Tree Simulation & Censoring:

    • Replaced CellVar heap object instantiations in LineageTree.rand_init with pure array generation (tree, obs, states).
    • Implemented vectorized temporal and fate censoring (censor_lineage_gamma and censor_lineage_gaphs) operating directly on CSR arrays and observation matrices.
    • Purged dead legacy CellVar helper functions (apply_censoring, basic_censor, assign_times, fate_censor, time_censor).
  3. Documentation & Validation:

    • Updated docs/tHMM-getting-started.rst to document the array and CSR sparse data model.
    • All 43 test suites passing cleanly with full typing (ty check) and linting (ruff check) validation.

@aarmey
aarmey merged commit bc649d6 into master Aug 20, 2026
0 of 2 checks passed
@aarmey
aarmey deleted the CSR branch August 20, 2026 14:10
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.

Replace linked-list lineage tree with CSR-style array representation

1 participant