1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2025-01-09 20:48:53 +01:00

Changes after review

This commit is contained in:
Anthony Scemama 2024-11-11 02:54:28 +01:00
parent 08674345a8
commit 9459377a3f

View File

@ -470,6 +470,7 @@ __trexio_path__ = None
| ~TREXIO_INVALID_STATE~ | 35 | 'Inconsistent state of the file' | | ~TREXIO_INVALID_STATE~ | 35 | 'Inconsistent state of the file' |
| ~TREXIO_VERSION_PARSING_ISSUE~ | 36 | 'Failed to parse package_version' | | ~TREXIO_VERSION_PARSING_ISSUE~ | 36 | 'Failed to parse package_version' |
| ~TREXIO_PHASE_CHANGE~ | 37 | 'The function succeeded with a change of sign' | | ~TREXIO_PHASE_CHANGE~ | 37 | 'The function succeeded with a change of sign' |
| ~TREXIO_INVALID_MO_INDEX~ | 38 | 'Invalid MO index' |
# We need to force Emacs not to indent the Python code: # We need to force Emacs not to indent the Python code:
# -*- org-src-preserve-indentation: t # -*- org-src-preserve-indentation: t
@ -554,6 +555,7 @@ return '\n'.join(result)
#define TREXIO_INVALID_STATE ((trexio_exit_code) 35) #define TREXIO_INVALID_STATE ((trexio_exit_code) 35)
#define TREXIO_VERSION_PARSING_ISSUE ((trexio_exit_code) 36) #define TREXIO_VERSION_PARSING_ISSUE ((trexio_exit_code) 36)
#define TREXIO_PHASE_CHANGE ((trexio_exit_code) 37) #define TREXIO_PHASE_CHANGE ((trexio_exit_code) 37)
#define TREXIO_INVALID_MO_INDEX ((trexio_exit_code) 38)
#+end_src #+end_src
#+begin_src f90 :tangle prefix_fortran.f90 :exports none #+begin_src f90 :tangle prefix_fortran.f90 :exports none
@ -596,6 +598,7 @@ return '\n'.join(result)
integer(trexio_exit_code), parameter :: TREXIO_INVALID_STATE = 35 integer(trexio_exit_code), parameter :: TREXIO_INVALID_STATE = 35
integer(trexio_exit_code), parameter :: TREXIO_VERSION_PARSING_ISSUE = 36 integer(trexio_exit_code), parameter :: TREXIO_VERSION_PARSING_ISSUE = 36
integer(trexio_exit_code), parameter :: TREXIO_PHASE_CHANGE = 37 integer(trexio_exit_code), parameter :: TREXIO_PHASE_CHANGE = 37
integer(trexio_exit_code), parameter :: TREXIO_INVALID_MO_INDEX = 38
#+end_src #+end_src
#+begin_src python :tangle prefix_python.py :exports none #+begin_src python :tangle prefix_python.py :exports none
@ -639,6 +642,7 @@ return '\n'.join(result)
TREXIO_INVALID_STATE = 35 TREXIO_INVALID_STATE = 35
TREXIO_VERSION_PARSING_ISSUE = 36 TREXIO_VERSION_PARSING_ISSUE = 36
TREXIO_PHASE_CHANGE = 37 TREXIO_PHASE_CHANGE = 37
TREXIO_INVALID_MO_INDEX = 38
#+end_src #+end_src
:end: :end:
@ -5456,6 +5460,12 @@ trexio_read_safe_determinant_list (trexio_t* const file, const int64_t offset_fi
} }
#+end_src #+end_src
When writing a determinant list, the indices of the MOs are checked. If they
are out of bounds (<0 or >= mo_num), the error ~TREXIO_INVALID_MO_INDEX~ is returned.
If the number of orbitals in up-spin or down-spin determinants is different from
the number of up-spin and down-spin electrons, the error ~TREXIO_INVALID_ELECTRON_NUM~
is returned.
#+begin_src c :tangle write_determinant_front.c #+begin_src c :tangle write_determinant_front.c
trexio_exit_code trexio_exit_code
trexio_write_determinant_list (trexio_t* const file, const int64_t offset_file, const int64_t buffer_size, const int64_t* dset) trexio_write_determinant_list (trexio_t* const file, const int64_t offset_file, const int64_t buffer_size, const int64_t* dset)
@ -5463,7 +5473,7 @@ trexio_write_determinant_list (trexio_t* const file, const int64_t offset_file,
if (file == NULL) return TREXIO_INVALID_ARG_1; if (file == NULL) return TREXIO_INVALID_ARG_1;
if (offset_file < 0) return TREXIO_INVALID_ARG_2; if (offset_file < 0) return TREXIO_INVALID_ARG_2;
if (buffer_size < 0) return TREXIO_INVALID_ARG_3; if (buffer_size <= 0) return TREXIO_INVALID_ARG_3;
if (dset == NULL) return TREXIO_INVALID_ARG_4; if (dset == NULL) return TREXIO_INVALID_ARG_4;
/* Get the number of int bit fields per determinant */ /* Get the number of int bit fields per determinant */
@ -5491,30 +5501,39 @@ trexio_write_determinant_list (trexio_t* const file, const int64_t offset_file,
if (rc != TREXIO_SUCCESS) return rc; if (rc != TREXIO_SUCCESS) return rc;
/* Check all determinants */ /* Check all determinants */
int32_t list_up[nup]; int32_t occ_num_up = 0;
int32_t list_dn[ndn]; int32_t occ_num_dn = 0;
int32_t occ_num_up;
int32_t occ_num_dn; /* list_up contains first the up-spin orbitals, then the down-spin
int32_t* list_up = (int32_t*) calloc(nup+ndn,sizeof(int32_t));
if (list_up == NULL) {
return TREXIO_ALLOCATION_FAILED;
}
int32_t* list_dn = &(list_up[nup]);
for (int64_t i=0 ; i<buffer_size ; i+= 2*int_num) { for (int64_t i=0 ; i<buffer_size ; i+= 2*int_num) {
rc = trexio_to_orbital_list_up_dn(int_num, &dset[i], rc = trexio_to_orbital_list_up_dn(int_num, &dset[i],
list_up, list_dn, list_up, list_dn,
&occ_num_up, &occ_num_dn); &occ_num_up, &occ_num_dn);
if (rc != TREXIO_SUCCESS) return rc; if (rc != TREXIO_SUCCESS) {
free(list_up);
return rc;
}
if (occ_num_up != nup || occ_num_dn != ndn) { if (occ_num_up != nup || occ_num_dn != ndn) {
return TREXIO_INVALID_ARG_4; free(list_up);
return TREXIO_INVALID_ELECTRON_NUM;
} }
for (int32_t j=0 ; j<occ_num_up ; ++j) { for (int32_t j=0 ; j<nup+ndn ; ++j) {
if (list_up[j] < 0 || list_up[j] >= mo_num) { if (list_up[j] < 0 || list_up[j] >= mo_num) {
return TREXIO_INVALID_ARG_4; free(list_up);
} return TREXIO_INVALID_MO_INDEX;
}
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;
} }
} }
} }
free(list_up);
/* Up to this point, all the determinants have been checked to /* Up to this point, all the determinants have been checked to
have the correct sizes (number of electrons), and MOs in the have the correct sizes (number of electrons), and MOs in the