From e28475f7b41528fff1a360b20ef09e9286205e87 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Mon, 20 Oct 2025 22:01:28 +0200 Subject: [PATCH] Check simulation tables Related to #278. --- src/python/test/test_base.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/python/test/test_base.py b/src/python/test/test_base.py index 282a4f6..54767bd 100644 --- a/src/python/test/test_base.py +++ b/src/python/test/test_base.py @@ -1,6 +1,9 @@ """Basic tests.""" +import pytest import benchmark_models_petab as models +from petab.v1.calculate import calculate_llh +import pandas as pd def test_constants(): @@ -19,3 +22,35 @@ def test_get_problem(): def test_get_simulation_df(): assert models.get_simulation_df("Elowitz_Nature2000").empty is False assert models.get_simulation_df("not a problem name") is None + + +@pytest.mark.parametrize("problem_id", models.MODELS) +def test_can_calculate_llh_from_simulation_df(problem_id): + """Test whether log-likelihood can be calculated from the simulation df.""" + problem = models.get_problem(problem_id) + sim_df = models.get_simulation_df(problem_id) + + if sim_df is None: + pytest.skip(f"No simulation table for problem {problem_id}") + + try: + calculate_llh( + observable_dfs=problem.observable_df, + measurement_dfs=problem.measurement_df, + parameter_dfs=problem.parameter_df, + simulation_dfs=sim_df, + ) + except Exception: + with pd.option_context( + "display.max_rows", + None, + "display.max_columns", + None, + "display.width", + 1000, + ): + print("Simulation table:") + print(sim_df) + print("Measurement table:") + print(problem.measurement_df) + raise