You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
can't find the cause to CrosscheckTreeSeqIntegrity #71
Hi,
I have been doing some simulations in which I stop and restart them from a tree sequence, and save a new one. This can go on for ~6 iterations.
In some cases, I have been getting a weird error, e.g.: ERROR (SLiMSim::CrosscheckTreeSeqIntegrity): (internal error) genome/allele size mismatch at position 365: the treeseq has 1 mutation of mutid 12, SLiM has 0 segregating and 0 fixed mutation(s).
@petrelharp has looked into the tree sequences and said they seem fine. You can try and load those tree sequences to SLiM and it will throw that error.
Do you have any idea why that would be happening? I am happy to provide more info on the type of simulation,etc. @petrelharp tried to come up with a minimal example but we weren't successful.
Hi Murillo. Interesting. Can you provide the script that produces these tree sequences, too? It may be that something non-obvious is wrong with the tree sequence files themselves, or it may be that something is wrong with the way that SLiM loads them in and creates its internal state from them. It's a little bit surprising, though, since this basic idea (write out a tree sequence and then read it back in) has been massively stress-tested, so I think there must be something a bit unusual about your model that triggers the problem. Thanks.
And I need the script that you're using to read the .trees files back in; the context into which a .trees file is read matters, so I can't just try to load your .trees files into the default SLiMgui model. You can email them to me if you don't want to post them publicly here. Thanks.
... but I've just discovered that, on this computer, it produces the error only on the command line and not in the GUI. I'm currently tracking down what difference there might be between the executables.
@petrelharp built SLiM GUI from the current HEAD (3.3.1 build 2158) and it threw an error, whereas it didn't in the previous build which was a version 3.3.1 build 2125
I can't obtain a build that fails to throw the error on the command line, even building the git commit that looks to have been the one used to build the non-erroring GUI. Once in the office I'll see if rebuilding the GUI with various git commits fails to throw the error, but this lack-of-error-in-the-GUI-once is feeling like a red herring...
printfs have got me this far through _InstantiateSLiMObjectsFromTables, and everything seems on track to be loading in the mutation which the error says in not in fact there in SLiM. I've no idea what could be leading to the mutation not ending up in the genome eventually.
I just ran the test model in SLiMgui and got the raise on my first try. I think the lack of raise in the GUI is a red herring, yes. I have noticed that catching and reporting raises in SLiMgui does not seem to be working reliably lately, for reasons I don't understand and have not yet been able to reproduce. But I think this bug occurs in the GUI as well as at the command line; it just maybe doesn't always get reported correctly by the GUI. So anyway, I see it happening on my machine, and will track it down. My guess is that it is a very long-standing bug; I don't think we've done anything any time recently that should have destabilized the loading of tree sequences. There's just something very special about these .trees files. @mufernando, please do post or email the model that produced them, if you can; seeing what it does might somehow help to diagnose why these .trees files are so special.
The data in the tree sequence appears to be corrupted in a way that the read code is not presently set up to catch, so it doesn't get caught until crosscheck. (Hooray for crosscheck!) Specifically, the mutation table appears to contain mutations (i.e., derived states) at multiple positions that reference the same mutation ID. This is not legal; a given mutation ID must refer uniquely to one mutation, which exists at one position. I added a log in __TabulateMutationsFromTables() that logs out each mutation that gets tabulated from the mutation table:
std::cout << "__TabulateMutationsFromTables: tabulating derived state at position " << position << " with stack_count " << stack_count << ", id " << mut_id << std::endl;
Among other output, it writes:
__TabulateMutationsFromTables: tabulating derived state at position 365 with stack_count 1, id 12
__TabulateMutationsFromTables: tabulating derived state at position 2678 with stack_count 1, id 12
Since mutations go into a tabulation map that is indexed by mutation ID, the mutation at position 2678 overwrites the mutation at position 365 in the tabulation. Later, when mutations are getting added to genomes, this means that when the position-365 mutation ought to be added to a genome, the position-2678 mutation is added instead; looking up mutation ID 12 in the tabulation produces the position-2678 mutation due to the overwritten entry. The crosscheck then catches that discrepancy.
So the .trees file itself is corrupted, and SLiM catches that and raises, so in that sense all is well. The question now is: how did it get that way? Now we really need to know exactly how this .trees file was produced. Either SLiM wrote out a corrupted .trees file (presumably after somehow, erroneously, re-using a mutation ID that was already in use), or the .trees file got corrupted downstream somehow by tskit/msprime/pyslim. Please supply the full SLiM model used to generate this .trees file, all necessary auxiliary files, a random number seed that reproducibly leads to a corrupted .trees file, and any post-run Python scripts that modify the .trees file. Thanks!
the mutation table appears to contain mutations (i.e., derived states) at multiple positions that reference the same mutation ID.
Oh, darn it, I vaguely noticed this and it seemed vaguely suspicious, but there were so many with the same ID that I didn't follow up on it...
I can't think of what is special about these simulations, other than the fact that we're simulating, saving, reloading, changing size, and simulating more several times. But, it works most of the time... it seems that you really do need to track down the seed, Murillo? Or, maybe just having the tree sequences that happened earlier in the chain would be sufficient - maybe the error occurs when loading the previous tree sequence.
Ok, so I trimmed down my recipe and found a combination of seeds that can produce the problem - i.e., accumulation of mutations with the same ID at different positions.
I noted that when I remove the treeSeqRememberIndividuals calls, I get no duplicated mutation IDs. This made me wonder that I'm blowing up the unique mutation IDs?
I attached the slim recipe and a bash file with all the slim runs. crosscheck_error.zip
So - sim6.trees is the first one that has duplicated mutation ID: mutation ID 362 appears twice, at positions 52 and 74. We are not running out of mutation IDs - the tree sequence has only 26 mutations. A possible clue is that the first instance of this mutation is recorded in the tree sequence as having appeared in the final generation (slim_generation 6001). This happened at least one of the other examples I've seen. Here's their information:
So - after sim_chain.sh has been run (with the fix above); to debug one can just run the second-to-last command (that produces sim6.trees); it is during this simulation that the bad thing occurs (duplicate mutation id recorded).
And, in case it's helpful, here's the info about the genomes those mutations occurred in:
Ha, figured it out. The bug is at line 7716 in slim_sim.cpp, @petrelharp. This is in SLiMSim::__CreateMutationsFromTabulation(); we're reading in mutations from the mutation table and creating Mutation objects in SLiM for them. If an existing mutation in the mutations table is not referenced by any genome (refcount == 0), we don't make a mutation object for it, which makes sense – as far as SLiM is concerned, it doesn't exist. BUT since it continues to exist in the mutation table, we need to be sure that we don't reuse its mutation ID, and at present this doesn't happen. So I think this bug requires specifically that a model (a) reads in a .trees file, (b) that .trees has a mutation that is not ancestral to any extant genome, and yet was retained (presumably by a rememberIndividuals() call), (c) that mutation has an ID that is higher than the highest mutation ID present in the .trees file for any mutation that does get instantiated, and (d) the model finishes by writing out a new .trees file. If all four conditions are true, the final .trees file can potentially have two mutations with the same ID (if the SLiM simulation ran long enough to re-use the previously used ID, and if that new mutation survives to the final generation or gets remembered).
Yikes! Now that the bug is found it's a trivial fix. I'll post again when it's done and I've tested.
Hi @petrelharp and @mufernando. I've just committed the fix. The test script now runs the whole chain of simulations without any error. A pretty subtle bug; I doubt it will bite anyone else any time soon. :-> If you want the fix, just run with the current GitHub head on the master branch, it's there now. Thanks for the very helpful report; this would have been hard to figure out without a good reproducible case!
Activity
bhaller commentedon Jan 30, 2020
Hi Murillo. Interesting. Can you provide the script that produces these tree sequences, too? It may be that something non-obvious is wrong with the tree sequence files themselves, or it may be that something is wrong with the way that SLiM loads them in and creates its internal state from them. It's a little bit surprising, though, since this basic idea (write out a tree sequence and then read it back in) has been massively stress-tested, so I think there must be something a bit unusual about your model that triggers the problem. Thanks.
bhaller commentedon Jan 30, 2020
And I need the script that you're using to read the .trees files back in; the context into which a .trees file is read matters, so I can't just try to load your .trees files into the default SLiMgui model. You can email them to me if you don't want to post them publicly here. Thanks.
petrelharp commentedon Jan 30, 2020
Here is a reload script that produces the error:
... but I've just discovered that, on this computer, it produces the error only on the command line and not in the GUI. I'm currently tracking down what difference there might be between the executables.
petrelharp commentedon Jan 30, 2020
Both are version 3.3.1, at least - but perhaps different points in the git history.
petrelharp commentedon Jan 30, 2020
Confirmed that it happens on current HEAD on the command line...
mufernando commentedon Jan 30, 2020
@petrelharp built SLiM GUI from the current HEAD (3.3.1 build 2158) and it threw an error, whereas it didn't in the previous build which was a version 3.3.1 build 2125
petrelharp commentedon Jan 31, 2020
Sounds like time for
git bisect...petrelharp commentedon Jan 31, 2020
I'll have a go at it.
petrelharp commentedon Jan 31, 2020
I can't obtain a build that fails to throw the error on the command line, even building the git commit that looks to have been the one used to build the non-erroring GUI. Once in the office I'll see if rebuilding the GUI with various git commits fails to throw the error, but this lack-of-error-in-the-GUI-once is feeling like a red herring...
petrelharp commentedon Jan 31, 2020
printfs have got me this far through
_InstantiateSLiMObjectsFromTables, and everything seems on track to be loading in the mutation which the error says in not in fact there in SLiM. I've no idea what could be leading to the mutation not ending up in the genome eventually.bhaller commentedon Jan 31, 2020
I just ran the test model in SLiMgui and got the raise on my first try. I think the lack of raise in the GUI is a red herring, yes. I have noticed that catching and reporting raises in SLiMgui does not seem to be working reliably lately, for reasons I don't understand and have not yet been able to reproduce. But I think this bug occurs in the GUI as well as at the command line; it just maybe doesn't always get reported correctly by the GUI. So anyway, I see it happening on my machine, and will track it down. My guess is that it is a very long-standing bug; I don't think we've done anything any time recently that should have destabilized the loading of tree sequences. There's just something very special about these .trees files. @mufernando, please do post or email the model that produced them, if you can; seeing what it does might somehow help to diagnose why these .trees files are so special.
bhaller commentedon Jan 31, 2020
The data in the tree sequence appears to be corrupted in a way that the read code is not presently set up to catch, so it doesn't get caught until crosscheck. (Hooray for crosscheck!) Specifically, the mutation table appears to contain mutations (i.e., derived states) at multiple positions that reference the same mutation ID. This is not legal; a given mutation ID must refer uniquely to one mutation, which exists at one position. I added a log in __TabulateMutationsFromTables() that logs out each mutation that gets tabulated from the mutation table:
std::cout << "__TabulateMutationsFromTables: tabulating derived state at position " << position << " with stack_count " << stack_count << ", id " << mut_id << std::endl;Among other output, it writes:
Since mutations go into a tabulation map that is indexed by mutation ID, the mutation at position 2678 overwrites the mutation at position 365 in the tabulation. Later, when mutations are getting added to genomes, this means that when the position-365 mutation ought to be added to a genome, the position-2678 mutation is added instead; looking up mutation ID 12 in the tabulation produces the position-2678 mutation due to the overwritten entry. The crosscheck then catches that discrepancy.
So the .trees file itself is corrupted, and SLiM catches that and raises, so in that sense all is well. The question now is: how did it get that way? Now we really need to know exactly how this .trees file was produced. Either SLiM wrote out a corrupted .trees file (presumably after somehow, erroneously, re-using a mutation ID that was already in use), or the .trees file got corrupted downstream somehow by tskit/msprime/pyslim. Please supply the full SLiM model used to generate this .trees file, all necessary auxiliary files, a random number seed that reproducibly leads to a corrupted .trees file, and any post-run Python scripts that modify the .trees file. Thanks!
petrelharp commentedon Jan 31, 2020
Oh, darn it, I vaguely noticed this and it seemed vaguely suspicious, but there were so many with the same ID that I didn't follow up on it...
I can't think of what is special about these simulations, other than the fact that we're simulating, saving, reloading, changing size, and simulating more several times. But, it works most of the time... it seems that you really do need to track down the seed, Murillo? Or, maybe just having the tree sequences that happened earlier in the chain would be sufficient - maybe the error occurs when loading the previous tree sequence.
petrelharp commentedon Jan 31, 2020
Ah, right - there is no python modification (right, Murillo?) - it's all in SLiM.
3 remaining items
petrelharp commentedon Jan 31, 2020
So, there's actually a lot of duplicated mutation IDs at different positions - it's not just a single one, I think.
bhaller commentedon Jan 31, 2020
Yep, looks that way. Which is very odd, since this has not come up for any other test model at all.
petrelharp commentedon Jan 31, 2020
Yeah, we did a test where we saved and reloaded several times and this did not happen.
bhaller commentedon Jan 31, 2020
Yes, and I run those tests regularly, with different seeds, etc.
mufernando commentedon Feb 4, 2020
Ok, so I trimmed down my recipe and found a combination of seeds that can produce the problem - i.e., accumulation of mutations with the same ID at different positions.
I noted that when I remove the
treeSeqRememberIndividualscalls, I get no duplicated mutation IDs. This made me wonder that I'm blowing up the unique mutation IDs?I attached the slim recipe and a bash file with all the slim runs.
crosscheck_error.zip
petrelharp commentedon Feb 4, 2020
Looks like the
sim_test.slimin that bash script should berecipe_crosscheck.slim.petrelharp commentedon Feb 4, 2020
So -
sim6.treesis the first one that has duplicated mutation ID: mutation ID 362 appears twice, at positions 52 and 74. We are not running out of mutation IDs - the tree sequence has only 26 mutations. A possible clue is that the first instance of this mutation is recorded in the tree sequence as having appeared in the final generation (slim_generation 6001). This happened at least one of the other examples I've seen. Here's their information:petrelharp commentedon Feb 4, 2020
So - after
sim_chain.shhas been run (with the fix above); to debug one can just run the second-to-last command (that producessim6.trees); it is during this simulation that the bad thing occurs (duplicate mutation id recorded).And, in case it's helpful, here's the info about the genomes those mutations occurred in:
bhaller commentedon Feb 4, 2020
OK, I'll see whether I can get this reproducing on my end and track it down today.
bhaller commentedon Feb 4, 2020
Reproduced the bug on my end with this script, thanks. Will look into the next-to-last run.
bhaller commentedon Feb 4, 2020
Ha, figured it out. The bug is at line 7716 in slim_sim.cpp, @petrelharp. This is in SLiMSim::__CreateMutationsFromTabulation(); we're reading in mutations from the mutation table and creating Mutation objects in SLiM for them. If an existing mutation in the mutations table is not referenced by any genome (refcount == 0), we don't make a mutation object for it, which makes sense – as far as SLiM is concerned, it doesn't exist. BUT since it continues to exist in the mutation table, we need to be sure that we don't reuse its mutation ID, and at present this doesn't happen. So I think this bug requires specifically that a model (a) reads in a .trees file, (b) that .trees has a mutation that is not ancestral to any extant genome, and yet was retained (presumably by a rememberIndividuals() call), (c) that mutation has an ID that is higher than the highest mutation ID present in the .trees file for any mutation that does get instantiated, and (d) the model finishes by writing out a new .trees file. If all four conditions are true, the final .trees file can potentially have two mutations with the same ID (if the SLiM simulation ran long enough to re-use the previously used ID, and if that new mutation survives to the final generation or gets remembered).
Yikes! Now that the bug is found it's a trivial fix. I'll post again when it's done and I've tested.
bhaller commentedon Feb 4, 2020
Hi @petrelharp and @mufernando. I've just committed the fix. The test script now runs the whole chain of simulations without any error. A pretty subtle bug; I doubt it will bite anyone else any time soon. :-> If you want the fix, just run with the current GitHub head on the master branch, it's there now. Thanks for the very helpful report; this would have been hard to figure out without a good reproducible case!
mufernando commentedon Feb 4, 2020
Thank you, @bhaller, for the speedy follow up!
petrelharp commentedon Feb 5, 2020
Damn. Good catch. Thanks!