mirror of
https://github.com/TREX-CoE/trexio.git
synced 2025-01-08 20:33:36 +01:00
Fix text interface for determinants
This commit is contained in:
parent
0a153491c9
commit
08674345a8
@ -5398,7 +5398,10 @@ trexio_read_determinant_list (trexio_t* const file, const int64_t offset_file, i
|
||||
{
|
||||
|
||||
if (file == NULL) return TREXIO_INVALID_ARG_1;
|
||||
if (dset == NULL) return TREXIO_INVALID_ARG_2;
|
||||
if (offset_file < 0) return TREXIO_INVALID_ARG_2;
|
||||
if (buffer_size_read == NULL) return TREXIO_INVALID_ARG_3;
|
||||
if (*buffer_size_read < 0) return TREXIO_INVALID_ARG_3;
|
||||
if (dset == NULL) return TREXIO_INVALID_ARG_4;
|
||||
if (trexio_has_determinant_list(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING;
|
||||
|
||||
/* Get the number of int bit fields per determinant */
|
||||
@ -5459,7 +5462,9 @@ trexio_write_determinant_list (trexio_t* const file, const int64_t offset_file,
|
||||
{
|
||||
|
||||
if (file == NULL) return TREXIO_INVALID_ARG_1;
|
||||
if (dset == NULL) return TREXIO_INVALID_ARG_2;
|
||||
if (offset_file < 0) return TREXIO_INVALID_ARG_2;
|
||||
if (buffer_size < 0) return TREXIO_INVALID_ARG_3;
|
||||
if (dset == NULL) return TREXIO_INVALID_ARG_4;
|
||||
|
||||
/* Get the number of int bit fields per determinant */
|
||||
int32_t int_num = 0;
|
||||
@ -5471,6 +5476,50 @@ trexio_write_determinant_list (trexio_t* const file, const int64_t offset_file,
|
||||
|
||||
assert(file->back_end < TREXIO_INVALID_BACK_END);
|
||||
|
||||
/* Read the number of mos */
|
||||
int64_t mo_num = 0L;
|
||||
rc = trexio_read_mo_num_64(file, &mo_num);
|
||||
if (rc != TREXIO_SUCCESS) return rc;
|
||||
|
||||
// Read up/dn num
|
||||
int32_t nup = 0;
|
||||
rc = trexio_read_electron_up_num(file, &nup);
|
||||
if (rc != TREXIO_SUCCESS) return rc;
|
||||
|
||||
int32_t ndn = 0;
|
||||
rc = trexio_read_electron_dn_num(file, &ndn);
|
||||
if (rc != TREXIO_SUCCESS) return rc;
|
||||
|
||||
/* Check all determinants */
|
||||
int32_t list_up[nup];
|
||||
int32_t list_dn[ndn];
|
||||
int32_t occ_num_up;
|
||||
int32_t occ_num_dn;
|
||||
for (int64_t i=0 ; i<buffer_size ; i+= 2*int_num) {
|
||||
rc = trexio_to_orbital_list_up_dn(int_num, &dset[i],
|
||||
list_up, list_dn,
|
||||
&occ_num_up, &occ_num_dn);
|
||||
if (rc != TREXIO_SUCCESS) return rc;
|
||||
if (occ_num_up != nup || occ_num_dn != ndn) {
|
||||
return TREXIO_INVALID_ARG_4;
|
||||
}
|
||||
for (int32_t j=0 ; j<occ_num_up ; ++j) {
|
||||
if (list_up[j] < 0 || list_up[j] >= mo_num) {
|
||||
return TREXIO_INVALID_ARG_4;
|
||||
}
|
||||
}
|
||||
for (int32_t j=0 ; j<occ_num_dn ; ++j) {
|
||||
if (list_dn[j] < 0 || list_dn[j] >= mo_num) {
|
||||
return TREXIO_INVALID_ARG_4;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Up to this point, all the determinants have been checked to
|
||||
have the correct sizes (number of electrons), and MOs in the
|
||||
correct range */
|
||||
|
||||
switch (file->back_end) {
|
||||
|
||||
case TREXIO_TEXT:
|
||||
|
@ -1660,12 +1660,12 @@ trexio_exit_code trexio_text_read_determinant_list(trexio_t* const file,
|
||||
if (f == NULL) return TREXIO_FILE_ERROR;
|
||||
|
||||
/* Specify the line length in order to offset properly.
|
||||
Each 64-bit integer takes at most 10 slots and requires one space,
|
||||
Each 64-bit integer takes at most 20 slots and requires one space,
|
||||
we have int_num integers per up-spin determinant,
|
||||
then this number is doubled because we have the same number for down-spin electrons,
|
||||
and then one newline char.
|
||||
,*/
|
||||
uint64_t line_length = dims[1]*11UL + 1UL; // 10 digits per int64_t bitfield + 1 space = 11 spots + 1 newline char
|
||||
uint64_t line_length = dims[1]*21UL + 1UL; // 20 digits per int64_t bitfield + 1 space = 11 spots + 1 newline char
|
||||
|
||||
/* Offset in the file according to the provided value of offset_file and optimal line_length */
|
||||
fseek(f, (long) offset_file * line_length, SEEK_SET);
|
||||
@ -1677,7 +1677,7 @@ trexio_exit_code trexio_text_read_determinant_list(trexio_t* const file,
|
||||
uint32_t buf_size = sizeof(buffer);
|
||||
/* Parameters to post-process the buffer and to get bit fields integers */
|
||||
uint64_t accum = 0UL;
|
||||
uint32_t shift_int64 = 11U;
|
||||
uint32_t shift_int64 = 21U;
|
||||
/* Counter for number of elements beind processed */
|
||||
uint64_t count = 0UL;
|
||||
for (uint64_t i=0UL; i < dims[0]; ++i) {
|
||||
@ -1697,7 +1697,7 @@ trexio_exit_code trexio_text_read_determinant_list(trexio_t* const file,
|
||||
Thus, we parse the buffer string int_num*2 times to get the bit field determinants.
|
||||
,*/
|
||||
for (uint32_t j=0; j < (uint32_t) dims[1]; ++j) {
|
||||
rc = sscanf(buffer+accum, "%10" SCNd64, list + dims[1]*i + j);
|
||||
rc = sscanf(buffer+accum, "%20" SCNd64, list + dims[1]*i + j);
|
||||
if (rc <= 0) {
|
||||
fclose(f);
|
||||
return TREXIO_FAILURE;
|
||||
@ -1747,7 +1747,7 @@ trexio_exit_code trexio_text_write_determinant_list(trexio_t* const file,
|
||||
|
||||
/* The loop below is needed to write a line with int bit fields for alpha and beta electrons */
|
||||
for (uint32_t j=0; j < (uint32_t) dims[1]; ++j) {
|
||||
rc = fprintf(f, "%10" PRId64 " ", *(list + i*dims[1] + j));
|
||||
rc = fprintf(f, "%20" PRId64 " ", *(list + i*dims[1] + j));
|
||||
if (rc <= 0) {
|
||||
fclose(f);
|
||||
return TREXIO_FAILURE;
|
||||
|
@ -32,6 +32,16 @@ static int test_write_determinant (const char* file_name, const back_end_t backe
|
||||
assert(rc == TREXIO_SUCCESS);
|
||||
}
|
||||
|
||||
// write number of up and down electrons for checking consistency of determinants
|
||||
if (trexio_has_electron_up_num(file) == TREXIO_HAS_NOT) {
|
||||
rc = trexio_write_electron_up_num(file, 4);
|
||||
assert(rc == TREXIO_SUCCESS);
|
||||
}
|
||||
if (trexio_has_electron_dn_num(file) == TREXIO_HAS_NOT) {
|
||||
rc = trexio_write_electron_dn_num(file, 3);
|
||||
assert(rc == TREXIO_SUCCESS);
|
||||
}
|
||||
|
||||
// get the number of int64 bit fields per determinant
|
||||
int int_num;
|
||||
rc = trexio_get_int64_num(file, &int_num);
|
||||
@ -218,7 +228,7 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
|
||||
/*
|
||||
printf("%s\n", trexio_string_of_error(rc));
|
||||
for (int i=0; i<size_r; i++) {
|
||||
printf("%lld %lld\n", det_list_read[6*i], det_list_read[6*i+5]);
|
||||
printf("%ld %ld\n", det_list_read[6*i], det_list_read[6*i+5]);
|
||||
}
|
||||
*/
|
||||
assert(rc == TREXIO_END);
|
||||
|
@ -79,6 +79,8 @@ subroutine test_write(file_name, back_end)
|
||||
double precision :: value_sparse_ao_2e_int_eri(100)
|
||||
|
||||
! determinants
|
||||
integer :: nup, ndn
|
||||
integer :: det_occ(10,2)
|
||||
integer*8 :: det_list(6, 50)
|
||||
integer*8 :: det_num
|
||||
integer :: int_num
|
||||
@ -87,6 +89,7 @@ subroutine test_write(file_name, back_end)
|
||||
integer(8) :: buf_size_sparse, buf_size_det, offset
|
||||
integer :: state_id
|
||||
|
||||
|
||||
buf_size_sparse = 100/n_buffers
|
||||
buf_size_det = 50/n_buffers
|
||||
|
||||
@ -100,10 +103,15 @@ subroutine test_write(file_name, back_end)
|
||||
enddo
|
||||
|
||||
! fill determinant list
|
||||
nup = 8
|
||||
ndn = 6
|
||||
det_occ(1:8,1) = (/ 1, 2, 3, 4, 76, 128, 129, 143 /)
|
||||
det_occ(1:6,2) = (/ 1, 3, 4, 80, 81, 139 /)
|
||||
do i = 1, 50
|
||||
do j = 1, 6
|
||||
det_list(j,i) = 6*i+(j-1) - 5
|
||||
enddo
|
||||
rc = trexio_to_bitfield_list(det_occ(1:8,1), nup, det_list(1:,i), 8)
|
||||
call trexio_assert(rc, TREXIO_SUCCESS)
|
||||
rc = trexio_to_bitfield_list(det_occ(1:6,2), ndn, det_list(4:,i), 6)
|
||||
call trexio_assert(rc, TREXIO_SUCCESS)
|
||||
enddo
|
||||
|
||||
! parameters to be written
|
||||
@ -161,6 +169,18 @@ subroutine test_write(file_name, back_end)
|
||||
rc = trexio_has_nucleus_charge(trex_file)
|
||||
call trexio_assert(rc, TREXIO_HAS_NOT, 'SUCCESS HAS NOT 2')
|
||||
|
||||
rc = trexio_has_electron_up_num(trex_file)
|
||||
call trexio_assert(rc, TREXIO_HAS_NOT, 'SUCCESS HAS NOT 2.1')
|
||||
|
||||
rc = trexio_write_electron_up_num(trex_file, nup)
|
||||
call trexio_assert(rc, TREXIO_SUCCESS)
|
||||
|
||||
rc = trexio_has_electron_dn_num(trex_file)
|
||||
call trexio_assert(rc, TREXIO_HAS_NOT, 'SUCCESS HAS NOT 2.2')
|
||||
|
||||
rc = trexio_write_electron_dn_num(trex_file, ndn)
|
||||
call trexio_assert(rc, TREXIO_SUCCESS)
|
||||
|
||||
rc = trexio_has_ao_2e_int_eri(trex_file)
|
||||
call trexio_assert(rc, TREXIO_HAS_NOT, 'SUCCESS HAS NOT 3')
|
||||
|
||||
@ -313,7 +333,7 @@ subroutine test_read(file_name, back_end)
|
||||
|
||||
! determinant data
|
||||
integer*8 :: det_list(6,50)
|
||||
integer*8 :: det_list_check(3)
|
||||
integer*8 :: det_list_check(6)
|
||||
integer*8 :: read_buf_det_size = 20
|
||||
integer*8 :: offset_det_read = 10
|
||||
integer*8 :: offset_det_data_read = 5
|
||||
@ -477,17 +497,39 @@ 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))
|
||||
!do i = 1,50
|
||||
! write(*,*) det_list(1,i)
|
||||
!enddo
|
||||
call trexio_assert(rc, TREXIO_SUCCESS)
|
||||
if (det_list(1, 1) == 0 .and. &
|
||||
det_list(1, offset_det_data_read + 1) == offset_det_read*6 + 1) then
|
||||
write(*,*) 'SUCCESS READ DET LIST'
|
||||
else
|
||||
print *, 'FAILURE DET LIST CHECK'
|
||||
call exit(-1)
|
||||
endif
|
||||
det_list_check = (/15_8, -9223372036854773760_8, 16385_8, 13_8, 98304_8, 1024_8 /)
|
||||
do i = 1,offset_det_data_read
|
||||
do j=1,6
|
||||
if (det_list(j,i) /= 0_8) then
|
||||
print *, det_list(j,i)
|
||||
print *, 'FAILURE DET LIST CHECK 1'
|
||||
call exit(-1)
|
||||
endif
|
||||
enddo
|
||||
enddo
|
||||
|
||||
do i = offset_det_data_read+1, offset_det_data_read+read_buf_det_size
|
||||
do j=1,6
|
||||
if (det_list(j,i) /= det_list_check(j)) then
|
||||
print *, det_list(j,i)
|
||||
print *, 'FAILURE DET LIST CHECK 2'
|
||||
call exit(-1)
|
||||
endif
|
||||
enddo
|
||||
enddo
|
||||
|
||||
do i = offset_det_data_read+read_buf_det_size+1,50
|
||||
do j=1,6
|
||||
if (det_list(j,i) /= 0_8) then
|
||||
print *, det_list(j,i)
|
||||
print *, 'FAILURE DET LIST CHECK 3'
|
||||
call exit(-1)
|
||||
endif
|
||||
enddo
|
||||
enddo
|
||||
|
||||
write(*,*) 'SUCCESS READ DET LIST'
|
||||
|
||||
! read the total number of stored determinants
|
||||
rc = trexio_read_determinant_num_64(trex_file, determinant_num)
|
||||
@ -509,7 +551,7 @@ subroutine test_read(file_name, back_end)
|
||||
! 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 (occ_num_up == 16 .and. occ_num_dn == 5) then
|
||||
if (occ_num_up == 8 .and. occ_num_dn == 6) then
|
||||
write(*,*) 'SUCCESS CONVERT DET LIST'
|
||||
else
|
||||
print *, 'FAILURE DET CONVERT CHECK'
|
||||
|
Loading…
Reference in New Issue
Block a user