Skip to content

Initial ARG traversal indexes for numba - #3256

Merged
jeromekelleher merged 5 commits into
tskit-dev:mainfrom
benjeffery:numba-arg
Aug 21, 2025
Merged

jeromekelleher merged 5 commits into
tskit-dev:mainfrom
benjeffery:numba-arg

Conversation

@benjeffery

Copy link
Copy Markdown
Member

I've followed the initial suggestions in #2869

I'm not sure about the part in descendant span where a node is considered to inherit from itself for the whole sequence, but as this is just an example I'm sure we can remove the TODO and leave as is?

@codecov

codecov Bot commented Aug 15, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.29630% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.73%. Comparing base (d1eb1b4) to head (7e4611d).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
python/tskit/jit/numba.py 96.29% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3256      +/-   ##
==========================================
+ Coverage   89.72%   89.73%   +0.01%     
==========================================
  Files          29       29              
  Lines       32500    32553      +53     
  Branches     5949     5961      +12     
==========================================
+ Hits        29160    29211      +51     
  Misses       1894     1894              
- Partials     1446     1448       +2     
Flag Coverage Δ
c-tests 86.71% <ø> (ø)
lwt-tests 80.38% <ø> (ø)
python-c-tests 88.24% <ø> (ø)
python-tests 98.79% <ø> (ø)
python-tests-no-jit 33.07% <96.29%> (+0.46%) ⬆️
python-tests-numpy1 50.65% <0.00%> (-0.35%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
python/tskit/jit/numba.py 97.55% <96.29%> (-0.37%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hyanwong

Copy link
Copy Markdown
Member

Is the idea to make a C version of the NumbaParentIndex later, so that C users also have an ARG interface?

@jeromekelleher

Copy link
Copy Markdown
Member

It's straightforward to do if someone wants it, but we're not planning to do it now.

@jeromekelleher

Copy link
Copy Markdown
Member

Some notes from discussion in person:

  1. Remove numba compiled classes and rename to functions return a single array (for child_index) and a named tuple (for parent_index).
  2. Two key operations to illustrate are the sub-ARGs looking down and up from a given node returned as a boolean mask on the edge table. So, functions that answer the question "is this edge an ancestor/decendant of the given node".
  3. Can we also define arg_preorder and arg_postorder which returns the edge IDs in these orders?

@benjeffery

Copy link
Copy Markdown
Member Author

@jeromekelleher I've done the refactoring to simplify the API that we discussed yesterday. I think this might be a good point to stop with the PR and do the traversal work in a subsequent PR?

@jeromekelleher jeromekelleher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, looks good. Just need to add O complexity statements to the operations so that people know what's involved. Can we add one for the tree index also, please? (Open an issue for adding this if it's not obvious)

Comment thread python/tskit/jit/numba.py Outdated

def child_index(self):
"""
Create child index array for finding child edges of nodes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a statement on the computational complexity of this task, like

This operation involves a linear pass through the edge table and therefore requires O(num_edges) time.

Comment thread python/tskit/jit/numba.py
def parent_index(self):
"""
Create a :class:`ParentIndex` for finding parent edges of nodes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a statement on complexity.

This operation involves sorting the edge data by child ID and left coordinate, and therefore requires O(E log E) time, there E is the number of edges.

@benjeffery

Copy link
Copy Markdown
Member Author

@jeromekelleher Notes on time complexity added.

I realised if we dropped the left sort from parent_index we can do it in O(E + N) time by doing a counting sort.

@jeromekelleher

Copy link
Copy Markdown
Member

I realised if we dropped the left sort from parent_index we can do it in O(E + N) time by doing a counting sort.

Huh - shall we address this in a follow up?

@jeromekelleher
jeromekelleher added this pull request to the merge queue Aug 21, 2025
Merged via the queue into tskit-dev:main with commit fdd6361 Aug 21, 2025
@benjeffery
benjeffery deleted the numba-arg branch August 21, 2025 13:53
@benjeffery benjeffery mentioned this pull request Sep 22, 2025
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.

3 participants