Skip to content

Don't load all ancestors when truncating #811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 30, 2023

Conversation

benjeffery
Copy link
Member

No description provided.

Copy link
Member

@hyanwong hyanwong left a comment

Choose a reason for hiding this comment

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

Nice, simple. LGTM. I don't know if there are other params to tsinfer.AncestorData(...) other than the sequence_length and chunk_size... arguments, but I presume not. E.g. at some point I wanted to associated a time_units value with the ancestors file, but that never got into the code base.

@codecov
Copy link

codecov bot commented Mar 21, 2023

Codecov Report

Merging #811 (62cfa3d) into main (96623e0) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #811      +/-   ##
==========================================
- Coverage   93.34%   93.34%   -0.01%     
==========================================
  Files          17       17              
  Lines        5652     5662      +10     
  Branches     1014     1016       +2     
==========================================
+ Hits         5276     5285       +9     
  Misses        247      247              
- Partials      129      130       +1     
Flag Coverage Δ
C 93.34% <100.00%> (-0.01%) ⬇️
python 96.29% <100.00%> (-0.02%) ⬇️

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

Impacted Files Coverage Δ
tsinfer/formats.py 97.52% <100.00%> (+0.01%) ⬆️

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

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 like an improvement to me 👍

@benjeffery
Copy link
Member Author

This was way too slow at around 8hours for the smallest chrom in my dataset. Have just pushed a change which I'm now testing where only changed ancestors are touched.

@benjeffery benjeffery force-pushed the iterate-truncate branch 2 times, most recently from dba0964 to 4a87fa2 Compare March 22, 2023 17:27
@benjeffery benjeffery marked this pull request as ready for review March 22, 2023 17:27
@benjeffery
Copy link
Member Author

@Mergifyio rebase

@mergify
Copy link
Contributor

mergify bot commented Mar 22, 2023

rebase

✅ Branch has been successfully rebased

@benjeffery benjeffery force-pushed the iterate-truncate branch 2 times, most recently from 68e9b49 to 38fb8c9 Compare March 27, 2023 15:50
@benjeffery
Copy link
Member Author

Fixed up, should be good to merge.

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, a few suggestions. Happy to merge when addressed so pre-approving

tsinfer.generate_ancestors(sample_data, path=d + "ancestors.tsi")
ancestors = tsinfer.AncestorData.load(d + "ancestors.tsi")
time = np.sort(ancestors.ancestors_time[:])
if (
Copy link
Member

Choose a reason for hiding this comment

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

Maybe put the comment on a different line? Seems like unnecessary line breakage here

else:
params = [(0.4, 0.6, 1), (0, 1, 10)]
for param in params:
truncated_ancestors = ancestors.truncate_ancestors(
Copy link
Member

Choose a reason for hiding this comment

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

will ancestors.truncate_ancestors(*param, buffer_length=2) work here ?

for anc in self.ancestors():
truncated = self.copy(**kwargs)

# Create a buffer of 1000 ancestors with their indexes
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Create a buffer of 1000 ancestors with their indexes
# Create a buffer of buffer_length ancestors with their indexes

truncated.ancestors_full_haplotype[:] = haplotypes
truncated.ancestors_full_haplotype_mask[:] = haplotypes == tskit.MISSING_DATA
buffer_pos += 1
if buffer_pos == buffer_length:
Copy link
Member

Choose a reason for hiding this comment

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

A local function would help here,

def flush_buffer(length):
       truncated.ancestors_start.set_orthogonal_selection(
              index_buffer[:length], start_buffer[:length]
         )
        # etc

Copy link
Member

Choose a reason for hiding this comment

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

I don't follow how this is working, so a few comments on how flush_buffer works and would be helpful here.

@benjeffery
Copy link
Member Author

Fixed up, merging.

@mergify mergify bot merged commit 18b51ae into tskit-dev:main Mar 30, 2023
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