Skip to content

Conversation

@benjeffery
Copy link
Member

@benjeffery benjeffery commented Sep 22, 2025

Fixes #2631

@codecov
Copy link

codecov bot commented Sep 22, 2025

Codecov Report

❌ Patch coverage is 95.16129% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.81%. Comparing base (3f92a90) to head (f210492).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
python/_tskitmodule.c 90.90% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3277   +/-   ##
=======================================
  Coverage   89.80%   89.81%           
=======================================
  Files          29       29           
  Lines       32612    32665   +53     
  Branches     5974     5982    +8     
=======================================
+ Hits        29288    29338   +50     
- Misses       1884     1886    +2     
- Partials     1440     1441    +1     
Flag Coverage Δ
c-tests 86.86% <100.00%> (+0.01%) ⬆️
lwt-tests 80.38% <ø> (ø)
python-c-tests 88.26% <90.90%> (+<0.01%) ⬆️
python-tests 98.77% <66.66%> (-0.03%) ⬇️
python-tests-no-jit 33.04% <81.81%> (+0.09%) ⬆️
python-tests-numpy1 50.57% <36.36%> (+0.01%) ⬆️

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

Files with missing lines Coverage Δ
c/tskit/trees.c 91.04% <100.00%> (+0.02%) ⬆️
python/tskit/jit/numba.py 97.90% <100.00%> (+0.02%) ⬆️
python/tskit/trees.py 98.84% <100.00%> (+<0.01%) ⬆️
python/_tskitmodule.c 88.26% <90.90%> (+<0.01%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@benjeffery benjeffery force-pushed the mutation-inherited-state branch 2 times, most recently from 617903d to e594e8e Compare September 22, 2025 13:51
Copy link
Member

@jeromekelleher jeromekelleher left a comment

Choose a reason for hiding this comment

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

Slightly concerned about tacking in a ref to the tree sequence to a dataclass here. These lightweight objects might want to be pickled for parallel processing, e.g.. Perhaps better to just compute and store the value at instantiation time?

time=time,
edge=edge,
metadata_decoder=self.table_metadata_schemas.mutation.decode_row,
tree_sequence=self,
Copy link
Member

Choose a reason for hiding this comment

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

Hmm - what does this mean for serialisation?

Copy link
Member Author

Choose a reason for hiding this comment

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

I copied the pattern from Individual, which we've been using since 8a8e61e in 2022. These can still be pickled as the reference is followed, and the TS pickled too. If you are pickling a collection of these, pickle is smart enough to only store the ts once.

Copy link
Member

Choose a reason for hiding this comment

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

I would find it surprising that the whole ts gets pickled if I just wanted to pass a simple mutation though. It it that bad if we just store an extra attribute on the object?

I'm not sure the individual thing was such a good idea looking back - we don't have to fix it now, but I don't want to reinforce a questionable decision there

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I get what you're saying. Let me think about the options and I'll make a proposal here.

@benjeffery benjeffery force-pushed the mutation-inherited-state branch from e594e8e to d9fec2c Compare September 22, 2025 15:26
@benjeffery
Copy link
Member Author

@jeromekelleher Hows this? We pre-compute, delaying any errors from that to when the property is actually accessed. I need to add a couple more tests for coverage but I'm pretty happy with this.

@benjeffery benjeffery force-pushed the mutation-inherited-state branch from d9fec2c to e3f2068 Compare September 22, 2025 15:28
@jeromekelleher
Copy link
Member

Ack, it all gets very messy! Maybe it's easier just do this right, starting at the bottom like this? #3279

Let's back out of the changes to Individual, it's not worth getting into

@benjeffery benjeffery force-pushed the mutation-inherited-state branch 2 times, most recently from 2830801 to b335fe7 Compare September 23, 2025 09:38
@benjeffery
Copy link
Member Author

@jeromekelleher I've pushed it down to the C API.

Now that it is pre-computed in C, we might as well pass the array versionup too?

Copy link
Member

@jeromekelleher jeromekelleher left a comment

Choose a reason for hiding this comment

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

Looks great! Let's update the C API changelog as we're here so we don't forget

c/tskit/trees.c Outdated
- sites_ancestral_state_offset[site_id];
} else {
/* Has parent: inherited state is parent's derived state */
tsk_id_t parent_id = mutation_parent[mutation_id];
Copy link
Member

Choose a reason for hiding this comment

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

Push variable declaration to the top of the function for consistency

@jeromekelleher
Copy link
Member

Now that it is pre-computed in C, we might as well pass the array versionup too?

If you like - I doubt it makes any difference though as we'll essentially be doing the same thing (it's still making a copy of the data for the numpy C string dtype).

@benjeffery benjeffery force-pushed the mutation-inherited-state branch from 24abce7 to e4e7bff Compare September 23, 2025 12:41
@benjeffery
Copy link
Member Author

@jeromekelleher I've moved the array down to CPython, and I've also added it to the JIT class.

@jeromekelleher
Copy link
Member

Out of curiosity, could you do a timing test on the numpy vs C Python way of computing this array?

@benjeffery
Copy link
Member Author

benjeffery commented Sep 23, 2025

Out of curiosity, could you do a timing test on the numpy vs C Python way of computing this array?

For chr21 of the Quebequios:
CPython ~0.26s
Numpy ~1.7s

Copy link
Member

@jeromekelleher jeromekelleher left a comment

Choose a reason for hiding this comment

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

LGTM! Very nice

@benjeffery benjeffery force-pushed the mutation-inherited-state branch from e4e7bff to dec1fa3 Compare September 24, 2025 08:57
@benjeffery benjeffery force-pushed the mutation-inherited-state branch from dec1fa3 to f210492 Compare September 24, 2025 08:59
@benjeffery benjeffery added this pull request to the merge queue Sep 24, 2025
Merged via the queue into tskit-dev:main with commit fac2400 Sep 24, 2025
18 checks passed
@benjeffery benjeffery deleted the mutation-inherited-state branch September 24, 2025 10:25
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.

Mutation's "inherited" state

2 participants