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

BUG: stats: distribution methods emit unnecessary warnings from Boost #14901

Closed
4 tasks
tupui opened this issue Oct 21, 2021 · 55 comments
Closed
4 tasks

BUG: stats: distribution methods emit unnecessary warnings from Boost #14901

tupui opened this issue Oct 21, 2021 · 55 comments
Assignees
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.stats
Milestone

Comments

@tupui
Copy link
Member

tupui commented Oct 21, 2021

Describe your issue

Several statistical distribution methods emit warnings stemming from Boost. This issue tracks the status of all of them.

gh-17272 will silence the failures in SciPy's tests temporarily, but as many of these marks as possible should be removed when gh-17207 merges.


Original Post

Describe your issue.

macOS CI is failing due to an overflow. I am still trying to reproduce locally.

NumPy was updated to 1.21.3, could be this or another dependency.

https://github.com/scipy/scipy/runs/3960228039

Reproducing Code Example

# from scipy/stats/tests/test_distributions.py:2878: in test_issue_12796
import numpy as np
from scipy import stats
q = 0.999995
a = np.array([ 2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20])
b = np.array([99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990, 99989, 99988, 99987, 99986, 99985, 99984, 99983, 99982, 99981])
stats.beta.ppf(q, a, b)

Error message

FAILED scipy/stats/tests/test_distributions.py::TestBeta::test_issue_12635 - ...
927
FAILED scipy/stats/tests/test_distributions.py::TestBeta::test_issue_12794 - ...
928
FAILED scipy/stats/tests/test_distributions.py::TestBeta::test_issue_12796 - ...
...
scipy/stats/_continuous_distns.py:626: in _ppf
916
    return _boost._beta_ppf(q, a, b)
917
E   RuntimeWarning: overflow encountered in _beta_ppf

SciPy/NumPy/Python version information

master on macOS/CI

@tupui tupui added defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.stats labels Oct 21, 2021
@tupui
Copy link
Member Author

tupui commented Oct 21, 2021

Not sure anymore it's NumPy since I cannot reproduce locally. Will have a look at the other deps. I am pretty sure it's not on our side since the issue appeared after 14341ea. In the PR CI passed while after the merge it did not anymore.

@tupui
Copy link
Member Author

tupui commented Oct 21, 2021

suite-sparse dependency changed. Now it's Installing dependencies for suite-sparse: metis and openblas and before Installing dependencies for suite-sparse: metis, openblas and tbb. Homebrew/homebrew-core@083d997#diff-2ac98c43f5e9e7b776c4d0883ac3d65d61db22b46d98918ce2ce26433f2ddfbb

@andyfaff
Copy link
Contributor

I'm not sure it's to do with the suite-sparse dependencies. Another thing is that the default macOS version (runs-on: macos-latest) was updated from 10.15 to 11. I think this happened when macOS tests started failing.

The most obvious thing is that a previously valid calculation is now not happening correctly. However, I'm not sure that a RuntimeWarning should be raised, these can be easy to ignore, should it be a RuntimeError instead?

@lordgrenville
Copy link

I can reproduce this on my machine, with this code (from the docs):

a, b = 2.31, 0.627
x = np.linspace(beta.ppf(0.01, a, b), beta.ppf(0.99, a, b), 100)

Happy to share details about my system info. (Running the latest macOS on M1.)

@andyfaff
Copy link
Contributor

I think CI is on Macos Intel.

@tupui
Copy link
Member Author

tupui commented Oct 25, 2021

It's on intel and apparently not failing on Travis for the wheels.

Might be the macOS version as you said.

@rgommers
Copy link
Member

This is getting annoying, I will try to silence these warnings before the PyData Global sprint tomorrow.

@rgommers
Copy link
Member

  • I cannot reproduce this on an arm64 machine with macOS 11.6 and XCode 12.5.1.
  • GitHub Actions uses macOS 11.6. Don't see an XCode version, but I assume it's up-to-date.
  • Azure has macOS 10.15.7, that's not failing.

The relevant tests and code seems to not have been touched after being introduced in the big Boost PR (gh-13328).

rgommers added a commit to rgommers/scipy that referenced this issue Oct 29, 2021
rgommers added a commit to rgommers/scipy that referenced this issue Oct 29, 2021
@rgommers
Copy link
Member

