<commit_before>module fciqmc_data

! Data for fciqmc calculations and procedures which manipulate fciqmc and only
! fciqmc data.

use const
use csr, only: csrp_t
use spawn_data, only: spawn_t
use hash_table, only: hash_table_t
use calc, only: parallel_t
use parallel, only: parallel_timing_t
implicit none

!--- Input data: FCIQMC ---

! [todo] - It is somewhat inelegant to store/pass around real_factor or real_bit_shift separately,
! [todo] - when really they are variables telling us about the representation of the population data.
! [todo] - As such, the separation is not entrely helpful.  It would make more sense encoded with the
! [todo] - data itself -  it makes no sense without the data, and the data make no sense without it.
! [todo] - Convert to a derived type.  (From AJWT.)
!
! [todo] - The code currently uses c = real(a)/real_factor everywhere.  However, one of 
! [todo] - the joys of fixed precision arithmetic is that c=(a*b)>>real_bit_shift.
! [todo] - is (or used to be) a lot faster than c=(real(a)/real_factor)*(real(b)/real_factor)
! [todo] - It is however a little more obfuscated though, but carrying fixed-precision all the
! [todo] - through the code might give a benefit.  Of course the best implementation would
! [todo] - be to hide the details in a class.  (From AJWT.)
!
! [todo] - real_bit_shift and real_factor really should be compile-time constants.
! Real amplitudes can be any multiple of 2**(-real_bit_shift). They are
! encoded as integers by multiplying them by 2**(real_bit_shift).
integer :: real_bit_shift
! real_factor = 2**(real_bit_shift)
integer(int_p) :: real_factor

!--- Walker data ---

! Rate of spawning.  This is a running total over MC cycles on each processor
! until it is summed over processors and averaged over cycles in
! update_energy_estimators.
real(p) :: rspawn

! In DMQMC the trace of the density matrix is an important quantity
! used in calculating all thermal estimators. This quantity stores
! the this value, Tr(\rho), where rho is the density matrix which
! the DMQMC algorithm calculates stochastically.
real(p), allocatable :: trace(:) ! (walker_global%nspaces)

! The following indicies are used to access components of DMQMC numerators.
enum, bind(c)
    enumerator :: energy_ind = 1
    enumerator :: energy_squared_ind
    enumerator :: correlation_fn_ind
    enumerator :: staggered_mag_ind
    enumerator :: full_r2_ind
    enumerator :: terminator ! unused except in num_dmqmc_operators
   ! NOTE: if you add a new estimator then you must insert it before terminator.
end enum

! This variable holds the total number of operators which are implemented
! for DMQMC.
integer, parameter :: num_dmqmc_operators = terminator - 1

! numerators stores the numerators for the estimators in DMQMC. These
! are, for a general operator O which we wish to find the thermal average of:
! \sum_{i,j} \rho_{ij} * O_{ji}
! This variabe will store this value from the first iteration of each
! report loop. At the end of a report loop, the values from each
! processor are combined and stored in numerators on the parent
! processor. This is then output, and the values of numerators
! are reset on each processor to start the next report loop.
real(p) :: numerators(num_dmqmc_operators)

! If this logical is true then the program runs the DMQMC algorithm with
! importance sampling.
! dmqmc_sampling_prob stores the factors by which the probabilities of
! spawning to a larger excitation are reduced by. So, when spawning from
! a diagonal element to a element with one excitation, the probability
! of spawning is reduced by a factor sampling_probs(1).
! accumulated_probs(i) stores the multiplication of all the elements
! of sampling_probs up to the ith element. This quantity is often
! needed, so it is stored.
real(p), allocatable :: accumulated_probs(:) ! (min(nel, nsites-nel) + 1)
real(p), allocatable :: accumulated_probs_old(:) ! (min(nel, nsites-nel) + 1)

real(dp), allocatable :: weight_altering_factors(:)

! Calculate replicas (ie evolve two wavefunctions/density matrices at once)?
! Currently only implemented for DMQMC.
logical :: replica_tricks = .false.

real(p), allocatable :: excit_dist(:) ! (0:max_number_excitations)

! The unit of the file reduced_dm.
integer :: rdm_unit

! When using the Neel singlet trial wavefunction, it is convenient
! to store all possible amplitudes in the wavefunction, since
! there are relativley few of them and they are expensive to calculate
real(dp), allocatable :: neel_singlet_amp(:) ! (nsites/2) + 1

!--- Restart data ---

! Restart data.
integer :: mc_cycles_done = 0

! Type for storing parallel information: see calc for description.
type(parallel_t) :: par_info

