jonathf / chaospy

Chaospy - Toolbox for performing uncertainty quantification.
https://chaospy.readthedocs.io/
MIT License
434 stars 87 forks source link

chaospy does not support numpy 2.0 #424

Open mbaudin47 opened 4 weeks ago

mbaudin47 commented 4 weeks ago

Describe the bug Importing the module makes Python fail when chaospy is installed from pip using numpy 2.0. It is likely to be a problem related to the support of numpy 2.0 in numpoly.

To Reproduce Provide a minimal code example that reproduces the error.

import chaospy

Expected behavior A clear and concise description of what you expected to happen. If an exception is raised, please provide the exception traceback.

Traceback (most recent call last):
  File "/home/circleci/project/script.py", line 13, in <module>
    import chaospy
  File "/home/circleci/.pyenv/versions/3.10.14/lib/python3.10/site-packages/chaospy/__init__.py", line 11, in <module>
    from numpoly import *
  File "/home/circleci/.pyenv/versions/3.10.14/lib/python3.10/site-packages/numpoly/__init__.py", line 34, in <module>
    from .array_function import *
  File "/home/circleci/.pyenv/versions/3.10.14/lib/python3.10/site-packages/numpoly/array_function/__init__.py", line 70, in <module>
    from .prod import prod
  File "/home/circleci/.pyenv/versions/3.10.14/lib/python3.10/site-packages/numpoly/array_function/prod.py", line 13, in <module>
    @implements(numpy.prod, numpy.product)
  File "/home/circleci/.pyenv/versions/3.10.14/lib/python3.10/site-packages/numpy/__init__.py", line 410, in __getattr__
    raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'product'

Desktop (please complete the following information):

Additional context Add any other context about the problem here. I installed chaospy using pip. Here are the versions used from the log:

chaospy-4.3.15-py3-none-any.whl (254 kB)
numpoly-1.2.12-py3-none-any.whl (148 kB)
numpy-2.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (19.3 MB)
mbaudin47 commented 4 weeks ago

It seems that the bug was already fixed in numpoly by @gboehl:

https://github.com/jonathf/numpoly/commit/ce854b4e24293e594238d06bbf3ad43fdf370896

jonathf commented 4 weeks ago

I just updated numpoly. Update to 1.2.13 and this should be resolved.

Let me know if it doesn't solve the issue.

mbaudin47 commented 4 weeks ago

Thank you very much for solving that issue. It seems to me that the library now fails a little later, with generate_quadrature:

    nodes, weights = chaospy.generate_quadrature(
  File "/home/circleci/.pyenv/versions/3.10.14/lib/python3.10/site-packages/chaospy/quadrature/frontend.py", line 152, in generate_quadrature
    return sparse_grid(
  File "/home/circleci/.pyenv/versions/3.10.14/lib/python3.10/site-packages/chaospy/quadrature/sparse_grid.py", line 81, in sparse_grid
    x_lookup, w_lookup = _construct_lookup(
  File "/home/circleci/.pyenv/versions/3.10.14/lib/python3.10/site-packages/chaospy/quadrature/sparse_grid.py", line 144, in _construct_lookup
    (abscissas,), weights = chaospy.generate_quadrature(
  File "/home/circleci/.pyenv/versions/3.10.14/lib/python3.10/site-packages/chaospy/quadrature/frontend.py", line 171, in generate_quadrature
    abscissas, weights = _generate_quadrature(
  File "/home/circleci/.pyenv/versions/3.10.14/lib/python3.10/site-packages/chaospy/quadrature/frontend.py", line 287, in _generate_quadrature
    abscissas, weights = quad_function(order, dist, **parameters)
  File "/home/circleci/.pyenv/versions/3.10.14/lib/python3.10/site-packages/chaospy/quadrature/gaussian.py", line 81, in gaussian
    coefficients = chaospy.construct_recurrence_coefficients(
  File "/home/circleci/.pyenv/versions/3.10.14/lib/python3.10/site-packages/chaospy/recurrence/frontend.py", line 117, in construct_recurrence_coefficients
    coeffs, _, _ = stieltjes(order, dist, rule=rule, tolerance=tolerance)
  File "/home/circleci/.pyenv/versions/3.10.14/lib/python3.10/site-packages/chaospy/recurrence/stieltjes.py", line 68, in stieltjes
    return analytical_stieltjes(order=order, dist=dist)
  File "/home/circleci/.pyenv/versions/3.10.14/lib/python3.10/site-packages/chaospy/recurrence/stieltjes.py", line 165, in analytical_stieltjes
    coeffs = dist.ttr(mom_order)
  File "/home/circleci/.pyenv/versions/3.10.14/lib/python3.10/site-packages/chaospy/distributions/baseclass/distribution.py", line 721, in ttr
    out[:, idx, idy] = self._get_ttr(kloc_[idx], idx)
  File "/home/circleci/.pyenv/versions/3.10.14/lib/python3.10/site-packages/chaospy/distributions/baseclass/distribution.py", line 735, in _get_ttr
    alpha = numpy.asfarray(alpha).item()
  File "/home/circleci/.pyenv/versions/3.10.14/lib/python3.10/site-packages/numpy/__init__.py", line 397, in __getattr__
    raise AttributeError(
AttributeError: `np.asfarray` was removed in the NumPy 2.0 release. Use `np.asarray` with a proper dtype instead.. Did you mean: 'asarray'?

Is that correct from your point of view?

gboehl commented 4 weeks ago

I resolved this issue in #425 but there are some other checks that are still failing.