@mckib2 if you have any memory of that code and some idea of what this could be, that would be great to hear (not very high-prio, we can live with just silencing the failures for a while).

tylerjereddy added a commit that referenced this issue Oct 30, 2021
* TST: silence test failures on macOS for `beta.ppf` overflow

See gh-14901 for details.

[skip azp]
[skip github]

Co-authored-by: Tyler Reddy <tyler.je.reddy@gmail.com>
@mckib2
Copy link
Contributor

mckib2 commented Oct 30, 2021

@mckib2 if you have any memory of that code and some idea of what this could be, that would be great to hear (not very high-prio, we can live with just silencing the failures for a while).

That warning was introduced by gh-14618, we've seen some other instances of strange behavior when building on different platforms, e.g. gh-14833. The only levers I know to pull in cases like this are the Boost.Math policy defines in the setup.py. Hard to experiment without local hardware though

@rgommers
Copy link
Member

Thanks for the details @mckib2!

That warning was introduced by gh-14901

That's this issue, want to edit your comment to point at the PR you meant?

@mckib2
Copy link
Contributor

mckib2 commented Oct 30, 2021

Thanks for the details @mckib2!

That warning was introduced by gh-14901

That's this issue, want to edit your comment to point at the PR you meant?

Good catch -- edited

tylerjereddy added a commit to tylerjereddy/scipy that referenced this issue Nov 5, 2021
)

* TST: silence test failures on macOS for `beta.ppf` overflow

See scipygh-14901 for details.

[skip azp]
[skip github]

Co-authored-by: Tyler Reddy <tyler.je.reddy@gmail.com>
@rgommers rgommers added this to the 1.7.3 milestone Nov 20, 2021
@rgommers
Copy link
Member

So this happened on Intel macOS in CI; I'm seeing them locally with a conda build on arm64 macOS, and gh-14722 sees them on arm64 macOS too (miniforge-from-Homebrew install). Looking at a fix or some skips for 1.7.3.

@mckib2
Copy link
Contributor

mckib2 commented Dec 1, 2021

Looking this over again and am a little confused as to why a RuntimeWarning is being produced by an overflow. gh-14833 set the Boost.Math policy to throw an OverflowError, so it's currently unclear to me why it's being treated as a runtime exception. I'm just getting back from a trip and getting settled in, but I will find time this weekend to review this more closely. beta seems to be the problem child in the Boost distributions...

@mdhaber
Copy link
Contributor

mdhaber commented Nov 27, 2022

@mckib2 some of these have been fixed in Boost, do you know if the fixes have made their way into SciPy yet? It would be good to close this before 1.10 branches, if possible.

@mborland
Copy link
Contributor

mborland commented Dec 5, 2022

nct should be fixed by boostorg/math#892. I'll look at ncx2 this week.

@mborland
Copy link
Contributor

mborland commented Dec 7, 2022

@mdhaber please make sure I am reading this right. I used this CI run's values where df = 21, nc = 1.0560466, and x = 6.77671634 or 21.36270226 or 49.09451392 to generate overflow. I was not able to re-produce overflow (only FE_INEXACT) with the following platform:

Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Are there other test values that are know to cause overflow with ncx2? The other distribution's test cases have all be integers that caused denominators to be 0.

@mdhaber
Copy link
Contributor

mdhaber commented Jan 25, 2023

Thanks for your patience @mborland. I don't know the details because I can't reproduce locally, but I think they will become more clear once we get all these fixes you've made into SciPy. We'll let you know if it's not already resolved.


Just another note relevant to this issue: we're now seeing these warnings in CI (e.g. gh-17853) again after gh-13699 was merged:

FAILED scipy/stats/tests/test_continuous_fit_censored.py::test_nct - RuntimeWarning: overflow encountered in _nct_sf
FAILED scipy/stats/tests/test_continuous_fit_censored.py::test_ncx2 - RuntimeWarning: overflow encountered in _ncx2_sf

We may xfail or skip these tests to silence the CI failure. Part of closing this issue will be removing the xfail/skip mark.

@mborland
Copy link
Contributor

Do you have the test cases that cause those two to overflow? If they are like the others it is floating-point environment oddities.

@mdhaber
Copy link
Contributor

mdhaber commented Jan 25, 2023