contains

    !--- Statistics. ---

    function spawning_rate(nspawn_events, ndeath, nattempts) result(rate)
<commit_msg>Remove global accumulated_probs arrays from fciqmc_data.<commit_after>module fciqmc_data

! Data for fciqmc calculations and procedures which manipulate fciqmc and only
! fciqmc data.

use const
use csr, only: csrp_t
use spawn_data, only: spawn_t
use hash_table, only: hash_table_t
use calc, only: parallel_t
use parallel, only: parallel_timing_t
implicit none

!--- Input data: FCIQMC ---

! [todo] - It is somewhat inelegant to store/pass around real_factor or real_bit_shift separately,
! [todo] - when really they are variables telling us about the representation of the population data.
! [todo] - As such, the separation is not entrely helpful.  It would make more sense encoded with the
! [todo] - data itself -  it makes no sense without the data, and the data make no sense without it.
! [todo] - Convert to a derived type.  (From AJWT.)
!
! [todo] - The code currently uses c = real(a)/real_factor everywhere.  However, one of 
! [todo] - the joys of fixed precision arithmetic is that c=(a*b)>>real_bit_shift.
! [todo] - is (or used to be) a lot faster than c=(real(a)/real_factor)*(real(b)/real_factor)
! [todo] - It is however a little more obfuscated though, but carrying fixed-precision all the
! [todo] - through the code might give a benefit.  Of course the best implementation would
! [todo] - be to hide the details in a class.  (From AJWT.)
!
! [todo] - real_bit_shift and real_factor really should be compile-time constants.
! Real amplitudes can be any multiple of 2**(-real_bit_shift). They are
! encoded as integers by multiplying them by 2**(real_bit_shift).
integer :: real_bit_shift
! real_factor = 2**(real_bit_shift)
integer(int_p) :: real_factor

!--- Walker data ---

! Rate of spawning.  This is a running total over MC cycles on each processor
! until it is summed over processors and averaged over cycles in
! update_energy_estimators.
real(p) :: rspawn

! In DMQMC the trace of the density matrix is an important quantity
! used in calculating all thermal estimators. This quantity stores
! the this value, Tr(\rho), where rho is the density matrix which
! the DMQMC algorithm calculates stochastically.
real(p), allocatable :: trace(:) ! (walker_global%nspaces)

! The following indicies are used to access components of DMQMC numerators.
enum, bind(c)
    enumerator :: energy_ind = 1
    enumerator :: energy_squared_ind
    enumerator :: correlation_fn_ind
    enumerator :: staggered_mag_ind
    enumerator :: full_r2_ind
    enumerator :: terminator ! unused except in num_dmqmc_operators
   ! NOTE: if you add a new estimator then you must insert it before terminator.
end enum

! This variable holds the total number of operators which are implemented
! for DMQMC.
integer, parameter :: num_dmqmc_operators = terminator - 1

! numerators stores the numerators for the estimators in DMQMC. These
! are, for a general operator O which we wish to find the thermal average of:
! \sum_{i,j} \rho_{ij} * O_{ji}
! This variabe will store this value from the first iteration of each
! report loop. At the end of a report loop, the values from each
! processor are combined and stored in numerators on the parent
! processor. This is then output, and the values of numerators
! are reset on each processor to start the next report loop.
real(p) :: numerators(num_dmqmc_operators)

real(dp), allocatable :: weight_altering_factors(:)

! Calculate replicas (ie evolve two wavefunctions/density matrices at once)?
! Currently only implemented for DMQMC.
logical :: replica_tricks = .false.

real(p), allocatable :: excit_dist(:) ! (0:max_number_excitations)

! The unit of the file reduced_dm.
integer :: rdm_unit

! When using the Neel singlet trial wavefunction, it is convenient
! to store all possible amplitudes in the wavefunction, since
! there are relativley few of them and they are expensive to calculate
real(dp), allocatable :: neel_singlet_amp(:) ! (nsites/2) + 1

!--- Restart data ---

! Restart data.
integer :: mc_cycles_done = 0

! Type for storing parallel information: see calc for description.
type(parallel_t) :: par_info

contains

    !--- Statistics. ---

    function spawning_rate(nspawn_events, ndeath, nattempts) result(rate)

{'fraction_non_alphanumeric': 0.08034624348019087, 'fraction_numerical': 0.0025524359116635225, 'mean_word_length': 4.3931777378815084, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1160137', 'n_tokens_mistral': 2725, 'n_tokens_neox': 2633, 'n_words': 1156}