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

Add external group (generic I/O of arrays beyond the trexio format) #117

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ CLEANFILES = trexio.mod
if HAVE_FORTRAN
BUILT_SOURCES = trexio.mod
else
BUILT_SOURCES =
BUILT_SOURCES =
endif
EXTRA_DIST = .git_hash

Expand Down Expand Up @@ -116,6 +116,7 @@ TESTS_C += \
tests/io_dset_float_hdf5 \
tests/io_dset_int_hdf5 \
tests/io_dset_sparse_hdf5 \
tests/io_dset_external_hdf5 \
tests/io_determinant_hdf5 \
tests/io_jastrow_hdf5 \
tests/io_safe_dset_float_hdf5 \
Expand Down Expand Up @@ -303,7 +304,7 @@ DEB_FILES = \
helpers-debian/libtrexio0.install \
helpers-debian/libtrexio-dev.install \
helpers-debian/source \
helpers-debian/README.source
helpers-debian/README.source

debian_from_dist: $(DEB_FILES) $(SOURCES) $(trexio_h)
cp ../trexio-$(PACKAGE_VERSION).tar.gz ../libtrexio_$(PACKAGE_VERSION).orig.tar.gz
Expand Down
3 changes: 3 additions & 0 deletions python/test/benzene_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@

orb_up_test = [0, 65, 128, 129]
orb_dn_test = [1, 64, 128, 129]

external_2Dfloat_name = "test external float matrix"
external_1Dint32_name = "test external int32 vector"
28 changes: 28 additions & 0 deletions python/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ def test_array_2D(self):
assert trexio.has_nucleus_coord(self.test_file)


def test_external_array(self):
"""Write external arrays."""
self.open()

assert not trexio.has_external_array(self.test_file, external_2Dfloat_name)
trexio.write_external_array(self.test_file, nucleus_coord, external_2Dfloat_name)
assert trexio.has_external_array(self.test_file, external_2Dfloat_name)

assert not trexio.has_external_array(self.test_file, external_1Dint32_name)
trexio.write_external_array(self.test_file, np.array(nucleus_charge,dtype=np.int32), external_1Dint32_name)
assert trexio.has_external_array(self.test_file, external_1Dint32_name)


def test_indices(self):
"""Write array of indices."""
self.open()
Expand Down Expand Up @@ -252,6 +265,21 @@ def test_read_array_2D(self):
np.testing.assert_array_almost_equal(coords_np, np.array(nucleus_coord).reshape(nucleus_num,3), decimal=8)


def test_read_external_array(self):
"""Read external arrays."""
self.open(mode='r')
# read nuclear coordinates without providing optional argument dim
coords_external_np = trexio.read_external_array(self.test_file, name=external_2Dfloat_name, dtype="float64", size=nucleus_num*3)
assert coords_external_np.dtype is np.dtype(np.float64)
assert coords_external_np.size == nucleus_num * 3
np.testing.assert_array_almost_equal(coords_external_np.reshape(nucleus_num,3), np.array(nucleus_coord).reshape(nucleus_num,3), decimal=8)

charge_external_np = trexio.read_external_array(self.test_file, name=external_1Dint32_name, dtype="int32", size=nucleus_num)
assert charge_external_np.dtype is np.dtype(np.int32)
assert charge_external_np.size == nucleus_num
np.testing.assert_array_almost_equal(charge_external_np, np.array(nucleus_charge, dtype=np.int32))


def test_read_errors(self):
"""Test some reading errors."""
self.open(mode='r')
Expand Down
3 changes: 3 additions & 0 deletions src/pytrexio.i
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ import_array();
/* For some reasons SWIG does not apply the proper bitfield_t typemap, so one has to manually specify int64_t* ARGOUT_ARRAY1 below */
%apply (int64_t* ARGOUT_ARRAY1, int32_t DIM1) {(bitfield_t* const bit_list, const int32_t N_int)};

/* For passing dimensions of external arrays fron Python front to C back */
%apply (uint64_t* IN_ARRAY1, int32_t DIM1) {(const uint64_t* dims_in, const int32_t dims_dim_in)};

/* This tells SWIG to treat char ** dset_in pattern as a special case
Enables access to trexio_[...]_write_dset_str set of functions directly, i.e.
by converting input list of strings from Python into char ** of C
Expand Down
Loading