Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numpy update with OpenBLAS and hypothesis test depends #883

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

dhomeier
Copy link
Contributor

@dhomeier dhomeier commented Feb 7, 2022

Running the hypothesis tests with tox installed failed on

'tox config file (either pyproject.toml, tox.ini, setup.cfg) not found'

In addition the PyPI source does not contain any tests that could be run, and tox would likely try to pip-install its own dependencies even if got to run, apart from the circular dependency.
I've therefore switched to the github source and running pytest directly. This still involves a circular dependency with numpy, the presence of which is now checked instead.

Numpy can in fact now be built against Accelerate again (see notes), but OpenBLAS should still be preferable; also the latter is detected and selected automatically, if present. So I made that a [Build]Depends and the preferred NPY_BLAS – otherwise a deterministic build against Accelerate would require deinstallation of openblas during the build.
The tests are also running on pytest; the nose-based runtest.py has not been recommended in numpy for some time, and appears to be omitting a number of tests compared to pytest. Pytest also prints clearer results. Tested on 10.14 and in mostly the same configuration on 10.13.

@dhomeier dhomeier requested a review from dmacks February 7, 2022 01:59
@nieder
Copy link
Member

nieder commented Feb 16, 2022

Missing updated numpy-py.patch.

@nieder nieder added waiting for reply Waiting for reply from submitter new upstream Package has an updated upstream version labels Feb 16, 2022
@dhomeier
Copy link
Contributor Author

Missing updated numpy-py.patch.

Doh, looking too hard only if I missed any dependency .infos...
But I took the opportunity to see if the patches are still needed at all, and found the only one still to be relevant the overriding of $SHELL in distutils.exec_command. Omitting this causes only a single failure, which can alternatively be avoided by running the tests with SHELL=/bin/sh. It might break downstream packages that are using numpy distutils, but I just built and tested scipy 1.8.0 and found no problems. Question is what is the Right Way™ to do this?
As I understood https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=225156 using $SHELL there is violating POSIX rules, thus the patch should be in; on the other hand it has never made it back into numpy. Thoughts?

@nieder
Copy link
Member

nieder commented Feb 17, 2022

It's fine to force SHELL=/bin/sh, either through a patch or by adding it to the test command in TestScript.

@dhomeier dhomeier force-pushed the numpy-hypothesis-openblas branch 2 times, most recently from 5eb025f to ec18743 Compare February 18, 2022 22:39
@nieder
Copy link
Member

nieder commented Feb 19, 2022

Build failure on 12.1. I'll try with 10.14.5 in a bit:

NPY_BLAS_ORDER=openblas,accelerate NPY_LAPACK_ORDER=openblas,accelerate ATLAS=None /opt/sw/bin/python3.8 setup.py build
Running from numpy source directory.
Cythonizing sources
Processing numpy/random/_bounded_integers.pxd.in
Processing numpy/random/_philox.pyx
Processing numpy/random/_bounded_integers.pyx.in
Processing numpy/random/_sfc64.pyx
Processing numpy/random/_mt19937.pyx
Processing numpy/random/bit_generator.pyx
Processing numpy/random/mtrand.pyx
Processing numpy/random/_generator.pyx
Processing numpy/random/_pcg64.pyx
Processing numpy/random/_common.pyx
INFO: blas_opt_info:
INFO: openblas_info:
INFO: customize UnixCCompiler
INFO: C compiler: gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wno-nullability-completeness -Wno-expansion-to-defined -mtune=intel -I/opt/sw/include

