1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-08-25 06:31:43 +02:00

Merge pull request #119 from TREX-CoE/state

Improvement on state
This commit is contained in:
Anthony Scemama 2023-05-12 19:21:58 +02:00 committed by GitHub
commit 16b9e0bcdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 116 additions and 30 deletions

View File

@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.16)
# Initialize the CMake project. # Initialize the CMake project.
project(Trexio project(Trexio
VERSION 2.3.2 VERSION 2.4.0
DESCRIPTION "TREX I/O library" DESCRIPTION "TREX I/O library"
LANGUAGES C Fortran LANGUAGES C Fortran
) )

View File

@ -1,6 +1,12 @@
CHANGES CHANGES
======= =======
2.4
---
- Added state/energy
- Made state/id an index instead of an int
2.3 2.3
--- ---

View File

@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script. # Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69]) AC_PREREQ([2.69])
AC_INIT([trexio],[2.3.2],[https://github.com/TREX-CoE/trexio/issues]) AC_INIT([trexio],[2.4.0],[https://github.com/TREX-CoE/trexio/issues])
AC_CONFIG_SRCDIR([Makefile.in]) AC_CONFIG_SRCDIR([Makefile.in])
AC_CONFIG_HEADERS([include/config.h]) AC_CONFIG_HEADERS([include/config.h])

View File

@ -1 +1 @@
__version__ = "1.3.2" __version__ = "2.4.0"

View File

@ -1732,6 +1732,12 @@ def _cp(source: str, destination: str):
and write it as ~state_id~ attribute. and write it as ~state_id~ attribute.
~trexio_get_state~ returns current state of the ~trexio_t~ file handle. ~trexio_get_state~ returns current state of the ~trexio_t~ file handle.
**Warning:** The ~trexio_set_state~ and ~trexio_get_state~ functions still
use the old convention where the ground state was state ~0~. From version 2.4.0,
the ~state_id~ variable has changed to ~index~ type, so using the more recent
~trexio_write_state_id~ and ~trexio_read_state_id~ will give different results
in Fortran.
input parameters: input parameters:
~file~ -- TREXIO file handle. ~file~ -- TREXIO file handle.
~state~ -- ~int32_t~ ID of a state (0 for ground state). ~state~ -- ~int32_t~ ID of a state (0 for ground state).
@ -2132,24 +2138,35 @@ trexio_read_$group_num$_64 (trexio_t* const file, $group_num_dtype_double$* cons
if (num == NULL) return TREXIO_INVALID_ARG_2; if (num == NULL) return TREXIO_INVALID_ARG_2;
if (trexio_has_$group_num$(file) != TREXIO_SUCCESS) return TREXIO_ATTR_MISSING; if (trexio_has_$group_num$(file) != TREXIO_SUCCESS) return TREXIO_ATTR_MISSING;
trexio_exit_code rc = TREXIO_GROUP_READ_ERROR;
switch (file->back_end) { switch (file->back_end) {
case TREXIO_TEXT: case TREXIO_TEXT:
return trexio_text_read_$group_num$(file, num); rc = trexio_text_read_$group_num$(file, num);
break;
case TREXIO_HDF5: case TREXIO_HDF5:
#ifdef HAVE_HDF5 #ifdef HAVE_HDF5
return trexio_hdf5_read_$group_num$(file, num); rc = trexio_hdf5_read_$group_num$(file, num);
#else #else
return TREXIO_BACK_END_MISSING; rc = TREXIO_BACK_END_MISSING;
#endif #endif
break;
/* /*
case TREXIO_JSON: case TREXIO_JSON:
return trexio_json_read_$group_num$(file, num); rc = trexio_json_read_$group_num$(file, num);
break;
,*/ ,*/
} }
return TREXIO_FAILURE; if (rc != TREXIO_SUCCESS) return rc;
/* Handle index type */
if ($is_index$) {
,*num += ($group_num_dtype_double$) 1;
}
return rc;
} }
#+end_src #+end_src
@ -2161,20 +2178,26 @@ trexio_write_$group_num$_64 (trexio_t* const file, const $group_num_dtype_double
//if (num <= 0L) return TREXIO_INVALID_NUM; /* this line is uncommented by the generator for dimensioning variables; do NOT remove! */ //if (num <= 0L) return TREXIO_INVALID_NUM; /* this line is uncommented by the generator for dimensioning variables; do NOT remove! */
if (trexio_has_$group_num$(file) == TREXIO_SUCCESS && file->mode != 'u') return TREXIO_ATTR_ALREADY_EXISTS; if (trexio_has_$group_num$(file) == TREXIO_SUCCESS && file->mode != 'u') return TREXIO_ATTR_ALREADY_EXISTS;
/* Handle index type */
$group_num_dtype_double$ num_write = num;
if ($is_index$) {
num_write -= ($group_num_dtype_double$) 1;
}
switch (file->back_end) { switch (file->back_end) {
case TREXIO_TEXT: case TREXIO_TEXT:
return trexio_text_write_$group_num$(file, num); return trexio_text_write_$group_num$(file, num_write);
case TREXIO_HDF5: case TREXIO_HDF5:
#ifdef HAVE_HDF5 #ifdef HAVE_HDF5
return trexio_hdf5_write_$group_num$(file, num); return trexio_hdf5_write_$group_num$(file, num_write);
#else #else
return TREXIO_BACK_END_MISSING; return TREXIO_BACK_END_MISSING;
#endif #endif
/* /*
case TREXIO_JSON: case TREXIO_JSON:
return trexio_json_write_$group_num$(file, num); return trexio_json_write_$group_num$(file, num_write);
,*/ ,*/
} }
@ -2219,6 +2242,12 @@ trexio_read_$group_num$_32 (trexio_t* const file, $group_num_dtype_single$* cons
if (rc != TREXIO_SUCCESS) return rc; if (rc != TREXIO_SUCCESS) return rc;
,*num = ($group_num_dtype_single$) num_64; ,*num = ($group_num_dtype_single$) num_64;
/* Handle index type */
if ($is_index$) {
,*num += ($group_num_dtype_single$) 1;
}
return TREXIO_SUCCESS; return TREXIO_SUCCESS;
} }
#+end_src #+end_src
@ -2232,20 +2261,26 @@ trexio_write_$group_num$_32 (trexio_t* const file, const $group_num_dtype_single
//if (num <= 0) return TREXIO_INVALID_NUM; /* this line is uncommented by the generator for dimensioning variables; do NOT remove! */ //if (num <= 0) return TREXIO_INVALID_NUM; /* this line is uncommented by the generator for dimensioning variables; do NOT remove! */
if (trexio_has_$group_num$(file) == TREXIO_SUCCESS && file->mode != 'u') return TREXIO_ATTR_ALREADY_EXISTS; if (trexio_has_$group_num$(file) == TREXIO_SUCCESS && file->mode != 'u') return TREXIO_ATTR_ALREADY_EXISTS;
/* Handle index type */
$group_num_dtype_single$ num_write = num;
if ($is_index$) {
num_write -= ($group_num_dtype_single$) 1;
}
switch (file->back_end) { switch (file->back_end) {
case TREXIO_TEXT: case TREXIO_TEXT:
return trexio_text_write_$group_num$(file, ($group_num_dtype_double$) num); return trexio_text_write_$group_num$(file, ($group_num_dtype_double$) num_write);
case TREXIO_HDF5: case TREXIO_HDF5:
#ifdef HAVE_HDF5 #ifdef HAVE_HDF5
return trexio_hdf5_write_$group_num$(file, ($group_num_dtype_double$) num); return trexio_hdf5_write_$group_num$(file, ($group_num_dtype_double$) num_write);
#else #else
return TREXIO_BACK_END_MISSING; return TREXIO_BACK_END_MISSING;
#endif #endif
/* /*
case TREXIO_JSON: case TREXIO_JSON:
return trexio_json_write_$group_num$(file, ($group_num_dtype_double$) num); return trexio_json_write_$group_num$(file, ($group_num_dtype_double$) num_write);
break; break;
,*/ ,*/
} }

View File

@ -17,6 +17,7 @@ static int test_write_dset (const char* file_name, const back_end_t backend) {
// parameters to be written // parameters to be written
int num = 12; int num = 12;
int nucl_index[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; int nucl_index[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
int state_id = 2;
/*================= START OF TEST ==================*/ /*================= START OF TEST ==================*/
@ -32,6 +33,10 @@ static int test_write_dset (const char* file_name, const back_end_t backend) {
rc = trexio_write_basis_nucleus_index(file, nucl_index); rc = trexio_write_basis_nucleus_index(file, nucl_index);
assert (rc == TREXIO_SUCCESS); assert (rc == TREXIO_SUCCESS);
// write index attribute in a file
rc = trexio_write_state_id(file, state_id);
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);
@ -89,8 +94,9 @@ static int test_read_dset (const char* file_name, const back_end_t backend) {
trexio_exit_code rc; trexio_exit_code rc;
// parameters to be read // parameters to be read
int num; int num = 0;
int* nucl_index; int* nucl_index = NULL;
int state_id = 0;
/*================= START OF TEST ==================*/ /*================= START OF TEST ==================*/
@ -103,6 +109,11 @@ static int test_read_dset (const char* file_name, const back_end_t backend) {
assert (rc == TREXIO_SUCCESS); assert (rc == TREXIO_SUCCESS);
assert (num == 12); assert (num == 12);
// read index attribute from the file
rc = trexio_read_state_id(file, &state_id);
assert (rc == TREXIO_SUCCESS);
assert (state_id == 2);
// read numerical dataset from the file // read numerical dataset from the file
nucl_index = (int*) calloc(num, sizeof(int)); nucl_index = (int*) calloc(num, sizeof(int));
rc = trexio_read_basis_nucleus_index(file, nucl_index); rc = trexio_read_basis_nucleus_index(file, nucl_index);

View File

@ -17,6 +17,7 @@ static int test_write_dset (const char* file_name, const back_end_t backend) {
// parameters to be written // parameters to be written
int num = 12; int num = 12;
int nucl_index[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; int nucl_index[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
int state_id = 2;
/*================= START OF TEST ==================*/ /*================= START OF TEST ==================*/
@ -32,6 +33,10 @@ static int test_write_dset (const char* file_name, const back_end_t backend) {
rc = trexio_write_basis_nucleus_index(file, nucl_index); rc = trexio_write_basis_nucleus_index(file, nucl_index);
assert (rc == TREXIO_SUCCESS); assert (rc == TREXIO_SUCCESS);
// write index attribute in a file
rc = trexio_write_state_id(file, state_id);
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);
@ -89,8 +94,9 @@ static int test_read_dset (const char* file_name, const back_end_t backend) {
trexio_exit_code rc; trexio_exit_code rc;
// parameters to be read // parameters to be read
int num; int num = 0;
int* nucl_index; int* nucl_index = NULL;
int state_id = 0;
/*================= START OF TEST ==================*/ /*================= START OF TEST ==================*/
@ -103,6 +109,11 @@ static int test_read_dset (const char* file_name, const back_end_t backend) {
assert (rc == TREXIO_SUCCESS); assert (rc == TREXIO_SUCCESS);
assert (num == 12); assert (num == 12);
// read index attribute from the file
rc = trexio_read_state_id(file, &state_id);
assert (rc == TREXIO_SUCCESS);
assert (state_id == 2);
// read numerical dataset from the file // read numerical dataset from the file
nucl_index = (int*) calloc(num, sizeof(int)); nucl_index = (int*) calloc(num, sizeof(int));
rc = trexio_read_basis_nucleus_index(file, nucl_index); rc = trexio_read_basis_nucleus_index(file, nucl_index);

View File

@ -85,6 +85,7 @@ subroutine test_write(file_name, back_end)
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
integer :: state_id
buf_size_sparse = 100/n_buffers buf_size_sparse = 100/n_buffers
buf_size_det = 50/n_buffers buf_size_det = 50/n_buffers
@ -107,6 +108,7 @@ subroutine test_write(file_name, back_end)
! parameters to be written ! parameters to be written
nucleus_num = 12 nucleus_num = 12
state_id = 2
charge = (/ 6., 6., 6., 6., 6., 6., 1., 1., 1., 1., 1., 1. /) charge = (/ 6., 6., 6., 6., 6., 6., 1., 1., 1., 1., 1., 1. /)
coord = reshape( (/ 0.00000000d0, 1.39250319d0 , 0.00000000d0 , & coord = reshape( (/ 0.00000000d0, 1.39250319d0 , 0.00000000d0 , &
-1.20594314d0, 0.69625160d0 , 0.00000000d0 , & -1.20594314d0, 0.69625160d0 , 0.00000000d0 , &
@ -182,6 +184,9 @@ subroutine test_write(file_name, back_end)
rc = trexio_write_basis_nucleus_index(trex_file, basis_nucleus_index) rc = trexio_write_basis_nucleus_index(trex_file, basis_nucleus_index)
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE INDEX') call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE INDEX')
rc = trexio_write_state_id(trex_file, state_id)
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE INDEX TYPE')
! write ao_num which will be used to determine the optimal size of int indices ! write ao_num which will be used to determine the optimal size of int indices
if (trexio_has_ao_num(trex_file) == TREXIO_HAS_NOT) then if (trexio_has_ao_num(trex_file) == TREXIO_HAS_NOT) then
rc = trexio_write_ao_num(trex_file, ao_num) rc = trexio_write_ao_num(trex_file, ao_num)
@ -302,6 +307,7 @@ subroutine test_read(file_name, back_end)
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 integer :: int_num
integer :: state_id
! orbital lists ! orbital lists
integer*4 :: orb_list_up(150) integer*4 :: orb_list_up(150)
@ -312,6 +318,7 @@ subroutine test_read(file_name, back_end)
num = 12 num = 12
basis_shell_num = 24 basis_shell_num = 24
state_id = 0
index_sparse_ao_2e_int_eri = 0 index_sparse_ao_2e_int_eri = 0
value_sparse_ao_2e_int_eri = 0.0d0 value_sparse_ao_2e_int_eri = 0.0d0
@ -379,6 +386,15 @@ subroutine test_read(file_name, back_end)
call exit(-1) call exit(-1)
endif endif
rc = trexio_read_state_id(trex_file, state_id)
call trexio_assert(rc, TREXIO_SUCCESS)
if (state_id == 2) then
write(*,*) 'SUCCESS READ INDEX TYPE'
else
print *, 'FAILURE INDEX TYPE CHECK'
call exit(-1)
endif
rc = trexio_read_nucleus_point_group(trex_file, sym_str, 10) rc = trexio_read_nucleus_point_group(trex_file, sym_str, 10)
call trexio_assert(rc, TREXIO_SUCCESS) call trexio_assert(rc, TREXIO_SUCCESS)

View File

@ -611,8 +611,13 @@ def get_detailed_num_dict (configuration: dict) -> dict:
tmp_dict.update(get_dtype_dict(v2[0], 'num')) tmp_dict.update(get_dtype_dict(v2[0], 'num'))
if v2[0] in ['int', 'dim', 'dim readonly']: if v2[0] in ['int', 'dim', 'dim readonly']:
tmp_dict['trex_json_int_type'] = v2[0] tmp_dict['trex_json_int_type'] = v2[0]
tmp_dict['is_index'] = 'false'
elif v2[0] in ['index']:
tmp_dict['trex_json_int_type'] = v2[0]
tmp_dict['is_index'] = 'file->one_based'
else: else:
tmp_dict['trex_json_int_type'] = '' tmp_dict['trex_json_int_type'] = ''
tmp_dict['is_index'] = 'false'
num_dict[tmp_num] = tmp_dict num_dict[tmp_num] = tmp_dict

View File

@ -191,9 +191,10 @@
#+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 the current state (0 is ground state) | | ~id~ | ~index~ | | Index of the current state (0 is ground state) |
| ~energy~ | ~float~ | | Energy of the current state |
| ~current_label~ | ~str~ | | Label of the current state | | ~current_label~ | ~str~ | | Label of the current state |
| ~label~ | ~str~ | ~(state.num)~ | Labels of all states | | ~label~ | ~str~ | ~(state.num)~ | Labels of all states |
| ~file_name~ | ~str~ | ~(state.num)~ | Names of the TREXIO files linked to the current one (i.e. containing data for other states) | | ~file_name~ | ~str~ | ~(state.num)~ | Names of the TREXIO files linked to the current one (i.e. containing data for other states) |
@ -205,7 +206,8 @@
#+begin_src python :tangle trex.json #+begin_src python :tangle trex.json
"state": { "state": {
"num" : [ "dim" , [] ] "num" : [ "dim" , [] ]
, "id" : [ "int", [] ] , "id" : [ "index", [] ]
, "energy" : [ "float", [] ]
, "current_label" : [ "str" , [] ] , "current_label" : [ "str" , [] ]
, "label" : [ "str" , [ "state.num" ] ] , "label" : [ "str" , [ "state.num" ] ]
, "file_name" : [ "str" , [ "state.num" ] ] , "file_name" : [ "str" , [ "state.num" ] ]