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

Fixes for Python 3.12, NumPy 2.0, and SciPy 1.14 #1050

Closed guyer closed 3 weeks ago

guyer commented 1 month ago

Fixes #1049 Fixes #997

wd15 commented 1 month ago

@guyer, you've broken Nix again!

guyer commented 1 month ago

@wd15, Nix is broken by design

wd15 commented 1 month ago

Nix passes in #1051 with a single tweak. Basically with the master branch with small change to flake.nix. Python still at 3.10.

wd15 commented 1 month ago

Nix runs and has some failures (see #1052) when testing this branch with updated Nix to 24.05 with Python 3.12 and Numpy 1.26.4. Latest version of release nixpkgs does not have Numpy 2.0.0, obviously.

wd15 commented 3 weeks ago

@guyer, you're not seeing this test failure anywhere, but on the Nix branch, right?

======================================================================
FAIL: CSR (fipy.matrices.scipyMatrix._ScipyMatrix)
Doctest: fipy.matrices.scipyMatrix._ScipyMatrix.CSR
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/nix/store/c7ycrgwv039nqglbif98yggx211sdbcl-python3-3.12.3/lib/python3.12/doctest.py", line 2249, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for fipy.matrices.scipyMatrix._ScipyMatrix.CSR
  File "/home/wd15/git/fipy/fipy/matrices/scipyMatrix.py", line 280, in CSR

----------------------------------------------------------------------
File "/home/wd15/git/fipy/fipy/matrices/scipyMatrix.py", line 302, in fipy.matrices.scipyMatrix._ScipyMatrix.CSR
Failed example:
    print(numerix.asarray(cols))
Expected:
    [0 1 2 1 2 0 2]
Got:
    [0 2 1 2 1 2 0]
----------------------------------------------------------------------
File "/home/wd15/git/fipy/fipy/matrices/scipyMatrix.py", line 304, in fipy.matrices.scipyMatrix._ScipyMatrix.CSR
Failed example:
    print(numerix.asarray(data))
Expected:
    [ 12.3         10.           3.           3.14159265   2.96
       2.5          2.2       ]
Got:
    [ 12.3          3.          10.           2.96         3.14159265
       2.2          2.5       ]

----------------------------------------------------------------------

This is with Numpy 1.26.4 and Scipy 1.13.0.

wd15 commented 3 weeks ago

This is with Numpy 1.26.4 and Scipy 1.13.0.

wd15 commented 3 weeks ago

@guyer, can I bring the changes from #1052 into this branch?

guyer commented 3 weeks ago

@guyer, you're not seeing this test failure anywhere, but on the Nix branch, right?

Nope

guyer commented 3 weeks ago

@guyer, can I bring the changes from #1052 into this branch?

@wd15, yes, please

wd15 commented 3 weeks ago

Next step might be to try and build a conda environment with the same numpy and scipy versions as the Nix build to see if it also fails that one test.

guyer commented 3 weeks ago

Next step might be to try and build a conda environment with the same numpy and scipy versions as the Nix build to see if it also fails that one test.

Agreed. I built such an environment on my Mac and get the same error:

python      3.12.4 | packaged by conda-forge | (main, Jun 17 2024, 10:13:44) [Clang 16.0.6 ]
fipy        3.4.4+41.ge25c210ec
numpy       1.26.4
pysparse    not installed
scipy       1.13.0
matplotlib  3.8.4
mpi4py      not installed
petsc4py    not installed
pyamgx      not installed
PyTrilinos  not installed
mayavi      4.8.2
gmsh        4.12.2
solver      scipy

 :
 :

======================================================================
FAIL: CSR (fipy.matrices.scipyMatrix._ScipyMatrix)
Doctest: fipy.matrices.scipyMatrix._ScipyMatrix.CSR
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/guyer/mambaforge-arm/envs/nix-scipy/lib/python3.12/doctest.py", line 2256, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for fipy.matrices.scipyMatrix._ScipyMatrix.CSR
  File "/Users/guyer/Documents/research/FiPy/fipy/fipy/matrices/scipyMatrix.py", line 280, in CSR

----------------------------------------------------------------------
File "/Users/guyer/Documents/research/FiPy/fipy/fipy/matrices/scipyMatrix.py", line 302, in fipy.matrices.scipyMatrix._ScipyMatrix.CSR
Failed example:
    print(numerix.asarray(cols))
Expected:
    [0 1 2 1 2 0 2]
Got:
    [0 2 1 2 1 2 0]
----------------------------------------------------------------------
File "/Users/guyer/Documents/research/FiPy/fipy/fipy/matrices/scipyMatrix.py", line 304, in fipy.matrices.scipyMatrix._ScipyMatrix.CSR
Failed example:
    print(numerix.asarray(data))
Expected:
    [ 12.3         10.           3.           3.14159265   2.96
       2.5          2.2       ]
Got:
    [ 12.3          3.          10.           2.96         3.14159265
       2.2          2.5       ]

----------------------------------------------------------------------
Ran 541 tests in 78.140s

FAILED (failures=1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Skipped 38 doctest examples because neither `lsmlib` nor `skfmm` can be found on the $PATH
Skipped 1 doctest examples because `skfmm` must be used to run some tests
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
guyer commented 3 weeks ago

SciPy 1.13.0, in combination with all versions of numpy 1.26.x or numpy 2.0.0, exhibits this issue under Python 3.12 (earlier numpy not an option)

guyer commented 3 weeks ago

The issue goes away with SciPy 1.13.1, with any compatible numpy. Possibly fixed by scipy/scipy#20670.

wd15 commented 3 weeks ago

The issue goes away with SciPy 1.13.1, with any compatible numpy. Possibly fixed by scipy/scipy#20670.

Oh, great. Let me see if I can get a newer scipy into the mix.