creating /private/tmp/tmpoychteav/private
creating /private/tmp/tmpoychteav/private/tmp
creating /private/tmp/tmpoychteav/private/tmp/tmpoychteav
INFO: compile options: '-c'
INFO: gcc: /private/tmp/tmpoychteav/source.c
error: unknown target CPU 'intel'
note: valid target CPU values are: i386, i486, winchip-c6, winchip2, c3, i586, pentium, pentium-mmx, pentiumpro, i686, pentium2, pentium3, pentium3m, pentium-m, c3-2, yonah, pentium4, pentium4m, prescott, nocona, core2, penryn, bonnell, atom, silvermont, slm, goldmont, goldmont-plus, tremont, nehalem, corei7, westmere, sandybridge, corei7-avx, ivybridge, core-avx-i, haswell, core-avx2, broadwell, skylake, skylake-avx512, skx, cascadelake, cooperlake, cannonlake, icelake-client, icelake-server, tigerlake, sapphirerapids, alderlake, knl, knm, lakemont, k6, k6-2, k6-3, athlon, athlon-tbird, athlon-xp, athlon-mp, athlon-4, k8, athlon64, athlon-fx, opteron, k8-sse3, athlon64-sse3, opteron-sse3, amdfam10, barcelona, btver1, btver2, bdver1, bdver2, bdver3, bdver4, znver1, znver2, znver3, x86-64, geode
Traceback (most recent call last):
  File "setup.py", line 461, in <module>
    setup_package()
  File "setup.py", line 453, in setup_package
    setup(**metadata)
  File "/opt/sw/build.build/numpy-py38-1.22.2-1/numpy-1.22.2/numpy/distutils/core.py", line 135, in setup
    config = configuration()
  File "setup.py", line 131, in configuration
    config.add_subpackage('numpy')
  File "/opt/sw/build.build/numpy-py38-1.22.2-1/numpy-1.22.2/numpy/distutils/misc_util.py", line 1054, in add_subpackage
    config_list = self.get_subpackage(subpackage_name, subpackage_path,
  File "/opt/sw/build.build/numpy-py38-1.22.2-1/numpy-1.22.2/numpy/distutils/misc_util.py", line 1020, in get_subpackage
    config = self._get_configuration_from_setup_py(
  File "/opt/sw/build.build/numpy-py38-1.22.2-1/numpy-1.22.2/numpy/distutils/misc_util.py", line 962, in _get_configuration_from_setup_py
    config = setup_module.configuration(*args)
  File "numpy/setup.py", line 9, in configuration
    config.add_subpackage('core')
  File "/opt/sw/build.build/numpy-py38-1.22.2-1/numpy-1.22.2/numpy/distutils/misc_util.py", line 1054, in add_subpackage
    config_list = self.get_subpackage(subpackage_name, subpackage_path,
  File "/opt/sw/build.build/numpy-py38-1.22.2-1/numpy-1.22.2/numpy/distutils/misc_util.py", line 1020, in get_subpackage
    config = self._get_configuration_from_setup_py(
  File "/opt/sw/build.build/numpy-py38-1.22.2-1/numpy-1.22.2/numpy/distutils/misc_util.py", line 962, in _get_configuration_from_setup_py
    config = setup_module.configuration(*args)
  File "numpy/core/setup.py", line 813, in configuration
    blas_info = get_info('blas_opt', 0)
  File "/opt/sw/build.build/numpy-py38-1.22.2-1/numpy-1.22.2/numpy/distutils/system_info.py", line 585, in get_info
    return cl().get_info(notfound_action)
  File "/opt/sw/build.build/numpy-py38-1.22.2-1/numpy-1.22.2/numpy/distutils/system_info.py", line 845, in get_info
    self.calc_info()
  File "/opt/sw/build.build/numpy-py38-1.22.2-1/numpy-1.22.2/numpy/distutils/system_info.py", line 2077, in calc_info
    if self._calc_info(blas):
  File "/opt/sw/build.build/numpy-py38-1.22.2-1/numpy-1.22.2/numpy/distutils/system_info.py", line 2063, in _calc_info
    return getattr(self, '_calc_info_{}'.format(name))()
  File "/opt/sw/build.build/numpy-py38-1.22.2-1/numpy-1.22.2/numpy/distutils/system_info.py", line 2000, in _calc_info_openblas
    info = get_info('openblas')
  File "/opt/sw/build.build/numpy-py38-1.22.2-1/numpy-1.22.2/numpy/distutils/system_info.py", line 585, in get_info
    return cl().get_info(notfound_action)
  File "/opt/sw/build.build/numpy-py38-1.22.2-1/numpy-1.22.2/numpy/distutils/system_info.py", line 845, in get_info
    self.calc_info()
  File "/opt/sw/build.build/numpy-py38-1.22.2-1/numpy-1.22.2/numpy/distutils/system_info.py", line 2283, in calc_info
    info = self._calc_info()
  File "/opt/sw/build.build/numpy-py38-1.22.2-1/numpy-1.22.2/numpy/distutils/system_info.py", line 2271, in _calc_info
    if not (skip_symbol_check or self.check_symbols(info)):
  File "/opt/sw/build.build/numpy-py38-1.22.2-1/numpy-1.22.2/numpy/distutils/system_info.py", line 2350, in check_symbols
    obj = c.compile([src], output_dir=tmpdir)
  File "/opt/sw/build.build/numpy-py38-1.22.2-1/numpy-1.22.2/numpy/distutils/ccompiler.py", line 89, in <lambda>
    m = lambda self, *args, **kw: func(self, *args, **kw)
  File "/opt/sw/build.build/numpy-py38-1.22.2-1/numpy-1.22.2/numpy/distutils/ccompiler.py", line 365, in CCompiler_compile
    single_compile(o)
  File "/opt/sw/build.build/numpy-py38-1.22.2-1/numpy-1.22.2/numpy/distutils/ccompiler.py", line 325, in single_compile
    self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
  File "/opt/sw/build.build/numpy-py38-1.22.2-1/numpy-1.22.2/numpy/distutils/ccompiler.py", line 89, in <lambda>
    m = lambda self, *args, **kw: func(self, *args, **kw)
  File "/opt/sw/build.build/numpy-py38-1.22.2-1/numpy-1.22.2/numpy/distutils/unixccompiler.py", line 58, in UnixCCompiler__compile
    raise CompileError(msg) from None
distutils.errors.CompileError: Command "gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wno-nullability-completeness -Wno-expansion-to-defined -mtune=intel -I/opt/sw/include -c /private/tmp/tmpoychteav/source.c -o /private/tmp/tmpoychteav/private/tmp/tmpoychteav/source.o -MMD -MF /private/tmp/tmpoychteav/private/tmp/tmpoychteav/source.o.d" failed with exit status 1
### execution of NPY_BLAS_ORDER=openblas,accelerate failed, exit code 1
### execution of /tmp/fink.33msp failed, exit code 1

@nieder
Copy link
Member

nieder commented Feb 19, 2022

numpy-py38/39/310-1.22.2 passed all tests on 10.14.5, with -mtune=intel as set in CFLAGS.

@nieder
Copy link
Member

nieder commented Feb 20, 2022

At least on macOS12 (clang 13), mtune does not accept "intel".
Since we already need gcc-11 for tests, should numpy just compile with gcc-11?
Adding the following built but errored 18 tests:

 SetCFLAGS: -mtune=intel
+SetCC: gcc-fsf-%type_raw[gcc]
+SetCXX: g++-fsf-%type_raw[gcc]

Just unsetting mtune leads to two failed tests: test_mem_policy.py::test_new_policy and test_ufunc.py::TestUfuncGenericLoops::test_unary_PyUFunc_O_O_method_full[reciprocal]

@nieder
Copy link
Member

nieder commented Feb 21, 2022

The update-alternatives for hypothesis-pyXX owner got changed from hypothesis-py just hypothesis. This breaks when trying to install any other variant or version.

@dhomeier
Copy link
Contributor Author

Sorry, thought "generic name" always referred to the link name, but I obviously overlooked the nonstandard usage in the old version!

@dhomeier
Copy link
Contributor Author

At least on macOS12 (clang 13), mtune does not accept "intel".

Ah, I had in fact been wondering what to do with that if Fink some day runs on M1...
BTW what is the (semi-official) recommendation to get some test-bed Fink running on macOS 11 or later at this time?
I might at least try to test some packages again on my alternative Big Sur boot....

Since we already need gcc-11 for tests, should numpy just compile with gcc-11?

Building any recent numpy with gcc at least since gcc-9 has failed for me with AVX512-related errors like

INFO: C compiler: gcc-fsf-11 -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wno-nullability-completeness -Wno-expansion-to-defined -mtune=native -I/opt/include

INFO: compile options: '-DNPY_INTERNAL_BUILD=1 -DHAVE_NPY_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -DHAVE_CBLAS -Ibuild/src.macosx-10.14-x86_64-3.10/numpy/core/src/common -Ibuild/src.macosx-10.14-x86_64-3.10/numpy/core/src/umath -Inumpy/core/include -Ibuild/src.macosx-10.14-x86_64-3.10/numpy/core/include/numpy -Ibuild/src.macosx-10.14-x86_64-3.10/numpy/distutils/include -Inumpy/core/src/common -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -Inumpy/core/src/_simd -I/opt/include/python3.10 -Ibuild/src.macosx-10.14-x86_64-3.10/numpy/core/src/common -Ibuild/src.macosx-10.14-x86_64-3.10/numpy/core/src/npymath -c'
extra options: '-msse -msse2 -msse3 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mavx -mf16c -mfma -mavx2 -mavx512f -mavx512cd -mavx512vl -mavx512bw -mavx512dq'
INFO: gcc-fsf-11: build/src.macosx-10.14-x86_64-3.10/numpy/core/src/umath/loops_exponent_log.dispatch.avx512_skx.c
/var/tmp//ccEFLMnT.s:5831:20: error: invalid operand for instruction
        vfpclasspsz     $159, %zmm1, %k2

I thought I had seen some old regressions on related gcc/assembler bugs, but could not find anything right now;
at face value the error is completely expectable, gcc trying to use zmm AVX512 registers as it is explicitly told so with -mavx512 although my i5 does not even have AVX2.
Not sure if this is still a bug on gcc's side not correctly reporting the CPU features at some point, or of the numpy build. And of course it would be interesting to know why it builds without problems on your machine – do you have an AVX512 chip?

Alternatively for clang one could make the mtune-option system-dependent, or just use -mtune=native – are there any pre-built binaries created these days at all?

@dhomeier
Copy link
Contributor Author

Maybe it's not as simple as incorrectly detecting AVX512; although setup.py does create a
config.h which has

#define HAVE_ATTRIBUTE_TARGET_AVX 1
#define HAVE_ATTRIBUTE_TARGET_AVX2 1
#define HAVE_ATTRIBUTE_TARGET_AVX512F 1
#define HAVE_ATTRIBUTE_TARGET_AVX512_SKX 1
#define HAVE_ATTRIBUTE_TARGET_AVX2_WITH_INTRINSICS 1
#define HAVE_ATTRIBUTE_TARGET_AVX512F_WITH_INTRINSICS 1
#define HAVE_ATTRIBUTE_TARGET_AVX512_SKX_WITH_INTRINSICS 1

and reports on optimisation (even with setup.py build --disable-optimization):

INFO: 
########### EXT COMPILER OPTIMIZATION ###########
INFO: Platform      : 
  Architecture: x64
  Compiler    : gcc

CPU baseline  : 
  Requested   : 'min'
  Enabled     : SSE SSE2 SSE3
  Flags       : -msse -msse2 -msse3
  Extra checks: none

CPU dispatch  : 
  Requested   : 'max -xop -fma4'
  Enabled     : SSSE3 SSE41 POPCNT SSE42 AVX F16C FMA3 AVX2 AVX512F AVX512CD AVX512_KNL AVX512_KNM AVX512_SKX AVX512_CLX AVX512_CNL AVX512_ICL
  Generated   : 
              : 
  SSE41       : SSE SSE2 SSE3 SSSE3
  Flags       : -msse -msse2 -msse3 -mssse3 -msse4.1
  Extra checks: none
  Detect      : SSE SSE2 SSE3 SSSE3 SSE41
              : build/src.macosx-10.14-x86_64-3.10/numpy/core/src/umath/loops_arithmetic.dispatch.c
              : build/src.macosx-10.14-x86_64-3.10/numpy/core/src/umath/loops_unary_fp.dispatch.c
              : 
  AVX2        : SSE SSE2 SSE3 SSSE3 SSE41 POPCNT SSE42 AVX F16C
  Flags       : -msse -msse2 -msse3 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mavx -mf16c -mavx2
  Extra checks: none
  Detect      : AVX F16C AVX2
              : build/src.macosx-10.14-x86_64-3.10/numpy/core/src/umath/loops_arithm_fp.dispatch.c
              : build/src.macosx-10.14-x86_64-3.10/numpy/core/src/umath/loops_arithmetic.dispatch.c
              : 
  (FMA3 AVX2) : SSE SSE2 SSE3 SSSE3 SSE41 POPCNT SSE42 AVX F16C
  Flags       : -msse -msse2 -msse3 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mavx -mf16c -mfma -mavx2
  Extra checks: none
  Detect      : AVX F16C FMA3 AVX2
              : build/src.macosx-10.14-x86_64-3.10/numpy/core/src/umath/loops_exponent_log.dispatch.c
              : build/src.macosx-10.14-x86_64-3.10/numpy/core/src/umath/loops_trigonometric.dispatch.c
              : 
  AVX512F     : SSE SSE2 SSE3 SSSE3 SSE41 POPCNT SSE42 AVX F16C FMA3 AVX2
  Flags       : -msse -msse2 -msse3 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mavx -mf16c -mfma -mavx2 -mavx512f
  Extra checks: AVX512F_REDUCE
  Detect      : AVX512F
              : build/src.macosx-10.14-x86_64-3.10/numpy/core/src/umath/loops_arithm_fp.dispatch.c
              : build/src.macosx-10.14-x86_64-3.10/numpy/core/src/umath/loops_arithmetic.dispatch.c
              : build/src.macosx-10.14-x86_64-3.10/numpy/core/src/umath/loops_exponent_log.dispatch.c
              : build/src.macosx-10.14-x86_64-3.10/numpy/core/src/umath/loops_trigonometric.dispatch.c
              : 
  AVX512_SKX  : SSE SSE2 SSE3 SSSE3 SSE41 POPCNT SSE42 AVX F16C FMA3 AVX2 AVX512F AVX512CD
  Flags       : -msse -msse2 -msse3 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mavx -mf16c -mfma -mavx2 -mavx512f -mavx512cd -mavx512vl -mavx512bw -mavx512dq
  Extra checks: AVX512BW_MASK AVX512DQ_MASK
  Detect      : AVX512_SKX
              : build/src.macosx-10.14-x86_64-3.10/numpy/core/src/umath/loops_arithmetic.dispatch.c
              : build/src.macosx-10.14-x86_64-3.10/numpy/core/src/umath/loops_exponent_log.dispatch.c
              : build/src.macosx-10.14-x86_64-3.10/numpy/core/src/umath/loops_umath_fp.dispatch.c

the clang build produces exactly the same, and successfully compiles all that avx512 custom code. In fact gcc11 also compiled

loops_arithm_fp.dispatch.avx512f.o
loops_arithmetic.dispatch.avx512_skx.o
loops_exponent_log.dispatch.avx512f.o
loops_trigonometric.dispatch.avx512f.o
loops_umath_fp.dispatch.avx512_skx.o

and only failed on loops_exponent_log.dispatch.avx512_skx.o. So this looks more like the compiler is expected (or at least promises) to provide the same AVX* API everywhere (and emulate as required), and falling back on the hw instructions for vfpclasspsz, vfpclasspdz is an open gcc bug after all. There are/have been a number of issues with that part of the code, like numpy/numpy#20405, but none of them seem related to this or any assembly level errors.

@dhomeier
Copy link
Contributor Author

Still more interesting, or confusing, I am getting the same failure with gcc10, but not with 9.4 – optimisation reports looking nearly identical, but gcc9 lists one extra file...

 AVX512_SKX  : SSE SSE2 SSE3 SSSE3 SSE41 POPCNT SSE42 AVX F16C FMA3 AVX2 AVX512F AVX512CD
  Flags       : -msse -msse2 -msse3 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mavx -mf16c -mfma -mavx2 -mavx512f -mavx512cd -mavx512vl -mavx512bw -mavx512dq
  Extra checks: AVX512BW_MASK AVX512DQ_MASK
  Detect      : AVX512_SKX
              : build/src.macosx-10.14-x86_64-3.9/numpy/core/src/_simd/_simd.dispatch.c
              : build/src.macosx-10.14-x86_64-3.9/numpy/core/src/umath/loops_arithmetic.dispatch.c
              : build/src.macosx-10.14-x86_64-3.9/numpy/core/src/umath/loops_exponent_log.dispatch.c
              : build/src.macosx-10.14-x86_64-3.9/numpy/core/src/umath/loops_umath_fp.dispatch.c

Xcode clang reports the same, and both are building

_simd.dispatch.avx512_skx.o
_simd.dispatch.avx512f.o
_simd.dispatch.fma3.avx2.o
_simd.dispatch.o
_simd.dispatch.sse42.o

in numpy/core/src/_simd.

@nieder
Copy link
Member

nieder commented Feb 22, 2022

At least on macOS12 (clang 13), mtune does not accept "intel".

Ah, I had in fact been wondering what to do with that if Fink some day runs on M1...
BTW what is the (semi-official) recommendation to get some test-bed Fink running on macOS 11 or later at this time?

My macOS12 in on intel.

To get a fink install working on 11.0 and up (intel), you need to checkout the dpkg1.16 branch from https://github.com/TheSin-/fink

@dhomeier
Copy link
Contributor Author

To get a fink install working on 11.0 and up (intel), you need to checkout the dpkg1.16 branch from https://github.com/TheSin-/fink

Thanks, that's not a place I would have found on my own. Seems to work overall, but somewhere along the upgrade to now dpkg 1.19.7 it appears the script versions

%p/sbin/dpkg-statoverride
%p/sbin/dpkg-divert
%p/sbin/update-alternatives
%p/sbin/cleanup-info
%p/sbin/install-info

have been moved to %p/bin or, for the *-info ones, removed entirely.
This is breaking the prerm calls to %p/sbin/install-info created by PkgVersion.pm.
I don't know where to file an issue for that branch...

@TheSin-
Copy link
Member

TheSin- commented Feb 28, 2022

install-info should never be called at all anymore, it's a trigger now.

see "Deprecate InfoDocs field (add a validator warning that it is deprecated, the triggers in install-info supersede it)" in fink/fink#66

@dhomeier
Copy link
Contributor Author

Is that a regression against fink-0.45.99.git-20220228.1334 then?

@dhomeier
Copy link
Contributor Author

At least on macOS12 (clang 13), mtune does not accept "intel".
Since we already need gcc-11 for tests, should numpy just compile with gcc-11?

I confirmed that gcc11 works on Monterey, but keep failing with the AVX512 errors on Mojave.
And under Monterey on arm64 gcc11 naturally does not accept "intel" either, so rather than using all different compiler setups depending on arch and OS version, I'd prefer to simply tune for the native arch (which is probably already the default). That should not break even if a binary package was installed over different machines, just being less performant.

@nieder
Copy link
Member

nieder commented Sep 6, 2022

I didn't notice that you force pushed changes. I tested the current state of the branch and all the hypothesis built (but requires itself to be installed to also pass tests). numpy-py37-py310 built and passed tests on 10.14.5.

py36 failed as described in numpy/numpy#10515, but adding LANG=en_US.UTF-8 to the TestScript command made it pass.

On 12.5.1, numpy-py38-310 built but failed these two tests for all variants:

FAILED numpy/core/tests/test_mem_policy.py::test_new_policy - AssertionError: assert False
FAILED numpy/core/tests/test_ufunc.py::TestUfuncGenericLoops::test_unary_PyUFunc_O_O_method_full[reciprocal] - AssertionError: FloatingPointError not raised

See numpy/numpy#10515
fink-bld has a minimal environment and TestFromTxt.test_utf8_file_nodtype_unicode requires more than plain ASCII.
@nieder
Copy link
Member

nieder commented Sep 11, 2022

Since hypothesis-py is working, I've cherry picked it's commits to master. This only leaves the two failing numpy tests on 12.5.1. If we think those are not necessary we can disable them and push through numpy and finish this.

@nieder
Copy link
Member

nieder commented Oct 3, 2022

Tested, numpy-py 1.22.4 (last of the 1.22 series), and it failed the same two tests on 12.5. Version 1.23.3 needs new package typing_extensions and a bump to the most recent cython.

@nieder
Copy link
Member

nieder commented Oct 5, 2022

I got typing-extensions-py working on my 12.5 machine (needs several new packages, will make a PR), but numpy-py-1.23.3 fails the same tests:

=============================================================== short test summary info ===============================================================
FAILED numpy/core/tests/test_mem_policy.py::test_new_policy - AssertionError: assert False
FAILED numpy/core/tests/test_ufunc.py::TestUfuncGenericLoops::test_unary_PyUFunc_O_O_method_full[reciprocal] - AssertionError: FloatingPointError no...
==================== 2 failed, 19563 passed, 1053 skipped, 1 deselected, 46 xfailed, 9 xpassed, 380 warnings in 558.78s (0:09:18) =====================

@dhomeier
Copy link
Contributor Author

I've pushed the new typing_extensions package; it depends on your bootstrap-modules-py from #926, thanks a lot for that!

@nieder
Copy link
Member

nieder commented Nov 11, 2022

I'm getting 404 on the test_typing_extensions.py file in TestDepends. Are there needed changes to it that are not part of the 4.4.0 tarball?

@nieder
Copy link
Member

nieder commented Nov 12, 2022

Also, getting this error in TestScript if I ignore the TestSource: ERROR: file or directory not found: ../test_*. I think this is wrong and should be src/test_* at the end, no?

@nieder
Copy link
Member

nieder commented Nov 12, 2022

And, I'm getting this failure then:

ImportError while importing test module '/sw/build.build/typing-extensions-py39-4.4.0-1/typing_extensions-4.4.0/src/test_typing_extensions.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/sw/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
src/test_typing_extensions.py:33: in <module>
    from _typed_dict_test_helper import FooGeneric
E   ModuleNotFoundError: No module named '_typed_dict_test_helper'

See python/typing_extensions#61

I used Debian's patch to get the missing module that's in upstream's github but not in the pypi tarball.

@dhomeier
Copy link
Contributor Author

Thanks! That test file was still left in my Fink sources from a pre-4.3.0 release, which had no tests included at all.

Co-authored-by: <nieder@users.noreply.github.com>
@nieder
Copy link
Member

nieder commented Nov 15, 2022

typing-extensions now works.
But I still get the same 2 test failures on 12.6 for numpy:

=============================================================== short test summary info ===============================================================
FAILED numpy/core/tests/test_mem_policy.py::test_new_policy - AssertionError: assert False
FAILED numpy/core/tests/test_ufunc.py::TestUfuncGenericLoops::test_unary_PyUFunc_O_O_method_full[reciprocal] - AssertionError: FloatingPointError no...
==================== 2 failed, 19563 passed, 1053 skipped, 1 deselected, 46 xfailed, 9 xpassed, 380 warnings in 558.78s (0:09:18) =====================

Test pass on 10.14.5.

@nieder
Copy link
Member

nieder commented Nov 27, 2022

Opened numpy/numpy#22680 for the two tests on 12.5.1. Not sure they're big errors, and it might be possible to ignore them, but we'll see what they say.

@nieder
Copy link
Member

nieder commented Feb 3, 2023

1.24.1 now has 19 test failures on 10.14.6 (numpy-1.24.0 passes all; other macOS untested). I thought numpy/numpy#22954 might take care of most of them even though the bug is for arm64, but it didn't help.

@nieder
Copy link
Member

nieder commented Feb 5, 2023

numpy-1.24.0 passes all tests on 10.14.6 and fails just the same two tests on 12.6 (no response upstream to the bug I filed).

Should we just skip those two tests?

@nieder
Copy link
Member

nieder commented Jun 21, 2023

numpy-1.25.0 is out. It only supports py3.9-3.11.
On 10.14.6, I get:

FAILED numpy/core/tests/test_mem_policy.py::test_new_policy - AssertionError: assert False
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data10-escape10-f-cos] - AssertionError: Got warnings: [<warnings.WarningMes...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data10-escape10-f-log] - AssertionError: Got warnings: [<warnings.WarningMes...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data10-escape10-f-sin] - AssertionError: Got warnings: [<warnings.WarningMes...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data11-escape11-f-cos] - AssertionError: Got warnings: [<warnings.WarningMes...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data11-escape11-f-log] - AssertionError: Got warnings: [<warnings.WarningMes...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data11-escape11-f-sin] - AssertionError: Got warnings: [<warnings.WarningMes...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data12-escape12-f-cos] - AssertionError: Got warnings: [<warnings.WarningMes...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data12-escape12-f-log] - AssertionError: Got warnings: [<warnings.WarningMes...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data12-escape12-f-sin] - AssertionError: Got warnings: [<warnings.WarningMes...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data13-escape13-f-cos] - AssertionError: Got warnings: [<warnings.WarningMes...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data13-escape13-f-log] - AssertionError: Got warnings: [<warnings.WarningMes...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data13-escape13-f-sin] - AssertionError: Got warnings: [<warnings.WarningMes...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data14-escape14-f-cos] - AssertionError: Got warnings: [<warnings.WarningMes...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data14-escape14-f-log] - AssertionError: Got warnings: [<warnings.WarningMes...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data14-escape14-f-sin] - AssertionError: Got warnings: [<warnings.WarningMes...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data15-escape15-f-cos] - AssertionError: Got warnings: [<warnings.WarningMes...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data15-escape15-f-log] - AssertionError: Got warnings: [<warnings.WarningMes...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data15-escape15-f-sin] - AssertionError: Got warnings: [<warnings.WarningMes...
==================================== 19 failed, 36383 passed, 1791 skipped, 33 xfailed, 7 xpassed, 578 warnings in 800.00s (0:13:19) ====================================

1 failure in test_mem_policy.py
18 failures in test_umath.py

All the failures in test_umath.py end like this:

<snip>
        ([-np.inf, 1.0, 1.0, 1.0]*32, NEG_INVALID_ERR + INF_INVALID_ERR),
        ([-np.inf], NEG_INVALID_ERR + INF_INVALID_ERR),
        ([-np.inf]*32, NEG_INVALID_ERR + INF_INVALID_ERR),
    ))
    def test_unary_spurious_fpexception(self, ufunc, dtype, data, escape):
        if escape and ufunc in escape:
            return
        # FIXME: NAN raises FP invalid exception:
        #  - ceil/float16 on MSVC:32-bit
        #  - spacing/float16 on almost all platforms
        if ufunc in (np.spacing, np.ceil) and dtype == 'e':
            return
        array = np.array(data, dtype=dtype)
        with assert_no_warnings():
>           ufunc(array)

numpy/core/tests/test_umath.py:1817: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <contextlib._GeneratorContextManager object at 0x14cc1afa0>, typ = None, value = None, traceback = None

    def __exit__(self, typ, value, traceback):
        if typ is None:
            try:
>               next(self.gen)
E               AssertionError: Got warnings: [<warnings.WarningMessage object at 0x14cc1a4f0>]

/sw/lib/python3.9/contextlib.py:126: AssertionError

So is it failing because a (compiler?) warning was thrown? There's no actual warning in the terminal output.

@dhomeier
Copy link
Contributor Author

So is it failing because a (compiler?) warning was thrown? There's no actual warning in the terminal output.

The warning is kept (intercepted) in the WarningMessage object, probably emitted on just calling the ufunc.
On 13.4 all tests are passing with the native arm64 build, on x86_64 (Rosetta) the same test is failing on a couple different warnings:

=================================================================== short test summary info ====================================================================
FAILED ../../../../opt/x64/lib/python3.10/site-packages/numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data0-escape0-d-reciprocal] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x165345090>]
FAILED ../../../../opt/x64/lib/python3.10/site-packages/numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data2-escape2-d-reciprocal] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x1651bba30>]
FAILED ../../../../opt/x64/lib/python3.10/site-packages/numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data4-escape4-d-reciprocal] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x165874280>]
FAILED ../../../../opt/x64/lib/python3.10/site-packages/numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data14-escape14-d-reciprocal] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x165e01a20>]
FAILED ../../../../opt/x64/lib/python3.10/site-packages/numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data20-escape20-d-reciprocal] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x16651d270>]
FAILED ../../../../opt/x64/lib/python3.10/site-packages/numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data26-escape26-d-reciprocal] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x166210ac0>]
================================================= 6 failed, 3354 passed, 1210 deselected, 5 warnings in 4.79s ==================================================

