1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-12-22 12:23:54 +01:00

Add tests for to_bitfield_list conversion

This commit is contained in:
q-posev 2022-07-12 17:21:53 +02:00
parent af828ea6cd
commit 755e94afab
5 changed files with 56 additions and 3 deletions

View File

@ -44,3 +44,6 @@ coeffs = [float(i/det_num) for i in range(det_num)]
coeffs_s2 = [float(i*2/det_num) for i in range(det_num)]
det_test = [1, 2, 3, 2, 1, 3]
orb_up_test = [0, 65, 128, 129]
orb_dn_test = [1, 64, 128, 129]

View File

@ -39,6 +39,17 @@ def test_orbital_list():
assert orb_list_dn[0] == 1
def test_bitfield_list():
"""Convert lists of occupied up- and down-spin orbitals into determinants."""
# convert det_test list into a numpy array for .all() assertion to work
det_test_np = np.array(det_test, dtype=np.int64)
det_list_up = trexio.to_bitfield_list(int64_num, orb_up_test)
assert (det_list_up == det_test_np[:int64_num]).all()
det_list_dn = trexio.to_bitfield_list(int64_num, orb_dn_test)
assert (det_list_dn == det_test_np[int64_num:]).all()
class TestIO:
"""Unit tests for writing/reading different blocks of the TREXIO file."""

View File

@ -307,6 +307,14 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
printf("\n");
*/
// check conversion of one orbital list into the bitfield determinant representation
int64_t* det_list_check = (int64_t*) calloc(int_num, sizeof(int64_t));
rc = trexio_to_bitfield_list (orb_list_up, occ_num_up, det_list_check, int_num);
assert (rc == TREXIO_SUCCESS);
for (int i=0; i<int_num; i++) {
assert (det_list_check[i] == det_list_read[2*int_num*5+i]);
}
// close current session
rc = trexio_close(file);
@ -316,6 +324,7 @@ 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(det_list_check);
free(orb_list_up);
free(orb_list_dn);

View File

@ -307,6 +307,14 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
printf("\n");
*/
// check conversion of one orbital list into the bitfield determinant representation
int64_t* det_list_check = (int64_t*) calloc(int_num, sizeof(int64_t));
rc = trexio_to_bitfield_list (orb_list_up, occ_num_up, det_list_check, int_num);
assert (rc == TREXIO_SUCCESS);
for (int i=0; i<int_num; i++) {
assert (det_list_check[i] == det_list_read[2*int_num*5+i]);
}
// close current session
rc = trexio_close(file);
@ -316,6 +324,7 @@ 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(det_list_check);
free(orb_list_up);
free(orb_list_dn);

View File

@ -6,11 +6,11 @@ program test_trexio
integer :: rc
logical :: have_hdf5
print * , "============================================"
print'(a)' , "============================================"
print'(a,a)' , " TREXIO VERSION STRING : ", TREXIO_PACKAGE_VERSION
print'(a,i3)', " TREXIO MAJOR VERSION : ", TREXIO_VERSION_MAJOR
print'(a,i3)', " TREXIO MINOR VERSION : ", TREXIO_VERSION_MINOR
print * , "============================================"
print'(a)' , "============================================"
rc = trexio_info()
@ -288,6 +288,7 @@ subroutine test_read(file_name, back_end)
! determinant data
integer*8 :: det_list(6,50)
integer*8 :: det_list_check(3)
integer*8 :: read_buf_det_size = 20
integer*8 :: offset_det_read = 10
integer*8 :: offset_det_data_read = 5
@ -479,6 +480,26 @@ subroutine test_read(file_name, back_end)
call exit(-1)
endif
! convert one orbital list into a bitfield determinant representation
rc = trexio_to_bitfield_list(orb_list_up, occ_num_up, det_list_check, 3)
!write(*,*) occ_num_up, occ_num_dn
! Print occupied orbitals for an up-spin component of a given determinant
!write(*,*) orb_list_up(1:occ_num_up)
! Print integers representanting a given determinant fully (up- and down-spin components)
!write(*,*) det_list(1:3, offset_det_data_read+1)
!write(*,*) det_list_check(1:3)
! Print binary representation of the first integer bit field of a given determinant
!write(*,'(B64.64)') det_list(1, offset_det_data_read+1)
call trexio_assert(rc, TREXIO_SUCCESS)
if (det_list_check(1) == det_list(1, offset_det_data_read+1) .and. &
det_list_check(2) == det_list(2, offset_det_data_read+1) .and. &
det_list_check(3) == det_list(3, offset_det_data_read+1)) then
write(*,*) 'SUCCESS CONVERT ORB LIST'
else
print *, 'FAILURE ORB CONVERT CHECK'
call exit(-1)
endif
rc = trexio_read_mo_num(trex_file, mo_num)
call trexio_assert(rc, TREXIO_SUCCESS)