Skip to content

Commit

Permalink
Closes #384
Browse files Browse the repository at this point in the history
  • Loading branch information
apragsdale committed Nov 28, 2021
1 parent 0676cf0 commit 5e9fd83
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion demes/demes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2220,7 +2220,7 @@ def collapse_demes(pairs):
source = migration["source"]
dest = migration["dest"]
time_hi = min(self[source].start_time, self[dest].start_time)
time_lo = max(self[dest].end_time, self[dest].end_time)
time_lo = max(self[source].end_time, self[dest].end_time)
if migration["end_time"] == time_lo:
del migration["end_time"]
if migration["start_time"] == time_hi:
Expand Down
20 changes: 20 additions & 0 deletions tests/test_demes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4045,6 +4045,23 @@ def test_simplify_symmetric_migrations_branching_demography(self):
assert len(d["migrations"]) == 1
assert dict(demes=["a", "b", "c"], rate=0.01) in d["migrations"]

def test_simplify_symmetric_migrations_demography_with_splits(self):
b = Builder()
b.add_deme("anc", epochs=[dict(start_size=1, end_time=10)])
b.add_deme("a", ancestors=["anc"], epochs=[dict(start_size=1)])
b.add_deme("b", ancestors=["anc"], epochs=[dict(start_size=1, end_time=5)])
b.add_deme("c", ancestors=["b"], epochs=[dict(start_size=1)])
b.add_deme("d", ancestors=["b"], epochs=[dict(start_size=1)])
b.add_migration(demes=["a", "b"], rate=0.01)
b.add_migration(demes=["a", "c", "d"], rate=0.01)
g = b.resolve()
d = g.asdict()
assert len(d["migrations"]) == 8
d = g.asdict_simplified()
assert len(d["migrations"]) == 2
assert dict(demes=["a", "b"], rate=0.01) in d["migrations"]
assert dict(demes=["a", "c", "d"], rate=0.01) in d["migrations"]

def test_invalid_fields(self):
b = Builder()
b.add_deme("a", epochs=[dict(start_size=1)])
Expand Down Expand Up @@ -4143,3 +4160,6 @@ def test_back_and_forth(self, graph):
b = Builder.fromdict(graph.asdict_simplified())
g = b.resolve()
assert g.isclose(graph)



0 comments on commit 5e9fd83

Please sign in to comment.