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: numpy throws AttributeError in base kernel #14

Closed
troyraen opened this issue Aug 23, 2024 · 9 comments
Closed

BUG: numpy throws AttributeError in base kernel #14

troyraen opened this issue Aug 23, 2024 · 9 comments

Comments

@troyraen
Copy link

There seems to be a problem with the numpy installation in the base kernel of the Dev Astrophysics image. From within a notebook, it throws an AttributeError until it is uninstalled and reinstalled (same version). I cannot reproduce the problem from the terminal, only in a notebook. I ran into this when trying to test the dask-labextension (hence using import hipscat) on daskhub-dev.fornax.smce but the problem also exists on daskhub.fornaxdev.mysmce.

Below is what it looks like for me. To reproduce, start the Dev Astrophysics image and open a new notebook using the base kernel, then copy/paste the input from below.

[1]: import hipscat
# The above throws an AttributeError. Full traceback pasted below.
[2]: !pip freeze | grep numpy
numpy==1.26.4
[3]: !pip uninstall numpy --yes
Found existing installation: numpy 1.26.4
Uninstalling numpy-1.26.4:
  Successfully uninstalled numpy-1.26.4
[4]: !pip install "numpy<2.0" --upgrade
Collecting numpy<2.0
  Using cached numpy-1.26.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (61 kB)
Using cached numpy-1.26.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.3 MB)
Installing collected packages: numpy
  Attempting uninstall: numpy
    Found existing installation: numpy 2.1.0
    Uninstalling numpy-2.1.0:
      Successfully uninstalled numpy-2.1.0
Successfully installed numpy-1.26.4

# I noticed that both numpy-1.26.4 and numpy-2.1.0 were uninstalled above. 
# Not sure if having both is part of the problem.

# Restart the kernel, then:
[1]: !pip freeze | grep numpy
numpy==1.26.4
[2]: import hipscat
# The above imports without error.

Full traceback:

[1]: import hipscat
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[2], line 1
----> 1 import hipscat

