Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numba warnings #110

Closed
kp992 opened this issue Dec 3, 2023 · 8 comments · Fixed by #112
Closed

Numba warnings #110

kp992 opened this issue Dec 3, 2023 · 8 comments · Fixed by #112

Comments

@kp992
Copy link

kp992 commented Dec 3, 2023

NumbaDeprecationWarning: numba.generated_jit is deprecated. Please see the documentation at: https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-generated-jit for more information and advice on a suitable replacement.
  warnings.warn(msg, NumbaDeprecationWarning)
@freol35241
Copy link

freol35241 commented Feb 6, 2024

Also this one shows up when using eval_splines:

NumbaPendingDeprecationWarning: Code using Numba extension API maybe depending on 'old_style' error-capturing, which is deprecated and will be replaced by 'new_style' in a future release. See details at https://numba.readthedocs.io/en/latest/reference/deprecation.html#deprecation-of-old-style-numba-captured-errors
Exception origin:
  File "...\interpolation\splines\eval_splines.py", line 106, in __eval_spline
    kk = (order).literal_value

@freol35241
Copy link

And further, generated_jit is now removed as of Numba 0.59.0. This mean useres of interpolaiton.py is unfortunately stuck at Numba < 0.59.0.

@mmcky
Copy link

mmcky commented Feb 21, 2024

@albop taking a closer look at the code in interpolation/multilinear/fungen.py for example do you see a reason why generated_jit can't be replaced by a direct njit?

I am reading https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-generated-jit

otherwise we can move some of this over to use overload

@albop
Copy link
Member

albop commented Feb 22, 2024

I used to like this function...
Anyway @mmcky, last time I touched the library I found a few bugs in numba (https://github.com/numba/numba/issues?q=is%3Aissue+is%3Aopen+albop ), stopped there and pledged to return to it after upstream was fixed.
These bugs were not directly related to the use of generated_jit though. I can look into it around the end of next week and make a release which is compatible with latest numba.
Reason one cannot use njit is because specific code is generated for specific dimensions combinations of inputs. Yes, overload should work

@mmcky
Copy link

mmcky commented Mar 13, 2024

@albop @kp992 I have been reading the deprecation notice this morning.

I think this is what is needed for all the generated_jit calls but it seems like a lot of boiler plate.

# returns the index of a 1d point along a 1d dimension (python)
def py_get_index(gc, x):
    if gc == t_coord:
        # regular coordinate
        def fun(gc, x):
            δ = (gc[1] - gc[0]) / (gc[2] - 1)
            d = x - gc[0]
            ii = d // δ
            i = int(ii)
            i = clamp(i, 0, gc[2] - 2)
            r = d - i * δ
            λ = r / δ
            return (i, λ)

        return fun
    else:
        # irregular coordinate
        def fun(gc, x):
            N = gc.shape[0]
            i = int(np.searchsorted(gc, x)) - 1
            i = clamp(i, 0, N - 2)
            λ = (x - gc[i]) / (gc[i + 1] - gc[i])
            return (i, λ)

        return fun

@overload(py_get_index)
def ol_get_index(gc, x):
    if gc == t_coord:
        # regular coordinate
        def fun(gc, x):
            δ = (gc[1] - gc[0]) / (gc[2] - 1)
            d = x - gc[0]
            ii = d // δ
            i = int(ii)
            i = clamp(i, 0, gc[2] - 2)
            r = d - i * δ
            λ = r / δ
            return (i, λ)

        return fun
    else:
        # irregular coordinate
        def fun(gc, x):
            N = gc.shape[0]
            i = int(np.searchsorted(gc, x)) - 1
            i = clamp(i, 0, N - 2)
            λ = (x - gc[i]) / (gc[i + 1] - gc[i])
            return (i, λ)

        return fun

@njit
def get_index(gc, x):
    return py_get_index(gc, x)

rather than the simpler generated_jit. Am I understanding this correctly? I think the types in the python only function should be python types so maybe that should be tuple(float64, float64, int64)) but using python types?

@oyamad
Copy link
Contributor

oyamad commented Mar 13, 2024

If get_index will only be called from inside a jitted function, it should be simpler like this (if I remember correctly from QuantEcon/QuantEcon.py#701):

def get_index(gc, x):  # This is called from pure Python
    pass


@overload(get_index)  # This is called from inside a jitted function
def ol_get_index(gc, x):
    if gc == t_coord:
        # regular coordinate
        def fun(gc, x):
            δ = (gc[1] - gc[0]) / (gc[2] - 1)
            d = x - gc[0]
            ii = d // δ
            i = int(ii)
            i = clamp(i, 0, gc[2] - 2)
            r = d - i * δ
            λ = r / δ
            return (i, λ)

        return fun
    else:
        # irregular coordinate
        def fun(gc, x):
            N = gc.shape[0]
            i = int(np.searchsorted(gc, x)) - 1
            i = clamp(i, 0, N - 2)
            λ = (x - gc[i]) / (gc[i + 1] - gc[i])
            return (i, λ)

        return fun

@mmcky
Copy link

mmcky commented Mar 13, 2024

thanks @oyamad for that link. That is really helpful.

@kp992
Copy link
Author

kp992 commented Mar 13, 2024

Thanks @mmcky and @oyamad. I have tried both the approaches, but the tests are failing. I tried to fix interpolation.multilinear first using #110 (comment), but that fails for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants