s2fft icon indicating copy to clipboard operation
s2fft copied to clipboard

Issue when import `pyssht`

Open ASKabalan opened this issue 1 year ago • 4 comments

Trying to finish up my PR https://github.com/astro-informatics/s2fft/pull/204 I ran to an issue

  File "<string>", line 1, in <module>
  File "/home/wassim/Projects/CMB/s2fft/s2fft/__init__.py", line 2, in <module>
    from .transforms import wigner
  File "/home/wassim/Projects/CMB/s2fft/s2fft/transforms/__init__.py", line 1, in <module>
    from . import spherical
  File "/home/wassim/Projects/CMB/s2fft/s2fft/transforms/spherical.py", line 16, in <module>
    from s2fft.transforms import c_backend_spherical as c_sph
  File "/home/wassim/Projects/CMB/s2fft/s2fft/transforms/c_backend_spherical.py", line 8, in <module>
    import pyssht
  File "/home/wassim/micromamba/envs/jax/lib/python3.10/site-packages/pyssht/__init__.py", line 11, in <module>
    from pyssht.cpyssht import *
  File "cpyssht.pyx", line 1, in init pyssht.cpyssht
ImportError: numpy.core.multiarray failed to import (auto-generated because you didn't call 'numpy.import_array()' after cimporting numpy; use '<void>numpy._import_array' to disabl
e if you are certain you don't need it).

I think that there is an issue with pyssht and it prevents is from even importing s2fft

I commented it in three places

  • https://github.com/astro-informatics/s2fft/blob/main/s2fft/transforms/init.py#L4
  • https://github.com/astro-informatics/s2fft/blob/main/s2fft/transforms/spherical.py#L16
  • https://github.com/astro-informatics/s2fft/blob/main/s2fft/transforms/wigner.py#L9

And I set c_sph to None

Just to be able to test my PR

I will look into it if you want, but the wise thing to do here is to wrap the import with a try catch et dynamically deactivate pyssht if it not working

ASKabalan avatar Jul 29 '24 11:07 ASKabalan

The issue is because of pyproject.toml I am gonna look into it

ASKabalan avatar Jul 29 '24 11:07 ASKabalan

Firstly, thanks for your great work on S2FFT!

I ran into this issue while installing S2FFT using pip in a Conda environment. It seems the issue is that pyssht, which is imported by default by s2fft, is built against an old version of NumPy.

This is related to https://github.com/astro-informatics/ssht/issues/74.

I tried to build pyssht from source. The build completes, but now I get

>>> import pyssht
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "[...]/pyssht/__init__.py", line 11, in <module>
    from pyssht.cpyssht import *
  File "cpyssht.pyx", line 1, in init pyssht.cpyssht
ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject

as2875 avatar Sep 10 '24 15:09 as2875

My workaround is to set numpy<2 in my package's pyproject.toml.

as2875 avatar Sep 11 '24 09:09 as2875

Hey @as2875 great to hear you're finding the code useful! So this conflict was introduced when NumPy incremented to v2.0 last month. Ultimately this broke the python wrappers of the SSHT C package, as you say, and we have it on our todo list to fix.

The current workaround we'd suggest is exactly what you found, just ensure that numpy<2.

CosmoMatt avatar Sep 11 '24 10:09 CosmoMatt