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: DiscreteAliasUrn construction fails with UNURANError for certain innocuous PVs #19359

Closed
colehaus opened this issue Oct 6, 2023 · 3 comments · Fixed by scipy/unuran#12 or #19364
Closed
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.stats
Milestone

Comments

@colehaus
Copy link

colehaus commented Oct 6, 2023

Describe your issue.

Certain seemingly arbitrary PVs cause DiscreteAliasUrn to crash during construction with an UNURANError.

Reproducing Code Example

import scipy as sp
from scipy.stats.sampling import DiscreteAliasUrn
import numpy as np

DiscreteAliasUrn(sp.special.softmax(np.ones((1531,))), random_state=None) # Fine
DiscreteAliasUrn(sp.special.softmax(np.ones((1533,))) * 10, random_state=None) # Fine
DiscreteAliasUrn(sp.special.softmax(np.ones((1533,))), random_state=None) # Error

Error message

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "scratch.py", line 7, in <module>
    DiscreteAliasUrn(sp.special.softmax(np.ones((1533,))), random_state=None)
  File "unuran_wrapper.pyx", line 2404, in scipy.stats._unuran.unuran_wrapper.DiscreteAliasUrn.__cinit__
  File "unuran_wrapper.pyx", line 443, in scipy.stats._unuran.unuran_wrapper.Method._set_rng
scipy.stats._unuran.unuran_wrapper.UNURANError: [objid: DAU.003] 240 : unknown error! => error should not happen, report this!

SciPy/NumPy/Python version and system information

1.11.3
1.26.0
sys.version_info(major=3, minor=11, micro=3, releaselevel='final', serial=0)
Build Dependencies:
  blas:
    detection method: pkgconfig
    found: true
    include directory: /usr/local/include
    lib directory: /usr/local/lib
    name: openblas
    openblas configuration: USE_64BITINT= DYNAMIC_ARCH=1 DYNAMIC_OLDER= NO_CBLAS=
      NO_LAPACK= NO_LAPACKE= NO_AFFINITY=1 USE_OPENMP= HASWELL MAX_THREADS=2
    pc file directory: /usr/local/lib/pkgconfig
    version: 0.3.21.dev
  lapack:
    detection method: pkgconfig
    found: true
    include directory: /usr/local/include
    lib directory: /usr/local/lib
    name: openblas
    openblas configuration: USE_64BITINT= DYNAMIC_ARCH=1 DYNAMIC_OLDER= NO_CBLAS=
      NO_LAPACK= NO_LAPACKE= NO_AFFINITY=1 USE_OPENMP= HASWELL MAX_THREADS=2
    pc file directory: /usr/local/lib/pkgconfig
    version: 0.3.21.dev
  pybind11:
    detection method: config-tool
    include directory: unknown
    name: pybind11
    version: 2.11.0
Compilers:
  c:
    commands: cc
    linker: ld.bfd
    name: gcc
    version: 10.2.1
  c++:
    commands: c++
    linker: ld.bfd
    name: gcc
    version: 10.2.1
  cython:
    commands: cython
    linker: cython
    name: cython
    version: 0.29.36
  fortran:
    commands: gfortran
    linker: ld.bfd
    name: gcc
    version: 10.2.1
  pythran:
    include directory: ../../tmp/pip-build-env-358nkn7q/overlay/lib/python3.11/site-packages/pythran
    version: 0.14.0
Machine Information:
  build:
    cpu: x86_64
    endian: little
    family: x86_64
    system: linux
  cross-compiled: false
  host:
    cpu: x86_64
    endian: little
    family: x86_64
    system: linux
Python Information:
  path: /opt/python/cp311-cp311/bin/python
  version: '3.11'
@colehaus colehaus added the defect A clear bug or issue that prevents SciPy from being installed or used as expected label Oct 6, 2023
@tirthasheshpatel
Copy link
Member

Thanks for the report @colehaus! I confirmed that this is an error in UNU.RAN. It happens because of floating point errors in the computation of the urn table.

@colehaus
Copy link
Author

colehaus commented Oct 7, 2023

Thanks!

@mdhaber
Copy link
Contributor

mdhaber commented Oct 9, 2023

@colehaus if you are able to build a feature branch, can you see whether gh-19364 resolves this for you?

@rgommers rgommers added this to the 1.12.0 milestone Oct 24, 2023
@tylerjereddy tylerjereddy modified the milestones: 1.12.0, 1.11.4 Nov 16, 2023
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
5 participants