Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only load QC models when running tests #1419

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,7 @@ original function by adding this bit of code to ``stdpopsim/qc/<SPECIES_ID>.py``

.. code-block:: python

_species.get_demographic_model(_MODEL_ID_).register_qc(_your_review_function())
_species.get_demographic_model(_MODEL_ID_).register_qc(_your_review_function)

Where ``_MODEL_ID_`` is the string specified by the original contributor as the
``id`` of the demographic model, and ``_your_review_function()`` is the function
Expand Down
4 changes: 2 additions & 2 deletions stdpopsim/dfe.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ def register_qc(self, qc_dfe):
"""
Register a QC model implementation for this DFE.
"""
if not isinstance(qc_dfe, self.__class__):
raise ValueError(f"Cannot register non-DFE '{qc_dfe}' as QC DFE.")
if not callable(qc_dfe):
raise ValueError(f"'{qc_dfe}' must be a function returning a QC DFE.")
if self.qc_dfe is not None:
raise ValueError(f"QC DFE already registered for {self.id}.")
self.qc_dfe = qc_dfe
Expand Down
6 changes: 2 additions & 4 deletions stdpopsim/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,8 @@ def register_qc(self, qc_model):
"""
Register a QC model implementation for this model.
"""
if not isinstance(qc_model, self.__class__):
raise ValueError(
f"Cannot register non-DemographicModel '{qc_model}' as QC model"
)
if not callable(qc_model):
raise ValueError(f"'{qc_model}' must be a function returning a QC model")
if self.qc_model is not None:
raise ValueError(f"QC model already registered for {self.id}.")
self.qc_model = qc_model
Expand Down
2 changes: 1 addition & 1 deletion stdpopsim/qc/AnaPla.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ def LavertskyEtAl2019TwoPop():


_species.get_demographic_model("MallardBlackDuck_2L19").register_qc(
LavertskyEtAl2019TwoPop()
LavertskyEtAl2019TwoPop
)
2 changes: 1 addition & 1 deletion stdpopsim/qc/AnoGam.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,4 @@ def GAS_stairwayplot():
)


_species.get_demographic_model("GabonAg1000G_1A17").register_qc(GAS_stairwayplot())
_species.get_demographic_model("GabonAg1000G_1A17").register_qc(GAS_stairwayplot)
6 changes: 3 additions & 3 deletions stdpopsim/qc/AraTha.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def Durvasula2017MSMC():
)


_species.get_demographic_model("SouthMiddleAtlas_1D17").register_qc(Durvasula2017MSMC())
_species.get_demographic_model("SouthMiddleAtlas_1D17").register_qc(Durvasula2017MSMC)


def HuberTwoEpoch():
Expand Down Expand Up @@ -164,7 +164,7 @@ def HuberTwoEpoch():
)


_species.get_demographic_model("African2Epoch_1H18").register_qc(HuberTwoEpoch())
_species.get_demographic_model("African2Epoch_1H18").register_qc(HuberTwoEpoch)


def HuberThreeEpoch():
Expand Down Expand Up @@ -207,4 +207,4 @@ def HuberThreeEpoch():
)


_species.get_demographic_model("African3Epoch_1H18").register_qc(HuberThreeEpoch())
_species.get_demographic_model("African3Epoch_1H18").register_qc(HuberThreeEpoch)
2 changes: 1 addition & 1 deletion stdpopsim/qc/BosTau.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ def McLeod2013_1Pop():
)


_species.get_demographic_model("HolsteinFriesian_1M13").register_qc(McLeod2013_1Pop())
_species.get_demographic_model("HolsteinFriesian_1M13").register_qc(McLeod2013_1Pop)
4 changes: 2 additions & 2 deletions stdpopsim/qc/DroMel.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def LiStephanTwoPopulation():
)


_species.get_demographic_model("OutOfAfrica_2L06").register_qc(LiStephanTwoPopulation())
_species.get_demographic_model("OutOfAfrica_2L06").register_qc(LiStephanTwoPopulation)


def SheehanSongThreeEpic():
Expand Down Expand Up @@ -114,4 +114,4 @@ def SheehanSongThreeEpic():
)


_species.get_demographic_model("African3Epoch_1S16").register_qc(SheehanSongThreeEpic())
_species.get_demographic_model("African3Epoch_1S16").register_qc(SheehanSongThreeEpic)
28 changes: 14 additions & 14 deletions stdpopsim/qc/HomSap.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def TennessenOnePopAfrica():
)


_species.get_demographic_model("Africa_1T12").register_qc(TennessenOnePopAfrica())
_species.get_demographic_model("Africa_1T12").register_qc(TennessenOnePopAfrica)


def TennessenTwoPopOutOfAfrica():
Expand Down Expand Up @@ -203,7 +203,7 @@ def TennessenTwoPopOutOfAfrica():


_species.get_demographic_model("OutOfAfrica_2T12").register_qc(
TennessenTwoPopOutOfAfrica()
TennessenTwoPopOutOfAfrica
)


Expand Down Expand Up @@ -328,7 +328,7 @@ def BrowningAmerica():
)


_species.get_demographic_model("AmericanAdmixture_4B11").register_qc(BrowningAmerica())
_species.get_demographic_model("AmericanAdmixture_4B11").register_qc(BrowningAmerica)


def RagsdaleArchaic():
Expand Down Expand Up @@ -491,7 +491,7 @@ def RagsdaleArchaic():


_species.get_demographic_model("OutOfAfricaArchaicAdmixture_5R19").register_qc(
RagsdaleArchaic()
RagsdaleArchaic
)


Expand Down Expand Up @@ -703,7 +703,7 @@ def KammAncientSamples():
)


_species.get_demographic_model("AncientEurasia_9K19").register_qc(KammAncientSamples())
_species.get_demographic_model("AncientEurasia_9K19").register_qc(KammAncientSamples)


def DenisovanAncestryInPapuans():
Expand Down Expand Up @@ -1011,7 +1011,7 @@ def DenisovanAncestryInPapuans():


_species.get_demographic_model("PapuansOutOfAfrica_10J19").register_qc(
DenisovanAncestryInPapuans()
DenisovanAncestryInPapuans
)


Expand Down Expand Up @@ -1097,7 +1097,7 @@ def GutenkunstOOA():
)


_species.get_demographic_model("OutOfAfrica_3G09").register_qc(GutenkunstOOA())
_species.get_demographic_model("OutOfAfrica_3G09").register_qc(GutenkunstOOA)


def GladsteinAshkSubstructure():
Expand Down Expand Up @@ -1190,7 +1190,7 @@ def GladsteinAshkSubstructure():
)


_species.get_demographic_model("AshkSub_7G19").register_qc(GladsteinAshkSubstructure())
_species.get_demographic_model("AshkSub_7G19").register_qc(GladsteinAshkSubstructure)


def ZigZag():
Expand Down Expand Up @@ -1255,7 +1255,7 @@ def ZigZag():
)


_species.get_demographic_model("Zigzag_1S14").register_qc(ZigZag())
_species.get_demographic_model("Zigzag_1S14").register_qc(ZigZag)


def JouganousOOA2017():
Expand Down Expand Up @@ -1351,7 +1351,7 @@ def JouganousOOA2017():
)


_species.get_demographic_model("OutOfAfrica_4J17").register_qc(JouganousOOA2017())
_species.get_demographic_model("OutOfAfrica_4J17").register_qc(JouganousOOA2017)


def Boyko2008():
Expand Down Expand Up @@ -1390,7 +1390,7 @@ def Boyko2008():
)


_species.get_demographic_model("Africa_1B08").register_qc(Boyko2008())
_species.get_demographic_model("Africa_1B08").register_qc(Boyko2008)


def Iasi2021():
Expand Down Expand Up @@ -1536,7 +1536,7 @@ def extended_pulse(

_species.get_demographic_model(
"OutOfAfricaExtendedNeandertalAdmixturePulse_3I21"
).register_qc(Iasi2021())
).register_qc(Iasi2021)


# Currently this is not in use, but we kept it here in case we need it when the
Expand Down Expand Up @@ -1690,7 +1690,7 @@ def PearsonAncientEurope():
)


_species.get_demographic_model("AncientEurope_4A21").register_qc(PearsonAncientEurope())
_species.get_demographic_model("AncientEurope_4A21").register_qc(PearsonAncientEurope)


def Huber2017():
Expand All @@ -1715,4 +1715,4 @@ def Huber2017():
)


_species.get_dfe("Gamma_H17").register_qc(Huber2017())
_species.get_dfe("Gamma_H17").register_qc(Huber2017)
2 changes: 1 addition & 1 deletion stdpopsim/qc/PanTro.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@ def KuhlwilmPan():
)


