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

Load functionality for multiple .npy files #1388

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
aac6577
Load functionality for .npy files
Reisii Feb 28, 2024
eec33c1
Merge branch 'main' into features/900-Improve_load-functionality_load…
mrfh92 Feb 28, 2024
44b8383
Added pseudo Unittests, not on par in terms of quality and functionality
Reisii Mar 4, 2024
68dee6a
Added self.asserts in Unittest and some error messages for wrong user…
Reisii Mar 7, 2024
7919a90
Added self.asserts in Unittest and some error messages for wrong user…
Reisii Mar 7, 2024
72b557e
Deleted old test data
Reisii Mar 7, 2024
5ffadb4
Datasets will now be created on the datasets direcotry but cannot be …
Reisii Mar 7, 2024
df2800a
fixed problem with paths: error was in io.py line 1185 since np.load …
Mar 7, 2024
c91e029
removed npy files
Mar 7, 2024
b27c8b7
Some exception testing added
Reisii Mar 7, 2024
afe23fb
Some exception testing added
Reisii Mar 7, 2024
1c2658d
Merge branch 'main' into features/900-Improve_load-functionality_load…
mrfh92 Mar 11, 2024
f5ce751
Now stuck on test_load_npy and unable to complete
Reisii Mar 11, 2024
bb88962
Now stuck on test_load_npy and unable to complete
Reisii Mar 11, 2024
0d902c3
Merge branch 'features/900-Improve_load-functionality_load_multiple_f…
Reisii Mar 11, 2024
6ed3cbd
added comparison of two numpy arrays
Mar 11, 2024
62175be
Still not the same arrays, however, the creation of the dataset runs …
Reisii Mar 13, 2024
9aafa97
Fixed split problem
Reisii Mar 15, 2024
ccd4072
Not so pretty solution for failed self.assertTrue() test, but now wor…
Reisii Mar 19, 2024
063b382
Not so pretty solution for failed self.assertTrue() test, but now wor…
Reisii Mar 19, 2024
975884d
Added a test for floats and different split axis. Test will now delet…
Reisii Mar 20, 2024
296acef
Added last exception tests
Reisii Mar 20, 2024
943ebfe
Test shouldn't fail if run on only one process now
Reisii Mar 20, 2024
ed205f1
...
Apr 2, 2024
01fd3ec
Merge branch 'features/900-Improve_load-functionality_load_multiple_f…
Apr 2, 2024
cf61f7c
Merge branch 'main' into features/900-Improve_load-functionality_load…
mrfh92 Apr 4, 2024
e6c3796
Merge branch 'main' into features/900-Improve_load-functionality_load…
ClaudiaComito Apr 22, 2024
f549589
Merge branch 'main' into features/900-Improve_load-functionality_load…
mrfh92 May 31, 2024
ed6f1fe
Added docstrings and got rid of the time.sleep()
Reisii Jul 1, 2024
269f86a
Merge branch 'main' into features/900-Improve_load-functionality_load…
mrfh92 Jul 1, 2024
db80b4b
Fixed some typos
Reisii Jul 1, 2024
4557cee
Removed the Examples block as there is no real need for it
Reisii Jul 1, 2024
3e6fa95
Merge branch 'main' into features/900-Improve_load-functionality_load…
mrfh92 Jul 2, 2024
3cee731
Suggested changes applied
Reisii Jul 2, 2024
6a0ce2d
Suggested changes applied
Reisii Jul 2, 2024
83d953e
Merge branch 'features/900-Improve_load-functionality_load_multiple_f…
Reisii Jul 2, 2024
cc75692
Raises Section
Reisii Jul 2, 2024
bff9ce0
Docstring for split fixed
Reisii Jul 2, 2024
a0c9ebe
Delete heat/datasets/npy_dummy directory
mrfh92 Jul 2, 2024
3428798
Merge branch 'features/900-Improve_load-functionality_load_multiple_f…
Jul 3, 2024
c519d51
q# neue Datei: heat/datasets/float_data.npy
Jul 3, 2024
6ca3540
removed files
Jul 3, 2024
77b937b
Update test_io.py
mrfh92 Jul 3, 2024
f4fa1d6
fixed wrong unindent
Jul 3, 2024
3666a9c
Update test_io.py
mrfh92 Jul 3, 2024
ea30011
Update test_io.py
mrfh92 Jul 3, 2024
39a2bc3
Commited changes from mtar
Reisii Jul 4, 2024
94d2882
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2024
b5a06b2
Merge branch 'main' into features/900-Improve_load-functionality_load…
mrfh92 Jul 4, 2024
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
50 changes: 49 additions & 1 deletion heat/core/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import numpy as np
import torch
import warnings
import fnmatch

from typing import Dict, Iterable, List, Optional, Tuple, Union

Expand All @@ -27,7 +28,15 @@
__NETCDF_EXTENSIONS = frozenset([".nc", ".nc4", "netcdf"])
__NETCDF_DIM_TEMPLATE = "{}_dim_{}"

__all__ = ["load", "load_csv", "save_csv", "save", "supports_hdf5", "supports_netcdf"]
__all__ = [
"load",
"load_csv",
"save_csv",
"save",
"supports_hdf5",
"supports_netcdf",
"load_npy_from_path",
]

try:
import h5py
Expand Down Expand Up @@ -1132,3 +1141,42 @@ def save(

DNDarray.save = lambda self, path, *args, **kwargs: save(self, path, *args, **kwargs)
DNDarray.save.__doc__ = save.__doc__


def load_npy_from_path(
path: str,
dtype: datatype = types.float32,
split: Optional[int] = None,
device: Optional[str] = None,
comm: Optional[Communication] = None,
):
Reisii marked this conversation as resolved.
Show resolved Hide resolved
"""
mrfh92 marked this conversation as resolved.
Show resolved Hide resolved
Abc
"""
process_number = MPI_WORLD.size
file_list = []
for file in os.listdir(path):
if fnmatch.fnmatch(file, "*.npy"):
file_list.append(file)
n_files = len(file_list)

rank = MPI_WORLD.rank
if rank + 1 != process_number:
n_for_procs = n_files // process_number
else:
n_for_procs = (n_files // process_number) + (n_files % process_number)

local_list = [
file_list[i]
for i in range(
rank * (n_files // process_number), rank * (n_files // process_number) + n_for_procs
)
]
array_list = []
for element in local_list:
array_list.append(np.load(element))
larray = np.concatenate(array_list, split)
larray = torch.from_numpy(larray)

x = factories.array(larray, dtype=dtype, device=device, split=split, comm=comm)
return x
18 changes: 18 additions & 0 deletions heat/core/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import torch
import tempfile
import random

import heat as ht
from .test_suites.basic_test import TestCase
Expand Down Expand Up @@ -739,3 +740,20 @@ def test_save_netcdf_exception(self):
# os.rmdir(os.getcwd() + '/tmp/')
# except OSError:
# pass

def test_load_npy(self):
# Abc
crea_array = np.random.randint(1024, size=(random.randint(1, 100), 5, 11))
np.save("data0", crea_array)

for i in range(1, 100):
x = np.random.randint(1024, size=(random.randint(1, 100), 5, 11))
crea_array = np.concatenate(x, 0)
np.save("data" + str(i), x)

array1 = ht.load_npy_from_path("/home/nguy_t4/home/heat/heat/core/tests")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Der Pfad wird natürlich nicht gefunden, da die Tests auf den Runnern nicht auf deinem Rechner laufen... du musst hier einen relativen Pfad angeben, vermutlich /heat/core/tests o.ä.


if array1.numpy() == crea_array:
print("Everything correct")
else:
print("Loaded array and created array do not match")
Loading