mirror of
https://github.com/TREX-CoE/trexio.git
synced 2024-08-24 22:21:43 +02:00
Add tests for to_orbital_list_up_dn functions
This commit is contained in:
parent
32cb2255c4
commit
109f3ea41f
@ -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)
|
||||
|
@ -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<size_r; i++) {
|
||||
@ -238,8 +248,8 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
|
||||
*/
|
||||
assert(rc == TREXIO_END);
|
||||
assert(chunk_read == eof_read_size_check);
|
||||
assert(det_list_read[6*size_r-1] == 0);
|
||||
assert(det_list_read[6*offset_data_read] == 6 * (int64_t) (offset_file_read-offset));
|
||||
assert(det_list_read[2*int_num*size_r-1] == 0);
|
||||
assert(det_list_read[2*int_num*offset_data_read] == 2 * int_num * (int64_t) (offset_file_read-offset));
|
||||
|
||||
chunk_read = read_size_check;
|
||||
rc = trexio_read_determinant_coefficient(file, offset_file_read, &chunk_read, &det_coef_read[offset_data_read]);
|
||||
@ -265,6 +275,30 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
|
||||
assert(rc == TREXIO_SUCCESS);
|
||||
assert(det_num == size_check);
|
||||
|
||||
|
||||
// check conversion of determinants into orbital lists
|
||||
int64_t size_list = NORB_PER_INT * int_num;
|
||||
int32_t* orb_list_up = (int32_t*) calloc(size_list, sizeof(int32_t));
|
||||
int32_t* orb_list_dn = (int32_t*) calloc(size_list, sizeof(int32_t));
|
||||
int32_t occ_num_up, occ_num_dn;
|
||||
|
||||
rc = trexio_to_orbital_list_up_dn (int_num, &det_list_read[2*int_num*5], orb_list_up, orb_list_dn, &occ_num_up, &occ_num_dn);
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
assert (occ_num_up == 14);
|
||||
assert (occ_num_dn == 17);
|
||||
/* // DEBUG printing
|
||||
printf("occ_num_up : %d ; occ_num_dn : %d \n", occ_num_up, occ_num_dn);
|
||||
for (int i=0; i<occ_num_up; i++) {
|
||||
printf("%d ", orb_list_up[i]);
|
||||
}
|
||||
printf("| ");
|
||||
for (int i=0; i<occ_num_dn; i++) {
|
||||
printf("%d ", orb_list_dn[i]);
|
||||
}
|
||||
printf("\n");
|
||||
*/
|
||||
|
||||
|
||||
// close current session
|
||||
rc = trexio_close(file);
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
@ -273,6 +307,8 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
|
||||
free(det_list_read);
|
||||
free(det_coef_read);
|
||||
free(det_coef_s2_read);
|
||||
free(orb_list_up);
|
||||
free(orb_list_dn);
|
||||
|
||||
/*================= END OF TEST ==================*/
|
||||
|
||||
|
@ -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<size_r; i++) {
|
||||
@ -238,8 +248,8 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
|
||||
*/
|
||||
assert(rc == TREXIO_END);
|
||||
assert(chunk_read == eof_read_size_check);
|
||||
assert(det_list_read[6*size_r-1] == 0);
|
||||
assert(det_list_read[6*offset_data_read] == 6 * (int64_t) (offset_file_read-offset));
|
||||
assert(det_list_read[2*int_num*size_r-1] == 0);
|
||||
assert(det_list_read[2*int_num*offset_data_read] == 2 * int_num * (int64_t) (offset_file_read-offset));
|
||||
|
||||
chunk_read = read_size_check;
|
||||
rc = trexio_read_determinant_coefficient(file, offset_file_read, &chunk_read, &det_coef_read[offset_data_read]);
|
||||
@ -265,6 +275,30 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
|
||||
assert(rc == TREXIO_SUCCESS);
|
||||
assert(det_num == size_check);
|
||||
|
||||
|
||||
// check conversion of determinants into orbital lists
|
||||
int64_t size_list = NORB_PER_INT * int_num;
|
||||
int32_t* orb_list_up = (int32_t*) calloc(size_list, sizeof(int32_t));
|
||||
int32_t* orb_list_dn = (int32_t*) calloc(size_list, sizeof(int32_t));
|
||||
int32_t occ_num_up, occ_num_dn;
|
||||
|
||||
rc = trexio_to_orbital_list_up_dn (int_num, &det_list_read[2*int_num*5], orb_list_up, orb_list_dn, &occ_num_up, &occ_num_dn);
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
assert (occ_num_up == 14);
|
||||
assert (occ_num_dn == 17);
|
||||
/* // DEBUG printing
|
||||
printf("occ_num_up : %d ; occ_num_dn : %d \n", occ_num_up, occ_num_dn);
|
||||
for (int i=0; i<occ_num_up; i++) {
|
||||
printf("%d ", orb_list_up[i]);
|
||||
}
|
||||
printf("| ");
|
||||
for (int i=0; i<occ_num_dn; i++) {
|
||||
printf("%d ", orb_list_dn[i]);
|
||||
}
|
||||
printf("\n");
|
||||
*/
|
||||
|
||||
|
||||
// close current session
|
||||
rc = trexio_close(file);
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
@ -273,6 +307,8 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
|
||||
free(det_list_read);
|
||||
free(det_coef_read);
|
||||
free(det_coef_s2_read);
|
||||
free(orb_list_up);
|
||||
free(orb_list_dn);
|
||||
|
||||
/*================= END OF TEST ==================*/
|
||||
|
||||
|
@ -86,7 +86,7 @@ subroutine test_write(file_name, back_end)
|
||||
index_sparse_ao_2e_int_eri(4,i) = 4*i+3 - 3
|
||||
value_sparse_ao_2e_int_eri(i) = 3.14 + float(i)
|
||||
enddo
|
||||
|
||||
|
||||
! fill determinant list
|
||||
do i = 1, 50
|
||||
do j = 1, 6
|
||||
@ -170,7 +170,7 @@ subroutine test_write(file_name, back_end)
|
||||
rc = trexio_write_ao_num(trex_file, ao_num)
|
||||
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE AO NUM')
|
||||
endif
|
||||
! write mo_num which will be used to determine the optimal size of the determinants bit fields
|
||||
! write mo_num which will be used to determine the optimal size of the determinants bit fields
|
||||
if (trexio_has_mo_num(trex_file) == TREXIO_HAS_NOT) then
|
||||
rc = trexio_write_mo_num(trex_file, mo_num)
|
||||
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE MO NUM')
|
||||
@ -256,7 +256,12 @@ subroutine test_read(file_name, back_end)
|
||||
integer*8 :: read_buf_det_size = 20
|
||||
integer*8 :: offset_det_read = 10
|
||||
integer*8 :: offset_det_data_read = 5
|
||||
integer*8 :: determinant_num
|
||||
integer*8 :: determinant_num
|
||||
|
||||
! orbital lists
|
||||
integer*4 :: orb_list_up(150)
|
||||
integer*4 :: orb_list_dn(150)
|
||||
integer*4 :: occ_num_up, occ_num_dn
|
||||
|
||||
character*(128) :: str
|
||||
|
||||
@ -267,6 +272,8 @@ subroutine test_read(file_name, back_end)
|
||||
value_sparse_ao_2e_int_eri = 0.0d0
|
||||
|
||||
det_list = 0_8
|
||||
orb_list_up = 0
|
||||
orb_list_dn = 0
|
||||
|
||||
! ================= START OF TEST ===================== !
|
||||
|
||||
@ -337,8 +344,8 @@ subroutine test_read(file_name, back_end)
|
||||
|
||||
|
||||
rc = trexio_read_ao_2e_int_eri(trex_file, offset_read, read_buf_size, &
|
||||
index_sparse_ao_2e_int_eri(1, offset_data_read + 1), &
|
||||
value_sparse_ao_2e_int_eri(offset_data_read + 1))
|
||||
index_sparse_ao_2e_int_eri(1, offset_data_read + 1), &
|
||||
value_sparse_ao_2e_int_eri(offset_data_read + 1))
|
||||
!do i = 1,20
|
||||
! write(*,*) index_sparse_ao_2e_int_eri(1,i)
|
||||
!enddo
|
||||
@ -355,8 +362,8 @@ subroutine test_read(file_name, back_end)
|
||||
! attempt to read reaching EOF: should return TREXIO_END and
|
||||
! NOT increment the existing values in the buffer (only upd with what has been read)
|
||||
rc = trexio_read_ao_2e_int_eri(trex_file, offset_eof, read_buf_size, &
|
||||
index_sparse_ao_2e_int_eri(1, offset_data_eof + 1), &
|
||||
value_sparse_ao_2e_int_eri(offset_data_eof + 1))
|
||||
index_sparse_ao_2e_int_eri(1, offset_data_eof + 1), &
|
||||
value_sparse_ao_2e_int_eri(offset_data_eof + 1))
|
||||
!do i = 1,20
|
||||
! write(*,*) index_sparse_ao_2e_int_eri(1,i)
|
||||
!enddo
|
||||
@ -384,7 +391,7 @@ subroutine test_read(file_name, back_end)
|
||||
|
||||
! read a chunk of determinants
|
||||
rc = trexio_read_determinant_list(trex_file, offset_det_read, read_buf_det_size, &
|
||||
det_list(1, offset_det_data_read + 1))
|
||||
det_list(1, offset_det_data_read + 1))
|
||||
!do i = 1,50
|
||||
! write(*,*) det_list(1,i)
|
||||
!enddo
|
||||
@ -407,6 +414,19 @@ subroutine test_read(file_name, back_end)
|
||||
call exit(-1)
|
||||
endif
|
||||
|
||||
! convert one given determinant into lists of orbitals
|
||||
rc = trexio_to_orbital_list_up_dn(3, det_list(:, offset_det_data_read+1), orb_list_up, orb_list_dn, occ_num_up, occ_num_dn)
|
||||
!write(*,*) occ_num_up, occ_num_dn
|
||||
!write(*,*) orb_list_up(1:occ_num_up)
|
||||
!write(*,*) det_list(:, offset_det_data_read+1)
|
||||
call trexio_assert(rc, TREXIO_SUCCESS)
|
||||
if (occ_num_up == 16 .and. occ_num_dn == 5) then
|
||||
write(*,*) 'SUCCESS CONVERT DET LIST'
|
||||
else
|
||||
print *, 'FAILURE DET CONVERT CHECK'
|
||||
call exit(-1)
|
||||
endif
|
||||
|
||||
! close the file
|
||||
rc = trexio_close(trex_file)
|
||||
call trexio_assert(rc, TREXIO_SUCCESS)
|
||||
|
Loading…
Reference in New Issue
Block a user