diff --git a/tests/benchmark-models/test_petab_benchmark.py b/tests/benchmark-models/test_petab_benchmark.py index 995017610d..7af50087d5 100644 --- a/tests/benchmark-models/test_petab_benchmark.py +++ b/tests/benchmark-models/test_petab_benchmark.py @@ -72,6 +72,7 @@ class GradientCheckSettings: ss_sensitivity_mode: amici.SteadyStateSensitivityMode = ( amici.SteadyStateSensitivityMode.integrateIfNewtonFails ) + noise_level: float = 0.05 settings = defaultdict(GradientCheckSettings) @@ -105,7 +106,7 @@ class GradientCheckSettings: atol_check=1e-5, rtol_check=1e-4, ) -# NOTE: Newton method fails badly for this model +# NOTE: Newton method fails badly with ASA for this model settings["Blasi_CellSystems2016"] = GradientCheckSettings( atol_check=1e-12, rtol_check=1e-4, @@ -193,10 +194,7 @@ def test_benchmark_gradient(model, scale, sensitivity_method, request): petab.flatten_timepoint_specific_output_overrides(petab_problem) # Only compute gradient for estimated parameters. - parameter_df_free = petab_problem.parameter_df.loc[ - petab_problem.x_free_ids - ] - parameter_ids = list(parameter_df_free.index) + parameter_ids = petab_problem.x_free_ids cur_settings = settings[model] # Setup AMICI objects. @@ -209,6 +207,7 @@ def test_benchmark_gradient(model, scale, sensitivity_method, request): amici_solver.setRelativeTolerance(cur_settings.rtol_sim) amici_solver.setMaxSteps(int(1e5)) amici_solver.setSensitivityMethod(sensitivity_method) + # TODO: we should probably test all sensitivity modes amici_model.setSteadyStateSensitivityMode(cur_settings.ss_sensitivity_mode) amici_function, amici_derivative = simulate_petab_to_cached_functions( @@ -224,23 +223,20 @@ def test_benchmark_gradient(model, scale, sensitivity_method, request): # cache=not debug, cache=False, ) - noise_level = 0.05 np.random.seed(cur_settings.rng_seed) # find a point where the derivative can be computed for _ in range(5): if scale: - point = np.asarray( - list( - petab_problem.scale_parameters( - dict(parameter_df_free.nominalValue) - ).values() - ) + point = petab_problem.x_nominal_free_scaled + point_noise = ( + np.random.randn(len(point)) * cur_settings.noise_level ) - point_noise = np.random.randn(len(point)) * noise_level else: - point = parameter_df_free.nominalValue.values - point_noise = np.random.randn(len(point)) * point * noise_level + point = petab_problem.x_nominal_free_unscaled + point_noise = ( + np.random.randn(len(point)) * point * cur_settings.noise_level + ) point += point_noise # avoid small gradients at nominal value try: