SWIFTSIM / swiftsimio

Python library for reading SWIFT data. Uses unyt and h5py.
GNU Lesser General Public License v3.0
15 stars 12 forks source link

Swiftsimio does not load with numpy 2.0.0 #192

Closed darwin-roduit closed 2 weeks ago

darwin-roduit commented 2 weeks ago

Hi everyone,

I encounter the following error when trying to load swiftsimio with numpy 2.0.0:

Traceback (most recent call last):
  File "plot_gas_density.py", line 8, in <module>
    import swiftsimio as sw
  File "py_analysis/lib/python3.11/site-packages/swiftsimio/__init__.py", line 1, in <module>
    from .reader import *
  File "py_analysis/lib/python3.11/site-packages/swiftsimio/reader.py", line 15, in <module>
    from swiftsimio.accelerated import read_ranges_from_file
  File "py_analysis/lib/python3.11/site-packages/swiftsimio/accelerated.py", line 87, in <module>
    columns: np.lib.index_tricks.IndexExpression = np.s_[:],
             ^^^^^^^^^^^^^^^^^^^
  File "py_analysis/lib/python3.11/site-packages/numpy/lib/__init__.py", line 77, in __getattr__
    raise AttributeError(
AttributeError: numpy.lib.index_tricks is now private. If you are using a public function, it should be available in the main numpy namespace, otherwise check the NumPy 2.0 migration guide.

Here are the first lines of my plot_gas_density.py script:

"""
Makes a gas density projection plot. Uses the swiftsimio library.
"""

import matplotlib.pyplot as plt
import numpy as np

import swiftsimio as sw #Here is line 8
from swiftsimio.visualisation.projection import project_gas

import unyt
from unyt import mh, cm
from tqdm import tqdm
from matplotlib.colors import LogNorm
from matplotlib.animation import FuncAnimation

Finally, the virtual env is created in the following way:

python3 -m venv py_analysis
source py_analysis/bin/activate
pip install numpy
pip install tqdm
pip install matplotlib
pip install swiftsimio

Notice that enforcing numpy version to be smaller than 2.0.0 works fine (pip install "numpy<2.0.0").

JBorrow commented 2 weeks ago

This is already fixed in the latest master, you can install it from the Git head. We'll be pushing a new release soon.

darwin-roduit commented 2 weeks ago

Great! Many thanks!