diff --git a/tests/benchmark-models/test_petab_benchmark.py b/tests/benchmark-models/test_petab_benchmark.py index 7af50087d5..eb6bf1ccb1 100644 --- a/tests/benchmark-models/test_petab_benchmark.py +++ b/tests/benchmark-models/test_petab_benchmark.py @@ -101,8 +101,8 @@ class GradientCheckSettings: rng_seed=1, ) settings["Sneyd_PNAS2002"] = GradientCheckSettings( - atol_sim=1e-16, - rtol_sim=1e-10, + atol_sim=1e-15, + rtol_sim=1e-12, atol_check=1e-5, rtol_check=1e-4, ) @@ -115,6 +115,11 @@ class GradientCheckSettings: settings["Brannmark_JBC2010"] = GradientCheckSettings( ss_sensitivity_mode=amici.SteadyStateSensitivityMode.integrationOnly, ) +settings["Borghans_BiophysChem1997"] = GradientCheckSettings( + rng_seed=2, + atol_check=1e-5, + rtol_check=1e-3, +) def assert_gradient_check_success( @@ -123,6 +128,7 @@ def assert_gradient_check_success( point: np.array, atol: float, rtol: float, + always_print: bool = False, ) -> None: if not derivative.df.success.all(): raise AssertionError( @@ -135,7 +141,7 @@ def assert_gradient_check_success( ) check_result = check(rtol=rtol, atol=atol) - if check_result.success is True: + if check_result.success is True and not always_print: return df = check_result.df @@ -144,12 +150,22 @@ def assert_gradient_check_success( max_adiff = df["abs_diff"].max() max_rdiff = df["rel_diff"].max() with pd.option_context("display.max_columns", None, "display.width", None): + message = ( + f"Gradient check failed:\n{df}\n\n" + f"Maximum absolute difference: {max_adiff}\n" + f"Maximum relative difference: {max_rdiff}" + ) + + if check_result.success is False: raise AssertionError( f"Gradient check failed:\n{df}\n\n" f"Maximum absolute difference: {max_adiff}\n" f"Maximum relative difference: {max_rdiff}" ) + if always_print: + print(message) + @pytest.mark.filterwarnings( "ignore:divide by zero encountered in log", @@ -205,7 +221,7 @@ def test_benchmark_gradient(model, scale, sensitivity_method, request): amici_solver = amici_model.getSolver() amici_solver.setAbsoluteTolerance(cur_settings.atol_sim) amici_solver.setRelativeTolerance(cur_settings.rtol_sim) - amici_solver.setMaxSteps(int(1e5)) + amici_solver.setMaxSteps(2 * 10**5) amici_solver.setSensitivityMethod(sensitivity_method) # TODO: we should probably test all sensitivity modes amici_model.setSteadyStateSensitivityMode(cur_settings.ss_sensitivity_mode) @@ -278,6 +294,7 @@ def test_benchmark_gradient(model, scale, sensitivity_method, request): point, rtol=cur_settings.rtol_check, atol=cur_settings.atol_check, + always_print=True, )