jeetsukumaran / DendroPy

A Python library for phylogenetic scripting, simulation, data processing and manipulation.
https://pypi.org/project/DendroPy/.
BSD 3-Clause "New" or "Revised" License
210 stars 61 forks source link

Pass rng in evolve_states #170

Closed actapia closed 1 year ago

actapia commented 1 year ago

This change makes the evolve_states method of DiscreteCharacterEvolver pass its rng parameter to seq_model.simulate_descendant_states.

Before the change, this code results in an AssertionError:

from random import Random
from dendropy.model import discrete
from dendropy.simulate import treesim

def test_chars(t, rng):
    return sorted(str(s) for s in discrete.hky85_chars(10, t, rng=rng).values())

if __name__ == "__main__":
    tree = treesim.birth_death_tree(
        birth_rate=1.0,
        death_rate=0.5,
        num_extant_tips=4,
        rng=Random(100)
    )
    t1 = test_chars(tree, Random(100))
    t2 = test_chars(tree, Random(100))
    assert t1 == t2

After this change, the assertion succeeds.

mmore500 commented 1 year ago

Good catch! Activated CI for this branch so we can test the change. Planning to add a regression test for this issue shortly to our unit test suite for this bug then merge and push a new release. Thanks for the PR!

codecov-commenter commented 1 year ago

Codecov Report

Merging #170 (c57b7c5) into main (877a172) will increase coverage by 0.66%. The diff coverage is 100.00%.

:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##             main     #170      +/-   ##
==========================================
+ Coverage   60.75%   61.42%   +0.66%     
==========================================
  Files         105      105              
  Lines       18646    18646              
==========================================
+ Hits        11329    11453     +124     
+ Misses       7317     7193     -124     
Flag Coverage Δ
unittests 61.42% <100.00%> (+0.66%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/dendropy/model/discrete.py 76.43% <100.00%> (+56.54%) :arrow_up:

... and 3 files with indirect coverage changes

mmore500 commented 1 year ago

Found another place where rng wasn't being passed!

mmore500 commented 1 year ago

A patch has been released as v.4.6.1

Thank you again for the contribution.