Cannot test on 10.14 or any native x86_64 atm, but what do you get e.g. when running

python3.9 -c 'import numpy as np; array = np.array([0.5, 0.5, 0.5, np.nan], dtype="f"); print(np.cos(array))'

?

@dhomeier
Copy link
Contributor Author

Also reproducing the two failures from #883 (comment) on 13.4/x86_64, plus

>       assert_(np.all(d < rtol), (np.argmax(d), x[np.argmax(d)], d.max(),
                                  'arctanh'))
E       AssertionError: (0, 9.9999999999999994515e-21, 3.9696755572509052902e+20, 'arctanh')

numpy/core/tests/test_umath.py:4190: AssertionError

for float128 – I suspect the latter might be specific to Rosetta, since the x86_64 emulation probably has no hardware 80-bit float types.
np.reciprocal seems to struggle with any dtype='d' inputs...

@nieder
Copy link
Member

nieder commented Jun 22, 2023

This is on 10.14.6:
Using our current 1.22.1-1:

$ python3.9 -c 'import numpy as np; array = np.array([0.5, 0.5, 0.5, np.nan], dtype="f"); print(np.cos(array))'
<string>:1: RuntimeWarning: invalid value encountered in cos
[0.87758255 0.87758255 0.87758255        nan]

Using 1.25.0:

$ python3.9 -c 'import numpy as np; array = np.array([0.5, 0.5, 0.5, np.nan], dtype="f"); print(np.cos(array))'
<string>:1: RuntimeWarning: invalid value encountered in cos
[0.87758255 0.87758255 0.87758255        nan]

@nieder
Copy link
Member

nieder commented Jan 18, 2024

Using our new openblas 0.3.26, numpy-py310-1.25.0 still fails those 19 tests:

=================================================== short test summary info ===================================================
FAILED numpy/core/tests/test_mem_policy.py::test_new_policy - AssertionError: assert False
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data10-escape10-f-cos] - Assertion...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data10-escape10-f-log] - Assertion...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data10-escape10-f-sin] - Assertion...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data11-escape11-f-cos] - Assertion...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data11-escape11-f-log] - Assertion...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data11-escape11-f-sin] - Assertion...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data12-escape12-f-cos] - Assertion...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data12-escape12-f-log] - Assertion...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data12-escape12-f-sin] - Assertion...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data13-escape13-f-cos] - Assertion...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data13-escape13-f-log] - Assertion...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data13-escape13-f-sin] - Assertion...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data14-escape14-f-cos] - Assertion...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data14-escape14-f-log] - Assertion...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data14-escape14-f-sin] - Assertion...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data15-escape15-f-cos] - Assertion...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data15-escape15-f-log] - Assertion...
FAILED numpy/core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data15-escape15-f-sin] - Assertion...
=============== 19 failed, 36390 passed, 1784 skipped, 33 xfailed, 7 xpassed, 580 warnings in 831.22s (0:13:51) ===============
nieder $ /sw/bin/python3.10 -c 'import numpy as np; array = np.array([0.5, 0.5, 0.5, np.nan], dtype="f"); print(np.cos(array))'
<string>:1: RuntimeWarning: invalid value encountered in cos
[0.87758255 0.87758255 0.87758255        nan]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new upstream Package has an updated upstream version waiting for reply Waiting for reply from submitter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants