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

Make unit tests compatible with NumPy 2.x #1826

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ReceivePR.yml
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ jobs:
- name: Use Python
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
with:
python-version: 3.9
python-version: '3.10'
architecture: x64

- name: Setup MPI
1 change: 0 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@ jobs:
fail-fast: false
matrix:
py-version:
- 3.9
- '3.10'
- 3.11
- 3.12
27 changes: 14 additions & 13 deletions heat/core/linalg/tests/test_basics.py
Original file line number Diff line number Diff line change
@@ -61,19 +61,20 @@ def test_cross(self):
self.assert_array_equal(cross_axisc, np_cross_axisc)

# test vector axes with 2 elements
b_2d = ht.array(np_b[:-1, :, :], split=1)
cross_3d_2d = ht.cross(a, b_2d, axisa=1, axisb=0)
np_cross_3d_2d = np.cross(np_a, np_b[:-1, :, :], axisa=1, axisb=0)
self.assert_array_equal(cross_3d_2d, np_cross_3d_2d)

a_2d = ht.array(np_a[:, :-1, :], split=0)
cross_2d_3d = ht.cross(a_2d, b, axisa=1, axisb=0)
np_cross_2d_3d = np.cross(np_a[:, :-1, :], np_b, axisa=1, axisb=0)
self.assert_array_equal(cross_2d_3d, np_cross_2d_3d)

cross_z_comp = ht.cross(a_2d, b_2d, axisa=1, axisb=0)
np_cross_z_comp = np.cross(np_a[:, :-1, :], np_b[:-1, :, :], axisa=1, axisb=0)
self.assert_array_equal(cross_z_comp, np_cross_z_comp)
if np.lib.NumpyVersion(np.__version__) < "2.0.0b1":
b_2d = ht.array(np_b[:-1, :, :], split=1)
cross_3d_2d = ht.cross(a, b_2d, axisa=1, axisb=0)
np_cross_3d_2d = np.cross(np_a, np_b[:-1, :, :], axisa=1, axisb=0)
self.assert_array_equal(cross_3d_2d, np_cross_3d_2d)

a_2d = ht.array(np_a[:, :-1, :], split=0)
cross_2d_3d = ht.cross(a_2d, b, axisa=1, axisb=0)
np_cross_2d_3d = np.cross(np_a[:, :-1, :], np_b, axisa=1, axisb=0)
self.assert_array_equal(cross_2d_3d, np_cross_2d_3d)

cross_z_comp = ht.cross(a_2d, b_2d, axisa=1, axisb=0)
np_cross_z_comp = np.cross(np_a[:, :-1, :], np_b[:-1, :, :], axisa=1, axisb=0)
self.assert_array_equal(cross_z_comp, np_cross_z_comp)
Comment on lines +64 to +77
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Marc-Jindra During the PR meeting this morning we decided to keep the "cross_2d" functionality in Heat for now and compare it to the pytorch result in the tests when numpy==2. I.e. compare the distributed ht.cross (on split arrays) with the non-distributed pytorch output.


a_wrong_split = ht.array(np_a[:, :-1, :], split=2)
with self.assertRaises(ValueError):
3 changes: 2 additions & 1 deletion heat/core/tests/test_exponential.py
Original file line number Diff line number Diff line change
@@ -96,7 +96,8 @@ def test_expm1(self):

def test_exp2(self):
elements = 10
tmp = np.exp2(torch.arange(elements, dtype=torch.float64))
tmp = np.exp2(torch.arange(elements, dtype=torch.float64).numpy())
tmp = torch.tensor(tmp)
tmp = tmp.to(self.device.torch_device)
comparison = ht.array(tmp, device=self.device)

20 changes: 16 additions & 4 deletions heat/core/tests/test_manipulations.py
Original file line number Diff line number Diff line change
@@ -2687,22 +2687,31 @@ def test_row_stack(self):
# test local row_stack, 2-D arrays
a = np.arange(10, dtype=np.float32).reshape(2, 5)
b = np.arange(15, dtype=np.float32).reshape(3, 5)
np_rstack = np.row_stack((a, b))
if np.lib.NumpyVersion(np.__version__) >= "2.0.0b1":
np_rstack = np.vstack((a, b))
else:
np_rstack = np.row_stack((a, b))
ht_a = ht.array(a)
ht_b = ht.array(b)
ht_rstack = ht.row_stack((ht_a, ht_b))
self.assertTrue((np_rstack == ht_rstack.numpy()).all())

# 2-D and 1-D arrays
c = np.arange(5, dtype=np.float32)
np_rstack = np.row_stack((a, b, c))
if np.lib.NumpyVersion(np.__version__) >= "2.0.0b1":
np_rstack = np.vstack((a, b, c))
else:
np_rstack = np.row_stack((a, b, c))
ht_c = ht.array(c)
ht_rstack = ht.row_stack((ht_a, ht_b, ht_c))
self.assertTrue((np_rstack == ht_rstack.numpy()).all())

# 2-D and 1-D arrays, distributed
c = np.arange(5, dtype=np.float32)
np_rstack = np.row_stack((a, b, c))
if np.lib.NumpyVersion(np.__version__) >= "2.0.0b1":
np_rstack = np.vstack((a, b, c))
else:
np_rstack = np.row_stack((a, b, c))
ht_a = ht.array(a, split=0)
ht_b = ht.array(b, split=0)
ht_c = ht.array(c, split=0)
@@ -2713,7 +2722,10 @@ def test_row_stack(self):
# 1-D arrays, distributed, different dtypes
d = np.arange(10).astype(np.float32)
e = np.arange(10)
np_rstack = np.row_stack((d, e))
if np.lib.NumpyVersion(np.__version__) >= "2.0.0b1":
np_rstack = np.vstack((d, e))
else:
np_rstack = np.row_stack((d, e))
ht_d = ht.array(d, split=0)
ht_e = ht.array(e, split=0)
ht_rstack = ht.row_stack((ht_d, ht_e))
2 changes: 1 addition & 1 deletion heat/fft/tests/test_fft.py
Original file line number Diff line number Diff line change
@@ -123,7 +123,7 @@ def test_fftn_ifftn(self):
x = ht.random.randn(10, 8, 6, dtype=ht.float64, split=0)
# FFT along last 2 axes
y = ht.fft.fftn(x, s=(6, 6))
np_y = np.fft.fftn(x.numpy(), s=(6, 6))
np_y = np.fft.fftn(x.numpy(), s=(6, 6), axes=(1, 2))
self.assertIsInstance(y, ht.DNDarray)
self.assertEqual(y.shape, np_y.shape)
self.assertTrue(y.split == 0)
7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -21,10 +21,9 @@
author_email="[email protected]",
url="https://github.com/helmholtz-analytics/heat",
keywords=["data", "analytics", "tensors", "distributed", "gpu"],
python_requires=">=3.9",
python_requires=">=3.10",
classifiers=[
"Development Status :: 4 - Beta",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
@@ -34,9 +33,9 @@
],
install_requires=[
"mpi4py>=3.0.0",
"numpy>=1.22.0, <2",
"numpy>=1.23.5",
"torch>=2.0.0, <2.6.1",
"scipy>=1.10.0",
"scipy>=1.14.0",
"pillow>=6.0.0",
"torchvision>=0.15.2, <0.21.1",
],