I think you already looked into these (#14901 (comment)), so I don't think there's anything new to be done yet.
It difficult for me to give you a test case associated with those because I can't reproduce locally, but based on the log, it looks like sf of ncx2 raise the warning with df = 1.0, nc = 1.0, loc=0, scale=1, and x as one of the following:

[2.7, 0.2, 6.5, 0.4, 0.1, 8., 0.6, 1.]

For nct.sf, that's df=0.4125, nc=1.571875, loc=0, scale=1. and x as one of the following:

[1., 2., 3., 5., 8., 10., 25.,]

@mborland
Copy link
Contributor

I think for those I would disable failure. They were setting the flag for FE_DIVBYZERO, but now the only one I can reproduce is FE_INEXACT which is defined as: "inexact result: rounding was necessary to store the result of an earlier floating-point operation". I don't think I would worry about that.

@h-vetinari
Copy link
Member

Let's hope that this got ameliorated by #17865, but unless that gets backported, this issue is not for 1.10 anymore - I adapted the milestone.

@mdhaber
Copy link
Contributor

mdhaber commented Jan 27, 2023

No, gh-17865 just treated one of the symptoms, silencing warnings in two tests. The np.errstate context I added should be removed when this issue is resolved.

@mdhaber
Copy link
Contributor

mdhaber commented Feb 28, 2023

@mckib2 was there anything else you wanted to investigate here (e.g. I'm not sure if you saw #17432 (comment)), or do we just wait for upstream changes?

@tupui Do you think #17432 (comment) and the np.errstates we added in gh-17432 close this issue?

@tupui
Copy link
Member Author

tupui commented Mar 1, 2023

@mdhaber looks like you covered all the warnings. +1 to close from me then.

@mckib2
Copy link
Contributor

mckib2 commented Mar 1, 2023

@mckib2 was there anything else you wanted to investigate here (e.g. I'm not sure if you saw #17432 (comment)), or do we just wait for upstream changes?

+1 to wait for upstream resolution, I think this issue can be closed

@mdhaber
Copy link
Contributor

mdhaber commented Mar 1, 2023

Thanks everyone!

@mdhaber mdhaber closed this as completed Mar 1, 2023
@saprykin
Copy link

I still have problems with Boost warnings on macOS running on M2 using SciPy 1.11.3. The following code throws a warning:

import scipy.stats as st
st.ncf.cdf(1.0, 9.3068452315593326, 2.5033839617676019, 2.2008593797340321, loc=-0.00428410694979, scale=2.96164351766)

The warnings looks like:

~/miniconda3/envs/scipy-test/lib/python3.11/site-packages/scipy/stats/_continuous_distns.py:7087: RuntimeWarning: overflow encountered in _ncf_cdf
  return _boost._ncf_cdf(x, dfn, dfd, nc)

Tested the same code on a Linux machine and no warnings.

@toolslive
Copy link

This might be a similar/identical issue

from scipy.stats import ncf

In [2]: ncf.cdf(1, 1.5, 2.5, 5)
Out[2]: 0.12644056682002736

In [3]: ncf.sf([2.5],[1],[1],[2.])
../3.11.6/envs/.../python3.11/site-packages/scipy/stats/_continuous_distns.py:7094: RuntimeWarning: divide by zero encountered in _ncf_sf
  return _boost._ncf_sf(x, dfn, dfd, nc)
Out[3]: array([0.58431814])

scipy version: 1.11.3 (scipy-1.11.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl)
python version: 3.11.6
OS: linux
Arch: 13th Gen Intel(R) Core(TM) i7-1365U

@mdhaber
Copy link
Contributor

mdhaber commented Nov 16, 2023

@mborland looks like we have another one of these warnings.

from scipy.stats import ncf
ncf.sf(2., 1., 1., 1.)

Can you help us? Thank you!

@mborland
Copy link
Contributor

@mborland looks like we have another one of these warnings.

from scipy.stats import ncf
ncf.sf(2., 1., 1., 1.)

Can you help us? Thank you!

I will take a look

@mborland
Copy link
Contributor

@mdhaber Fix for has been merged on my end.

@mdhaber
Copy link
Contributor

mdhaber commented Nov 17, 2023

Thanks @mborland!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.stats
Projects
None yet
Development

No branches or pull requests

11 participants