mirror of
https://github.com/TREX-CoE/trexio.git
synced 2025-01-03 01:56:13 +01:00
Remove excited state switch for I/O and add state_id
This commit is contained in:
parent
6ba8c5ddc3
commit
99d0ef70bd
@ -1588,7 +1588,7 @@ def _inquire(file_name: str) -> bool:
|
|||||||
** File state
|
** File state
|
||||||
|
|
||||||
~trexio_set_state~ set an existing ~trexio_t~ file handle to a given state.
|
~trexio_set_state~ set an existing ~trexio_t~ file handle to a given state.
|
||||||
~trexio_get_state~ returns current sate of the ~trexio_t~ file handle.
|
~trexio_get_state~ returns current state of the ~trexio_t~ file handle.
|
||||||
|
|
||||||
input parameters:
|
input parameters:
|
||||||
~file~ -- TREXIO file handle.
|
~file~ -- TREXIO file handle.
|
||||||
|
@ -693,15 +693,7 @@ trexio_exit_code trexio_hdf5_read_$group_dset$(trexio_t* const file,
|
|||||||
if (eof_read_size == NULL) return TREXIO_INVALID_ARG_5;
|
if (eof_read_size == NULL) return TREXIO_INVALID_ARG_5;
|
||||||
if (dset == NULL) return TREXIO_INVALID_ARG_6;
|
if (dset == NULL) return TREXIO_INVALID_ARG_6;
|
||||||
|
|
||||||
char dset_dset_name[256];
|
const char dset_name[256] = "$group_dset$";
|
||||||
memset(dset_dset_name, 0, sizeof(dset_dset_name));
|
|
||||||
const int32_t trexio_state = $with_state$ ;
|
|
||||||
|
|
||||||
if (trexio_state != 0) {
|
|
||||||
sprintf(dset_dset_name, "$group_dset$_state_%" PRId32, trexio_state);
|
|
||||||
} else {
|
|
||||||
strncpy(dset_dset_name, "$group_dset$", 256);
|
|
||||||
}
|
|
||||||
|
|
||||||
const trexio_hdf5_t* f = (const trexio_hdf5_t*) file;
|
const trexio_hdf5_t* f = (const trexio_hdf5_t*) file;
|
||||||
|
|
||||||
@ -710,7 +702,7 @@ trexio_exit_code trexio_hdf5_read_$group_dset$(trexio_t* const file,
|
|||||||
|
|
||||||
/* Attempt to read values (if EOF -> eof_read_size is modified with the number of elements read and return code is TREXIO_END)
|
/* Attempt to read values (if EOF -> eof_read_size is modified with the number of elements read and return code is TREXIO_END)
|
||||||
0 argument below is requires to skip internal treatment specific to sparse indices (i.e. their de-compression).*/
|
0 argument below is requires to skip internal treatment specific to sparse indices (i.e. their de-compression).*/
|
||||||
return trexio_hdf5_open_read_dset_sparse(f->$group$_group, dset_dset_name, 1, offset, count, eof_read_size, 0, dset);
|
return trexio_hdf5_open_read_dset_sparse(f->$group$_group, dset_name, 1, offset, count, eof_read_size, 0, dset);
|
||||||
}
|
}
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
@ -725,15 +717,7 @@ trexio_exit_code trexio_hdf5_write_$group_dset$(trexio_t* const file,
|
|||||||
if (file == NULL) return TREXIO_INVALID_ARG_1;
|
if (file == NULL) return TREXIO_INVALID_ARG_1;
|
||||||
if (dset == NULL) return TREXIO_INVALID_ARG_5;
|
if (dset == NULL) return TREXIO_INVALID_ARG_5;
|
||||||
|
|
||||||
char dset_dset_name[256];
|
const char dset_name[256] = "$group_dset$";
|
||||||
memset(dset_dset_name, 0, sizeof(dset_dset_name));
|
|
||||||
const int32_t trexio_state = $with_state$ ;
|
|
||||||
|
|
||||||
if (trexio_state != 0) {
|
|
||||||
sprintf(dset_dset_name, "$group_dset$_state_%" PRId32, trexio_state);
|
|
||||||
} else {
|
|
||||||
strncpy(dset_dset_name, "$group_dset$", 256);
|
|
||||||
}
|
|
||||||
|
|
||||||
trexio_hdf5_t* f = (trexio_hdf5_t*) file;
|
trexio_hdf5_t* f = (trexio_hdf5_t*) file;
|
||||||
|
|
||||||
@ -744,11 +728,11 @@ trexio_exit_code trexio_hdf5_write_$group_dset$(trexio_t* const file,
|
|||||||
|
|
||||||
trexio_exit_code rc_write = TREXIO_FAILURE;
|
trexio_exit_code rc_write = TREXIO_FAILURE;
|
||||||
/* NOTE: chunk size is set upon creation of the HDF5 dataset and cannot be changed ! */
|
/* NOTE: chunk size is set upon creation of the HDF5 dataset and cannot be changed ! */
|
||||||
if ( H5LTfind_dataset(f->$group$_group, dset_dset_name) != 1 ) {
|
if ( H5LTfind_dataset(f->$group$_group, dset_name) != 1 ) {
|
||||||
/* If the file does not exist -> create it and write */
|
/* If the file does not exist -> create it and write */
|
||||||
|
|
||||||
/* Create chunked dataset with dtype datatype and write indices into it */
|
/* Create chunked dataset with dtype datatype and write indices into it */
|
||||||
rc_write = trexio_hdf5_create_write_dset_sparse(f->$group$_group, dset_dset_name, dtype, chunk_dims, dset);
|
rc_write = trexio_hdf5_create_write_dset_sparse(f->$group$_group, dset_name, dtype, chunk_dims, dset);
|
||||||
if (rc_write != TREXIO_SUCCESS) return rc_write;
|
if (rc_write != TREXIO_SUCCESS) return rc_write;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -756,7 +740,7 @@ trexio_exit_code trexio_hdf5_write_$group_dset$(trexio_t* const file,
|
|||||||
hsize_t offset_data[1] = {(hsize_t) offset_file};
|
hsize_t offset_data[1] = {(hsize_t) offset_file};
|
||||||
|
|
||||||
/* Create chunked dataset with dtype datatype and write indices into it */
|
/* Create chunked dataset with dtype datatype and write indices into it */
|
||||||
rc_write = trexio_hdf5_open_write_dset_sparse(f->$group$_group, dset_dset_name, dtype, chunk_dims, offset_data, dset);
|
rc_write = trexio_hdf5_open_write_dset_sparse(f->$group$_group, dset_name, dtype, chunk_dims, offset_data, dset);
|
||||||
if (rc_write != TREXIO_SUCCESS) return rc_write;
|
if (rc_write != TREXIO_SUCCESS) return rc_write;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -771,19 +755,11 @@ trexio_hdf5_read_$group_dset$_size (trexio_t* const file, int64_t* const size_ma
|
|||||||
if (file == NULL) return TREXIO_INVALID_ARG_1;
|
if (file == NULL) return TREXIO_INVALID_ARG_1;
|
||||||
if (size_max == NULL) return TREXIO_INVALID_ARG_2;
|
if (size_max == NULL) return TREXIO_INVALID_ARG_2;
|
||||||
|
|
||||||
char dset_dset_name[128];
|
const char dset_name[256] = "$group_dset$";
|
||||||
memset(dset_dset_name, 0, sizeof(dset_dset_name));
|
|
||||||
const int32_t trexio_state = file->state;
|
|
||||||
|
|
||||||
if (trexio_state != 0) {
|
|
||||||
sprintf(dset_dset_name, "$group_dset$_state_%" PRId32, trexio_state);
|
|
||||||
} else {
|
|
||||||
strncpy(dset_dset_name, "$group_dset$", 24);
|
|
||||||
}
|
|
||||||
|
|
||||||
const trexio_hdf5_t* f = (const trexio_hdf5_t*) file;
|
const trexio_hdf5_t* f = (const trexio_hdf5_t*) file;
|
||||||
|
|
||||||
hid_t dset_id = H5Dopen(f->$group$_group, dset_dset_name, H5P_DEFAULT);
|
hid_t dset_id = H5Dopen(f->$group$_group, dset_name, H5P_DEFAULT);
|
||||||
if (dset_id <= 0) return TREXIO_INVALID_ID;
|
if (dset_id <= 0) return TREXIO_INVALID_ID;
|
||||||
|
|
||||||
hid_t fspace_id = H5Dget_space(dset_id);
|
hid_t fspace_id = H5Dget_space(dset_id);
|
||||||
@ -815,17 +791,9 @@ trexio_exit_code trexio_hdf5_has_$group_dset$(trexio_t* const file)
|
|||||||
trexio_hdf5_t* f = (trexio_hdf5_t*) file;
|
trexio_hdf5_t* f = (trexio_hdf5_t*) file;
|
||||||
if (f->$group$_group == (hsize_t) 0) return TREXIO_HAS_NOT;
|
if (f->$group$_group == (hsize_t) 0) return TREXIO_HAS_NOT;
|
||||||
|
|
||||||
char dset_dset_name[128];
|
const char dset_name[256] = "$group_dset$";
|
||||||
memset(dset_dset_name, 0, sizeof(dset_dset_name));
|
|
||||||
const int32_t trexio_state = file->state;
|
|
||||||
|
|
||||||
if (trexio_state != 0) {
|
herr_t status = H5LTfind_dataset(f->$group$_group, dset_name);
|
||||||
sprintf(dset_dset_name, "$group_dset$_state_%" PRId32, trexio_state);
|
|
||||||
} else {
|
|
||||||
strncpy(dset_dset_name, "$group_dset$", 24);
|
|
||||||
}
|
|
||||||
|
|
||||||
herr_t status = H5LTfind_dataset(f->$group$_group, dset_dset_name);
|
|
||||||
/* H5LTfind_dataset returns 1 if dataset exists, 0 otherwise */
|
/* H5LTfind_dataset returns 1 if dataset exists, 0 otherwise */
|
||||||
if (status == 1){
|
if (status == 1){
|
||||||
return TREXIO_SUCCESS;
|
return TREXIO_SUCCESS;
|
||||||
|
@ -1359,23 +1359,14 @@ trexio_exit_code trexio_text_read_$group_dset$(trexio_t* const file,
|
|||||||
if (eof_read_size == NULL) return TREXIO_INVALID_ARG_5;
|
if (eof_read_size == NULL) return TREXIO_INVALID_ARG_5;
|
||||||
if (dset == NULL) return TREXIO_INVALID_ARG_6;
|
if (dset == NULL) return TREXIO_INVALID_ARG_6;
|
||||||
|
|
||||||
char file_name[256];
|
const char file_name[256] = "/$group_dset$.txt";
|
||||||
memset(file_name, 0, sizeof(file_name));
|
|
||||||
const int32_t trexio_state = $with_state$;
|
|
||||||
|
|
||||||
if (trexio_state != 0) {
|
|
||||||
sprintf(file_name, "/$group_dset$_state_%" PRId32 ".txt", trexio_state);
|
|
||||||
} else {
|
|
||||||
strncpy(file_name, "/$group_dset$.txt", 256);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The full path to the destination TXT file with sparse data. This will include TREXIO directory name. */
|
/* The full path to the destination TXT file with sparse data. This will include TREXIO directory name. */
|
||||||
char file_full_path[TREXIO_MAX_FILENAME_LENGTH];
|
char file_full_path[TREXIO_MAX_FILENAME_LENGTH];
|
||||||
/* Copy directory name in file_full_path */
|
/* Copy directory name in file_full_path */
|
||||||
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH);
|
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH - sizeof(file_name));
|
||||||
/* Append name of the file with sparse data */
|
/* Append name of the file with sparse data */
|
||||||
strncat (file_full_path, file_name,
|
strncat (file_full_path, file_name, sizeof(file_name));
|
||||||
TREXIO_MAX_FILENAME_LENGTH-strlen(file_name));
|
|
||||||
|
|
||||||
/* Open the file in "r" (read) mode to guarantee that no truncation happens upon consecutive reads */
|
/* Open the file in "r" (read) mode to guarantee that no truncation happens upon consecutive reads */
|
||||||
FILE* f = fopen(file_full_path, "r");
|
FILE* f = fopen(file_full_path, "r");
|
||||||
@ -1430,23 +1421,14 @@ trexio_text_read_$group_dset$_size(trexio_t* const file, int64_t* const size_max
|
|||||||
if (file == NULL) return TREXIO_INVALID_ARG_1;
|
if (file == NULL) return TREXIO_INVALID_ARG_1;
|
||||||
if (size_max == NULL) return TREXIO_INVALID_ARG_2;
|
if (size_max == NULL) return TREXIO_INVALID_ARG_2;
|
||||||
|
|
||||||
char file_name[256];
|
const char file_name[256] = "/$group_dset$.txt.size";
|
||||||
memset(file_name, 0, sizeof(file_name));
|
|
||||||
const int32_t trexio_state = $with_state$;
|
|
||||||
|
|
||||||
if (trexio_state != 0) {
|
|
||||||
sprintf(file_name, "/$group_dset$_state_%" PRId32 ".txt.size", trexio_state);
|
|
||||||
} else {
|
|
||||||
strncpy(file_name, "/$group_dset$.txt.size", 256);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The full path to the destination TXT file with sparse data. This will include TREXIO directory name. */
|
/* The full path to the destination TXT file with sparse data. This will include TREXIO directory name. */
|
||||||
char file_full_path[TREXIO_MAX_FILENAME_LENGTH];
|
char file_full_path[TREXIO_MAX_FILENAME_LENGTH];
|
||||||
/* Copy directory name in file_full_path */
|
/* Copy directory name in file_full_path */
|
||||||
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH);
|
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH - sizeof(file_name));
|
||||||
/* Append name of the file with sparse data */
|
/* Append name of the file with sparse data */
|
||||||
strncat (file_full_path, file_name,
|
strncat (file_full_path, file_name, sizeof(file_name));
|
||||||
TREXIO_MAX_FILENAME_LENGTH-strlen(file_name));
|
|
||||||
|
|
||||||
/* Open the file in "r" (read) mode to guarantee that no truncation happens upon consecutive reads */
|
/* Open the file in "r" (read) mode to guarantee that no truncation happens upon consecutive reads */
|
||||||
FILE* f = fopen(file_full_path, "r");
|
FILE* f = fopen(file_full_path, "r");
|
||||||
@ -1488,23 +1470,15 @@ trexio_exit_code trexio_text_write_$group_dset$(trexio_t* const file,
|
|||||||
if (file == NULL) return TREXIO_INVALID_ARG_1;
|
if (file == NULL) return TREXIO_INVALID_ARG_1;
|
||||||
if (dset == NULL) return TREXIO_INVALID_ARG_5;
|
if (dset == NULL) return TREXIO_INVALID_ARG_5;
|
||||||
|
|
||||||
char file_name[256];
|
const char file_name[256] = "/$group_dset$.txt";
|
||||||
memset(file_name, 0, sizeof(file_name));
|
const int append_str_len = 6;
|
||||||
const int32_t trexio_state = $with_state$;
|
|
||||||
|
|
||||||
if (trexio_state != 0) {
|
|
||||||
sprintf(file_name, "/$group_dset$_state_%" PRId32 ".txt", trexio_state);
|
|
||||||
} else {
|
|
||||||
strncpy(file_name, "/$group_dset$.txt", 256);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The full path to the destination TXT file with sparse data. This will include TREXIO directory name. */
|
/* The full path to the destination TXT file with sparse data. This will include TREXIO directory name. */
|
||||||
char file_full_path[TREXIO_MAX_FILENAME_LENGTH];
|
char file_full_path[TREXIO_MAX_FILENAME_LENGTH];
|
||||||
/* Copy directory name in file_full_path */
|
/* Copy directory name in file_full_path */
|
||||||
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH);
|
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH - sizeof(file_name) - append_str_len);
|
||||||
/* Append name of the file with sparse data */
|
/* Append name of the file with sparse data */
|
||||||
strncat (file_full_path, file_name,
|
strncat (file_full_path, file_name, sizeof(file_name));
|
||||||
TREXIO_MAX_FILENAME_LENGTH-strlen(file_name));
|
|
||||||
|
|
||||||
/* Open the file in "a" (append) mode to guarantee that no truncation happens upon consecutive writes */
|
/* Open the file in "a" (append) mode to guarantee that no truncation happens upon consecutive writes */
|
||||||
FILE* f = fopen(file_full_path, "a");
|
FILE* f = fopen(file_full_path, "a");
|
||||||
@ -1527,7 +1501,7 @@ trexio_exit_code trexio_text_write_$group_dset$(trexio_t* const file,
|
|||||||
if (rc != 0) return TREXIO_FILE_ERROR;
|
if (rc != 0) return TREXIO_FILE_ERROR;
|
||||||
|
|
||||||
/* Append .size to the file_full_path in order to write additional info about the written buffer of data */
|
/* Append .size to the file_full_path in order to write additional info about the written buffer of data */
|
||||||
strncat(file_full_path, ".size", 6);
|
strncat(file_full_path, ".size", append_str_len);
|
||||||
|
|
||||||
/* Open the new file in "a" (append) mode to append info about the buffer that has been just written */
|
/* Open the new file in "a" (append) mode to append info about the buffer that has been just written */
|
||||||
FILE *f_wSize = fopen(file_full_path, "a");
|
FILE *f_wSize = fopen(file_full_path, "a");
|
||||||
@ -1549,10 +1523,9 @@ trexio_exit_code trexio_text_write_$group_dset$(trexio_t* const file,
|
|||||||
|
|
||||||
memset (file_full_path, 0, TREXIO_MAX_FILENAME_LENGTH);
|
memset (file_full_path, 0, TREXIO_MAX_FILENAME_LENGTH);
|
||||||
/* Copy directory name in file_full_path */
|
/* Copy directory name in file_full_path */
|
||||||
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH);
|
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH - sizeof(group_file_name));
|
||||||
/* Append name of the file with sparse data */
|
/* Append name of the file with sparse data */
|
||||||
strncat (file_full_path, group_file_name,
|
strncat (file_full_path, group_file_name, sizeof(group_file_name));
|
||||||
TREXIO_MAX_FILENAME_LENGTH-strlen(group_file_name));
|
|
||||||
|
|
||||||
bool file_exists = trexio_text_file_exists(file_full_path);
|
bool file_exists = trexio_text_file_exists(file_full_path);
|
||||||
|
|
||||||
@ -1573,23 +1546,14 @@ trexio_exit_code trexio_text_has_$group_dset$(trexio_t* const file)
|
|||||||
{
|
{
|
||||||
if (file == NULL) return TREXIO_INVALID_ARG_1;
|
if (file == NULL) return TREXIO_INVALID_ARG_1;
|
||||||
|
|
||||||
char file_name[256];
|
const char file_name[256] = "/$group_dset$.txt";
|
||||||
memset(file_name, 0, sizeof(file_name));
|
|
||||||
const int32_t trexio_state = $with_state$;
|
|
||||||
|
|
||||||
if (trexio_state != 0) {
|
|
||||||
sprintf(file_name, "/$group_dset$_state_%" PRId32 ".txt", trexio_state);
|
|
||||||
} else {
|
|
||||||
strncpy(file_name, "/$group_dset$.txt", 256);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The full path to the destination TXT file with sparse data. This will include TREXIO directory name. */
|
/* The full path to the destination TXT file with sparse data. This will include TREXIO directory name. */
|
||||||
char file_full_path[TREXIO_MAX_FILENAME_LENGTH];
|
char file_full_path[TREXIO_MAX_FILENAME_LENGTH];
|
||||||
/* Copy directory name in file_full_path */
|
/* Copy directory name in file_full_path */
|
||||||
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH);
|
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH - sizeof(file_name));
|
||||||
/* Append name of the file with sparse data */
|
/* Append name of the file with sparse data */
|
||||||
strncat (file_full_path, file_name,
|
strncat (file_full_path, file_name, sizeof(file_name));
|
||||||
TREXIO_MAX_FILENAME_LENGTH-strlen(file_name));
|
|
||||||
|
|
||||||
/* Check the return code of access function to determine whether the file with data exists or not */
|
/* Check the return code of access function to determine whether the file with data exists or not */
|
||||||
if (access(file_full_path, F_OK) == 0){
|
if (access(file_full_path, F_OK) == 0){
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#define TEST_BACKEND TREXIO_HDF5
|
#define TEST_BACKEND TREXIO_HDF5
|
||||||
#define TREXIO_FILE "test_determinant.h5"
|
#define TREXIO_FILE "test_determinant.h5"
|
||||||
#define RM_COMMAND "rm -f " TREXIO_FILE
|
#define RM_COMMAND "rm -rf " TREXIO_FILE
|
||||||
#define SIZE 100
|
#define SIZE 100
|
||||||
#define N_CHUNKS 5
|
#define N_CHUNKS 5
|
||||||
#define STATE_TEST 2
|
#define STATE_TEST 2
|
||||||
@ -64,6 +64,12 @@ static int test_write_determinant (const char* file_name, const back_end_t backe
|
|||||||
uint64_t offset_d = 0UL;
|
uint64_t offset_d = 0UL;
|
||||||
if (offset != 0L) offset_f += offset;
|
if (offset != 0L) offset_f += offset;
|
||||||
|
|
||||||
|
// write the state_id of a given file: 0 is ground state
|
||||||
|
if (trexio_has_state_id(file) == TREXIO_HAS_NOT) {
|
||||||
|
rc = trexio_write_state_id(file, 0);
|
||||||
|
assert(rc == TREXIO_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
// 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){
|
||||||
|
|
||||||
@ -73,13 +79,10 @@ 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]);
|
rc = trexio_write_determinant_coefficient(file, offset_f, chunk_size, &det_coef[offset_d]);
|
||||||
assert(rc == TREXIO_SUCCESS);
|
assert(rc == TREXIO_SUCCESS);
|
||||||
|
|
||||||
// The block below will write the coefficients for STATE_TEST
|
// The block below will check the set_state
|
||||||
rc = trexio_set_state(file, STATE_TEST);
|
rc = trexio_set_state(file, STATE_TEST);
|
||||||
assert(rc == TREXIO_SUCCESS);
|
assert(rc == TREXIO_SUCCESS);
|
||||||
|
|
||||||
rc = trexio_write_determinant_coefficient(file, offset_f, chunk_size, &det_coef[offset_d]);
|
|
||||||
assert(rc == TREXIO_SUCCESS);
|
|
||||||
|
|
||||||
// set state back to the default 0 (ground state)
|
// set state back to the default 0 (ground state)
|
||||||
rc = trexio_set_state(file, 0);
|
rc = trexio_set_state(file, 0);
|
||||||
assert(rc == TREXIO_SUCCESS);
|
assert(rc == TREXIO_SUCCESS);
|
||||||
@ -100,13 +103,6 @@ static int test_write_determinant (const char* file_name, const back_end_t backe
|
|||||||
assert(rc == TREXIO_SUCCESS);
|
assert(rc == TREXIO_SUCCESS);
|
||||||
assert(determinant_num == coeff_size);
|
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
|
// close current session
|
||||||
rc = trexio_close(file);
|
rc = trexio_close(file);
|
||||||
assert (rc == TREXIO_SUCCESS);
|
assert (rc == TREXIO_SUCCESS);
|
||||||
@ -142,16 +138,6 @@ static int test_has_determinant(const char* file_name, const back_end_t backend)
|
|||||||
rc = trexio_has_determinant_coefficient(file);
|
rc = trexio_has_determinant_coefficient(file);
|
||||||
assert(rc==TREXIO_SUCCESS);
|
assert(rc==TREXIO_SUCCESS);
|
||||||
|
|
||||||
// also check for STATE_TEST
|
|
||||||
rc = trexio_set_state(file, STATE_TEST);
|
|
||||||
assert(rc == TREXIO_SUCCESS);
|
|
||||||
|
|
||||||
rc = trexio_has_determinant_coefficient(file);
|
|
||||||
assert(rc==TREXIO_SUCCESS);
|
|
||||||
|
|
||||||
rc = trexio_set_state(file, 0);
|
|
||||||
assert(rc == TREXIO_SUCCESS);
|
|
||||||
|
|
||||||
// close current session
|
// close current session
|
||||||
rc = trexio_close(file);
|
rc = trexio_close(file);
|
||||||
assert (rc == TREXIO_SUCCESS);
|
assert (rc == TREXIO_SUCCESS);
|
||||||
@ -189,13 +175,11 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
|
|||||||
// define arrays to read into
|
// define arrays to read into
|
||||||
int64_t* det_list_read;
|
int64_t* det_list_read;
|
||||||
double* det_coef_read;
|
double* det_coef_read;
|
||||||
double* det_coef_s2_read;
|
|
||||||
double check_diff;
|
double check_diff;
|
||||||
uint64_t size_r = 40L;
|
uint64_t size_r = 40L;
|
||||||
|
|
||||||
det_list_read = (int64_t*) calloc(2*int_num*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_read = (double*) calloc(size_r,sizeof(double));
|
||||||
det_coef_s2_read = (double*) calloc(size_r,sizeof(double));
|
|
||||||
|
|
||||||
// specify the read parameters, here:
|
// specify the read parameters, here:
|
||||||
// 1 chunk of 10 elements using offset of 40 (i.e. lines No. 40--59) into elements of the array starting from 5
|
// 1 chunk of 10 elements using offset of 40 (i.e. lines No. 40--59) into elements of the array starting from 5
|
||||||
@ -225,19 +209,10 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
|
|||||||
//printf("%lf %lf\n", check_diff, det_coef_read[offset_data_read]);
|
//printf("%lf %lf\n", check_diff, det_coef_read[offset_data_read]);
|
||||||
assert(check_diff*check_diff < 1e-14);
|
assert(check_diff*check_diff < 1e-14);
|
||||||
|
|
||||||
// read one chuk of coefficients for a different state
|
int32_t read_state_id = 666;
|
||||||
rc = trexio_set_state(file, STATE_TEST);
|
rc = trexio_read_state_id(file, &read_state_id);
|
||||||
assert(rc == TREXIO_SUCCESS);
|
|
||||||
|
|
||||||
rc = trexio_read_determinant_coefficient(file, offset_file_read, &chunk_read, &det_coef_s2_read[offset_data_read]);
|
|
||||||
assert(rc == TREXIO_SUCCESS);
|
|
||||||
assert(chunk_read == read_size_check);
|
|
||||||
|
|
||||||
check_diff = det_coef_s2_read[0] - 0.;
|
|
||||||
assert(check_diff*check_diff < 1e-14);
|
|
||||||
|
|
||||||
rc = trexio_set_state(file, 0);
|
|
||||||
assert(rc == TREXIO_SUCCESS);
|
assert(rc == TREXIO_SUCCESS);
|
||||||
|
assert(read_state_id == 0);
|
||||||
|
|
||||||
// now attempt to read so that one encounters end of file during reading (i.e. offset_file_read + chunk_read > size_max)
|
// now attempt to read so that one encounters end of file during reading (i.e. offset_file_read + chunk_read > size_max)
|
||||||
offset_file_read = 97L;
|
offset_file_read = 97L;
|
||||||
@ -284,7 +259,6 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
|
|||||||
assert(rc == TREXIO_SUCCESS);
|
assert(rc == TREXIO_SUCCESS);
|
||||||
assert(det_num == size_check);
|
assert(det_num == size_check);
|
||||||
|
|
||||||
|
|
||||||
// check conversion of determinants into orbital lists
|
// check conversion of determinants into orbital lists
|
||||||
int64_t size_list = TREXIO_NORB_PER_INT * int_num;
|
int64_t size_list = TREXIO_NORB_PER_INT * int_num;
|
||||||
int32_t* orb_list_up = (int32_t*) calloc(size_list, sizeof(int32_t));
|
int32_t* orb_list_up = (int32_t*) calloc(size_list, sizeof(int32_t));
|
||||||
@ -323,7 +297,6 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
|
|||||||
// free the memory
|
// free the memory
|
||||||
free(det_list_read);
|
free(det_list_read);
|
||||||
free(det_coef_read);
|
free(det_coef_read);
|
||||||
free(det_coef_s2_read);
|
|
||||||
free(det_list_check);
|
free(det_list_check);
|
||||||
free(orb_list_up);
|
free(orb_list_up);
|
||||||
free(orb_list_dn);
|
free(orb_list_dn);
|
||||||
|
@ -64,6 +64,12 @@ static int test_write_determinant (const char* file_name, const back_end_t backe
|
|||||||
uint64_t offset_d = 0UL;
|
uint64_t offset_d = 0UL;
|
||||||
if (offset != 0L) offset_f += offset;
|
if (offset != 0L) offset_f += offset;
|
||||||
|
|
||||||
|
// write the state_id of a given file: 0 is ground state
|
||||||
|
if (trexio_has_state_id(file) == TREXIO_HAS_NOT) {
|
||||||
|
rc = trexio_write_state_id(file, 0);
|
||||||
|
assert(rc == TREXIO_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
// 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){
|
||||||
|
|
||||||
@ -73,13 +79,10 @@ 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]);
|
rc = trexio_write_determinant_coefficient(file, offset_f, chunk_size, &det_coef[offset_d]);
|
||||||
assert(rc == TREXIO_SUCCESS);
|
assert(rc == TREXIO_SUCCESS);
|
||||||
|
|
||||||
// The block below will write the coefficients for STATE_TEST
|
// The block below will check the set_state
|
||||||
rc = trexio_set_state(file, STATE_TEST);
|
rc = trexio_set_state(file, STATE_TEST);
|
||||||
assert(rc == TREXIO_SUCCESS);
|
assert(rc == TREXIO_SUCCESS);
|
||||||
|
|
||||||
rc = trexio_write_determinant_coefficient(file, offset_f, chunk_size, &det_coef[offset_d]);
|
|
||||||
assert(rc == TREXIO_SUCCESS);
|
|
||||||
|
|
||||||
// set state back to the default 0 (ground state)
|
// set state back to the default 0 (ground state)
|
||||||
rc = trexio_set_state(file, 0);
|
rc = trexio_set_state(file, 0);
|
||||||
assert(rc == TREXIO_SUCCESS);
|
assert(rc == TREXIO_SUCCESS);
|
||||||
@ -100,13 +103,6 @@ static int test_write_determinant (const char* file_name, const back_end_t backe
|
|||||||
assert(rc == TREXIO_SUCCESS);
|
assert(rc == TREXIO_SUCCESS);
|
||||||
assert(determinant_num == coeff_size);
|
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
|
// close current session
|
||||||
rc = trexio_close(file);
|
rc = trexio_close(file);
|
||||||
assert (rc == TREXIO_SUCCESS);
|
assert (rc == TREXIO_SUCCESS);
|
||||||
@ -142,16 +138,6 @@ static int test_has_determinant(const char* file_name, const back_end_t backend)
|
|||||||
rc = trexio_has_determinant_coefficient(file);
|
rc = trexio_has_determinant_coefficient(file);
|
||||||
assert(rc==TREXIO_SUCCESS);
|
assert(rc==TREXIO_SUCCESS);
|
||||||
|
|
||||||
// also check for STATE_TEST
|
|
||||||
rc = trexio_set_state(file, STATE_TEST);
|
|
||||||
assert(rc == TREXIO_SUCCESS);
|
|
||||||
|
|
||||||
rc = trexio_has_determinant_coefficient(file);
|
|
||||||
assert(rc==TREXIO_SUCCESS);
|
|
||||||
|
|
||||||
rc = trexio_set_state(file, 0);
|
|
||||||
assert(rc == TREXIO_SUCCESS);
|
|
||||||
|
|
||||||
// close current session
|
// close current session
|
||||||
rc = trexio_close(file);
|
rc = trexio_close(file);
|
||||||
assert (rc == TREXIO_SUCCESS);
|
assert (rc == TREXIO_SUCCESS);
|
||||||
@ -189,13 +175,11 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
|
|||||||
// define arrays to read into
|
// define arrays to read into
|
||||||
int64_t* det_list_read;
|
int64_t* det_list_read;
|
||||||
double* det_coef_read;
|
double* det_coef_read;
|
||||||
double* det_coef_s2_read;
|
|
||||||
double check_diff;
|
double check_diff;
|
||||||
uint64_t size_r = 40L;
|
uint64_t size_r = 40L;
|
||||||
|
|
||||||
det_list_read = (int64_t*) calloc(2*int_num*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_read = (double*) calloc(size_r,sizeof(double));
|
||||||
det_coef_s2_read = (double*) calloc(size_r,sizeof(double));
|
|
||||||
|
|
||||||
// specify the read parameters, here:
|
// specify the read parameters, here:
|
||||||
// 1 chunk of 10 elements using offset of 40 (i.e. lines No. 40--59) into elements of the array starting from 5
|
// 1 chunk of 10 elements using offset of 40 (i.e. lines No. 40--59) into elements of the array starting from 5
|
||||||
@ -225,19 +209,10 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
|
|||||||
//printf("%lf %lf\n", check_diff, det_coef_read[offset_data_read]);
|
//printf("%lf %lf\n", check_diff, det_coef_read[offset_data_read]);
|
||||||
assert(check_diff*check_diff < 1e-14);
|
assert(check_diff*check_diff < 1e-14);
|
||||||
|
|
||||||
// read one chuk of coefficients for a different state
|
int32_t read_state_id = 666;
|
||||||
rc = trexio_set_state(file, STATE_TEST);
|
rc = trexio_read_state_id(file, &read_state_id);
|
||||||
assert(rc == TREXIO_SUCCESS);
|
|
||||||
|
|
||||||
rc = trexio_read_determinant_coefficient(file, offset_file_read, &chunk_read, &det_coef_s2_read[offset_data_read]);
|
|
||||||
assert(rc == TREXIO_SUCCESS);
|
|
||||||
assert(chunk_read == read_size_check);
|
|
||||||
|
|
||||||
check_diff = det_coef_s2_read[0] - 0.;
|
|
||||||
assert(check_diff*check_diff < 1e-14);
|
|
||||||
|
|
||||||
rc = trexio_set_state(file, 0);
|
|
||||||
assert(rc == TREXIO_SUCCESS);
|
assert(rc == TREXIO_SUCCESS);
|
||||||
|
assert(read_state_id == 0);
|
||||||
|
|
||||||
// now attempt to read so that one encounters end of file during reading (i.e. offset_file_read + chunk_read > size_max)
|
// now attempt to read so that one encounters end of file during reading (i.e. offset_file_read + chunk_read > size_max)
|
||||||
offset_file_read = 97L;
|
offset_file_read = 97L;
|
||||||
@ -284,7 +259,6 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
|
|||||||
assert(rc == TREXIO_SUCCESS);
|
assert(rc == TREXIO_SUCCESS);
|
||||||
assert(det_num == size_check);
|
assert(det_num == size_check);
|
||||||
|
|
||||||
|
|
||||||
// check conversion of determinants into orbital lists
|
// check conversion of determinants into orbital lists
|
||||||
int64_t size_list = TREXIO_NORB_PER_INT * int_num;
|
int64_t size_list = TREXIO_NORB_PER_INT * int_num;
|
||||||
int32_t* orb_list_up = (int32_t*) calloc(size_list, sizeof(int32_t));
|
int32_t* orb_list_up = (int32_t*) calloc(size_list, sizeof(int32_t));
|
||||||
@ -323,7 +297,6 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
|
|||||||
// free the memory
|
// free the memory
|
||||||
free(det_list_read);
|
free(det_list_read);
|
||||||
free(det_coef_read);
|
free(det_coef_read);
|
||||||
free(det_coef_s2_read);
|
|
||||||
free(det_list_check);
|
free(det_list_check);
|
||||||
free(orb_list_up);
|
free(orb_list_up);
|
||||||
free(orb_list_dn);
|
free(orb_list_dn);
|
||||||
|
@ -111,7 +111,7 @@ def recursive_populate_file(fname: str, paths: dict, detailed_source: dict) -> N
|
|||||||
'group_dset_rank', 'group_dset_dim_list', 'group_dset_f_dims',
|
'group_dset_rank', 'group_dset_dim_list', 'group_dset_f_dims',
|
||||||
'group_num_f_dtype_default', 'group_num_f_dtype_double', 'group_num_f_dtype_single',
|
'group_num_f_dtype_default', 'group_num_f_dtype_double', 'group_num_f_dtype_single',
|
||||||
'group_num_dtype_default', 'group_num_dtype_double', 'group_num_dtype_single',
|
'group_num_dtype_default', 'group_num_dtype_double', 'group_num_dtype_single',
|
||||||
'group_num_h5_dtype', 'group_num_py_dtype', 'with_state',
|
'group_num_h5_dtype', 'group_num_py_dtype',
|
||||||
'group_dset_format_scanf', 'group_dset_format_printf', 'group_dset_sparse_dim',
|
'group_dset_format_scanf', 'group_dset_format_printf', 'group_dset_sparse_dim',
|
||||||
'group_dset_sparse_indices_printf', 'group_dset_sparse_indices_scanf',
|
'group_dset_sparse_indices_printf', 'group_dset_sparse_indices_scanf',
|
||||||
'sparse_format_printf_8', 'sparse_format_printf_16', 'sparse_format_printf_32',
|
'sparse_format_printf_8', 'sparse_format_printf_16', 'sparse_format_printf_32',
|
||||||
@ -715,19 +715,7 @@ def split_dset_dict_detailed (datasets: dict) -> tuple:
|
|||||||
tmp_dict['is_index'] = 'false'
|
tmp_dict['is_index'] = 'false'
|
||||||
|
|
||||||
# add the list of dimensions
|
# add the list of dimensions
|
||||||
if 'state.num' in v[1] and len(v[1]) > 1:
|
tmp_dict['dims'] = [dim.replace('.','_') for dim in v[1]]
|
||||||
tmp_dict['with_state'] = 'file->state'
|
|
||||||
# we have to remove state.num from the list of dimensions
|
|
||||||
# because it is opaque dimension, namely it is controlled by a global state switch
|
|
||||||
tmp_dict['dims'] = [dim.replace('.','_') for dim in v[1] if 'state.num' not in dim]
|
|
||||||
rank -= 1
|
|
||||||
elif 'state.num' in v[1] and len(v[1]) == 1:
|
|
||||||
tmp_dict['with_state'] = '0'
|
|
||||||
tmp_dict['dims'] = ['state_num']
|
|
||||||
rank = 1
|
|
||||||
else:
|
|
||||||
tmp_dict['with_state'] = '0'
|
|
||||||
tmp_dict['dims'] = [dim.replace('.','_') for dim in v[1]]
|
|
||||||
|
|
||||||
# add the rank
|
# add the rank
|
||||||
tmp_dict['rank'] = rank
|
tmp_dict['rank'] = rank
|
||||||
|
33
trex.org
33
trex.org
@ -702,11 +702,11 @@ prim_factor =
|
|||||||
An illustration on how to read determinants is presented in the [[./examples.html][examples]].
|
An illustration on how to read determinants is presented in the [[./examples.html][examples]].
|
||||||
|
|
||||||
#+NAME: determinant
|
#+NAME: determinant
|
||||||
| Variable | Type | Dimensions | Description |
|
| Variable | Type | Dimensions | Description |
|
||||||
|---------------+----------------+-------------------------------+--------------------------------------------------------|
|
|---------------+----------------+---------------------+--------------------------------------------------------|
|
||||||
| ~num~ | ~dim readonly~ | | Number of determinants |
|
| ~num~ | ~dim readonly~ | | Number of determinants |
|
||||||
| ~list~ | ~int special~ | ~(determinant.num)~ | List of determinants as integer bit fields |
|
| ~list~ | ~int special~ | ~(determinant.num)~ | List of determinants as integer bit fields |
|
||||||
| ~coefficient~ | ~float buffer~ | ~(state.num,determinant.num)~ | Coefficients of the determinants from the CI expansion |
|
| ~coefficient~ | ~float buffer~ | ~(determinant.num)~ | Coefficients of the determinants from the CI expansion |
|
||||||
|
|
||||||
#+CALL: json(data=determinant, title="determinant")
|
#+CALL: json(data=determinant, title="determinant")
|
||||||
|
|
||||||
@ -714,9 +714,9 @@ prim_factor =
|
|||||||
:results:
|
:results:
|
||||||
#+begin_src python :tangle trex.json
|
#+begin_src python :tangle trex.json
|
||||||
"determinant": {
|
"determinant": {
|
||||||
"num" : [ "dim readonly", [] ]
|
"num" : [ "dim readonly", [] ]
|
||||||
, "list" : [ "int special" , [ "determinant.num" ] ]
|
, "list" : [ "int special" , [ "determinant.num" ] ]
|
||||||
, "coefficient" : [ "float buffer", [ "determinant.num", "state.num" ] ]
|
, "coefficient" : [ "float buffer", [ "determinant.num" ] ]
|
||||||
} ,
|
} ,
|
||||||
#+end_src
|
#+end_src
|
||||||
:end:
|
:end:
|
||||||
@ -741,7 +741,7 @@ prim_factor =
|
|||||||
| Variable | Type | Dimensions | Description |
|
| Variable | Type | Dimensions | Description |
|
||||||
|-------------------+----------------+-----------------------------+------------------------------------------------|
|
|-------------------+----------------+-----------------------------+------------------------------------------------|
|
||||||
| ~num~ | ~dim readonly~ | | Number of CSFs |
|
| ~num~ | ~dim readonly~ | | Number of CSFs |
|
||||||
| ~coefficient~ | ~float buffer~ | ~(state.num,csf.num)~ | Coefficients of the CSFs from the CI expansion |
|
| ~coefficient~ | ~float buffer~ | ~(csf.num)~ | Coefficients of the CSFs from the CI expansion |
|
||||||
| ~det_coefficient~ | ~float sparse~ | ~(determinant.num,csf.num)~ | Projection on the determinant basis |
|
| ~det_coefficient~ | ~float sparse~ | ~(determinant.num,csf.num)~ | Projection on the determinant basis |
|
||||||
|
|
||||||
#+CALL: json(data=csf, title="csf")
|
#+CALL: json(data=csf, title="csf")
|
||||||
@ -751,7 +751,7 @@ prim_factor =
|
|||||||
#+begin_src python :tangle trex.json
|
#+begin_src python :tangle trex.json
|
||||||
"csf": {
|
"csf": {
|
||||||
"num" : [ "dim readonly", [] ]
|
"num" : [ "dim readonly", [] ]
|
||||||
, "coefficient" : [ "float buffer", [ "csf.num", "state.num" ] ]
|
, "coefficient" : [ "float buffer", [ "csf.num" ] ]
|
||||||
, "det_coefficient" : [ "float sparse", [ "csf.num", "determinant.num" ] ]
|
, "det_coefficient" : [ "float sparse", [ "csf.num", "determinant.num" ] ]
|
||||||
} ,
|
} ,
|
||||||
#+end_src
|
#+end_src
|
||||||
@ -759,15 +759,15 @@ prim_factor =
|
|||||||
|
|
||||||
* Excited states (state group)
|
* Excited states (state group)
|
||||||
|
|
||||||
By default, the ~determinant~ group corresponds to the ground state.
|
This group contains information about excited state. Since TREXIO version 2.3.0
|
||||||
However, it should be also possible to store the coefficients that
|
the state-specific data (e.g. CI/CSF coeffcients, RDMs) is written in a separate
|
||||||
correspond to excited state wave functions for the same set of
|
file in order to avoid over-complicated internal logics and global state switches.
|
||||||
determinants. This is the goal of the present group
|
|
||||||
|
|
||||||
#+NAME: state
|
#+NAME: state
|
||||||
| Variable | Type | Dimensions | Description |
|
| Variable | Type | Dimensions | Description |
|
||||||
|----------+-------+---------------+------------------------------------------------|
|
|----------+-------+---------------+------------------------------------------------|
|
||||||
| ~num~ | ~dim~ | | Number of states (including the ground state) |
|
| ~num~ | ~dim~ | | Number of states (including the ground state) |
|
||||||
|
| ~id~ | ~int~ | | Index of a current state (0 is ground state) |
|
||||||
| ~label~ | ~str~ | ~(state.num)~ | Label of a given state (e.g. 'S' for singlets) |
|
| ~label~ | ~str~ | ~(state.num)~ | Label of a given state (e.g. 'S' for singlets) |
|
||||||
|
|
||||||
#+CALL: json(data=state, title="state")
|
#+CALL: json(data=state, title="state")
|
||||||
@ -776,8 +776,9 @@ prim_factor =
|
|||||||
:results:
|
:results:
|
||||||
#+begin_src python :tangle trex.json
|
#+begin_src python :tangle trex.json
|
||||||
"state": {
|
"state": {
|
||||||
"num" : [ "dim", [] ]
|
"num" : [ "dim", [] ]
|
||||||
, "label" : [ "str", [ "state.num" ] ]
|
, "id" : [ "int", [] ]
|
||||||
|
, "label" : [ "str", [ "state.num" ] ]
|
||||||
} ,
|
} ,
|
||||||
#+end_src
|
#+end_src
|
||||||
:end:
|
:end:
|
||||||
|
Loading…
Reference in New Issue
Block a user