Repository navigation
Table subset - #2700
Table subset#2700
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2700 +/- ##
==========================================
+ Coverage 94.00% 94.05% +0.05%
==========================================
Files 29 29
Lines 28080 28409 +329
Branches 1585 1586 +1
==========================================
+ Hits 26396 26720 +324
- Misses 1648 1653 +5
Partials 36 36
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
628c157 to
6afacc6
Compare
|
This is ready for a review now @benjeffery - I went with Ping @petrelharp and @bhaller also, since this is a basic utility needed for breaking up the simplify operation into smaller bits for parallelisation |
|
Dammit, went copy-paste mad too soon, and didn't test it properly. Back to draft! |
|
I think the core of this is more-or-less in place now, and it would be good to get some feedback. The main thing that might raise some controversy is the semantics around mutation parent ID remapping (look at mutation_table_keep_rows). Basically, we want to make it easy to get rid of mutations, which is currently a major faff because of the parents column. This does involve making sure that reference integrity is maintained, though, and the approach I've taken is to do some basic checks and to error-out if someone tries to do something that doesn't appear to make sense. We could easily add some options to change this behaviour, but I think this is a good default. If we agree I'll write up the details in the documentation, and apply the same logic to the individual table (which is the only other place we have self-referential tables. @molpopgen - this is also adjacent to the "more modular simplify" work you're interested in, so good to see what you think of the proposed API also. |
|
If I'm following along correctly: after simplifying "chunks", the client aggregates a list of nodes to delete, and can get back a new node "global" node mapping for the start of the next recording epoch? |
Yeah, that's one of the things that's made easier - you can efficiently repack the node table at the end of a simplification epoch to get rid of unused nodes. Also, I'm planning to use this internally within the simplifier to make updating the site, mutation and individual tables easier. We should be able to get to a point where we don't copy any of the tables during simplification (although will need to think about how to handle the input edges - but that's close to what you're thinking about too). |
89a9f7c to
8ee4ff6
Compare
|
Sounds good. I'll try to take a closer look at this early this week. My "modular simplification" idea has the nice property of not interacting with the input edge table. Hopefully that'll mean things "just work" in the face of any refactoring. |
benjeffery
left a comment
There was a problem hiding this comment.
Very nice, seems all the hairy details are under control.
One extra test that might be worth doing is adding rows to the table after this operation - seeing that it resizes by changing num_rows and the old memory getting reused. As it looks this should be all fine, as max_rows keeps track of that, but maybe worth testing? Fine if not, but it's the only extra thing I could think of!
|
Good call @benjeffery - I'll add some tests for adding more rows |
f9ef394 to
4db41e5
Compare
b037635 to
a5aabc6
Compare
|
OK, I think this is ready for final review now. Jeez that was a lot of code for a simple operation, but I'm hoping this (and a few similar ops like #2707) will help us trim down the code as well as making things more efficient over time. |
|
Great -- I was feeling guilty for not looking yet. We have a holiday weekend coming up, but I'll definitely look next week. |
molpopgen
left a comment
There was a problem hiding this comment.
This LGTM. There's one technical issue that can only be handled via documentation.
| @return Return 0 on success or a negative value on failure. | ||
| */ | ||
| int tsk_node_table_keep_rows( | ||
| tsk_node_table_t *self, const bool *keep, tsk_flags_t options, tsk_id_t *id_map); |
There was a problem hiding this comment.
Overall, the API makes sense. There's one technical issue that should be documented:
- When interacting with C functions, C++ code will tend to store things in a vector and obtain the pointer via the data member function. For example,
x.data()yields a pointer to the first element, which is then passed to a C API. - C++
vector<bool>totally breaks all of what I just said. Due to a grave lapse of judgement, whether bool is stored or individual elements are bit fields is implementation defined.
There's nothing we can do except to note that "the pointer from a c++ vector<bool> is not the right thing to pass in here".
EDIT: fix formatting in the last sentence.
There was a problem hiding this comment.
Or tell people to use std::vector<uint8_t> instead of std::vector<bool>, right? As I understand it, that avoids the problem.
There was a problem hiding this comment.
Yes, so long as uint8_t and bool have the same sizeof everywhere. That's true for all platforms that I expect to encounter, but I'd still use a static_assert to check it at compile time.
There was a problem hiding this comment.
Yet another reason why I'm drifting away from C++. From cppreference:
bool - type, capable of holding one of the two values: [true](https://en.cppreference.com/w/cpp/language/bool_literal) or [false](https://en.cppreference.com/w/cpp/language/bool_literal). The value of sizeof(bool) is implementation defined and might differ from 1.
And the first passes but the second fails:
#include <cstdint>
#include <type_traits>
int
main(int, char**)
{
static_assert(sizeof(std::uint8_t) == sizeof(bool), "sizeof failure");
static_assert(std::is_same<std::uint8_t, bool>::value,
"uint8_t and bool aren't the same");
}
I think we have to say "be careful here" when using C++. Too much is platform-dependent.
There was a problem hiding this comment.
Technically, true that they could be different – but as you said, on all platforms that we expect to encounter, they are in fact the same. A matter of taste how much one wants to worry about that, I guess. :->
|
That's a really good point @molpopgen that I struggled a bit with at the Python C API level as well - the C99 bool type is frustratingly vague and I think it could end up being a problem in the future. How about we follow numpy and do this: typedef uint8_t tsk_bool_t;and then change the signature of these functions to use That should make things a bit easier to do portably? For C++ we put in documentation warning saying "make sure you use |
That's what I do in SLiM/Eidos:
|
Yes, this is the way to go. |
|
OK, great, I'll make that change. |
|
OK, I think this is ready to go now! |
|
LGTM. (This codecov thing is annoying!) |
|
@Mergifyio rebase |
✅ Branch has been successfully rebased |
acd4382 to
6c8c779
Compare
|
I'm going to merge this manually, as the only thing that's failing is one codecov upload, which has occurred successfully on other builds. |
A start on #2666
The nice thing about the boolean mask is that it does let us do the subsetting efficiently in-place (because the output order is fixed) so I think we should probably do this more efficiently, avoiding the intermediate copy. I'll tip along at this as I get a chance.