sagemath / sage

Main repository of SageMath. Now open for Issues and Pull Requests.
https://www.sagemath.org
Other
1.19k stars 411 forks source link

numpy 1.23.x #34110

Closed mkoeppe closed 1 year ago

mkoeppe commented 2 years ago

(split out from #34081)

https://numpy.org/doc/stable/release/1.23.0-notes.html# (released)

The upgrade looks harmless.

1.23.x requires GCC >= 6.5. (This has been documented in https://github.com/numpy/numpy/pull/22155 - to be included in 1.23.3.)

We set #34266 as a dependency, which increases our requirement from GCC >= 6.3 to GCC >= 8)

Previous update:

32423 Update numpy to 1.22.x, scipy 1.8.x, networkx 2.8.x

Depends on #34266

CC: @sagetrac-tmonteil

Component: packages: standard

Author: Matthias Koeppe

Branch/Commit: 03fad7d

Reviewer: Dima Pasechnik, John Palmieri

Issue created by migration from https://trac.sagemath.org/ticket/34110

mkoeppe commented 2 years ago

Branch: u/mkoeppe/numpy_1_23

mkoeppe commented 2 years ago

Commit: d87212c

mkoeppe commented 2 years ago

Last 10 new commits:

e1998daMerge #32423
507fc2ebuild/pkgs/numpy: Update to 1.23.0
58d62f4build/bin/write-dockerfile.sh: ADD src/VERSION.txt
99f3617Merge #34017
3fab415build/pkgs/numpy: Switch to using .tar.gz
443b3d3build/pkgs/numpy/spkg-install.in: Fix 32bit build on x86_64
9cd5ea6Merge #34017
ee79c2ebuild/pkgs/numpy/spkg-install.in: Fix 32bit build on x86_64 (fixup)
2534f5abuild/pkgs/numpy/patches/21891.patch: New
d87212cMerge #32423
mkoeppe commented 2 years ago

Dependencies: #32423

mkoeppe commented 1 year ago

Reviewer: https://github.com/mkoeppe/sage/actions/runs/2611393906, https://github.com/mkoeppe/sage/actions/runs/2611393910

mkoeppe commented 1 year ago
comment:4

On debian-stretch-standard (https://github.com/mkoeppe/sage/runs/7184259105?check_suite_focus=true):

In file included from numpy/core/src/common/simd/avx512/avx512.h:75:0,
                   from numpy/core/src/common/simd/simd.h:50,
                   from /sage/local/var/lib/sage/venv-python3.10.3/var/tmp/sage/build/numpy-1.23.0/src/numpy/core/src/npysort/x86-qsort.dispatch.cpp:17,
                   from build/src.linux-x86_64-3.10/numpy/core/src/npysort/x86-qsort.dispatch.avx512_skx.cpp:21:
  numpy/core/src/common/simd/avx512/arithmetic.h: In function 'npy_uint32 npyv_reducemax_u32(npyv_u32)':
  numpy/core/src/common/simd/avx512/arithmetic.h:387:89: error: invalid conversion from 'int' to '_MM_PERM_ENUM' [-fpermissive]
           npyv_u32 a3 = _mm512_max_epu32(a2, _mm512_shuffle_epi32(a2, (1<<6 | 0<<4 | 3<<2 | 2)));
                                                                       ~~~~~~~~~~~~~~~~~~~~^~~~
...
 In file included from build/src.linux-x86_64-3.10/numpy/core/src/npysort/x86-qsort.dispatch.avx512_skx.cpp:21:0:
  /sage/local/var/lib/sage/venv-python3.10.3/var/tmp/sage/build/numpy-1.23.0/src/numpy/core/src/npysort/x86-qsort.dispatch.cpp: In function 'npy_int partition_vec(type_t*, npy_intp, npy_intp, zmm_t, zmm_t, zmm_t*, zmm_t*)':
  /sage/local/var/lib/sage/venv-python3.10.3/var/tmp/sage/build/numpy-1.23.0/src/numpy/core/src/npysort/x86-qsort.dispatch.cpp:654:64: error: there are no arguments to '_knot_mask16' that depend on a template parameter, so a declaration of '_knot_mask16' must be available [-fpermissive]
       vtype::mask_compressstoreu(arr + left, _knot_mask16(gt_mask), curr_vec);
                                                                  ^

(regression from numpy 1.22.x). Reported at https://github.com/numpy/numpy/issues/21920

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Changed commit from d87212c to 8f5860a

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Branch pushed to git repo; I updated commit sha1. New commits:

4cce3efMerge tag '9.7.beta4' into t/34110/numpy_1_23
8f5860abuild/pkgs/numpy: Update to 1.23.1
mkoeppe commented 1 year ago
comment:7

ubuntu-trusty-toolchain-gcc_9 (https://github.com/mkoeppe/sage/runs/7532140899?check_suite_focus=true) and other ubuntu releases

sage -t --random-seed=291926986539572225544641036716487640141 src/sage/matrix/matrix_double_dense.pyx
**********************************************************************
File "src/sage/matrix/matrix_double_dense.pyx", line 3642, in sage.matrix.matrix_double_dense.Matrix_double_dense.exp
Failed example:
    A.exp()  # tol 1e-15
Expected:
    [51.968956198705044  74.73656456700327]
    [112.10484685050491 164.07380304920997]
Got:
    [ 51.96895619870499  74.73656456700321]
    [112.10484685050481 164.07380304920983]
Tolerance exceeded in 1 of 4:
    51.968956198705044 vs 51.96895619870499, tolerance 2e-15 > 1e-15
**********************************************************************
File "src/sage/matrix/matrix_double_dense.pyx", line 3655, in sage.matrix.matrix_double_dense.Matrix_double_dense.exp
Failed example:
    A.exp()   # tol 1e-15
Expected:
    [51.968956198705044  74.73656456700327]
    [112.10484685050491 164.07380304920997]
Got:
    [ 51.96895619870499  74.73656456700321]
    [112.10484685050481 164.07380304920983]
Tolerance exceeded in 1 of 4:
    51.968956198705044 vs 51.96895619870499, tolerance 2e-15 > 1e-15
**********************************************************************

sage -t --random-seed=291926986539572225544641036716487640141 src/sage/symbolic/constants_c_impl.pxi
**********************************************************************
File "src/sage/symbolic/constants_c_impl.pxi", line 164, in sage.symbolic.constants_c_impl.E.__pow__
Failed example:
    e^A  # rel tol 1e-15
Expected:
    [51.968956198705044  74.73656456700327]
    [112.10484685050491 164.07380304920997]
Got:
    [ 51.96895619870499  74.73656456700321]
    [112.10484685050481 164.07380304920983]
Tolerance exceeded in 1 of 4:
    51.968956198705044 vs 51.96895619870499, tolerance 2e-15 > 1e-15
mkoeppe commented 1 year ago

Changed reviewer from https://github.com/mkoeppe/sage/actions/runs/2611393906, https://github.com/mkoeppe/sage/actions/runs/2611393910 to https://github.com/mkoeppe/sage/actions/runs/2748565810, https://github.com/mkoeppe/sage/actions/runs/2743631299

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Branch pushed to git repo; I updated commit sha1. New commits:

7aec01asrc/sage/matrix/matrix_double_dense.pyx, src/sage/symbolic/constants_c_impl.pxi: Increase tolerances for RDF matrix exp
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Changed commit from 8f5860a to 7aec01a

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Changed commit from 7aec01a to 8f5860a

mkoeppe commented 1 year ago

Changed dependencies from #32423 to #34266

mkoeppe commented 1 year ago
comment:11

Replying to @mkoeppe:

On debian-stretch-standard

This platform is dropped in #34266, I've set it as a dependency

mkoeppe commented 1 year ago

Description changed:

--- 
+++ 
@@ -2,7 +2,11 @@

 ​https://numpy.org/doc/stable/release/1.23.0-notes.html# (released)

-The upgrade looks harmless
+The upgrade looks harmless.
+
+1.23.x requires GCC >= 6.5. (This has been documented in https://github.com/numpy/numpy/pull/22155 - to be included in 1.23.3.)
+
+We set #34266 as a dependency, which increases our requirement from GCC >= 6.3 to GCC >= 8)

 Previous update:
jhpalmieri commented 1 year ago
comment:13

On OS X + various homebrew packages, I am getting two doctest failures:

File "src/sage/modules/vector_double_dense.pyx", line 405, in sage.modules.vector_double_dense.Vector_double_dense.norm
Failed example:
    v.norm(p=6)
Expected:
    8.744039097...
Got:
    doctest:warning
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/bin/sage-runtests", line 154, in <module>
        err = DC.run()
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/sage/doctest/control.py", line 1384, in run
        self.run_doctests()
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/sage/doctest/control.py", line 1059, in run_doctests
        self.dispatcher.dispatch()
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/sage/doctest/forker.py", line 2021, in dispatch
        self.parallel_dispatch()
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/sage/doctest/forker.py", line 1916, in parallel_dispatch
        w.start()  # This might take some time
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/sage/doctest/forker.py", line 2190, in start
        super().start()
      File "/usr/local/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/process.py", line 121, in start
        self._popen = self._Popen(self)
      File "/usr/local/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/context.py", line 224, in _Popen
        return _default_context.get_context().Process._Popen(process_obj)
      File "/usr/local/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/context.py", line 277, in _Popen
        return Popen(process_obj)
      File "/usr/local/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_fork.py", line 19, in __init__
        self._launch(process_obj)
      File "/usr/local/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_fork.py", line 71, in _launch
        code = process_obj._bootstrap(parent_sentinel=child_r)
      File "/usr/local/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
        self.run()
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/sage/doctest/forker.py", line 2162, in run
        task(self.options, self.outtmpfile, msgpipe, self.result_queue)
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/sage/doctest/forker.py", line 2492, in __call__
        doctests, extras = self._run(runner, options, results)
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/sage/doctest/forker.py", line 2544, in _run
        result = runner.run(test)
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/sage/doctest/forker.py", line 866, in run
        return self._run(test, compileflags, out)
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/sage/doctest/forker.py", line 695, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/sage/doctest/forker.py", line 1093, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.modules.vector_double_dense.Vector_double_dense.norm[3]>", line 1, in <module>
        v.norm(p=Integer(6))
      File "<__array_function__ internals>", line 180, in norm
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/local/var/lib/sage/venv-python3.9/lib/python3.9/site-packages/numpy/linalg/linalg.py", line 2566, in norm
        ret **= reciprocal(ord, dtype=ret.dtype)
      File "/usr/local/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/warnings.py", line 109, in _showwarnmsg
        sw(msg.message, msg.category, msg.filename, msg.lineno,
    :
    RuntimeWarning: invalid value encountered in reciprocal
    8.744039097709175
**********************************************************************
1 item had failures:
   1 of  24 in sage.modules.vector_double_dense.Vector_double_dense.norm
    [103 tests, 1 failure, 1.05 s]
sage -t --random-seed=328052423492298536457904078933829346088 src/sage/modules/free_module_element.pyx
**********************************************************************
File "src/sage/modules/free_module_element.pyx", line 1677, in sage.modules.free_module_element.FreeModuleElement.norm
Failed example:
    v.norm(5)
Expected:
    3.077384885394063
Got:
    doctest:warning
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/bin/sage-runtests", line 154, in <module>
        err = DC.run()
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/sage/doctest/control.py", line 1384, in run
        self.run_doctests()
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/sage/doctest/control.py", line 1059, in run_doctests
        self.dispatcher.dispatch()
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/sage/doctest/forker.py", line 2021, in dispatch
        self.parallel_dispatch()
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/sage/doctest/forker.py", line 1916, in parallel_dispatch
        w.start()  # This might take some time
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/sage/doctest/forker.py", line 2190, in start
        super().start()
      File "/usr/local/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/process.py", line 121, in start
        self._popen = self._Popen(self)
      File "/usr/local/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/context.py", line 224, in _Popen
        return _default_context.get_context().Process._Popen(process_obj)
      File "/usr/local/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/context.py", line 277, in _Popen
        return Popen(process_obj)
      File "/usr/local/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_fork.py", line 19, in __init__
        self._launch(process_obj)
      File "/usr/local/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_fork.py", line 71, in _launch
        code = process_obj._bootstrap(parent_sentinel=child_r)
      File "/usr/local/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
        self.run()
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/sage/doctest/forker.py", line 2162, in run
        task(self.options, self.outtmpfile, msgpipe, self.result_queue)
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/sage/doctest/forker.py", line 2492, in __call__
        doctests, extras = self._run(runner, options, results)
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/sage/doctest/forker.py", line 2544, in _run
        result = runner.run(test)
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/sage/doctest/forker.py", line 866, in run
        return self._run(test, compileflags, out)
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/sage/doctest/forker.py", line 695, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/src/sage/doctest/forker.py", line 1093, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.modules.free_module_element.FreeModuleElement.norm[7]>", line 1, in <module>
        v.norm(Integer(5))
      File "<__array_function__ internals>", line 180, in norm
      File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.7.beta8/local/var/lib/sage/venv-python3.9/lib/python3.9/site-packages/numpy/linalg/linalg.py", line 2566, in norm
        ret **= reciprocal(ord, dtype=ret.dtype)
      File "/usr/local/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/warnings.py", line 109, in _showwarnmsg
        sw(msg.message, msg.category, msg.filename, msg.lineno,
    :
    RuntimeWarning: invalid value encountered in reciprocal
    3.077384885394063
**********************************************************************
1 item had failures:
   1 of  24 in sage.modules.free_module_element.FreeModuleElement.norm
    [1079 tests, 1 failure, 9.35 s]
----------------------------------------------------------------------
sage -t --random-seed=328052423492298536457904078933829346088 src/sage/modules/vector_double_dense.pyx  # 1 doctest failed
sage -t --random-seed=328052423492298536457904078933829346088 src/sage/modules/free_module_element.pyx  # 1 doctest failed
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

fdb7764build/pkgs/numpy: Update to 1.23.0
09066c8build/pkgs/numpy: Switch to using .tar.gz
5b0f244build/pkgs/numpy: Update to 1.23.1
d4ff77dbuild/pkgs/numpy: Update to 1.23.2
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Changed commit from 8f5860a to d4ff77d

mkoeppe commented 1 year ago
comment:15

Haven't built this in a while, but there's already 1.23.2

mkoeppe commented 1 year ago
comment:16

Just built it on my Mac (with openblas from current homebrew), and I see these failures too.

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Changed commit from d4ff77d to bccc17d

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Branch pushed to git repo; I updated commit sha1. New commits:

ecda67eMerge tag '9.7.rc1' into t/34110/numpy_1_23
bccc17dbuild/pkgs/numpy: Update to 1.23.3
dimpase commented 1 year ago
comment:18

test, please ignore

mkoeppe commented 1 year ago
comment:19

The failures from comment:13 are still present with 1.23.3

dimpase commented 1 year ago
comment:21

I saw

File "src/sage/rings/number_field/number_field_rel.py", line 2207, in sage.rings.number_field.number_field_rel.NumberField_relative.relative_discriminant
Failed example:
    K.relative_discriminant() == F.ideal(4*b)
Expected:
    True
Got:
    False

but I presume it's not related. Is it?

dimpase commented 1 year ago

Changed reviewer from https://github.com/mkoeppe/sage/actions/runs/2748565810, https://github.com/mkoeppe/sage/actions/runs/2743631299 to Dima Pasechnik

dimpase commented 1 year ago
comment:22

Ah, right, an old Pari version there. All good.

vbraun commented 1 year ago
comment:23

On OSX BigSur & Monterey I get

**********************************************************************
File "src/sage/modules/free_module_element.pyx", line 1677, in sage.modules.free_module_element.FreeModuleElement.norm
Failed example:
    v.norm(5)
Expected:
    3.077384885394063
Got:
    doctest:warning
      File "/Users/buildbot-sage/worker/sage_git/build/src/bin/sage-runtests", line 154, in <module>
        err = DC.run()
      File "/Users/buildbot-sage/worker/sage_git/build/src/sage/doctest/control.py", line 1384, in run
        self.run_doctests()
      File "/Users/buildbot-sage/worker/sage_git/build/src/sage/doctest/control.py", line 1059, in run_doctests
        self.dispatcher.dispatch()
      File "/Users/buildbot-sage/worker/sage_git/build/src/sage/doctest/forker.py", line 2021, in dispatch
        self.parallel_dispatch()
      File "/Users/buildbot-sage/worker/sage_git/build/src/sage/doctest/forker.py", line 1916, in parallel_dispatch
        w.start()  # This might take some time
      File "/Users/buildbot-sage/worker/sage_git/build/src/sage/doctest/forker.py", line 2190, in start
        super().start()
      File "/Users/buildbot-sage/worker/sage_git/build/local/var/lib/sage/venv-python3.10.5/lib/python3.10/multiprocessing/process.py", line 121, in start
        self._popen = self._Popen(self)
      File "/Users/buildbot-sage/worker/sage_git/build/local/var/lib/sage/venv-python3.10.5/lib/python3.10/multiprocessing/context.py", line 224, in _Popen
        return _default_context.get_context().Process._Popen(process_obj)
      File "/Users/buildbot-sage/worker/sage_git/build/local/var/lib/sage/venv-python3.10.5/lib/python3.10/multiprocessing/context.py", line 277, in _Popen
        return Popen(process_obj)
      File "/Users/buildbot-sage/worker/sage_git/build/local/var/lib/sage/venv-python3.10.5/lib/python3.10/multiprocessing/popen_fork.py", line 19, in __init__
        self._launch(process_obj)
      File "/Users/buildbot-sage/worker/sage_git/build/local/var/lib/sage/venv-python3.10.5/lib/python3.10/multiprocessing/popen_fork.py", line 71, in _launch
        code = process_obj._bootstrap(parent_sentinel=child_r)
      File "/Users/buildbot-sage/worker/sage_git/build/local/var/lib/sage/venv-python3.10.5/lib/python3.10/multiprocessing/process.py", line 315, in _bootstrap
        self.run()
      File "/Users/buildbot-sage/worker/sage_git/build/src/sage/doctest/forker.py", line 2162, in run
        task(self.options, self.outtmpfile, msgpipe, self.result_queue)
      File "/Users/buildbot-sage/worker/sage_git/build/src/sage/doctest/forker.py", line 2492, in __call__
        doctests, extras = self._run(runner, options, results)
      File "/Users/buildbot-sage/worker/sage_git/build/src/sage/doctest/forker.py", line 2544, in _run
        result = runner.run(test)
      File "/Users/buildbot-sage/worker/sage_git/build/src/sage/doctest/forker.py", line 866, in run
        return self._run(test, compileflags, out)
      File "/Users/buildbot-sage/worker/sage_git/build/src/sage/doctest/forker.py", line 695, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/buildbot-sage/worker/sage_git/build/src/sage/doctest/forker.py", line 1093, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.modules.free_module_element.FreeModuleElement.norm[7]>", line 1, in <module>
        v.norm(Integer(5))
      File "<__array_function__ internals>", line 180, in norm
      File "/Users/buildbot-sage/worker/sage_git/build/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/numpy/linalg/linalg.py", line 2566, in norm
        ret **= reciprocal(ord, dtype=ret.dtype)
      File "/Users/buildbot-sage/worker/sage_git/build/local/var/lib/sage/venv-python3.10.5/lib/python3.10/warnings.py", line 109, in _showwarnmsg
        sw(msg.message, msg.category, msg.filename, msg.lineno,
    :
    RuntimeWarning: invalid value encountered in reciprocal
    3.077384885394063
**********************************************************************
1 item had failures:

Looks like https://github.com/numpy/numpy/issues/18555 but that was supposedly fixed in 1.22 %-)

vbraun commented 1 year ago
comment:24

I see that this was already reported, please only set this to positive review when its fixed.

mkoeppe commented 1 year ago
comment:25

There's some strangeness in numpy. https://numpy.org/doc/stable/reference/generated/numpy.reciprocal.html clearly states "This function is not designed to work with integers", but numpy.linalg.norm happily passes integers to it, which causes this warning.

mkoeppe commented 1 year ago
comment:26

Actually not just a problem with integers.

sage: from numpy import reciprocal
sage: reciprocal(5)
0
sage: reciprocal(5, dtype='float')
<ipython-input-5-2bc6023357a9>:1: RuntimeWarning: invalid value encountered in reciprocal
  reciprocal(Integer(5), dtype='float')
0.2
sage: reciprocal(5r, dtype='float')
<ipython-input-6-9907a3b698c1>:1: RuntimeWarning: invalid value encountered in reciprocal
  reciprocal(5, dtype='float')
0.2
sage: reciprocal(5.0, dtype='float')
<ipython-input-7-01a4dd4f3fe6>:1: RuntimeWarning: invalid value encountered in reciprocal
  reciprocal(RealNumber('5.0'), dtype='float')
0.2
sage: reciprocal(RDF('5.0'), dtype='float')
<ipython-input-8-74f364341d5b>:1: RuntimeWarning: invalid value encountered in reciprocal
  reciprocal(RDF('5.0'), dtype='float')
0.2
sage: reciprocal(float('5.0'), dtype='float')
<ipython-input-9-4e429d5f8dcc>:1: RuntimeWarning: invalid value encountered in reciprocal
  reciprocal(float('5.0'), dtype='float')
0.2

(this is on macOS Intel)

mkoeppe commented 1 year ago
comment:27

This goes away if one installs the wheels provided by upstream (tested with numpy-1.23.3-cp310-cp310-macosx_10_9_x86_64.whl)

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Branch pushed to git repo; I updated commit sha1. New commits:

499f10bbuild/pkgs/numpy/spkg-install.in: Remove outdated workaround for numpy 1.20.x from Trac #32021
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Changed commit from bccc17d to 499f10b

mkoeppe commented 1 year ago
comment:29

(This does not fix it; just backing out old workarounds before we add new ones.)

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Branch pushed to git repo; I updated commit sha1. New commits:

81a5e8ebuild/pkgs/numpy/spkg-install.in: Remove unexplained 'config_fc --noopt --noarch' introduced in 908f93fedb12b48f5366c7a141837b82595ee1d1 (2010)
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Changed commit from 499f10b to 81a5e8e

mkoeppe commented 1 year ago
comment:31

(Also does not fix it.)

mkoeppe commented 1 year ago
comment:32

Upstream's macOS wheel configuration: https://github.com/numpy/numpy/blob/main/pyproject.toml#L90

mkoeppe commented 1 year ago
comment:33

Using ./configure --enable-fat-binary does not make a difference.

mkoeppe commented 1 year ago
comment:34

As the fix in https://github.com/numpy/numpy/pull/19926 suggests, this is compiler-specific. Using make numpy-uninstall numpy CC=gcc-12 CXX=g++-12 (homebrew gcc) fixes it.

mkoeppe commented 1 year ago
comment:35

It looks like the workaround in https://github.com/numpy/numpy/blob/main/numpy/core/src/umath/loops_unary_fp.dispatch.c.src#L105 relies on using -ftrapping-math on Apple clang v12+ (which apparently still has the bug). "-ftrapping-math is set by default of Numpy builds in numpy/distutils/ccompiler.py."

But the logic there https://github.com/numpy/numpy/blob/main/numpy/distutils/ccompiler.py#L394 uses string comparison to decide whether the compiler is clang or not.

mkoeppe commented 1 year ago
comment:36

Indeed

diff --git a/build/pkgs/numpy/spkg-install.in b/build/pkgs/numpy/spkg-install.in
index 986a14255e..1cf4c5eb3e 100644
--- a/build/pkgs/numpy/spkg-install.in
+++ b/build/pkgs/numpy/spkg-install.in
@@ -7,6 +7,7 @@ if [ `uname` = "Darwin" ]; then
     unset ATLAS
     unset BLAS
     unset LAPACK
+    export CFLAGS="$CFLAGS -ftrapping-math"
 else
     export {ATLAS,PTATLAS,OPENBLAS,MKL,MKLROOT}=None
     export LDFLAGS="${LDFLAGS} -shared"

fixes it.

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Branch pushed to git repo; I updated commit sha1. New commits:

03fad7dbuild/pkgs/numpy/spkg-install.in: Workaround for clang compiler bug affecting 'reciprocal' and incomplete numpy fix
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Changed commit from 81a5e8e to 03fad7d

jhpalmieri commented 1 year ago
comment:39

Works on both Intel and M2, so let's restore the positive review. (I haven't checked on an old version of OS X, though.)

mkoeppe commented 1 year ago
comment:40

Thanks!

mkoeppe commented 1 year ago

Changed reviewer from Dima Pasechnik to Dima Pasechnik, John Palmieri