usnistgov / fipy

FiPy is a Finite Volume PDE solver written in Python
http://pages.nist.gov/fipy/en/latest
Other
489 stars 148 forks source link

Numpy 2.0.0 breaks things #1049

Closed wd15 closed 3 weeks ago

wd15 commented 1 month ago

Running with Numpy 2.0.0 breaks things. See fipy.log.

Test failures like this:

   Traceback (most recent call last):                                                                                                                                                         
      File "/nix/store/ffy6s77zhixlwvzprz5j0zj4ma8n8h2q-python3-3.11.8/lib/python3.11/doctest.py", line 1355, in __run                                                                         
        exec(compile(example.source, filename, "single",                                                                                                                                       
...                                                                                             
      File "/nix/store/4xbcd56id9azry5srn5fwh83qlin9lgb-python3-3.11.8-env/lib/python3.11/site-packages/fipy/variables/meshVariable.py", line 99, in __init__                                  
        dtype = numerix.obj2sctype(value)                                                                                                                                                      
                ^^^^^^^^^^^^^^^^^^                                                                                                                                                             
    AttributeError: module 'fipy.tools.numerix' has no attribute 'obj2sctype'

Versions are as follows:

python 3.11.8 (main, Feb 6 2024, 21:21:21) [GCC 12.3.0] fipy 3.4.4 numpy 2.0.0 pysparse not installed scipy 1.13.1 matplotlib 3.9.0

guyer commented 1 month ago

numpy.obj2sctype was deprecated in numpy 2.0.0. It looks like its original usage of converting to numpy's internal data types was deprecated in numpy 1.20.0.

Unfortunately, the proposed replacement, np.dtype(obj).type, cannot be used as FiPy used numpy.obj2sctype, e.g., with numpy 1.24.3:

>>> np.obj2sctype(np.array([1.0, 2.0]))
numpy.float64

but, with numpy 1.24.3 or 2.0.0,

>>> np.dtype(np.array([1.0, 2.0])).type
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Cannot construct a dtype from an array
>>> np.array([1.0, 2.0]).dtype
dtype('float64')

works with either, but I'm not sure if that covers all the cases where we used it.

guyer commented 1 month ago

I think I've fixed these issues in #1050