From f5a2e635cfdcdae921050c98c39623bdff546a88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Coppens?= Date: Sun, 28 Feb 2021 09:28:42 +0100 Subject: [PATCH] Added environment variables source script. Added test script that loops over update cycles. Added test program that loops internally over test cycles. --- Makefile | 7 +- runtests.sh | 22 ++++ smvarsrc | 3 + tests/{test_h5.cpp => test_external_h5.cpp} | 5 +- tests/test_internal_h5.cpp | 112 ++++++++++++++++++++ 5 files changed, 145 insertions(+), 4 deletions(-) create mode 100755 runtests.sh create mode 100644 smvarsrc rename tests/{test_h5.cpp => test_external_h5.cpp} (93%) create mode 100644 tests/test_internal_h5.cpp diff --git a/Makefile b/Makefile index 147c26e..0f646cd 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,8 @@ OBJ_DIR := build BIN_DIR := bin EXEC := $(BIN_DIR)/cMaponiA3_test_3x3_3 \ - $(BIN_DIR)/test_h5 \ + $(BIN_DIR)/test_internal_h5 \ + $(BIN_DIR)/test_external_h5 \ $(BIN_DIR)/fMaponiA3_test_3x3_3 \ $(BIN_DIR)/fMaponiA3_test_4x4_2 \ $(BIN_DIR)/QMCChem_dataset_test @@ -71,7 +72,9 @@ $(OBJ_DIR)/SM_MaponiA3.o: $(SRC_DIR)/SM_MaponiA3.cpp $(INC_DIR)/* | $(OBJ_DIR) $(BIN_DIR)/cMaponiA3_test_3x3_3: $(OBJ_DIR)/cMaponiA3_test_3x3_3.o $(DEPS_CXX) | $(BIN_DIR) $(CXX) -o $@ $^ -$(BIN_DIR)/test_h5: $(OBJ_DIR)/test_h5.o $(DEPS_CXX) | $(BIN_DIR) +$(BIN_DIR)/test_internal_h5: $(OBJ_DIR)/test_internal_h5.o $(DEPS_CXX) | $(BIN_DIR) + $(H5CXX) -o $@ $^ +$(BIN_DIR)/test_external_h5: $(OBJ_DIR)/test_external_h5.o $(DEPS_CXX) | $(BIN_DIR) $(H5CXX) -o $@ $^ $(BIN_DIR)/fMaponiA3_test_3x3_3: $(DEPS_F) $(OBJ_DIR)/fMaponiA3_test_3x3_3.o | $(BIN_DIR) diff --git a/runtests.sh b/runtests.sh new file mode 100755 index 0000000..11b3704 --- /dev/null +++ b/runtests.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +start_cycle=$1 +stop_cycle=$2 + +if [ "$#" -ne 2 ] +then + echo "usage: ./run-tests.sh " + exit 1 +fi + +if [ ! -f "bin/test_external_h5" ] +then + make bin/test_external_h5 +fi + +cd datasets/ + +for ((cycle = start_cycle; cycle < stop_cycle+1; cycle++)) +do + ../bin/test_external_h5 $cycle +done \ No newline at end of file diff --git a/smvarsrc b/smvarsrc new file mode 100644 index 0000000..0265f11 --- /dev/null +++ b/smvarsrc @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +export PATH=$PWD/bin:$PATH diff --git a/tests/test_h5.cpp b/tests/test_external_h5.cpp similarity index 93% rename from tests/test_h5.cpp rename to tests/test_external_h5.cpp index ef96b0e..3f090bb 100644 --- a/tests/test_h5.cpp +++ b/tests/test_external_h5.cpp @@ -1,7 +1,7 @@ #include #include #include "hdf5/serial/hdf5.h" -#include "H5Cpp.h" +#include "hdf5/serial/H5Cpp.h" #include "SM_MaponiA3.hpp" #include "Helpers.hpp" @@ -87,7 +87,8 @@ int test_cycle(H5File file, int cycle) { int main(int argc, char **argv) { if (argc != 2) { - std::cerr << "usage: ./test " << std::endl; + std::cerr << "Execute from within 'datasets/'" << std::endl; + std::cerr << "usage: test_external_h5 " << std::endl; return 1; } int cycle = std::stoi(argv[1]); diff --git a/tests/test_internal_h5.cpp b/tests/test_internal_h5.cpp new file mode 100644 index 0000000..949ff4c --- /dev/null +++ b/tests/test_internal_h5.cpp @@ -0,0 +1,112 @@ +#include +#include +#include "hdf5/serial/hdf5.h" +#include "hdf5/serial/H5Cpp.h" + +#include "SM_MaponiA3.hpp" +#include "Helpers.hpp" + +using namespace H5; +//#define DEBUG + +const H5std_string FILE_NAME( "datasets.hdf5" ); + +void read_int(H5File file, std::string key, unsigned int * data) { + DataSet ds = file.openDataSet(key); + ds.read(data, PredType::STD_U32LE); + ds.close(); +} + +void read_double(H5File file, std::string key, double * data) { + DataSet ds = file.openDataSet(key); + ds.read(data, PredType::IEEE_F64LE); + ds.close(); +} + +int test_cycle(H5File file, int cycle) { + + /* Read the data */ + + std::string group = "cycle_" + std::to_string(cycle); + + unsigned int dim, nupdates, col, i, j; + read_int(file, group + "/slater_matrix_dim", &dim); + read_int(file, group + "/nupdates", &nupdates); + + double * slater_matrix = new double[dim*dim]; + read_double(file, group + "/slater_matrix", slater_matrix); + + double * slater_inverse = new double[dim*dim]; + read_double(file, group + "/slater_inverse", slater_inverse); + slater_inverse = transpose(slater_inverse, dim); + + unsigned int * col_update_index = new unsigned int[nupdates]; + read_int(file, group + "/col_update_index", col_update_index); + + double * updates = new double[nupdates*dim]; + read_double(file, group + "/updates", updates); + + /* Test */ +#ifdef DEBUG + showMatrix(slater_matrix, dim, "OLD Slater"); +#endif + +#ifdef DEBUG + showMatrix(slater_inverse, dim, "OLD Inverse"); +#endif + + for (j = 0; j < nupdates; j++) { + for (i = 0; i < dim; i++) { + col = col_update_index[j]; + slater_matrix[i*dim + (col - 1)] += updates[i + j*dim]; + } + } + + MaponiA3(slater_inverse, dim, nupdates, updates, col_update_index); + +#ifdef DEBUG + showMatrix(slater_matrix, dim, "NEW Slater"); +#endif + +#ifdef DEBUG + showMatrix(slater_inverse, dim, "NEW Inverse"); +#endif + + double * res = matMul(slater_matrix, slater_inverse, dim); + bool ok = is_identity(res, dim, 0.5e-4); + +#ifdef DEBUG + showMatrix(res, dim, "Result"); +#endif + + delete [] res, updates, col_update_index, + slater_matrix, slater_inverse; + + return ok; +} + +int main(int argc, char **argv) { + if (argc != 3) { + std::cerr << "Execute from within 'datasets/'" << std::endl; + std::cerr << "usage: test_internal_h5 " << std::endl; + return 1; + } + int start_cycle = std::stoi(argv[1]); + int stop_cycle = std::stoi(argv[2]); + H5File file(FILE_NAME, H5F_ACC_RDONLY); + + bool ok; + for (int cycle = start_cycle; cycle < stop_cycle+1; cycle++) { + ok = test_cycle(file, cycle); + if (ok) { + std::cerr << "ok -- cycle " << std::to_string(cycle) + << std::endl; + } + else { + std::cerr << "failed -- cycle " << std::to_string(cycle) + << std::endl; + } + } + + return ok; +}