Skip to content

Commit

Permalink
Suppress warnings and speed up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromekelleher committed Jul 13, 2023
1 parent 3843e87 commit 256768e
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions python/tests/test_haplotype_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"""
Python implementation of the Li and Stephens forwards and backwards algorithms.
"""
import itertools
import warnings

import lshmm as ls
import msprime
Expand Down Expand Up @@ -874,13 +874,16 @@ def example_parameters_haplotypes(self, ts, seed=42):
for s in haplotypes:
yield n, H, s, r, mu

# Mixture of random and extremes
rs = [np.zeros(m) + 0.999, np.zeros(m) + 1e-6, np.random.rand(m)]
mus = [np.zeros(m) + 0.33, np.zeros(m) + 1e-6, np.random.rand(m) * 0.33]
# FIXME removing these as tests are abominably slow.
# We'll be refactoring all this to use pytest anyway, so let's not
# worry too much about coverage for now.
# # Mixture of random and extremes
# rs = [np.zeros(m) + 0.999, np.zeros(m) + 1e-6, np.random.rand(m)]
# mus = [np.zeros(m) + 0.33, np.zeros(m) + 1e-6, np.random.rand(m) * 0.33]

for s, r, mu in itertools.product(haplotypes, rs, mus):
r[0] = 0
yield n, H, s, r, mu
# for s, r, mu in itertools.product(haplotypes, rs, mus):
# r[0] = 0
# yield n, H, s, r, mu

def assertAllClose(self, A, B):
"""Assert that all entries of two matrices are 'close'"""
Expand Down Expand Up @@ -1029,13 +1032,18 @@ class TestForwardHapTree(FBAlgorithmBase):
def verify(self, ts):
for n, H, s, r, mu in self.example_parameters_haplotypes(ts):
for scale_mutation in [False, True]:
F, c, ll = ls.forwards(
H,
s,
r,
mutation_rate=mu,
scale_mutation_based_on_n_alleles=scale_mutation,
)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
# Warning from lshmm:
# Passed a vector of mutation rates, but rescaling each mutation
# rate conditional on the number of alleles
F, c, ll = ls.forwards(
H,
s,
r,
mutation_rate=mu,
scale_mutation_based_on_n_alleles=scale_mutation,
)
# Note, need to remove the first sample from the ts, and ensure
# that invariant sites aren't removed.
ts_check = ts.simplify(range(1, n + 1), filter_sites=False)
Expand Down

0 comments on commit 256768e

Please sign in to comment.