Skip to content

Create Python IbdSegmentList and IbdSegment - #1707

Merged
mergify[bot] merged 4 commits into
tskit-dev:mainfrom
jeromekelleher:ibd_segment_list
Sep 22, 2021
Merged

mergify[bot] merged 4 commits into
tskit-dev:mainfrom
jeromekelleher:ibd_segment_list

Conversation

@jeromekelleher

@jeromekelleher jeromekelleher commented Sep 16, 2021 •

Copy link
Copy Markdown
Member

This updates the types that we return from the IBD calculations to make them more flexible and renames find_ibd to ibd_segments

@codecov

codecov Bot commented Sep 16, 2021 •

Copy link
Copy Markdown

Codecov Report

Merging #1707 (d6dd3fa) into main (c830df1) will increase coverage by 0.00%.
The diff coverage is 98.18%.

❗ Current head d6dd3fa differs from pull request most recent head f808ebf. Consider uploading reports for the commit f808ebf to get more accurate results
Impacted file tree graph

@@           Coverage Diff            @@
##             main    #1707    +/-   ##
========================================
  Coverage   93.36%   93.37%            
========================================
  Files          27       27            
  Lines       24251    24363   +112     
  Branches     1093     1095     +2     
========================================
+ Hits        22643    22750   +107     
- Misses       1573     1578     +5     
  Partials       35       35            
Flag Coverage Δ
c-tests 92.10% <100.00%> (-0.01%) ⬇️
lwt-tests 89.25% <ø> (ø)
python-c-tests 94.52% <97.88%> (+0.01%) ⬆️
python-tests 98.76% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
python/_tskitmodule.c 91.52% <97.31%> (+0.03%) ⬆️
c/tskit/tables.c 90.19% <100.00%> (-0.01%) ⬇️
python/tskit/tables.py 98.86% <100.00%> (+0.04%) ⬆️
python/tskit/trees.py 97.84% <100.00%> (ø)
c/tskit/core.c 97.77% <0.00%> (-0.02%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c830df1...f808ebf. Read the comment docs.

@jeromekelleher
jeromekelleher marked this pull request as ready for review September 17, 2021 11:04
@jeromekelleher

Copy link
Copy Markdown
Member Author

This diff is probably big enough that we should merge it before going ahead with further changes. I'll open a few follow up issues (mostly around documentation). This is nearly the end for the big IBD changes and I think it'll settle down pretty quickly now.

@jeromekelleher

Copy link
Copy Markdown
Member Author

Nice to get this merged fairly soon - any chance you could take a look through please @gtsambos?

result.get(0, 1)
with pytest.raises(SystemError):
result.print_state()
with pytest.raises(SystemError):

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.

Is there a reason why these new attributes are uninitialised (as opposed to 0)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is reflecting a tricky detail about how we're managing memory. The low-level IbdSegments class is a thin wrapper around the tsk_ibd_segments_t class in C. We only ever create a new IbdSegments class as a result of calling tables.find_ibd(), which ensures that the memory management is handled correctly. What this test is doing is ensuring that if someone deliberately sidesteps all this, and tries to create an IbdSegments instance manually they don't get a segfault (which they would, if we weren't carefully checking the state of things).

Basically this will never happen, it's just low-level stuff to make sure the memory management is all water tight.

with pytest.raises(SystemError, match="not initialised"):
getattr(seglist, attr)

def test_memory_management(self):

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.

I don't understand what this test is doing -- can you explain a bit?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's basically the same as the previous comment - we're checking some tricky details about how memory is managed, making sure we don't leak or segfault in odd situations. In this case, the ownership of the underlying memory is being managed by the object that we del, and we're making sure that this object doesn't actually disappear until after all the things that reference it also disappear.

Some background on reference counting in Python might clear things up a bit, if you're interested.

@gtsambos gtsambos 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.

Looks good Jerome! These new classes (esp. the IbdSegment one) look like they'll make this output a lot nicer to work with.

@jeromekelleher

Copy link
Copy Markdown
Member Author

@benjeffery, any chance you could have a quick look over this please?

@benjeffery benjeffery 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.

LGTM!
One paranoia suggestion.

I am running the stress test on this branch, looks good so far but will leave running.

Comment thread python/tests/test_lowlevel.py Resolved
Comment thread python/tskit/tables.py Resolved
@jeromekelleher

Copy link
Copy Markdown
Member Author

Great, thanks @benjeffery. Updated with nice extra paranoia - please merge whenever you're happy.

Jerome Kelleher added 4 commits September 22, 2021 09:44
Also rename ibd_result to ibd_segments

Closes tskit-dev#1708
Decouples the internal library details from the external structure.

Also minor fixups in the Python implementation
@mergify
mergify Bot merged commit f9b47ea into tskit-dev:main Sep 22, 2021
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