Skip to content

Commit

Permalink
Fix sweep model termination logic (#894)
Browse files Browse the repository at this point in the history
* Fix logic in GlobalFixation and FocalDemeFixation
for cases where the mutation key has changed.

Fixes #893

* update change log
  • Loading branch information
molpopgen committed Jan 11, 2022
1 parent 6097a4b commit bad3142
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
12 changes: 11 additions & 1 deletion doc/misc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
Major changes are listed below. Each release likely contains fiddling with back-end code,
updates to latest `fwdpp` version, etc.

## Next release
## 0.17.1

Bug fixes

* Fix bug in fixation checking in `fwdpy11.conditional_models`.
Previous results were not incorrect.
Rather, they took too long to be obtained because some simulations did not terminate early enough.
Issue {issue}`893`
PR {pr}`894`

Miscellaneous

- Improved exception message for invalid migrations during a simulation.
PR {pr}`892`
Expand Down
18 changes: 16 additions & 2 deletions fwdpy11/conditional_models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ class SimulationStatus:
For examples, see implementations of :class:`GlobalFixation` and :class:`FocalDemeFixation`.
"""

should_terminate: bool = attr.ib(validator=attr.validators.instance_of(bool))
condition_met: bool = attr.ib(validator=attr.validators.instance_of(bool))

Expand All @@ -241,7 +242,15 @@ def __call__(
self, pop: fwdpy11.DiploidPopulation, index: int, key: tuple
) -> SimulationStatus:
if pop.mutations[index].key != key:
return SimulationStatus(False, False)
# The key has changed, meaning the mutation is
# flagged for recycling.
# First, check if it is in the fixations list
for m in pop.fixations:
if m.key == key:
# It is fixed, so we are done
return SimulationStatus(True, False)
# The mutation is gone from the simulation
return SimulationStatus(True, False)
if pop.mcounts[index] == 0:
return SimulationStatus(True, False)
if pop.mcounts[index] == 2 * pop.N:
Expand All @@ -262,7 +271,12 @@ class FocalDemeFixation:
def __call__(self, pop: fwdpy11.DiploidPopulation, index, key) -> SimulationStatus:
deme_sizes = pop.deme_sizes(as_dict=True)
if pop.mutations[index].key != key:
return SimulationStatus(False, False)
# check for a global fixation
for m in pop.fixations:
if m.key == key:
return SimulationStatus(True, False)
# The mutation is gone from the simulation
return SimulationStatus(True, False)
if self.deme not in deme_sizes:
return SimulationStatus(False, False)
count = 0
Expand Down

0 comments on commit bad3142

Please sign in to comment.