From c5f63b8bf7082f12c15712930589c2d9d22d867d Mon Sep 17 00:00:00 2001 From: "Kevin R. Thornton" Date: Thu, 21 Nov 2024 16:04:47 -0800 Subject: [PATCH] Raise error when simulations w/neutral mutations are badly specified --- lib/evolve_discrete_demes/evolvets.cc | 4 +-- ...t_tree_sequences_with_neutral_mutations.py | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/evolve_discrete_demes/evolvets.cc b/lib/evolve_discrete_demes/evolvets.cc index 20fc1a8cf..98440cdfa 100644 --- a/lib/evolve_discrete_demes/evolvets.cc +++ b/lib/evolve_discrete_demes/evolvets.cc @@ -255,12 +255,12 @@ evolve_with_tree_sequences( { if (options.track_mutation_counts_during_sim) { - if (simplification_interval != 1) + if (simplification_interval != 1 or options.suppress_edge_table_indexing == true) { throw std::invalid_argument( "when track_mutation_counts is True and simulating " "neutral mutations, the simplification interval must be " - "1"); + "1 and edge table indexing must not be suppressed"); } } } diff --git a/tests/test_tree_sequences_with_neutral_mutations.py b/tests/test_tree_sequences_with_neutral_mutations.py index 2993a1659..c6f7865a7 100644 --- a/tests/test_tree_sequences_with_neutral_mutations.py +++ b/tests/test_tree_sequences_with_neutral_mutations.py @@ -2,6 +2,7 @@ import unittest import numpy as np +import pytest import fwdpy11 from test_tree_sequences import set_up_quant_trait_model, set_up_standard_pop_gen_model @@ -183,5 +184,38 @@ def test_trigger_final_simplification_with_fixations_to_remove(): ) +def test_track_mutation_counts(): + burnin = 10 + N = 100 + pdict = { + # Add a region for neutral mutations: + "nregions": [fwdpy11.Region(0, 1, 1)], + "sregions": [fwdpy11.ExpS(beg=0, end=1, weight=1, mean=0.2)], + "recregions": [fwdpy11.PoissonInterval(0, 1, 1e-2)], + "gvalue": [fwdpy11.Multiplicative(2.0)], + "rates": (1e-3, 1e-3, None), + "simlen": burnin * N, + "demography": fwdpy11.ForwardDemesGraph.tubes( + [N], burnin=10 * N, burnin_is_exact=True + ), + "prune_selected": True, + } + params = fwdpy11.ModelParams(**pdict) + pop = fwdpy11.DiploidPopulation(N, 1.0) + rng = fwdpy11.GSLrng(54321) + + with pytest.raises(ValueError): + fwdpy11.evolvets( + rng, + pop, + params, + 1, + # This is the bad thing... + suppress_table_indexing=True, + # ...combined with this + track_mutation_counts=True, + ) + + if __name__ == "__main__": unittest.main()