Skip to content

Initial sketch of read-only tables implementatation - #2057

Closed
jeromekelleher wants to merge 4 commits into
tskit-dev:mainfrom
jeromekelleher:read-only-tables
Closed

jeromekelleher wants to merge 4 commits into
tskit-dev:mainfrom
jeromekelleher:read-only-tables

Conversation

@jeromekelleher

Copy link
Copy Markdown
Member

Initial proof of concept for making the TableCollection returned by ts.tables read-only. I've only done the plumbing for the NodeTable here, but the extension is pretty clear. The implementation is pretty confusing at the moment, I think it could be simplified quite a bit.

I also had a look at what we could do in terms of returning direct read-only views of the column data. I think we could do this when the tables are in read-only model, so that ts.tables.nodes.time is an efficient operation. It doesn't look too bad, actually.

While we're breaking stuff, we should also set all column arrays that we return to being read-only, even when they are copies returned when the tables aren't in read-only mode. This will hopefully let us support the (much more difficult) direct setting of table column memory from numpy arrays, at some point.

Any thoughts?

@benjeffery

Copy link
Copy Markdown
Member

I'm trying to wrap my head round this. So when tables get made from a tree sequence the tables are marked as read only by having a reference to the ts, makes sense.

What about the other way around when TableCollection.tree_sequence is called? Do we keep that as a copy operation?

@jeromekelleher

Copy link
Copy Markdown
Member Author

What about the other way around when TableCollection.tree_sequence is called? Do we keep that as a copy operation?

For the first pass I think yes. The main thing we're trying to streamline here is:

ts = tskit.load("bigfile.trees")
# analyse ts in lots of ways including using ts.tables.nodes.time and other column references

The creating-a-tree sequence-from-tables operation is much more niche I think.

I guess we could mark the input TableCollection as read-only when we call .tree_sequence() on it, though.

@benjeffery

Copy link
Copy Markdown
Member

Great, was thinking that would be the first workflow to optimise, and doing just that one first makes sense.

I guess we could mark the input TableCollection as read-only when we call .tree_sequence() on it, though.

Pretty sure this would break a lot of things and is an unexpected side-effect to make the TC read-only, we'd likely need to make copy be the default and add an argument, or have a separate method?

@jeromekelleher

Copy link
Copy Markdown
Member Author

We should make sure this change fixes #2080 while we're in here doing this type of stuff.

@jeromekelleher
jeromekelleher force-pushed the read-only-tables branch 2 times, most recently from 3fbc92f to 2a7ad57 Compare July 25, 2022 17:00
@jeromekelleher

Copy link
Copy Markdown
Member Author

Revisiting this in the light of #2441 and recent updates (and rebasing on them), and it looks like it basically works so we should probably try and push it through. I'll tip away at it as I have time.

This is a significant breaking change so we'd need a major version number bump for it.

@codecov

codecov Bot commented Jul 25, 2022 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 73.13433% with 18 lines in your changes missing coverage. Please review.

Project coverage is 91.88%. Comparing base (4c4ca2c) to head (c41dca7).
Report is 248 commits behind head on main.

Files with missing lines Patch % Lines
python/_tskitmodule.c 72.72% 18 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2057      +/-   ##
==========================================
- Coverage   93.44%   91.88%   -1.56%     
==========================================
  Files          28       28              
  Lines       27380    27071     -309     
  Branches     1253     1253              
==========================================
- Hits        25584    24875     -709     
- Misses       1762     2162     +400     
  Partials       34       34              
Flag Coverage Δ
c-tests 92.26% <ø> (ø)
lwt-tests 89.05% <ø> (ø)
python-c-tests 67.74% <73.13%> (-3.46%) ⬇️
python-tests 98.95% <100.00%> (ø)

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

Files with missing lines Coverage Δ
python/tskit/trees.py 98.72% <100.00%> (ø)
python/_tskitmodule.c 84.46% <72.72%> (-6.55%) ⬇️

... and 1 file with indirect coverage changes

@jeromekelleher
jeromekelleher force-pushed the read-only-tables branch 2 times, most recently from fdfffca to 251f559 Compare July 31, 2022 09:02
Jerome Kelleher added 4 commits August 2, 2022 20:13
The "locked" attribute on table classes was unused, so we replace it
with the new "state" variable that captures table states.
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.

2 participants