From 109f3ea41f356a0513469f8fedd477b6ce579e6e Mon Sep 17 00:00:00 2001 From: q-posev Date: Fri, 22 Apr 2022 13:18:29 +0200 Subject: [PATCH] Add tests for to_orbital_list_up_dn functions --- python/test/test_api.py | 14 +++++++++- tests/io_determinant_hdf5.c | 52 +++++++++++++++++++++++++++++++------ tests/io_determinant_text.c | 52 +++++++++++++++++++++++++++++++------ tests/test_f.f90 | 36 +++++++++++++++++++------ 4 files changed, 129 insertions(+), 25 deletions(-) diff --git a/python/test/test_api.py b/python/test/test_api.py index 13f4b42..4528559 100644 --- a/python/test/test_api.py +++ b/python/test/test_api.py @@ -308,7 +308,7 @@ assert indices_sparse_np[read_buf_size-1][3]==(offset_file+read_buf_size)*4-1 assert trexio.has_determinant_list(test_file2) assert trexio.read_determinant_num(test_file2)==num_dets -# read sparse arrays on ao_2e_int_eri integrals +# read determinants (list of ints and float coefficients) buf_size = 20 offset_file = 0 # read full buf_size (i.e. the one that does not reach EOF) @@ -326,6 +326,18 @@ print(f'First complete read of determinant coefficients: {read_buf_size}') assert not eof assert read_buf_size==buf_size +# convert one determinant into a list of orbitals + +dets_tmp = dets_np[read_buf_size-1][:] +#print(dets_tmp) + +# divide by 2 because in this test int_num is the total number of integers (i.e. up-spin + down_spin) +orb_list_up, orb_list_dn = trexio.to_orbital_list_up_dn(int(int_num/2), dets_tmp) +assert(orb_list_up[0] == 2) +assert(orb_list_dn[0] == 1) +#print(orb_list_up) +#print(orb_list_dn) + # read array of nuclear labels rlabels_2d = trexio.read_nucleus_label(test_file2, dim=nucleus_num) print(rlabels_2d) diff --git a/tests/io_determinant_hdf5.c b/tests/io_determinant_hdf5.c index 35cbe11..7ca2e7c 100644 --- a/tests/io_determinant_hdf5.c +++ b/tests/io_determinant_hdf5.c @@ -10,6 +10,7 @@ #define SIZE 100 #define N_CHUNKS 5 #define STATE_TEST 2 +#define MO_NUM 150 static int test_write_determinant (const char* file_name, const back_end_t backend, const int64_t offset) { @@ -29,7 +30,7 @@ static int test_write_determinant (const char* file_name, const back_end_t backe int64_t* det_list; double* det_coef; - int mo_num = 150; + int mo_num = MO_NUM; det_list = (int64_t*) calloc(2*3*SIZE, sizeof(int64_t)); det_coef = (double*) calloc(SIZE, sizeof(double)); @@ -167,14 +168,23 @@ static int test_read_determinant (const char* file_name, const back_end_t backen assert (file != NULL); assert (rc == TREXIO_SUCCESS); - // define arrays to read into + // compute how many integer bit fields is needed per determinant (for a given spin) + int64_t mo_num; + rc = trexio_read_mo_num_64(file, &mo_num); + assert (rc == TREXIO_SUCCESS); + assert (mo_num == MO_NUM); + + int int_num = (mo_num - 1)/64 + 1; + assert (int_num == 3); + + // define arrays to read into int64_t* det_list_read; double* det_coef_read; double* det_coef_s2_read; double check_diff; uint64_t size_r = 40L; - det_list_read = (int64_t*) calloc(2*3*size_r,sizeof(int64_t)); + det_list_read = (int64_t*) calloc(2*int_num*size_r,sizeof(int64_t)); det_coef_read = (double*) calloc(size_r,sizeof(double)); det_coef_s2_read = (double*) calloc(size_r,sizeof(double)); @@ -189,11 +199,11 @@ static int test_read_determinant (const char* file_name, const back_end_t backen if (offset != 0L) offset_file_read += offset; // read one chunk using the aforementioned parameters - rc = trexio_read_determinant_list(file, offset_file_read, &chunk_read, &det_list_read[6*offset_data_read]); + rc = trexio_read_determinant_list(file, offset_file_read, &chunk_read, &det_list_read[2*int_num*offset_data_read]); assert(rc == TREXIO_SUCCESS); assert(chunk_read == read_size_check); assert(det_list_read[0] == 0); - assert(det_list_read[6*offset_data_read] == 6 * (int64_t) (offset_file_read-offset)); + assert(det_list_read[2*int_num*offset_data_read] == 2 * int_num * (int64_t) (offset_file_read-offset)); rc = trexio_read_determinant_coefficient(file, offset_file_read, &chunk_read, &det_coef_read[offset_data_read]); assert(rc == TREXIO_SUCCESS); @@ -229,7 +239,7 @@ static int test_read_determinant (const char* file_name, const back_end_t backen chunk_read = read_size_check; // read one chunk that will reach EOF and return TREXIO_END code - rc = trexio_read_determinant_list(file, offset_file_read, &chunk_read, &det_list_read[6*offset_data_read]); + rc = trexio_read_determinant_list(file, offset_file_read, &chunk_read, &det_list_read[2*int_num*offset_data_read]); /* printf("%s\n", trexio_string_of_error(rc)); for (int i=0; i