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
Fix 639 and 646 #647
Fix 639 and 646 #647
Conversation
f182ad6
to
a7abc47
Compare
The implementation of But, because we want the final population to have all of its variants fully counted, we need a check to make sure counting happens if there are ancient samples or if there are neutral mutations. |
Implementing both of these is not going to be the full solution; if we do the second, and add a check that all mutations in the table must have counts > 0, the check can fail. The failed check suggests that there's some logic missing earlier, likely during post-simplification actions. |
6281d12
to
3cc373d
Compare
So, 378f13e causes the test for #646 to pass. But, I am thinking that that change is a band-aid and not the real cause, as the commit is forcing mutation counting. After counting, if |
annoyingly, tests are passing but the example that originally triggered this whole business can still fail. This block of code seems to be to blame: if (pop.generation == last_preserved_generation)
{
std::transform(begin(pop.mcounts_from_preserved_nodes),
end(pop.mcounts_from_preserved_nodes),
begin(last_preserved_generation_counts),
begin(pop.mcounts_from_preserved_nodes),
std::minus<std::uint32_t>());
} Since all tests are passing, we clearly don't have the right test in place to get whatever's happening here. This is probably a new issue/bug? Update: I will guess that |
The debug code was indeed wrong. |
For the existing test: Changing the "simlen" for the second params fixture values results affects if error being triggered or not. Likewise, in the original test script, adjusting simlen and/or simplification interval affects if it happens or not. |
b4a64c7
to
968207d
Compare
A recent force-push undid some candidate fixes. I did this because it forced the tests to fail in a binary way based on if neutral variants are simulated or not. For posterity, the removed changes were: In simplify_tables.hpp:
In index_and_count_mutations.cc:
#include <numeric>
#include <stdexcept>
#include <fwdpy11/types/DiploidPopulation.hpp>
#include <fwdpp/ts/count_mutations.hpp>
#include <fwdpp/internal/sample_diploid_helpers.hpp>
#include "index_and_count_mutations.hpp"
void
index_and_count_mutations(const bool suppress_edge_table_indexing,
fwdpy11::DiploidPopulation& pop)
{
pop.mcounts_from_preserved_nodes.resize(pop.mutations.size(), 0);
bool neutral_variants_present = false;
for (auto& m : pop.tables->mutations)
{
if (m.neutral)
{
neutral_variants_present = true;
break;
}
}
// FIXME: there must be a way to remove this awkward check?
if (!suppress_edge_table_indexing && !neutral_variants_present)
{
return;
}
if (pop.tables->preserved_nodes.empty() || neutral_variants_present)
{
pop.tables->build_indexes();
pop.fill_alive_nodes();
if (pop.tables->preserved_nodes.empty())
{
fwdpp::ts::count_mutations(*pop.tables, pop.mutations,
pop.alive_nodes, pop.mcounts);
}
else
{
fwdpp::ts::count_mutations(*pop.tables, pop.mutations,
pop.alive_nodes, pop.mcounts,
pop.mcounts_from_preserved_nodes);
}
for (auto& mr : pop.tables->mutations)
{
if (pop.mcounts[mr.key] + pop.mcounts_from_preserved_nodes[mr.key]
== 0)
{
throw std::runtime_error(
"mutation in table has count of zero.");
}
}
}
else
{
fwdpp::fwdpp_internal::process_haploid_genomes(pop.haploid_genomes,
pop.mutations, pop.mcounts);
}
} |
88d755a
to
afcfe74
Compare
A check used in this PR is to assert that mutation table rows have nonzero counts. See 80689f1, for example. This check is not correct when resetting--the deletion of ancient sample records can cause a mutation to be in the tables but have no descendants. Thus, |
This works to make all tests pass:
Although this is a good clue, it is likely not the solution we need. We cannot disable |
The reason why is that we'd need to count mutations from tables after simplification. Currently, we don't do that if there are ancient samples. The So, getting closer. Need to enumerate the various behavior combos and make sure we do the right thing. Will probably need more tests. |
Fixes #646 Add extensive tests of ancient samples w/ and w/o neutral mutations. Change test to trigger more failures. Add run time checks of mutation table consistency. For final mutation counting, always use tables when simulating neutral mutations. After simplification, build recycling queue from simplification results if simulating neutral mutations. index_and_count_mutations removes mutations from tables whose counts are adjusted to zero if reset_treeseqs_to_alive_nodes_after_simplification is true. Only adjust mcounts_from_preserved_nodes using last_preserved_generation_counts if reset_treeseqs_to_alive_nodes_after_simplification is false. Only adjust mutation counts by last_preserved_generation_counts if not simulating neutral mutations.
00ab1ee
to
1db6544
Compare
if any. This can arise when preserving nodes very often.
preserve_selected_fixations is false, remove fixations from haploid genomes.
06a8a41 needs a test, which can be pulled from the example I'm working on for the freq tracking. |
final simplification post-simulation. See 06a8a41.
0da3214
to
f2d8a71
Compare
WIP to fix #639 and #646
To follow up on in a later PR: