mirror of
https://github.com/TREX-CoE/trexio.git
synced 2024-12-22 20:35:44 +01:00
Update unit tests to use get_int64_num
This commit is contained in:
parent
c1131347a8
commit
9bbfc34ee5
@ -43,7 +43,7 @@ trexio.info()
|
|||||||
|
|
||||||
# test with ... as ... block
|
# test with ... as ... block
|
||||||
with trexio.File(output_filename, mode='w', back_end=TEST_TREXIO_BACKEND) as tfile:
|
with trexio.File(output_filename, mode='w', back_end=TEST_TREXIO_BACKEND) as tfile:
|
||||||
trexio.write_metadata_description(tfile, "Test file produced by the Python API")
|
trexio.write_metadata_description(tfile, 'Test file produced by the Python API')
|
||||||
assert trexio.has_metadata_description(tfile)
|
assert trexio.has_metadata_description(tfile)
|
||||||
assert tfile.isOpen
|
assert tfile.isOpen
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ nucleus_num = 12
|
|||||||
try:
|
try:
|
||||||
trexio.write_nucleus_num(test_file, -100)
|
trexio.write_nucleus_num(test_file, -100)
|
||||||
except trexio.Error:
|
except trexio.Error:
|
||||||
print("Raise error for an attempt to write negative nucleus_num: checked.")
|
print('Raise error for an attempt to write negative nucleus_num: checked.')
|
||||||
|
|
||||||
# write nucleus_num in the file
|
# write nucleus_num in the file
|
||||||
try:
|
try:
|
||||||
@ -74,7 +74,7 @@ except:
|
|||||||
try:
|
try:
|
||||||
trexio.write_nucleus_num(test_file, nucleus_num*2)
|
trexio.write_nucleus_num(test_file, nucleus_num*2)
|
||||||
except trexio.Error:
|
except trexio.Error:
|
||||||
print("Raise error for an attempt to overwrite nucleus_num: checked.")
|
print('Raise error for an attempt to overwrite nucleus_num: checked.')
|
||||||
|
|
||||||
# initialize charge arrays as a list and convert it to numpy array
|
# initialize charge arrays as a list and convert it to numpy array
|
||||||
charges = [6., 6., 6., 6., 6., 6., 1., 1., 1., 1., 1., 1.]
|
charges = [6., 6., 6., 6., 6., 6., 1., 1., 1., 1., 1., 1.]
|
||||||
@ -133,7 +133,9 @@ trexio.write_ao_2e_int_eri(test_file, 0, num_integrals, indices, values)
|
|||||||
mo_num = 150
|
mo_num = 150
|
||||||
trexio.write_mo_num(test_file, mo_num)
|
trexio.write_mo_num(test_file, mo_num)
|
||||||
|
|
||||||
int_num = 2*int((mo_num-1)/64+1)
|
int_num = trexio.get_int64_num(test_file)
|
||||||
|
assert(int_num == int((mo_num-1)/64+1))
|
||||||
|
int_num *= 2
|
||||||
|
|
||||||
# write determinants in the file
|
# write determinants in the file
|
||||||
num_dets = 50
|
num_dets = 50
|
||||||
@ -197,7 +199,7 @@ trexio.write_nucleus_coord(unsafe_file, coords)
|
|||||||
trexio.write_nucleus_label(unsafe_file,labels)
|
trexio.write_nucleus_label(unsafe_file,labels)
|
||||||
trexio.write_nucleus_point_group(unsafe_file, point_group)
|
trexio.write_nucleus_point_group(unsafe_file, point_group)
|
||||||
|
|
||||||
print("Overwriting the data in UNSAFE mode: checked")
|
print('Overwriting the data in UNSAFE mode: checked')
|
||||||
|
|
||||||
# delete existing group (only allowed in 'u' - unsafe mode)
|
# delete existing group (only allowed in 'u' - unsafe mode)
|
||||||
trexio.delete_nucleus(unsafe_file)
|
trexio.delete_nucleus(unsafe_file)
|
||||||
@ -208,7 +210,7 @@ assert not trexio.has_nucleus_coord(unsafe_file)
|
|||||||
assert not trexio.has_nucleus_label(unsafe_file)
|
assert not trexio.has_nucleus_label(unsafe_file)
|
||||||
assert not trexio.has_nucleus_point_group(unsafe_file)
|
assert not trexio.has_nucleus_point_group(unsafe_file)
|
||||||
|
|
||||||
print("Deleting nucleus group in UNSAFE mode: checked")
|
print('Deleting nucleus group in UNSAFE mode: checked')
|
||||||
|
|
||||||
# restore the deleted data
|
# restore the deleted data
|
||||||
trexio.write_nucleus_num(unsafe_file, nucleus_num)
|
trexio.write_nucleus_num(unsafe_file, nucleus_num)
|
||||||
@ -250,7 +252,7 @@ np.testing.assert_array_almost_equal(rcharges_np, charges_np, decimal=8)
|
|||||||
try:
|
try:
|
||||||
rcharges_fail = trexio.read_nucleus_charge(test_file2, dim=nucleus_num*5)
|
rcharges_fail = trexio.read_nucleus_charge(test_file2, dim=nucleus_num*5)
|
||||||
except trexio.Error:
|
except trexio.Error:
|
||||||
print("Unsafe call to safe API: checked")
|
print('Unsafe call to safe API: checked')
|
||||||
|
|
||||||
# safe call to read array of int values (nuclear indices)
|
# safe call to read array of int values (nuclear indices)
|
||||||
rindices_np_16 = trexio.read_basis_nucleus_index(test_file2, dim=basis_shell_num, dtype=np.int16)
|
rindices_np_16 = trexio.read_basis_nucleus_index(test_file2, dim=basis_shell_num, dtype=np.int16)
|
||||||
@ -352,7 +354,7 @@ assert rpoint_group==point_group
|
|||||||
if trexio.has_ao_num(test_file2):
|
if trexio.has_ao_num(test_file2):
|
||||||
rao_num = trexio.read_ao_num(test_file2)
|
rao_num = trexio.read_ao_num(test_file2)
|
||||||
else:
|
else:
|
||||||
print("Pass on reading the non-existing variable ao_num: checked")
|
print('Pass on reading the non-existing variable ao_num: checked')
|
||||||
|
|
||||||
# close TREXIO file
|
# close TREXIO file
|
||||||
#trexio.close(test_file2)
|
#trexio.close(test_file2)
|
||||||
@ -376,8 +378,8 @@ try:
|
|||||||
void_file = trexio.File('non_existing.file', 'r', TEST_TREXIO_BACKEND)
|
void_file = trexio.File('non_existing.file', 'r', TEST_TREXIO_BACKEND)
|
||||||
except trexio.Error as e:
|
except trexio.Error as e:
|
||||||
if e.error == trexio.TREXIO_OPEN_ERROR:
|
if e.error == trexio.TREXIO_OPEN_ERROR:
|
||||||
print("Opening non-existing file returns TREXIO_OPEN_ERROR: checked")
|
print('Opening non-existing file returns TREXIO_OPEN_ERROR: checked')
|
||||||
else:
|
else:
|
||||||
raise ValueError("[DEV]: error handling of trexio_open function has changed; check the consistency")
|
raise ValueError('[DEV]: error handling of trexio_open function has changed; check the consistency')
|
||||||
|
|
||||||
#==========================================================#
|
#==========================================================#
|
||||||
|
@ -32,7 +32,20 @@ static int test_write_determinant (const char* file_name, const back_end_t backe
|
|||||||
|
|
||||||
int mo_num = MO_NUM;
|
int mo_num = MO_NUM;
|
||||||
|
|
||||||
det_list = (int64_t*) calloc(2*3*SIZE, sizeof(int64_t));
|
// write mo_num which will be used to determine the optimal size of int indices
|
||||||
|
if (trexio_has_mo_num(file) == TREXIO_HAS_NOT) {
|
||||||
|
rc = trexio_write_mo_num(file, mo_num);
|
||||||
|
assert(rc == TREXIO_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the number of int64 bit fields per determinant
|
||||||
|
int int_num;
|
||||||
|
rc = trexio_get_int64_num(file, &int_num);
|
||||||
|
assert(rc == TREXIO_SUCCESS);
|
||||||
|
assert(int_num == (MO_NUM-1)/64 + 1);
|
||||||
|
|
||||||
|
// allocate memory and fill with values to be written
|
||||||
|
det_list = (int64_t*) calloc(2 * int_num * SIZE, sizeof(int64_t));
|
||||||
det_coef = (double*) calloc(SIZE, sizeof(double));
|
det_coef = (double*) calloc(SIZE, sizeof(double));
|
||||||
|
|
||||||
for(int i=0; i<SIZE; i++){
|
for(int i=0; i<SIZE; i++){
|
||||||
@ -45,12 +58,6 @@ static int test_write_determinant (const char* file_name, const back_end_t backe
|
|||||||
det_coef[i] = 3.14 + (double) i;
|
det_coef[i] = 3.14 + (double) i;
|
||||||
}
|
}
|
||||||
|
|
||||||
// write mo_num which will be used to determine the optimal size of int indices
|
|
||||||
if (trexio_has_mo_num(file) == TREXIO_HAS_NOT) {
|
|
||||||
rc = trexio_write_mo_num(file, mo_num);
|
|
||||||
assert(rc == TREXIO_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
// write dataset chunks of sparse data in the file (including FAKE statements)
|
// write dataset chunks of sparse data in the file (including FAKE statements)
|
||||||
uint64_t chunk_size = (uint64_t) SIZE/N_CHUNKS;
|
uint64_t chunk_size = (uint64_t) SIZE/N_CHUNKS;
|
||||||
uint64_t offset_f = 0UL;
|
uint64_t offset_f = 0UL;
|
||||||
@ -60,7 +67,7 @@ static int test_write_determinant (const char* file_name, const back_end_t backe
|
|||||||
// write n_chunks times using write_sparse
|
// write n_chunks times using write_sparse
|
||||||
for(int i=0; i<N_CHUNKS; ++i){
|
for(int i=0; i<N_CHUNKS; ++i){
|
||||||
|
|
||||||
rc = trexio_write_determinant_list(file, offset_f, chunk_size, &det_list[6*offset_d]);
|
rc = trexio_write_determinant_list(file, offset_f, chunk_size, &det_list[2*int_num*offset_d]);
|
||||||
assert(rc == TREXIO_SUCCESS);
|
assert(rc == TREXIO_SUCCESS);
|
||||||
|
|
||||||
rc = trexio_write_determinant_coefficient(file, offset_f, chunk_size, &det_coef[offset_d]);
|
rc = trexio_write_determinant_coefficient(file, offset_f, chunk_size, &det_coef[offset_d]);
|
||||||
@ -174,8 +181,10 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
|
|||||||
assert (rc == TREXIO_SUCCESS);
|
assert (rc == TREXIO_SUCCESS);
|
||||||
assert (mo_num == MO_NUM);
|
assert (mo_num == MO_NUM);
|
||||||
|
|
||||||
int int_num = (mo_num - 1)/64 + 1;
|
int int_num;
|
||||||
assert (int_num == 3);
|
rc = trexio_get_int64_num(file, &int_num);
|
||||||
|
assert (rc == TREXIO_SUCCESS);
|
||||||
|
assert (int_num == (MO_NUM - 1)/64 + 1);
|
||||||
|
|
||||||
// define arrays to read into
|
// define arrays to read into
|
||||||
int64_t* det_list_read;
|
int64_t* det_list_read;
|
||||||
|
@ -32,7 +32,20 @@ static int test_write_determinant (const char* file_name, const back_end_t backe
|
|||||||
|
|
||||||
int mo_num = MO_NUM;
|
int mo_num = MO_NUM;
|
||||||
|
|
||||||
det_list = (int64_t*) calloc(2*3*SIZE, sizeof(int64_t));
|
// write mo_num which will be used to determine the optimal size of int indices
|
||||||
|
if (trexio_has_mo_num(file) == TREXIO_HAS_NOT) {
|
||||||
|
rc = trexio_write_mo_num(file, mo_num);
|
||||||
|
assert(rc == TREXIO_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the number of int64 bit fields per determinant
|
||||||
|
int int_num;
|
||||||
|
rc = trexio_get_int64_num(file, &int_num);
|
||||||
|
assert(rc == TREXIO_SUCCESS);
|
||||||
|
assert(int_num == (MO_NUM-1)/64 + 1);
|
||||||
|
|
||||||
|
// allocate memory and fill with values to be written
|
||||||
|
det_list = (int64_t*) calloc(2 * int_num * SIZE, sizeof(int64_t));
|
||||||
det_coef = (double*) calloc(SIZE, sizeof(double));
|
det_coef = (double*) calloc(SIZE, sizeof(double));
|
||||||
|
|
||||||
for(int i=0; i<SIZE; i++){
|
for(int i=0; i<SIZE; i++){
|
||||||
@ -45,12 +58,6 @@ static int test_write_determinant (const char* file_name, const back_end_t backe
|
|||||||
det_coef[i] = 3.14 + (double) i;
|
det_coef[i] = 3.14 + (double) i;
|
||||||
}
|
}
|
||||||
|
|
||||||
// write mo_num which will be used to determine the optimal size of int indices
|
|
||||||
if (trexio_has_mo_num(file) == TREXIO_HAS_NOT) {
|
|
||||||
rc = trexio_write_mo_num(file, mo_num);
|
|
||||||
assert(rc == TREXIO_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
// write dataset chunks of sparse data in the file (including FAKE statements)
|
// write dataset chunks of sparse data in the file (including FAKE statements)
|
||||||
uint64_t chunk_size = (uint64_t) SIZE/N_CHUNKS;
|
uint64_t chunk_size = (uint64_t) SIZE/N_CHUNKS;
|
||||||
uint64_t offset_f = 0UL;
|
uint64_t offset_f = 0UL;
|
||||||
@ -60,7 +67,7 @@ static int test_write_determinant (const char* file_name, const back_end_t backe
|
|||||||
// write n_chunks times using write_sparse
|
// write n_chunks times using write_sparse
|
||||||
for(int i=0; i<N_CHUNKS; ++i){
|
for(int i=0; i<N_CHUNKS; ++i){
|
||||||
|
|
||||||
rc = trexio_write_determinant_list(file, offset_f, chunk_size, &det_list[6*offset_d]);
|
rc = trexio_write_determinant_list(file, offset_f, chunk_size, &det_list[2*int_num*offset_d]);
|
||||||
assert(rc == TREXIO_SUCCESS);
|
assert(rc == TREXIO_SUCCESS);
|
||||||
|
|
||||||
rc = trexio_write_determinant_coefficient(file, offset_f, chunk_size, &det_coef[offset_d]);
|
rc = trexio_write_determinant_coefficient(file, offset_f, chunk_size, &det_coef[offset_d]);
|
||||||
@ -174,8 +181,10 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
|
|||||||
assert (rc == TREXIO_SUCCESS);
|
assert (rc == TREXIO_SUCCESS);
|
||||||
assert (mo_num == MO_NUM);
|
assert (mo_num == MO_NUM);
|
||||||
|
|
||||||
int int_num = (mo_num - 1)/64 + 1;
|
int int_num;
|
||||||
assert (int_num == 3);
|
rc = trexio_get_int64_num(file, &int_num);
|
||||||
|
assert (rc == TREXIO_SUCCESS);
|
||||||
|
assert (int_num == (MO_NUM - 1)/64 + 1);
|
||||||
|
|
||||||
// define arrays to read into
|
// define arrays to read into
|
||||||
int64_t* det_list_read;
|
int64_t* det_list_read;
|
||||||
|
@ -71,6 +71,7 @@ subroutine test_write(file_name, back_end)
|
|||||||
! determinants
|
! determinants
|
||||||
integer*8 :: det_list(6, 50)
|
integer*8 :: det_list(6, 50)
|
||||||
integer*8 :: det_num
|
integer*8 :: det_num
|
||||||
|
integer :: int_num
|
||||||
|
|
||||||
integer :: i, j, n_buffers = 5
|
integer :: i, j, n_buffers = 5
|
||||||
integer(8) :: buf_size_sparse, buf_size_det, offset
|
integer(8) :: buf_size_sparse, buf_size_det, offset
|
||||||
@ -257,6 +258,7 @@ subroutine test_read(file_name, back_end)
|
|||||||
integer*8 :: offset_det_read = 10
|
integer*8 :: offset_det_read = 10
|
||||||
integer*8 :: offset_det_data_read = 5
|
integer*8 :: offset_det_data_read = 5
|
||||||
integer*8 :: determinant_num
|
integer*8 :: determinant_num
|
||||||
|
integer :: int_num
|
||||||
|
|
||||||
! orbital lists
|
! orbital lists
|
||||||
integer*4 :: orb_list_up(150)
|
integer*4 :: orb_list_up(150)
|
||||||
@ -389,6 +391,16 @@ subroutine test_read(file_name, back_end)
|
|||||||
call exit(-1)
|
call exit(-1)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
! obtain a number of int64 bit fields per determinant
|
||||||
|
rc = trexio_get_int64_num(trex_file, int_num)
|
||||||
|
call trexio_assert(rc, TREXIO_SUCCESS)
|
||||||
|
if (int_num == 3) then
|
||||||
|
write(*,*) 'SUCCESS GET INT64_NUM'
|
||||||
|
else
|
||||||
|
print *, 'FAILURE DET INT64_NUM CHECK'
|
||||||
|
call exit(-1)
|
||||||
|
endif
|
||||||
|
|
||||||
! read a chunk of determinants
|
! read a chunk of determinants
|
||||||
rc = trexio_read_determinant_list(trex_file, offset_det_read, read_buf_det_size, &
|
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))
|
||||||
|
Loading…
Reference in New Issue
Block a user