fix: Error handling for fits and root finding with numpy instead of autograd.numpy

improved. Tests added.
This commit is contained in:
Fabian Joswig 2022-03-02 15:10:07 +00:00
parent 7f5989dfb9
commit b14314b424
4 changed files with 53 additions and 10 deletions

View file

@ -31,7 +31,10 @@ def find_root(d, func, guess=1.0, **kwargs):
# Error propagation as detailed in arXiv:1809.01289
dx = jacobian(func)(root[0], d.value)
da = jacobian(lambda u, v: func(v, u))(d.value, root[0])
try:
da = jacobian(lambda u, v: func(v, u))(d.value, root[0])
except TypeError:
raise Exception("It is required to use autograd.numpy instead of numpy within root functions, see the documentation for details.") from None
deriv = - da / dx
res = derived_observable(lambda x, **kwargs: (x[0] + np.finfo(np.float64).eps) / (d.value + np.finfo(np.float64).eps) * root[0], [d], man_grad=[deriv])