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

Add tests

This commit is contained in:
q-posev 2022-04-15 15:21:20 +02:00
parent c4ccd006ca
commit 7f16ade48f
3 changed files with 67 additions and 12 deletions

View File

@ -137,10 +137,20 @@ int_num = 2*int((mo_num-1)/64+1)
# write determinants in the file
num_dets = 50
offset = 0
dets = [i for i in range(num_dets*int_num)]
coeffs = [(3.14 + float(i)) for i in range(num_dets)]
coeffs_s2 = [(6.28 + float(i)) for i in range(num_dets)]
trexio.write_determinant_list(test_file, 0, num_dets, dets)
trexio.write_determinant_list(test_file, offset, num_dets, dets)
trexio.write_determinant_coefficient(test_file, offset, num_dets, coeffs)
test_file.set_state(2)
trexio.write_determinant_coefficient(test_file, offset, num_dets, coeffs_s2)
test_file.set_state(0)
# manually check the consistency between coefficient_size and number of determinants
assert trexio.read_determinant_coefficient_size(test_file) == trexio.read_determinant_num(test_file)
# write nucleus_point_group in the file
point_group = 'B3U'
@ -225,6 +235,7 @@ assert trexio.has_nucleus_label(test_file2)
assert trexio.has_nucleus_point_group(test_file2)
assert trexio.has_ao_2e_int_eri(test_file2)
assert trexio.has_determinant_list(test_file2)
assert trexio.has_determinant_coefficient(test_file2)
# read nucleus_num from file
rnum = trexio.read_nucleus_num(test_file2)
@ -309,6 +320,12 @@ assert read_buf_size==buf_size
assert dets_np[0][0]==0
assert dets_np[read_buf_size-1][int_num-1]==read_buf_size*int_num-1
coefficients_np, read_buf_size, eof = trexio.read_determinant_coefficient(test_file2, offset_file, buf_size)
print(f'First complete read of determinant coefficients: {read_buf_size}')
#print(indices_sparse_np)
assert not eof
assert read_buf_size==buf_size
# read array of nuclear labels
rlabels_2d = trexio.read_nucleus_label(test_file2, dim=nucleus_num)
print(rlabels_2d)

View File

@ -9,6 +9,7 @@
#define RM_COMMAND "rm -f " TREXIO_FILE
#define SIZE 100
#define N_CHUNKS 5
#define STATE_TEST 2
static int test_write_determinant (const char* file_name, const back_end_t backend, const int64_t offset) {
@ -64,8 +65,8 @@ static int test_write_determinant (const char* file_name, const back_end_t backe
rc = trexio_write_determinant_coefficient(file, offset_f, chunk_size, &det_coef[offset_d]);
assert(rc == TREXIO_SUCCESS);
// The block below will write the coefficients for state #2
rc = trexio_set_state(file, 2);
// The block below will write the coefficients for STATE_TEST
rc = trexio_set_state(file, STATE_TEST);
assert(rc == TREXIO_SUCCESS);
rc = trexio_write_determinant_coefficient(file, offset_f, chunk_size, &det_coef[offset_d]);
@ -80,6 +81,24 @@ static int test_write_determinant (const char* file_name, const back_end_t backe
offset_f += chunk_size;
}
// manually check the consistency of the determinant_num and coefficient_size after writing
int64_t coeff_size = 0L;
int64_t determinant_num = 0L;
rc = trexio_read_determinant_num_64(file, &determinant_num);
assert(rc == TREXIO_SUCCESS);
rc = trexio_read_determinant_coefficient_size(file, &coeff_size);
assert(rc == TREXIO_SUCCESS);
assert(determinant_num == coeff_size);
rc = trexio_set_state(file, STATE_TEST);
assert(rc == TREXIO_SUCCESS);
rc = trexio_read_determinant_coefficient_size(file, &coeff_size);
assert(rc == TREXIO_SUCCESS);
assert(determinant_num == coeff_size);
// close current session
rc = trexio_close(file);
assert (rc == TREXIO_SUCCESS);
@ -115,8 +134,8 @@ static int test_has_determinant(const char* file_name, const back_end_t backend)
rc = trexio_has_determinant_coefficient(file);
assert(rc==TREXIO_SUCCESS);
// also check for state 2
rc = trexio_set_state(file, 2);
// also check for STATE_TEST
rc = trexio_set_state(file, STATE_TEST);
assert(rc == TREXIO_SUCCESS);
rc = trexio_has_determinant_coefficient(file);
@ -188,7 +207,7 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
assert(check_diff*check_diff < 1e-14);
// read one chuk of coefficients for a different state
rc = trexio_set_state(file, 2);
rc = trexio_set_state(file, STATE_TEST);
assert(rc == TREXIO_SUCCESS);
rc = trexio_read_determinant_coefficient(file, offset_file_read, &chunk_read, &det_coef_s2_read[offset_data_read]);

View File

@ -9,6 +9,7 @@
#define RM_COMMAND "rm -rf " TREXIO_FILE
#define SIZE 100
#define N_CHUNKS 5
#define STATE_TEST 2
static int test_write_determinant (const char* file_name, const back_end_t backend, const int64_t offset) {
@ -64,8 +65,8 @@ static int test_write_determinant (const char* file_name, const back_end_t backe
rc = trexio_write_determinant_coefficient(file, offset_f, chunk_size, &det_coef[offset_d]);
assert(rc == TREXIO_SUCCESS);
// The block below will write the coefficients for state #2
rc = trexio_set_state(file, 2);
// The block below will write the coefficients for STATE_TEST
rc = trexio_set_state(file, STATE_TEST);
assert(rc == TREXIO_SUCCESS);
rc = trexio_write_determinant_coefficient(file, offset_f, chunk_size, &det_coef[offset_d]);
@ -80,6 +81,24 @@ static int test_write_determinant (const char* file_name, const back_end_t backe
offset_f += chunk_size;
}
// manually check the consistency of the determinant_num and coefficient_size after writing
int64_t coeff_size = 0L;
int64_t determinant_num = 0L;
rc = trexio_read_determinant_num_64(file, &determinant_num);
assert(rc == TREXIO_SUCCESS);
rc = trexio_read_determinant_coefficient_size(file, &coeff_size);
assert(rc == TREXIO_SUCCESS);
assert(determinant_num == coeff_size);
rc = trexio_set_state(file, STATE_TEST);
assert(rc == TREXIO_SUCCESS);
rc = trexio_read_determinant_coefficient_size(file, &coeff_size);
assert(rc == TREXIO_SUCCESS);
assert(determinant_num == coeff_size);
// close current session
rc = trexio_close(file);
assert (rc == TREXIO_SUCCESS);
@ -115,8 +134,8 @@ static int test_has_determinant(const char* file_name, const back_end_t backend)
rc = trexio_has_determinant_coefficient(file);
assert(rc==TREXIO_SUCCESS);
// also check for state 2
rc = trexio_set_state(file, 2);
// also check for STATE_TEST
rc = trexio_set_state(file, STATE_TEST);
assert(rc == TREXIO_SUCCESS);
rc = trexio_has_determinant_coefficient(file);
@ -188,7 +207,7 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
assert(check_diff*check_diff < 1e-14);
// read one chuk of coefficients for a different state
rc = trexio_set_state(file, 2);
rc = trexio_set_state(file, STATE_TEST);
assert(rc == TREXIO_SUCCESS);
rc = trexio_read_determinant_coefficient(file, offset_file_read, &chunk_read, &det_coef_s2_read[offset_data_read]);