Skip to content

Commit

Permalink
Ensure generation_time is 1 when time_units are generations
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamgower committed Apr 22, 2022
1 parent 910c329 commit 3b657c2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
4 changes: 0 additions & 4 deletions examples/browning_america.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ description: The Browning et al. (2011) model of admixture in the Americas.
doi:
- https://doi.org/10.1371/journal.pgen.1007385
time_units: generations
# TODO the parser currently raises an error if we set this value. See the
# note in the code for details.
# generation_time: 25

demes:
- name: ancestral
description: Equilibrium/root population
Expand Down
4 changes: 4 additions & 0 deletions reference_implementation/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,10 @@ def validate(self):
"Must specify Graph.generation_time if time_units is not "
"'generations'"
)
if self.time_units == "generations" and self.generation_time != 1:
raise ValueError(
"If time_units are in generations, generation_time must be 1"
)
for deme in self.demes.values():
deme.validate()
for pulse in self.pulses:
Expand Down
9 changes: 7 additions & 2 deletions reference_implementation/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,17 @@ def test_time_units(self):
def test_generation_time_generations(self):
data = minimal_graph()
data["time_units"] = "generations"
data["generation_time"] = 12
parser.parse(data)
data["generation_time"] = 1
graph = parser.parse(data)
assert graph.generation_time == 1

def test_bad_generation_time(self):
data = minimal_graph()
data["time_units"] = "generations"
data["generation_time"] = 12
with pytest.raises(ValueError):
parser.parse(data)

def test_generation_time(self):
data = minimal_graph()
data["time_units"] = "years"
Expand Down
File renamed without changes.

0 comments on commit 3b657c2

Please sign in to comment.