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

Merge pull request #109 from TREX-CoE/phases

Introduced phase change
This commit is contained in:
Evgeny Posenitskiy 2023-01-08 17:17:06 +01:00 committed by GitHub
commit f6623c1579
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 89 additions and 50 deletions

View File

@ -171,7 +171,7 @@ __trexio_path__ = None
#+NAME: table-exit-codes #+NAME: table-exit-codes
| Macro | Code | Description | | Macro | Code | Description |
|----------------------------------+------+----------------------------------------| |----------------------------------+------+------------------------------------------------|
| ~TREXIO_FAILURE~ | -1 | 'Unknown failure' | | ~TREXIO_FAILURE~ | -1 | 'Unknown failure' |
| ~TREXIO_SUCCESS~ | 0 | 'Success' | | ~TREXIO_SUCCESS~ | 0 | 'Success' |
| ~TREXIO_INVALID_ARG_1~ | 1 | 'Invalid argument 1' | | ~TREXIO_INVALID_ARG_1~ | 1 | 'Invalid argument 1' |
@ -210,6 +210,7 @@ __trexio_path__ = None
| ~TREXIO_INVALID_DETERMINANT_NUM~ | 34 | 'Inconsistent number of determinants' | | ~TREXIO_INVALID_DETERMINANT_NUM~ | 34 | 'Inconsistent number of determinants' |
| ~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' |
# 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
@ -253,7 +254,7 @@ return '\n'.join(result)
#+RESULTS: #+RESULTS:
:RESULTS: :results:
#+begin_src c :tangle prefix_front.h :exports none #+begin_src c :tangle prefix_front.h :exports none
#define TREXIO_FAILURE ((trexio_exit_code) -1) #define TREXIO_FAILURE ((trexio_exit_code) -1)
#define TREXIO_SUCCESS ((trexio_exit_code) 0) #define TREXIO_SUCCESS ((trexio_exit_code) 0)
@ -293,6 +294,7 @@ return '\n'.join(result)
#define TREXIO_INVALID_DETERMINANT_NUM ((trexio_exit_code) 34) #define TREXIO_INVALID_DETERMINANT_NUM ((trexio_exit_code) 34)
#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)
#+end_src #+end_src
#+begin_src f90 :tangle prefix_fortran.f90 :exports none #+begin_src f90 :tangle prefix_fortran.f90 :exports none
@ -334,6 +336,7 @@ return '\n'.join(result)
integer(trexio_exit_code), parameter :: TREXIO_INVALID_DETERMINANT_NUM = 34 integer(trexio_exit_code), parameter :: TREXIO_INVALID_DETERMINANT_NUM = 34
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
#+end_src #+end_src
#+begin_src python :tangle prefix_python.py :exports none #+begin_src python :tangle prefix_python.py :exports none
@ -376,8 +379,9 @@ return '\n'.join(result)
TREXIO_INVALID_DETERMINANT_NUM = 34 TREXIO_INVALID_DETERMINANT_NUM = 34
TREXIO_INVALID_STATE = 35 TREXIO_INVALID_STATE = 35
TREXIO_VERSION_PARSING_ISSUE = 36 TREXIO_VERSION_PARSING_ISSUE = 36
TREXIO_PHASE_CHANGE = 37
#+end_src #+end_src
:END: :end:
*** Decoding errors *** Decoding errors
@ -5571,8 +5575,9 @@ def has_determinant_list(trexio_file) -> bool:
~trexio_to_orbital_list_up_dn~ function does the same but for both up- and down-spin components ~trexio_to_orbital_list_up_dn~ function does the same but for both up- and down-spin components
of the determinant and returns two list of orbitals each corresponding to a different component. of the determinant and returns two list of orbitals each corresponding to a different component.
~trexio_to_bitfield_list~ function converts the list of occupied orbitals (up- or down-spin) ~trexio_to_bitfield_list~ function converts the list of occupied orbitals (up- or down-spin) into the corresponding ~int64_t~
into the corresponding ~int64_t~ bitfield representation of the determinant. bitfield representation of the determinant. If the creation of the bitfield requires a change of sign, the return code is
~TREXIO_PHASE_CHANGE~.
** C ** C
@ -5606,22 +5611,38 @@ trexio_exit_code trexio_to_bitfield_list (const int32_t* orb_list,
if (bit_list == NULL) return TREXIO_INVALID_ARG_3; if (bit_list == NULL) return TREXIO_INVALID_ARG_3;
if (N_int <= 0) return TREXIO_INVALID_ARG_4; if (N_int <= 0) return TREXIO_INVALID_ARG_4;
uint32_t i;
uint32_t k;
uint32_t iorb;
for (int32_t j = 0 ; j < N_int ; j++) { for (int32_t j = 0 ; j < N_int ; j++) {
bit_list[j] = (bitfield_t) 0; bit_list[j] = (bitfield_t) 0;
} }
uint32_t i;
uint32_t k;
uint32_t iorb;
bitfield_t mask;
uint32_t nswaps = 0;
for (int32_t pos = 0 ; pos < occupied_num ; pos++) { for (int32_t pos = 0 ; pos < occupied_num ; pos++) {
iorb = ((uint32_t) (orb_list[pos] + 1)) - TREXIO_ORBITAL_SHIFT; iorb = ((uint32_t) (orb_list[pos] + 1)) - TREXIO_ORBITAL_SHIFT;
// Set the bit of to one
i = (uint32_t) (iorb >> TREXIO_NORB_PER_INT_SHIFT); i = (uint32_t) (iorb >> TREXIO_NORB_PER_INT_SHIFT);
k = (uint32_t) (iorb & (TREXIO_NORB_PER_INT - 1) ); k = (uint32_t) (iorb & (TREXIO_NORB_PER_INT - 1) );
bit_list[i] |= ((bitfield_t) 1) << k; mask = ((bitfield_t) 1) << k;
bit_list[i] |= mask;
// Check for phase changes
mask = ~(mask - (bitfield_t) 1);
nswaps += popcnt(mask & bit_list[i]) - 1;
for (int j=i+1 ; j < N_int ; ++j) {
if (bit_list[j] != (bitfield_t) 0)
nswaps += popcnt(bit_list[j]);
}
} }
if ( (nswaps & 1) == 0)
return TREXIO_SUCCESS; return TREXIO_SUCCESS;
else
return TREXIO_PHASE_CHANGE;
} }
#+end_src #+end_src

View File

@ -508,6 +508,24 @@ subroutine test_read(file_name, back_end)
call exit(-1) call exit(-1)
endif endif
occ_num_dn = occ_num_up
orb_list_dn(:) = orb_list_up(:)
orb_list_dn(2) = orb_list_up(1)
orb_list_dn(1) = orb_list_up(2)
rc = trexio_to_bitfield_list(orb_list_dn, occ_num_dn, det_list_check, 3)
call trexio_assert(rc, TREXIO_PHASE_CHANGE)
do i=1,occ_num_dn
orb_list_dn(occ_num_up-i+1) = orb_list_up(i)
enddo
rc = trexio_to_bitfield_list(orb_list_dn, occ_num_dn, det_list_check, 3)
call trexio_assert(rc, TREXIO_SUCCESS)
rc = trexio_to_bitfield_list(orb_list_dn, occ_num_dn-1, det_list_check, 3)
call trexio_assert(rc, TREXIO_PHASE_CHANGE)
rc = trexio_read_mo_num(trex_file, mo_num) rc = trexio_read_mo_num(trex_file, mo_num)
call trexio_assert(rc, TREXIO_SUCCESS) call trexio_assert(rc, TREXIO_SUCCESS)