-
Notifications
You must be signed in to change notification settings - Fork 6
/
test_ModelParams_with_recregions.py
100 lines (91 loc) · 2.92 KB
/
test_ModelParams_with_recregions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#
# Copyright (C) 2023 Kevin Thornton <krthornt@uci.edu>
#
# This file is part of fwdpy11.
#
# fwdpy11 is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# fwdpy11 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with fwdpy11. If not, see <http://www.gnu.org/licenses/>.
#
import demes
import pytest
import fwdpy11
def _validate_expected(regions, numbers):
assert (
len([i for i in regions if isinstance(i, fwdpy11.PoissonCrossoverGenerator)])
== numbers[0]
)
assert (
len([i for i in regions if isinstance(i, fwdpy11.NonPoissonCrossoverGenerator)])
== numbers[1]
)
def roundtrip(regions):
yaml = """
time_units: generations
demes:
- name: A
epochs:
- {end_time: 0, start_size: 10}
"""
graph = demes.loads(yaml)
demog = fwdpy11.ForwardDemesGraph.from_demes(graph, burnin=1)
pdict = {
"recregions": regions,
"nregions": [],
"sregions": [],
"rates": (0, 0, None),
"gvalue": fwdpy11.Multiplicative(2.0),
"simlen": 10,
"demography": demog,
}
params = fwdpy11.ModelParams(**pdict)
pop = fwdpy11.DiploidPopulation(10, 2)
rng = fwdpy11.GSLrng(123)
fwdpy11.evolvets(rng, pop, params, 100)
# The setup is ([regions], (number poisson, number non-poisson))
# The latter is used to mimic the internal idiom that we
# use to set up the genetic map to send to C++
@pytest.mark.parametrize(
"data",
[
([fwdpy11.PoissonInterval(0, 1, 1e-3)], (1, 0)),
([fwdpy11.PoissonPoint(1, 1e-3)], (1, 0)),
([fwdpy11.PoissonInterval(0, 1, 1e-3), fwdpy11.PoissonPoint(1, 1e-3)], (2, 0)),
([fwdpy11.BinomialInterval(0, 1, 1e-3)], (0, 1)),
([fwdpy11.BinomialPoint(1, 1e-3)], (0, 1)),
(
[fwdpy11.BinomialInterval(0, 1, 1e-3), fwdpy11.BinomialPoint(1, 1e-3)],
(0, 2),
),
(
[
fwdpy11.PoissonInterval(0, 0.1, 1e-3),
fwdpy11.PoissonPoint(0.1, 1e-3),
fwdpy11.BinomialInterval(0.1, 0.2, 1e-3),
fwdpy11.BinomialPoint(0.2, 1e-3),
],
(2, 2),
),
(
[
fwdpy11.BinomialIntervalMap(
0.5, [fwdpy11.Region(0, 1, 1e-5), fwdpy11.Region(1, 2, 2)]
)
],
(0, 1),
),
],
)
def test_model_params_with_recregions(data):
regions, expected = data
_validate_expected(regions, expected)
roundtrip(regions)