pyPESTO icon indicating copy to clipboard operation
pyPESTO copied to clipboard

Conditional variable initialisation in `AmiciObjective.check_gradients_match_finite_differences`

Open m-philipps opened this issue 1 year ago • 3 comments

Gradient check for an AmiciObjective

pypesto_problem.objective.check_gradients_match_finite_differences(
        x=startpoints[0],
    )

invokes an error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/maren/pyPESTO/pypesto/objective/amici/amici.py", line 665, in check_gradients_match_finite_differences
    *args, x=x, x_free=x_free, **kwargs
                       ^^^^^^
UnboundLocalError: cannot access local variable 'x_free' where it is not associated with a value

This is because x_free is only created if the condition in line 651 is True.

Version 0.5.1

m-philipps avatar Oct 20 '24 15:10 m-philipps

Is there a point to inheriting the check_gradients_match_finite_differences in the scope of AmiciObjective. at all? Using the PEtab nominal parameter vector is only used for testing and that default behaviour should at least be documented.

m-philipps avatar Oct 20 '24 19:10 m-philipps

Linked to https://github.com/ICB-DCM/pyPESTO/issues/723

m-philipps avatar Oct 20 '24 21:10 m-philipps

Is there a point to inheriting the check_gradients_match_finite_differences in the scope of AmiciObjective. at all? Using the PEtab nominal parameter vector is only used for testing and that default behaviour should at least be documented.

From my point of view, this could be removed completely. There is no clear understanding of what should be given as nominal parameter, but most often this will be the optimized parameters, which is not the best location for the finite difference checks due to vanishing gradients.

dweindl avatar Oct 21 '24 06:10 dweindl

closing this for now, due to new release

PaulJonasJost avatar Nov 14 '25 18:11 PaulJonasJost