Skip to content

Commit

Permalink
try to make tests faster. Triggered #836
Browse files Browse the repository at this point in the history
  • Loading branch information
molpopgen committed Oct 27, 2021
1 parent bf1d435 commit bd0653e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 37 deletions.
5 changes: 5 additions & 0 deletions fwdpy11/src/functions/add_mutation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ add_mutation(const fwdpy11::GSLrng_t& rng, const double left, const double right
}
}

for(auto & d : pop.diploids)
{
if(pop.haploid_genomes[d.first].n == 0) { throw std::runtime_error("bad1a"); }
if(pop.haploid_genomes[d.second].n == 0) { throw std::runtime_error("bad2a"); }
}
std::size_t new_mutation_key = std::numeric_limits<std::size_t>::max();
auto candidates = generate_canidate_list(left, right, ndescendants, deme, pop);

Expand Down
59 changes: 22 additions & 37 deletions tests/test_selective_sweeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@


def make_pop_with_msprime_ancestry(seed):
N = 500
N = 100
rho = 1000
L = 1.0
initial_ts = msprime.sim_ancestry(
samples=N,
population_size=1000,
population_size=2 * N,
recombination_rate=rho / 4 / N,
random_seed=seed,
sequence_length=L,
Expand All @@ -59,15 +59,15 @@ def run_selective_sweep(
msprime_seed,
fp11_seed,
ndescendants,
N=500,
N=100,
alpha=1000, # 2Ns
rho=100,
L=1.0,
max_attempts=100,
):
for initial_ts in msprime.sim_ancestry(
samples=N,
population_size=1000,
population_size=2 * N,
recombination_rate=rho / 4 / N,
random_seed=msprime_seed,
sequence_length=1.0,
Expand All @@ -91,6 +91,13 @@ def run_selective_sweep(
if idx is None:
continue

c = 0
for dip in pop.diploids:
for genome in [dip.first, dip.second]:
if idx in pop.haploid_genomes[genome].smutations:
c += 1
assert c == ndescendants

# Make sure we've chosen a valid time
assert (
pop.mutations[idx].g <= pop.tables.nodes[pop.tables.mutations[0].node].time
Expand Down Expand Up @@ -135,7 +142,7 @@ def test_sweep_from_new_mutation(msprime_seed, fp11_seed):

@pytest.mark.parametrize("msprime_seed", seed_list(135123, 5))
@pytest.mark.parametrize("fp11_seed", seed_list(5130125, 5))
@pytest.mark.parametrize("ndescendants", [2, 7, 10, 23, 100, 257])
@pytest.mark.parametrize("ndescendants", [2, 7, 10, 23, 12, 100])
def test_sweep_from_standing_variation(msprime_seed, fp11_seed, ndescendants):
pop_with_fixation, idx = run_selective_sweep(msprime_seed, fp11_seed, ndescendants)
if pop_with_fixation is not None:
Expand All @@ -162,11 +169,7 @@ def test_sweep_from_new_mutation_using_API(msprime_seed, fp11_seed, alpha):
"window": (0.49, 0.51),
}
rng = fwdpy11.GSLrng(fp11_seed)
(
pop_with_fixation,
idx,
_,
) = fwdpy11.conditional_models.selective_sweep(
(pop_with_fixation, idx, _,) = fwdpy11.conditional_models.selective_sweep(
rng,
pop,
params,
Expand All @@ -181,7 +184,7 @@ def test_sweep_from_new_mutation_using_API(msprime_seed, fp11_seed, alpha):

@pytest.mark.parametrize("msprime_seed", seed_list(135123, 5))
@pytest.mark.parametrize("fp11_seed", seed_list(5130125, 5))
@pytest.mark.parametrize("ndescendants", [2, 7, 10, 23, 100, 257])
@pytest.mark.parametrize("ndescendants", [2, 7, 10, 23, 12, 100])
@pytest.mark.parametrize("alpha", [1000.0])
def test_sweep_from_standing_variation_using_API(
msprime_seed, fp11_seed, ndescendants, alpha
Expand All @@ -200,13 +203,10 @@ def test_sweep_from_standing_variation_using_API(
"data": fwdpy11.NewMutationData(effect_size=alpha / 2 / pop.N, dominance=1.0),
"window": (0.49, 0.51),
}
finished = False
rng = fwdpy11.GSLrng(fp11_seed)
try:
rng = fwdpy11.GSLrng(fp11_seed)
(
pop_with_fixation,
idx,
_,
) = fwdpy11.conditional_models.selective_sweep(
(pop_with_fixation, idx, _,) = fwdpy11.conditional_models.selective_sweep(
rng,
pop,
params,
Expand All @@ -217,6 +217,7 @@ def test_sweep_from_standing_variation_using_API(
if pop_with_fixation is not None:
assert pop_with_fixation.mcounts[idx] == 2 * pop_with_fixation.N
_ = pop_with_fixation.dump_tables_to_tskit()
finished = True
except fwdpy11.conditional_models.AddMutationFailure as a:
pass
except Exception as e:
Expand Down Expand Up @@ -334,11 +335,7 @@ def test_sweep_from_new_mutation_in_singe_deme_using_API(fp11_seed, demes_yaml,
"window": (0.49, 0.51),
}
rng = fwdpy11.GSLrng(fp11_seed)
(
pop_with_fixation,
idx,
_,
) = fwdpy11.conditional_models.selective_sweep(
(pop_with_fixation, idx, _,) = fwdpy11.conditional_models.selective_sweep(
rng,
pop,
params,
Expand Down Expand Up @@ -389,11 +386,7 @@ def test_sweep_from_new_mutation_with_demography_using_API(
"window": (0.49, 0.51),
}
rng = fwdpy11.GSLrng(fp11_seed)
(
pop_with_fixation,
idx,
_,
) = fwdpy11.conditional_models.selective_sweep(
(pop_with_fixation, idx, _,) = fwdpy11.conditional_models.selective_sweep(
rng,
pop,
params,
Expand Down Expand Up @@ -438,11 +431,7 @@ def test_origination_deme1_fixation_in_deme_2(fp11_seed, demes_yaml, alpha):
"window": (0.49, 0.51),
}
rng = fwdpy11.GSLrng(fp11_seed)
(
pop_with_fixation,
idx,
_,
) = fwdpy11.conditional_models.selective_sweep(
(pop_with_fixation, idx, _,) = fwdpy11.conditional_models.selective_sweep(
rng,
pop,
params,
Expand Down Expand Up @@ -547,11 +536,7 @@ def test_origination_deme2_fixation_in_deme_2_no_migration(
"window": (0.49, 0.51),
}
rng = fwdpy11.GSLrng(fp11_seed)
(
pop_with_fixation,
idx,
_,
) = fwdpy11.conditional_models.selective_sweep(
(pop_with_fixation, idx, _,) = fwdpy11.conditional_models.selective_sweep(
rng,
pop,
params,
Expand Down

0 comments on commit bd0653e

Please sign in to comment.