mcocdawc / chemcoord

A python module for manipulating cartesian and internal coordinates.
GNU Lesser General Public License v3.0
72 stars 19 forks source link

Numba deprecation warning #76

Closed ghutchis closed 5 months ago

ghutchis commented 1 year ago

Running the code with current numba yields the following warnings:

/opt/local/mambaforge/lib/python3.9/site-packages/numba/core/decorators.py:262: 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)
ghutchis commented 1 year ago

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

mcocdawc commented 1 year ago

Thank you very much for reporting this. I have to check if I can just change to numba.jit or if I relied on the overloading and it requires deeper architectural changes.

mcocdawc commented 1 year ago

A proper fix is is doable without architecture changes by following the instructions in your supplied link.

I will not do it yet though, because the use of isinstance inside a jitted function is still an experimental feature. Even in numba 0.57 I get a

 NumbaExperimentalFeatureWarning: Use of isinstance() detected. This is an experimental feature.

warning.

I don't want to break with earlier versions, where generated_jit is not yet deprecated, while a jitted isinstance is not yet supported, if it is not clear that jitted isinstance will become the correct replacement.

As soon as a clear successor of generated_jit emerges, I will switch.

For example their code:

@njit # NOTE: standard @njit decorator.
def select(x):
    if isinstance(x, float):
        return x + 1
    elif isinstance(x, str):
        return x + " the number one"
    else:
        raise TypeError("Unsupported Type")

@njit
def foo(x):
    return select(x)

print(foo(1.))
print(foo("a string"))

throws a warning about isinstance being experimental. So I will have replaced one warning with another warning.

klauspdoll commented 6 months ago

I have numba version 0.59.0 where this now stops with an error:

>>> import chemcoord as cc
[...truncated...]
chemcoord/cartesian_coordinates/_cart_transformation.py", line 6, in <module>
   from numba import jit, generated_jit
ImportError: cannot import name 'generated_jit' from 'numba'

This is consistent with the information Removal took place in version 0.59.0. at https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-generated-jit isinstance seems to be okay, the demo at this web page works.

mcocdawc commented 6 months ago

Sorry for answering so late to this issue. I was quite occupied with my defense two days ago. Now I am free again to do software maintenance and will take care of it. (In the case that you already fixed it yourself, I am also happily accepting PRs.)

mcocdawc commented 5 months ago

Solved now