_species.get_demographic_model("BonoboGhost_4K19").register_qc(KuhlwilmPan())
_species.get_demographic_model("BonoboGhost_4K19").register_qc(KuhlwilmPan)
2 changes: 1 addition & 1 deletion stdpopsim/qc/PapAnu.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ def WallOnePopPapio():
)


_species.get_demographic_model("SinglePopSMCpp_1W22").register_qc(WallOnePopPapio())
_species.get_demographic_model("SinglePopSMCpp_1W22").register_qc(WallOnePopPapio)
2 changes: 1 addition & 1 deletion stdpopsim/qc/PonAbe.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ def LockePongo():
)


_species.get_demographic_model("TwoSpecies_2L11").register_qc(LockePongo())
_species.get_demographic_model("TwoSpecies_2L11").register_qc(LockePongo)
24 changes: 10 additions & 14 deletions tests/test_dfes.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,24 +624,20 @@ def make_dfe(self, name):

def test_register_qc(self):
dfe = self.make_dfe("test")
dfe.register_qc(dfe)
assert dfe.qc_dfe == dfe
dfe.register_qc(lambda: dfe)
assert dfe.qc_dfe() == dfe

def test_already_registered(self):
dfe = self.make_dfe("test")
dfe.register_qc(dfe)
with pytest.raises(ValueError) as e_info:
dfe.register_qc(dfe)
assert str(e_info.value) == "QC DFE already registered for test."
dfe.register_qc(lambda: self.make_dfe("test"))
with pytest.raises(ValueError, match="already registered"):
dfe.register_qc(lambda: self.make_dfe("test"))

def test_bad_qc_dfe(self):
dfe = self.make_dfe("test")
for not_a_dfe in [None, 15, "Zigzag_1S14"]:
with pytest.raises(ValueError) as e_info:
dfe.register_qc(not_a_dfe)
assert (
str(e_info.value) == f"Cannot register non-DFE '{not_a_dfe}' as QC DFE."
)
for not_a_dfe_func in [None, 15, "Zigzag_1S14", dfe]:
with pytest.raises(ValueError, match="must be a function"):
dfe.register_qc(not_a_dfe_func)


@pytest.mark.skipif(IS_WINDOWS, reason="SLiM not available on windows")
Expand Down Expand Up @@ -713,7 +709,7 @@ class QcdCatalogDFETestMixin(CatalogDFETestMixin):

def test_mutation_types_match(self):
mt1 = self.dfe.mutation_types
mt2 = self.dfe.qc_dfe.mutation_types
mt2 = self.dfe.qc_dfe().mutation_types
assert len(mt1) == len(mt2)

for i in range(len(mt1)):
Expand All @@ -724,7 +720,7 @@ def test_mutation_types_match(self):

def test_proporitions_match(self):
p1 = self.dfe.proportions
p2 = self.dfe.qc_dfe.proportions
p2 = self.dfe.qc_dfe().proportions
assert np.allclose(p1, p2)


Expand Down
16 changes: 8 additions & 8 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,18 @@ class QcdCatalogDemographicModelTestMixin(CatalogDemographicModelTestMixin):

def test_qc_model_equal(self):
d1 = self.model.model
d2 = self.model.qc_model.model
d2 = self.model.qc_model().model
d1.assert_equivalent(d2, rel_tol=1e-5)
assert d1 != d2

def test_generation_time_match(self):
g1 = self.model.generation_time
g2 = self.model.qc_model.generation_time
g2 = self.model.qc_model().generation_time
assert g1 == g2

def test_mutation_rate_match(self):
u1 = self.model.mutation_rate
u2 = self.model.qc_model.mutation_rate
u2 = self.model.qc_model().mutation_rate
assert u1 == u2


Expand Down Expand Up @@ -115,19 +115,19 @@ def make_model(self, name):

def test_register_qc(self):
model = self.make_model("test")
model.register_qc(model)
model.register_qc(lambda: model)

def test_already_registered(self):
model = self.make_model("test")
model.register_qc(model)
model.register_qc(lambda: model)
with pytest.raises(ValueError):
model.register_qc(model)
model.register_qc(lambda: model)

def test_bad_qc_models(self):
model = self.make_model("test")
for not_a_model in [None, 15, "Zigzag_1S14"]:
for not_a_model_func in [None, 15, "Zigzag_1S14", model]:
with pytest.raises(ValueError):
model.register_qc(not_a_model)
model.register_qc(not_a_model_func)


class TestAllModels:
Expand Down