From 157fd81f04bd866127bc75f46887c4ce7c43566d Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Mon, 16 Sep 2024 19:46:09 +0200 Subject: [PATCH] PEtab import: Priors aren't support -> raise (#384) So far, parPE doesn't support priors. Most of the PEtab import was written before priors were introduced. That's why unfortunately there wasn't any warning/error in place so far. --- benchmark_collection/all.sh | 5 +++-- python/parpe/hdf5_pe_input.py | 25 ++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/benchmark_collection/all.sh b/benchmark_collection/all.sh index d0737d04..6cab7283 100755 --- a/benchmark_collection/all.sh +++ b/benchmark_collection/all.sh @@ -13,7 +13,6 @@ Borghans_BiophysChem1997 Crauste_CellSystems2017 Elowitz_Nature2000 Fujita_SciSignal2010 -Schwen_PONE2014 Sneyd_PNAS2002 Weber_BMC2015 Zheng_PNAS2012 @@ -47,7 +46,9 @@ Zheng_PNAS2012 # Brannmark_JBC2010 FAILED: Expected llh 283.778227541074, got nllh 141.889034 # Lucarelli_CellSystems2018 # Fiedler_BMC2016 FAILED: Expected llh -117.16780323362, got nllh 109391.496205 - +# +# Unsupported priors: +# Schwen_PONE2014 for model_name in $expected_to_work; do printf '=%.0s' {1..20} printf %s "${model_name}" diff --git a/python/parpe/hdf5_pe_input.py b/python/parpe/hdf5_pe_input.py index 9957dd2d..7e5f35a9 100644 --- a/python/parpe/hdf5_pe_input.py +++ b/python/parpe/hdf5_pe_input.py @@ -93,9 +93,6 @@ def __init__(self, self.petab_problem: petab.Problem = petab_problem self.amici_model: amici.Model = amici_model - # ensure we have valid inputs - petab.lint_problem(self.petab_problem) - # index for no reference/preequilibration condition self.NO_PREEQ_CONDITION_IDX: int = NO_PREEQ_CONDITION_IDX @@ -105,6 +102,28 @@ def __init__(self, # hdf5 dataset compression self.compression = "gzip" + self._check_support() + + def _check_support(self): + """ + Check if the model is supported by parPE + """ + # ensure we have valid inputs + petab.lint_problem(self.petab_problem) + + # We can't handle priors yet + # Initialization priors would work in principle when we sample + # starting points using petab. However, the current parpe C++ + # resampling would ignore the initialization prior. + # And they wouldn't be supported for hierarchical optimization. + parameter_df = self.petab_problem.parameter_df + for col_id in [ + ptc.INITIALIZATION_PRIOR_TYPE, ptc.INITIALIZATION_PRIOR_PARAMETERS, + ptc.OBJECTIVE_PRIOR_TYPE, ptc.OBJECTIVE_PRIOR_PARAMETERS + ]: + if (col := parameter_df.get(col_id)) is not None and col.notna().any(): + raise NotImplementedError("Priors are not supported yet.") + def generate_file(self, hdf5_file_name: str) -> None: """ Create the output file