File [/opt/conda/lib/python3.11/site-packages/hipscat/__init__.py:3](https://daskhub-dev.fornax.smce.nasa.gov/opt/conda/lib/python3.11/site-packages/hipscat/__init__.py#line=2)
      1 """High-level namespace, hipscat"""
----> 3 from . import catalog, inspection, io, pixel_math
      4 from .loaders import read_from_hipscat

File [/opt/conda/lib/python3.11/site-packages/hipscat/catalog/__init__.py:3](https://daskhub-dev.fornax.smce.nasa.gov/opt/conda/lib/python3.11/site-packages/hipscat/catalog/__init__.py#line=2)
      1 """Catalog data wrappers"""
----> 3 from .association_catalog.association_catalog import AssociationCatalog
      4 from .catalog import Catalog
      5 from .catalog_type import CatalogType

File [/opt/conda/lib/python3.11/site-packages/hipscat/catalog/association_catalog/__init__.py:1](https://daskhub-dev.fornax.smce.nasa.gov/opt/conda/lib/python3.11/site-packages/hipscat/catalog/association_catalog/__init__.py#line=0)
----> 1 from .association_catalog import AssociationCatalog
      2 from .association_catalog_info import AssociationCatalogInfo
      3 from .partition_join_info import PartitionJoinInfo

File [/opt/conda/lib/python3.11/site-packages/hipscat/catalog/association_catalog/association_catalog.py:7](https://daskhub-dev.fornax.smce.nasa.gov/opt/conda/lib/python3.11/site-packages/hipscat/catalog/association_catalog/association_catalog.py#line=6)
      5 import pandas as pd
      6 import pyarrow as pa
----> 7 from mocpy import MOC
      8 from typing_extensions import TypeAlias
     10 from hipscat.catalog.association_catalog.association_catalog_info import AssociationCatalogInfo

File [/opt/conda/lib/python3.11/site-packages/mocpy/__init__.py:12](https://daskhub-dev.fornax.smce.nasa.gov/opt/conda/lib/python3.11/site-packages/mocpy/__init__.py#line=11)
      2 """
      3 MOCPy is a Python library allowing easy creation and manipulation of MOCs (Multi-Order Coverage maps).
      4 
   (...)
      8 It allows creation, parsing and comparison of TMOCs.
      9 """
     11 from .fmoc import FrequencyMOC
---> 12 from .moc import MOC, WCS
     13 from .stmoc import STMOC
     14 from .tmoc import TimeMOC

File [/opt/conda/lib/python3.11/site-packages/mocpy/moc/__init__.py:1](https://daskhub-dev.fornax.smce.nasa.gov/opt/conda/lib/python3.11/site-packages/mocpy/moc/__init__.py#line=0)
----> 1 from .moc import MOC
      2 from .plot.wcs import WCS
      4 __all__ = ["MOC", "WCS"]

File [/opt/conda/lib/python3.11/site-packages/mocpy/moc/moc.py:13](https://daskhub-dev.fornax.smce.nasa.gov/opt/conda/lib/python3.11/site-packages/mocpy/moc/moc.py#line=12)
     11 import numpy as np
     12 from astropy import units as u
---> 13 from astropy import wcs
     14 from astropy.coordinates import (
     15     ICRS,
     16     Angle,
   (...)
     21     SkyCoord,
     22 )
     23 from astropy.io import fits

File [/opt/conda/lib/python3.11/site-packages/astropy/wcs/__init__.py:27](https://daskhub-dev.fornax.smce.nasa.gov/opt/conda/lib/python3.11/site-packages/astropy/wcs/__init__.py#line=26)
      1 # Licensed under a 3-clause BSD style license - see LICENSE.rst
      2 """World Coordinate System (WCS) transformations in FITS files.
      3 
      4 .. _wcslib: https://www.atnf.csiro.au/people/mcalabre/WCS/wcslib/index.html
   (...)
     24 a standard pipeline.
     25 """
---> 27 from . import utils
     28 from .wcs import *
     29 from .wcs import InvalidTabularParametersError  # just for docs

File /opt/conda/lib/python3.11/site-packages/astropy/wcs/utils.py:9
      6 import numpy as np
      8 import astropy.units as u
----> 9 from astropy.coordinates import (
     10     ITRS,
     11     BaseBodycentricRepresentation,
     12     BaseCoordinateFrame,
     13     BaseGeodeticRepresentation,
     14     CartesianRepresentation,
     15     SphericalRepresentation,
     16 )
     17 from astropy.utils import unbroadcast
     19 from .wcs import WCS, WCSSUB_LATITUDE, WCSSUB_LONGITUDE

File [/opt/conda/lib/python3.11/site-packages/astropy/coordinates/__init__.py:9](https://daskhub-dev.fornax.smce.nasa.gov/opt/conda/lib/python3.11/site-packages/astropy/coordinates/__init__.py#line=8)
      1 # Licensed under a 3-clause BSD style license - see LICENSE.rst
      3 """
      4 This subpackage contains classes and functions for celestial coordinates
      5 of astronomical objects. It also contains a framework for conversions
      6 between coordinate systems.
      7 """
----> 9 from .angles import *
     10 from .attributes import *
     11 from .baseframe import *

File [/opt/conda/lib/python3.11/site-packages/astropy/coordinates/angles/__init__.py:11](https://daskhub-dev.fornax.smce.nasa.gov/opt/conda/lib/python3.11/site-packages/astropy/coordinates/angles/__init__.py#line=10)
      9 from .core import *
     10 from .errors import *
---> 11 from .utils import *
     13 # isort: split
     14 from . import core as _core

File [/opt/conda/lib/python3.11/site-packages/astropy/coordinates/angles/utils.py:21](https://daskhub-dev.fornax.smce.nasa.gov/opt/conda/lib/python3.11/site-packages/astropy/coordinates/angles/utils.py#line=20)
     19 # Astropy
     20 import astropy.units as u
---> 21 from astropy.coordinates.representation import (
     22     SphericalRepresentation,
     23     UnitSphericalRepresentation,
     24 )
     25 from astropy.utils.compat import COPY_IF_NEEDED
     27 _TWOPI = 2 * np.pi

File [/opt/conda/lib/python3.11/site-packages/astropy/coordinates/representation/__init__.py:10](https://daskhub-dev.fornax.smce.nasa.gov/opt/conda/lib/python3.11/site-packages/astropy/coordinates/representation/__init__.py#line=9)
      8 from .cartesian import CartesianDifferential, CartesianRepresentation
      9 from .cylindrical import CylindricalDifferential, CylindricalRepresentation
---> 10 from .geodetic import (
     11     BaseBodycentricRepresentation,
     12     BaseGeodeticRepresentation,
     13     GRS80GeodeticRepresentation,
     14     WGS72GeodeticRepresentation,
     15     WGS84GeodeticRepresentation,
     16 )
     17 from .spherical import (
     18     BaseSphericalCosLatDifferential,
     19     BaseSphericalDifferential,
   (...)
     29     UnitSphericalRepresentation,
     30 )
     32 # The following imports are included for backwards compatibility.
     33 # isort: split

File [/opt/conda/lib/python3.11/site-packages/astropy/coordinates/representation/geodetic.py:175](https://daskhub-dev.fornax.smce.nasa.gov/opt/conda/lib/python3.11/site-packages/astropy/coordinates/representation/geodetic.py#line=174)
    170         lon = np.arctan2(cart.y, cart.x)
    171         return cls(lon, lat, height, copy=False)
    174 @format_doc(geodetic_base_doc)
--> 175 class WGS84GeodeticRepresentation(BaseGeodeticRepresentation):
    176     """Representation of points in WGS84 3D geodetic coordinates."""
    178     _ellipsoid = "WGS84"

File <frozen abc>:106, in __new__(mcls, name, bases, namespace, **kwargs)

File [/opt/conda/lib/python3.11/site-packages/astropy/coordinates/representation/geodetic.py:56](https://daskhub-dev.fornax.smce.nasa.gov/opt/conda/lib/python3.11/site-packages/astropy/coordinates/representation/geodetic.py#line=55), in BaseGeodeticRepresentation.__init_subclass__(cls, **kwargs)
     54 def __init_subclass__(cls, **kwargs):
     55     if "_ellipsoid" in cls.__dict__:
---> 56         equatorial_radius, flattening = erfa.eform(getattr(erfa, cls._ellipsoid))
     57         cls._equatorial_radius = equatorial_radius * u.m
     58         cls._flattening = flattening * u.dimensionless_unscaled

File [/opt/conda/lib/python3.11/site-packages/erfa/core.py:15760](https://daskhub-dev.fornax.smce.nasa.gov/opt/conda/lib/python3.11/site-packages/erfa/core.py#line=15759), in eform(n)
  15684 """
  15685 Earth reference ellipsoids.
  15686 
   (...)
  15757 
  15758 """
  15759 a, f, c_retval = ufunc.eform(n)
> 15760 check_errwarn(c_retval, 'eform')
  15761 return a, f

File [/opt/conda/lib/python3.11/site-packages/erfa/core.py:105](https://daskhub-dev.fornax.smce.nasa.gov/opt/conda/lib/python3.11/site-packages/erfa/core.py#line=104), in check_errwarn(statcodes, func_name)
    104 def check_errwarn(statcodes, func_name):
--> 105     if not np.any(statcodes):
    106         return
    107     # Remap any errors into warnings in the STATUS_CODES_REMAP dict.

File [/opt/conda/lib/python3.11/site-packages/numpy/core/fromnumeric.py:2412](https://daskhub-dev.fornax.smce.nasa.gov/opt/conda/lib/python3.11/site-packages/numpy/core/fromnumeric.py#line=2411), in any(a, axis, out, keepdims, where)
   2322 @array_function_dispatch(_any_dispatcher)
   2323 def any(a, axis=None, out=None, keepdims=np._NoValue, *, where=np._NoValue):
   2324     """
   2325     Test whether any array element along a given axis evaluates to True.
   2326 
   (...)
   2410 
   2411     """
-> 2412     return _wrapreduction(a, np.logical_or, 'any', axis, None, out,
   2413                           keepdims=keepdims, where=where)

File [/opt/conda/lib/python3.11/site-packages/numpy/core/fromnumeric.py:86](https://daskhub-dev.fornax.smce.nasa.gov/opt/conda/lib/python3.11/site-packages/numpy/core/fromnumeric.py#line=85), in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs)
     84             return reduction(axis=axis, dtype=dtype, out=out, **passkwargs)
     85         else:
---> 86             return reduction(axis=axis, out=out, **passkwargs)
     88 return ufunc.reduce(obj, axis, dtype, out, **passkwargs)

File [/opt/conda/lib/python3.11/site-packages/numpy/_core/_methods.py:15](https://daskhub-dev.fornax.smce.nasa.gov/opt/conda/lib/python3.11/site-packages/numpy/_core/_methods.py#line=14)
     13 from numpy._core import umath as um
     14 from numpy._core.multiarray import asanyarray
---> 15 from numpy._core import numerictypes as nt
     16 from numpy._core import _exceptions
     17 from numpy._core._ufunc_config import _no_nep50_warning

File [/opt/conda/lib/python3.11/site-packages/numpy/_core/numerictypes.py:102](https://daskhub-dev.fornax.smce.nasa.gov/opt/conda/lib/python3.11/site-packages/numpy/_core/numerictypes.py#line=101)
     96 # we don't need all these imports, but we need to keep them for compatibility
     97 # for users using np._core.numerictypes.UPPER_TABLE
     98 from ._string_helpers import (
     99     english_lower, english_upper, english_capitalize, LOWER_TABLE, UPPER_TABLE
    100 )
--> 102 from ._type_aliases import (
    103     sctypeDict, allTypes, sctypes
    104 )
    105 from ._dtype import _kind_name
    107 # we don't export these for import *, but we do want them accessible
    108 # as numerictypes.bool, etc.

File [/opt/conda/lib/python3.11/site-packages/numpy/_core/_type_aliases.py:38](https://daskhub-dev.fornax.smce.nasa.gov/opt/conda/lib/python3.11/site-packages/numpy/_core/_type_aliases.py#line=37)
     31 _abstract_type_names = {
     32     "generic", "integer", "inexact", "floating", "number",
     33     "flexible", "character", "complexfloating", "unsignedinteger",
     34     "signedinteger"
     35 }
     37 for _abstract_type_name in _abstract_type_names:
---> 38     allTypes[_abstract_type_name] = getattr(ma, _abstract_type_name)
     40 for k, v in typeinfo.items():
     41     if k.startswith("NPY_") and v not in c_names_dict:

AttributeError: module 'numpy.core.multiarray' has no attribute 'floating'
@zoghbi-a
Copy link

zoghbi-a commented Aug 23, 2024

I suspect this is caused by numpy version conflict somewhere. I will have a look.

@zoghbi-a
Copy link

As far as I can see, this error is caused by a conflict in the numpy version. Version 2.1.0 was installed with conda, and 1.26 was installed with pip from the requirements of the IVOA_2024_demo notebooks.
Forcing the conda version to be <2 fixes the issues. It is deployed in the Dev Astrophysics image.

@bsipocz
Copy link
Member

bsipocz commented Aug 23, 2024

I don't see any numpy<2 pins in the demo notebooks repo, nor in hipscat/lsdb. Can we dive into where it was actually coming from? (In the readme there is an lsdb pin to an old version, but it's not present in the requirements file)

@zoghbi-a
Copy link

Yes, I don't know where it is coming from, but doing pip install -r requirements.txt, grabs 1.26, so it is somewhere in the dependency chain.

@zoghbi-a
Copy link

It would've been easier if the lsdb notebook was in a separate environment, but that does not work because of dask. It needs to be in the same environment running jupyterlab

@bsipocz
Copy link
Member

bsipocz commented Aug 23, 2024

And I cannot investigate locally as I cannot build healpy atm (but this is a know osx issue that should not affect fornax)

@troyraen
Copy link
Author

Looks like mocpy requires numpy<2.0. mocpy is required by hipscat, which is required by lsdb.

@bsipocz
Copy link
Member

bsipocz commented Aug 26, 2024

OK, this is tracked here, with references for more upstream:
cds-astro/mocpy#145

@troyraen
Copy link
Author

Works for me now. Thanks @zoghbi-a .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants