1
0
mirror of https://gitlab.com/scemama/qp_plugins_scemama.git synced 2024-11-07 14:43:41 +01:00

Merge branch 'master' of gitlab.com:scemama/qp_plugins_scemama

This commit is contained in:
Anthony Scemama 2023-05-04 14:32:04 +02:00
commit 77600429a3
61 changed files with 10398 additions and 240 deletions

View File

@ -1,7 +1,7 @@
[dmc_delta_h] [dmc_delta_h]
type: double precision type: double precision
doc: Dressing matrix obtained from DMC doc: Dressing matrix obtained from DMC
size: (determinants.n_det) size: (determinants.n_det,determinants.n_states)
interface: ezfio, provider interface: ezfio, provider
[dmc_delta_htc] [dmc_delta_htc]
@ -10,3 +10,39 @@ doc: Dressing matrix obtained from H_TC
size: (determinants.n_det) size: (determinants.n_det)
interface: ezfio interface: ezfio
[la]
interface: ezfio
doc: min rows nb of delta in SVD basis
type: integer
default: 0
[lb]
interface: ezfio
doc: min cols nb of delta in SVD basis
type: integer
default: 0
[ld]
interface: ezfio
doc: min diag elements of delta in SVD basis
type: integer
default: 0
[lla]
interface: ezfio
doc: max rows nb of delta in SVD basis
type: integer
default: 0
[llb]
interface: ezfio
doc: max cols nb of delta in SVD basis
type: integer
default: 0
[lld]
interface: ezfio
doc: max diag elements of delta in SVD basis
type: integer
default: 0

View File

@ -0,0 +1,36 @@
program dmc_dress_1state
implicit none
BEGIN_DOC
! Program that extracts the lowest states of the Hamiltonian dressed by the QMC
! dressing vector stored in :option:`dmc_dressing dmc_delta_h`
!
END_DOC
read_wf = .True.
touch read_wf
! call pre
call routine
call save_wavefunction_general(N_det,N_states,psi_det_sorted,size(psi_coef_sorted,1),psi_coef_sorted)
end
subroutine pre
implicit none
double precision, allocatable :: left(:,:), right(:,:), tmp(:,:), res(:,:)
integer :: i
allocate (left(1,1:N_det), right(1:N_det,1), tmp(1:N_det,1), res(1,1))
left(1,1:N_det) = psi_coef(1:N_det,1)
right(1:N_det,1) = psi_coef(1:N_det,1)
tmp(1:N_det,1:1) = matmul(h_matrix_dressed(1:N_det,1:N_det), right(1:N_det,1:1))
res(1:1,1:1) = matmul(left(1:1,1:N_det), tmp(1:N_det,1:1))
print *, 'E_in = ', res(1,1)
do i=1,N_det
print *, 'HPsi/c0 = ', tmp(i,1)/psi_coef(i,1)
enddo
end
subroutine routine
implicit none
psi_coef(1:N_det,1) = ci_eigenvectors_dressed(1:N_det,1)
print*,'N_det = ',N_det
print *, 'E = ', ci_energy_dressed(1) + nuclear_repulsion
SOFT_TOUCH psi_coef
end

View File

@ -0,0 +1,37 @@
program dmc_dress_multistate
BEGIN_DOC
! Program that extracts the lowest states of the Hamiltonian dressed by the QMC
! dressing vector stored in :option:`dmc_dressing dmc_delta_h`
!
END_DOC
implicit none
read_wf = .True.
touch read_wf
call routine()
call save_wavefunction_general(N_det, N_states, psi_det_sorted, size(psi_coef_sorted, 1), psi_coef_sorted)
end
! ---
subroutine routine
implicit none
integer :: k
do k = 1, N_states
print *, ' state:', k
psi_coef(1:N_det,k) = ci_eigenvectors_nonsym_dressed(1:N_det,k)
print *, 'E = ', ci_energy_nonsym_dressed(k) + nuclear_repulsion
enddo
SOFT_TOUCH psi_coef
end
! ---

182
devel/dmc_dress/dress_SVD.py Executable file
View File

@ -0,0 +1,182 @@
#!/usr/bin/env python
import numpy as np
import subprocess
import sys, os
import time
from datetime import datetime
QP_PATH=os.environ["QP_ROOT"]+"/external/ezfio/Python/"
sys.path.insert(0,QP_PATH)
from ezfio import ezfio
#____________________________________________________________________________________
#
def get_energy():
energy_buffer = subprocess.check_output(
['qmcchem', 'result', '-e', 'e_loc', EZFIO_file]
, encoding='UTF-8')
if energy_buffer.strip() != "":
energy_buffer = energy_buffer.splitlines()[-1]
_, energy, error = [float(x) for x in energy_buffer.split()]
return energy, error
else:
return None, None
#____________________________________________________________________________________
#____________________________________________________________________________________
#
def read_scalar(scalar):
scal_txt = scalar + ' : '
beg_read = results.find(scal_txt) + len(scal_txt)
scal_buf = results[beg_read:beg_read+100].split('\n')[0].split()
scal_val , scal_err = float( scal_buf[0] ) , float( scal_buf[2] )
return(scal_val,scal_err)
#____________________________________________________________________________________
#____________________________________________________________________________________
#
def read_ci_dress_svd():
Ci_dress_svd_val = np.zeros((n_svd))
Ci_dress_svd_err = np.zeros((n_svd))
beg_read = results.find('Ci_dress_svd : [ ') + len( 'Ci_dress_svd : [ ' )
end_read = len(results)
vect_buf = results[beg_read:end_read]
vect_buf = vect_buf.split( '\n' )
for iline in range(1, n_svd+1):
line = vect_buf[iline].split()
# check
indc = int( line[0] )
if( indc != iline ):
print(' Error in reading Ci_dress_svd')
print(' indc = {}'.format(indc) )
print(' iline = {}'.format(iline) )
break
else:
Ci_dress_svd_val[indc-1] = float( line[2] )
Ci_dress_svd_err[indc-1] = float( line[4] )
# !!!
# !!!
# !!!
return(Ci_dress_svd_val,Ci_dress_svd_err)
#____________________________________________________________________________________
#____________________________________________________________________________________
#
def get_ci_dress():
U_svd = np.array(ezfio.get_spindeterminants_psi_svd_alpha())
V_svd = np.array(ezfio.get_spindeterminants_psi_svd_beta())
U_svd = U_svd[0,:,:].T
V_svd = V_svd[0,:,:].T
ci_dress_mat_val = np.dot(U_svd,np.dot(np.diagflat(Ci_dress_svd_val),V_svd.T))
ci_dress_mat_err = np.dot(U_svd,np.dot(np.diagflat(Ci_dress_svd_err),V_svd.T))
n_det = ezfio.get_spindeterminants_n_det()
i_row = np.array(ezfio.get_spindeterminants_psi_coef_matrix_rows())
j_col = np.array(ezfio.get_spindeterminants_psi_coef_matrix_columns())
Ci_dress_val = np.zeros((n_det))
Ci_dress_err = np.zeros((n_det))
for k in range(n_det):
i = i_row[k] - 1
j = j_col[k] - 1
Ci_dress_val[k] = ci_dress_mat_val[i,j]
Ci_dress_err[k] = ci_dress_mat_err[i,j]
Ci_dress_val = Ci_dress_val / psi_norm
Ci_dress_err = Ci_dress_err / psi_norm
return(Ci_dress_val,Ci_dress_err)
#____________________________________________________________________________________
#____________________________________________________________________________________
#
def save_to_file(v_val,v_err, name_f):
with open(name_f, 'w') as ff:
for i in range(len(v_val)):
ff.write(' {} {} {}\n'.format(i, v_val[i], v_err[i]))
#____________________________________________________________________________________
if __name__ == '__main__':
t0 = time.time()
# _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
#
#EZFIO_file = sys.argv[1]
#EZFIO_file = "/home/aammar/qp2/src/svdwf/cr2_work/cr2_1p6_dress"
EZFIO_file = "/home/aammar/qp2/src/svdwf/cr2_work/cr2_1p6_dress_0"
# _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ezfio.set_file(EZFIO_file)
n_svd = ezfio.get_spindeterminants_n_svd_coefs()
print(" ")
print(" Today's date:", datetime.now() )
print(" EZFIO file = {}".format(EZFIO_file))
print(" n_svd = {}\n".format(n_svd) )
t_read = time.time()
print(' getting QMCCHEM results from {}'.format(EZFIO_file) )
results = subprocess.check_output(['qmcchem', 'result', EZFIO_file], encoding='UTF-8')
print(' getting results after {} minutes \n'.format( (time.time()-t_read)/60. ))
# read QMC results
E_loc, ErrE_loc = get_energy()
print(' E_loc = {} +/- {}'.format(E_loc, ErrE_loc))
print(' {} <= E_loc <= {}\n'.format(E_loc-ErrE_loc,E_loc+ErrE_loc))
E_loc_qmcvar, ErrE_loc_qmcvar = read_scalar('E_loc_qmcvar')
print(' E_loc_qmcvar = {} +/- {} \n'.format(E_loc_qmcvar,ErrE_loc_qmcvar))
psi_norm, Errpsi_norm = read_scalar('Psi_norm')
print(' psi_norm = {} +/- {}\n'.format(psi_norm,Errpsi_norm))
psi_norm_qmcvar, Errpsi_norm_qmcvar = read_scalar('Psi_norm_qmcvar')
print(' Psi_norm_qmcvar = {} +/- {} \n'.format(psi_norm_qmcvar, Errpsi_norm_qmcvar))
Ci_dress_svd_val, Ci_dress_svd_err = read_ci_dress_svd()
save_to_file(Ci_dress_svd_val,Ci_dress_svd_err, 'ci_dress_svd.txt')
Ci_dress_val, Ci_dress_err = get_ci_dress()
save_to_file(Ci_dress_val,Ci_dress_err, 'ci_dress.txt')
# _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
#
# SAVE TO EZFIO
#
#ezfio.set_dmc_dress_dmc_delta_h(Ci_dress_val)
# _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
#
print("end after {:.3f} minutes".format((time.time()-t0)/60.) )
# !!!
# !!!

View File

@ -1,35 +1,78 @@
! ---
BEGIN_PROVIDER [ double precision, dressing_column_h, (N_det,N_states) ] BEGIN_PROVIDER [ double precision, dressing_column_h, (N_det,N_states) ]
&BEGIN_PROVIDER [ double precision, dressing_column_s, (N_det,N_states) ] &BEGIN_PROVIDER [ double precision, dressing_column_s, (N_det,N_states) ]
implicit none
BEGIN_DOC
! \Delta_{state-specific}. \Psi
! Diagonal element is divided by 2 because Delta = D + D^t
END_DOC
integer :: i,ii,k,j, l BEGIN_DOC
double precision :: f, tmp ! \Delta_{state-specific}. \Psi
double precision, allocatable :: delta(:) ! Diagonal element is divided by 2 because Delta = D + D^t
END_DOC
allocate(delta(N_det)) implicit none
delta (1:N_det) = dmc_delta_h(1:N_det) + dmc_delta_htc(1:N_det) integer :: i,ii,k,j, l
double precision :: f, tmp
double precision, allocatable :: delta(:)
call dset_order(delta,psi_bilinear_matrix_order_reverse,N_det) allocate(delta(N_det))
delta(1:N_det) = dmc_delta_h(1:N_det,1)
dressing_column_h(:,:) = 0.d0 call dset_order(delta,psi_bilinear_matrix_order_reverse,N_det)
dressing_column_s(:,:) = 0.d0
l = dressed_column_idx(1) dressing_column_h(:,:) = 0.d0
do j = 1, n_det dressing_column_s(:,:) = 0.d0
if (j == l) cycle
dressing_column_h(j,1) = delta(j) l = dressed_column_idx(1)
dressing_column_h(l,1) -= psi_coef(j,1) * delta(j) / psi_coef(l,1) do j = 1, n_det
enddo if(j == l) cycle
dressing_column_h(l,1) += delta(l) dressing_column_h(j,1) = delta(j)
dressing_column_h(l,1) *= 0.5d0 dressing_column_h(l,1) -= psi_coef(j,1) * delta(j) / psi_coef(l,1)
enddo
dressing_column_h(l,1) += delta(l)
dressing_column_h(l,1) *= 0.5d0
deallocate(delta)
END_PROVIDER END_PROVIDER
! ---
BEGIN_PROVIDER [ double precision, dressing_delta, (N_det, N_states) ]
BEGIN_DOC
!
! dressing_delta is:
! [\delta_K]_I = < I | \tilde{H} - H | \Phi_K >
!
END_DOC
implicit none
integer :: i, j, k
double precision, allocatable :: delta(:,:)
dressing_delta(1:N_det,1:N_states) = 0.d0
allocate(delta(N_det,N_states))
do k = 1, N_states
do j = 1, N_det
delta(j,k) = dmc_delta_h(j,k)
enddo
call dset_order(delta(1:N_det,k), psi_bilinear_matrix_order_reverse, N_det)
do j = 1, N_det
dressing_delta(j,k) = delta(j,k)
enddo
enddo
deallocate(delta)
END_PROVIDER
! ---
BEGIN_PROVIDER [ double precision, dmc_delta_htc , (n_det) ] BEGIN_PROVIDER [ double precision, dmc_delta_htc , (n_det) ]
implicit none implicit none

View File

@ -45,3 +45,4 @@ program save_for_qmc
call export_trexio call export_trexio
end end
! ---

View File

@ -0,0 +1,361 @@
#!/usr/bin/env python
from ezfio import ezfio
import numpy as np
import sys
import time
from datetime import datetime
import matplotlib.pyplot as plt
#import seaborn as sns
from matplotlib.colors import LogNorm
# ____________________________________________________________________________________________
#
def read_AO_2eCoulomb():
lines = []
with open(ao_file) as f_in:
for line in f_in:
lines.append( float(line) )
J = np.zeros((ao_num2,ao_num2))
i_l = 0
for mu in range(ao_num):
for nu in range(ao_num):
ii = nu + ao_num * mu
for sig in range(ao_num):
for lam in range(ao_num):
jj = lam + ao_num * sig
J[ii,jj] = lines[i_l]
i_l += 1
return(J)
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
#
def read_H_det():
H_det = np.zeros((n_det_alpha*n_det_beta,n_det_alpha*n_det_beta))
with open("fort.7000") as f_in:
for line in f_in:
ll = line.split()
i = int( ll[0] ) - 1
j = int( ll[1] ) - 1
ii = j + n_det_beta * i
k = int( ll[2] ) - 1
l = int( ll[3] ) - 1
jj = l + n_det_beta * k
H_det[ii,jj] = float(ll[4])
return(H_det)
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
#
def read_T():
lines = []
with open("ij_T_kl.dat") as f_in:
for line in f_in:
lines.append( float(line) )
T = np.zeros( (n_det_alpha*n_det_beta,n_det_alpha*n_det_beta) )
i_l = 0
for i in range(n_det_alpha):
for j in range(n_det_beta):
ii = j + n_det_beta * i
for k in range(n_det_alpha):
for l in range(n_det_beta):
jj = l + n_det_beta * k
T[ii,jj] = lines[i_l]
i_l += 1
return(T)
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
#
def check_symmetric(a, rtol=1e-05, atol=1e-08):
return( np.allclose(a, a.T, rtol=rtol, atol=atol) )
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
#
def plot_mat(M, xstep, ystep, namefile):
Mp = np.abs(M) + 1e-15
ax = sns.heatmap(Mp, linewidths=0.0, rasterized=True, norm=LogNorm())
# x axis
ax.xaxis.tick_top()
xgrid = np.arange(1, M.shape[1]+1, xstep-1)
plt.xticks( np.arange(0, M.shape[1], xstep-1) + .5, xgrid )
# y axis
ygrid = np.arange(1, M.shape[0]+1, ystep-1)
plt.yticks( np.arange(0, M.shape[0], ystep-1) + .5, ygrid )
plt.savefig(namefile)
plt.clf()
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
#
def incomplete_Cholesky(M, ma, mb, theta_CD):
D = np.zeros((ma,mb))
for lam in range(ma):
for sig in range(mb):
ii = sig + mb * lam
D[sig,lam] = M[ii,ii]
# find the maximum
val_max = np.amax(D)
ind_max = np.where(D == val_max)
sig_max = ind_max[0][0]
lam_max = ind_max[1][0]
ii_max = sig_max + mb * lam_max
#print( sig_max, lam_max, D[sig_max,lam_max], val_max )
# define the initial resudual
mab = ma * mb
R = np.zeros((mab))
R[:] = M[:,ii_max]
m = 0
L = np.zeros((mab))
List_vec = []
while(val_max>theta_CD):
if(m>0):
# update the residual
for ii in range(mab):
sumii = 0
for i in range(m):
sumii += List_vec[i][ii] * List_vec[i][ii_max]
R[ii] = M[ii,ii_max] - sumii
# compute Cholesky vector
L = R / np.sqrt(val_max)
List_vec.append(L)
# update diagonals
for lam in range(ma):
for sig in range(mb):
ii = sig + mb * lam
D[sig,lam] = D[sig,lam] - L[ii]*L[ii]
m += 1
# find the new maximum
val_max = np.amax(D)
ind_max = np.where(D == val_max)
sig_max = ind_max[0][0]
lam_max = ind_max[1][0]
ii_max = sig_max + mb * lam_max
return(m, List_vec)
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
#
def err_p_estim(M, List_vec):
mM = M.shape[0]
mL = len(List_vec)
normM = np.linalg.norm(M)
L_CD = np.zeros((mM,mL))
for i in range(mL):
L_CD[:,i] = List_vec[i]
print(" size of L_CD: {} MB\n".format( sys.getsizeof(L_CD) / 1024. ) )
err_p = 100. * np.linalg.norm( M - np.dot(L_CD, L_CD.T) ) / normM
return( L_CD, err_p , normM)
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
#
def save_L_CD(List_vec, file_List):
with open(file_List, 'w') as the_file:
for i in range(List_vec.shape[0]):
for j in range(List_vec.shape[1]):
ff.write(" {:+e} \n".format(List_vec[i,j]))
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________________________________________________
# ____________________________________________________________________________________________________________________________________
#
if __name__=="__main__":
t_beg = time.time()
print("")
print(" date and time = {} \n".format(datetime.now().strftime("%d/%m/%Y %H:%M:%S")))
EZFIO_name = "/home/aammar/qp2/src/svdwf/f2_work/f2_fci"
ezfio.set_file(EZFIO_name)
# ------------------------------------------------------------------------------------------------------
# 2-e integrals in AO basis
# ------------------------------------------------------------------------------------------------------
ao_num = ezfio.get_ao_basis_ao_num()
ao_num2 = ao_num * ao_num
print(" nb of AO = {} \n".format(ao_num))
ao_file = "/home/aammar/qp2/src/svdwf/f2_work/ao_2eCoulombIntegrals.txt"
J = read_AO_2eCoulomb()
print(" size of J: {} MB ".format( sys.getsizeof(J) / 1024. ) )
print(" J is symmetric ? {} ".format(check_symmetric(J)) )
#plot_mat(J, ao_num, ao_num, 'J.pdf')
# pivoted incomplete Cholesky decomposition
theta_CD_J = 1e-02
m_J, List_vec_J = incomplete_Cholesky(J, ao_num, ao_num, theta_CD_J)
print(" nb of L_CD vectors = {} for theta = {}".format(m_J,theta_CD_J))
# check error
L_CD_J, err_p_J, normJ = err_p_estim(J, List_vec_J)
print(" norm of J = {} \n".format(normJ))
print(" error estimation on J = {} % \n".format(err_p_J))
save_L_CD(L_CD_J, 'L_CD_J.txt')
#plot_mat(L_CD_J, 2, ao_num, 'L_CD_J.pdf')
# ------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------
print('\n \n \n')
# ------------------------------------------------------------------------------------------------------
# < d_i d_j | T | d_k d_l >
# ------------------------------------------------------------------------------------------------------
# n_det_alpha = ezfio.get_spindeterminants_n_det_alpha()
# n_det_beta = ezfio.get_spindeterminants_n_det_beta ()
# n_ab = n_det_alpha * n_det_beta
# print(" n_det_alpha = {} ".format(n_det_alpha))
# print(" n_det_beta = {} \n".format(n_det_beta ))
#
# T = read_T()
# print(" T is symmetric ? {} \n".format(check_symmetric(T)) )
#
# plot_mat(T, 50, 50, 'T.pdf')
#
#
# # pivoted incomplete Cholesky decomposition
# theta_CD_T = 1.5
# m_T, List_vec_T = incomplete_Cholesky(T, n_det_alpha, n_det_beta, theta_CD_T)
# print(" nb of L_CD vectors = {} for theta = {}".format(m_T,theta_CD_T))
#
# # check error
# L_CD_T, err_p_T, normT = err_p_estim(T, List_vec_T)
# print(" norm of T = {} ".format(normT))
# print(" error estimation on T = {} % \n".format(err_p_T))
#
# plot_mat(L_CD_T, 2, n_det_beta, 'L_CD_T.pdf')
# ------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------
print('\n \n \n')
# ------------------------------------------------------------------------------------------------------
# < d_i d_j | H | d_k d_l >
#
# WARNING: this isn't semipositive definite
# ------------------------------------------------------------------------------------------------------
#
# # get H_det
# n_det_alpha = ezfio.get_spindeterminants_n_det_alpha()
# n_det_beta = ezfio.get_spindeterminants_n_det_beta ()
# n_ab = n_det_alpha * n_det_beta
# print(" n_det_alpha = {} ".format(n_det_alpha))
# print(" n_det_beta = {} \n".format(n_det_beta ))
#
# H_det = read_H_det()
# print(" size of H_det: {} MB ".format( sys.getsizeof(H_det) / 1024. ) )
# print(" H_det is symmetric ? {} \n".format(check_symmetric(H_det)) )
#
# # plot H_det
# H_det = H_det + 1e-15
# plot_mat(H_det, 50, 50, 'H_det.pdf')
#
#
# # pivoted incomplete Cholesky decomposition
# theta_CD_H_det = 1e-02
# m_H_det, List_vec_H_det = incomplete_Cholesky(H_det, n_det_alpha, n_det_beta, theta_CD_H_det)
# print(" nb of L_CD_H_det vectors = {} for a precision of {}".format(m_H_det,theta_CD_H_det))
# #print(" size of L_CD_H_det: {} MB\n".format( sys.getsizeof(List_vec_H_det) / 1024. ) )
#
# # check error
# L_CD_H_det, err_p_H_det, normH_det = err_p_estim(H_det, List_vec_H_det)
# print(" norm of H_det = {} \n".format(normH_det))
# print(" error estimation on H_det = {} % \n".format(err_p_H_det))
#
# plot_mat(L_CD_H_det, 2, n_det_beta, 'L_CD_H_det.pdf')
# ------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------
print('\n\n')
t_end = time.time()
print(' end after {} min'.format((t_end-t_beg)/60.))
# ____________________________________________________________________________________________________________________________________
# ____________________________________________________________________________________________________________________________________
# ____________________________________________________________________________________________________________________________________

View File

@ -1,14 +1,18 @@
program FSVD_trunc program FSVD_trunc
implicit none
BEGIN_DOC BEGIN_DOC
! study precision variation with truncated SVD ! perform a Full SVD
! then truncate if you want
END_DOC END_DOC
implicit none
read_wf = .True. read_wf = .True.
TOUCH read_wf TOUCH read_wf
! !!!
call run() call run()
! !!!
end end
@ -18,9 +22,16 @@ subroutine run
integer :: mm, nn, i_state, low_rank, lrank_min, lrank_max integer :: mm, nn, i_state, low_rank, lrank_min, lrank_max
integer :: i, j, k, l integer :: i, j, k, l
double precision :: norm_psi, err_verif, err_tmp double precision :: norm_psi, err_verif, err_tmp
double precision, allocatable :: U_FSVD(:,:), D_FSVD(:), Vt_FSVD(:,:), A_FSVD(:,:) double precision, allocatable :: U_FSVD(:,:), D_FSVD(:), Vt_FSVD(:,:), A_FSVD(:,:)
double precision, allocatable :: Uezfio(:,:,:), Dezfio(:,:), Vezfio(:,:,:) double precision, allocatable :: Uezfio(:,:,:), Dezfio(:,:), Vezfio(:,:,:)
double precision, allocatable :: US(:,:), A_TSVD(:,:)
double precision :: t0, t1, t2
call CPU_TIME(t0)
i_state = 1 i_state = 1
mm = n_det_alpha_unique mm = n_det_alpha_unique
@ -42,28 +53,68 @@ subroutine run
call svd_s( A_FSVD, size(A_FSVD,1), U_FSVD, size(U_FSVD,1), D_FSVD, Vt_FSVD, size(Vt_FSVD,1), mm, nn) call svd_s( A_FSVD, size(A_FSVD,1), U_FSVD, size(U_FSVD,1), D_FSVD, Vt_FSVD, size(Vt_FSVD,1), mm, nn)
print *, ' --- Full SVD: ok --- ' print *, ' --- Full SVD: ok --- '
call CPU_TIME(t1)
print *, (t1-t0)/60.d0, 'min'
!lrank_min = 100
!lrank_max = nn
!do low_rank = lrank_min, lrank_max, 1
! err_verif = 0.d0
! do j = 1, nn
! do i = 1, mm
! err_tmp = 0.d0
! do l = 1, low_rank
! err_tmp = err_tmp + D_FSVD(l) * U_FSVD(i,l) * Vt_FSVD(l,j)
! enddo
! err_verif = err_verif + (A_FSVD(i,j)-err_tmp) * (A_FSVD(i,j)-err_tmp)
! enddo
! enddo
! print*, ' low rank = ', low_rank
! print*, ' err verif (%) = ', 100.d0 * dsqrt(err_verif/norm_psi)
!enddo
! ------------------------------------------------------------------------------------------------ ! ----------------------------------------------------------------------
! set to EZFIO for a fixed low rank ! check error
! ----------------------------------------------------------------------
low_rank = min(mm,nn) low_rank = min(mm,nn)
!low_rank = 45
!low_rank = 30
!low_rank = 15
! CO_old
!low_rank = 51
!low_rank = 144
! CO_old
!low_rank = 133
!low_rank = 36
!low_rank = 18
!low_rank = 9
!low_rank = 1
! US = U x SV :
allocate( US(mm,low_rank) )
US(:,:) = 0.d0
do i = 1, mm
do l = 1, low_rank
US(i,l) = U_FSVD(i,l) * D_FSVD(l)
enddo
enddo
! A_TSVD = US x Vt_FSVD
allocate( A_TSVD(mm,nn) )
A_TSVD(:,:) = 0.d0
call dgemm( 'N', 'N', mm, nn, low_rank, 1.d0 &
, US , size(US ,1) &
, Vt_FSVD, size(Vt_FSVD,1) &
, 0.d0, A_TSVD, size(A_TSVD,1) )
deallocatE(US)
! |A_FSVD-A_TSVD|
err_verif = 0.d0
do j = 1, nn
do i = 1, mm
err_tmp = A_FSVD(i,j) - A_TSVD(i,j)
err_verif = err_verif + err_tmp * err_tmp
enddo
enddo
print*, ' rank = ', low_rank
print*, ' err verif (%) = ', 100.d0 * dsqrt(err_verif/norm_psi)
deallocate( A_FSVD , A_TSVD )
! ----------------------------------------------------------------------
! ----------------------------------------------------------------------
! set to EZFIO for a fixed low rank
! ----------------------------------------------------------------------
allocate( Uezfio(mm,low_rank,1), Dezfio(low_rank,1), Vezfio(nn,low_rank,1)) allocate( Uezfio(mm,low_rank,1), Dezfio(low_rank,1), Vezfio(nn,low_rank,1))
do l = 1, low_rank do l = 1, low_rank
@ -76,22 +127,27 @@ subroutine run
enddo enddo
enddo enddo
!call ezfio_set_spindeterminants_n_det(N_det) deallocate( U_FSVD, D_FSVD, Vt_FSVD )
!call ezfio_set_spindeterminants_n_states(N_states)
!call ezfio_set_spindeterminants_n_det_alpha(n_det_alpha_unique) call ezfio_set_spindeterminants_n_det(N_det)
!call ezfio_set_spindeterminants_n_det_beta(n_det_beta_unique) call ezfio_set_spindeterminants_n_states(N_states)
!call ezfio_set_spindeterminants_psi_coef_matrix_rows(psi_bilinear_matrix_rows) call ezfio_set_spindeterminants_n_det_alpha(n_det_alpha_unique)
!call ezfio_set_spindeterminants_psi_coef_matrix_columns(psi_bilinear_matrix_columns) call ezfio_set_spindeterminants_n_det_beta(n_det_beta_unique)
!call ezfio_set_spindeterminants_psi_coef_matrix_values(psi_bilinear_matrix_values) call ezfio_set_spindeterminants_psi_coef_matrix_rows(psi_bilinear_matrix_rows)
call ezfio_set_spindeterminants_psi_coef_matrix_columns(psi_bilinear_matrix_columns)
call ezfio_set_spindeterminants_psi_coef_matrix_values(psi_bilinear_matrix_values)
call ezfio_set_spindeterminants_n_svd_coefs(low_rank) call ezfio_set_spindeterminants_n_svd_coefs(low_rank)
call ezfio_set_spindeterminants_psi_svd_alpha(Uezfio) call ezfio_set_spindeterminants_psi_svd_alpha(Uezfio)
call ezfio_set_spindeterminants_psi_svd_beta(Vezfio ) call ezfio_set_spindeterminants_psi_svd_beta(Vezfio )
call ezfio_set_spindeterminants_psi_svd_coefs(Dezfio) call ezfio_set_spindeterminants_psi_svd_coefs(Dezfio)
! ------------------------------------------------------------------------------------------------
deallocate( Uezfio, Dezfio, Vezfio ) deallocate( Uezfio, Dezfio, Vezfio )
deallocate( U_FSVD, D_FSVD, Vt_FSVD ) ! ----------------------------------------------------------------------
call CPU_TIME(t2)
print *, ''
print *, ' end after'
print *, (t2-t0)/60.d0, 'min'
end end

View File

@ -0,0 +1,311 @@
program RSVD_ijHkl_det
BEGIN_DOC
!
! decompose < di dj | H | dk dl > by a RSVD:
!
! H_{ik jl} = < di dj | H | dk dl >
! = \sum_{s=1}^{n_svd} U_{ik s} V_{jl s}
! = \sum_{s=1}^{n_svd} U_{ik s} U_{jl s}
!
! where n_svd << min( NaxNa , NbxNb )
!
END_DOC
read_wf = .true.
TOUCH read_wf
call run()
end
subroutine run()
implicit none
integer(bit_kind) :: det1(N_int,2), det2(N_int,2)
integer :: degree, i_state
double precision :: h12
integer*8 :: dim_Hdet
integer*8, allocatable :: Hdet_ik(:), Hdet_jl(:)
double precision, allocatable :: Hdet_v(:)
integer :: dim_U , dim_V, dim_RSVD
double precision :: t_beg, t_end
call wall_time(t_beg)
i_state = 1
det1(:,1) = psi_det_alpha_unique(:,1)
det2(:,1) = psi_det_alpha_unique(:,1)
det1(:,2) = psi_det_beta_unique(:,1)
det2(:,2) = psi_det_beta_unique(:,1)
call get_excitation_degree_spin(det1(1,1),det2(1,1),degree,N_int)
call get_excitation_degree(det1,det2,degree,N_int)
call i_H_j(det1, det2, N_int, h12)
! sparse representation of < di dj | H | dk dl >
!dim_Hdet = 7486379362
dim_Hdet = 1000000
allocate( Hdet_ik(dim_Hdet), Hdet_jl(dim_Hdet), Hdet_v(dim_Hdet) )
call const_ij_hdet_kl_sparse(dim_hdet, hdet_ik, hdet_jl, hdet_v)
! decompose Hdet by a Randomized SVD
dim_U = n_det_alpha_unique * n_det_alpha_unique
dim_V = n_det_beta_unique * n_det_beta_unique
dim_RSVD = min(dim_U, dim_V)
dim_RSVD = min(5000, dim_RSVD)
call perform_RSVD(dim_U, dim_V, dim_RSVD, dim_Hdet, Hdet_ik, Hdet_jl, Hdet_v)
deallocate( Hdet_ik, Hdet_jl, Hdet_v )
call wall_time(t_end)
print *, ' end after (min)', (t_end-t_beg)/60.d0
end
! _________________________________________________________________________________________________
! _________________________________________________________________________________________________
! _________________________________________________________________________________________________
! _________________________________________________________________________________________________
!
subroutine const_ij_Hdet_kl_sparse(dim_Hdet, Hdet_ik, Hdet_jl, Hdet_v)
implicit none
integer*8, intent(in) :: dim_Hdet
integer*8, intent(out) :: Hdet_ik(dim_Hdet), Hdet_jl(dim_Hdet)
double precision, intent(out) :: Hdet_v(dim_Hdet)
integer(bit_kind) :: det1(N_int,2), det2(N_int,2)
integer :: degree
integer :: na, nb, i, j, k, l, ii
double precision :: h12
double precision :: t1, t2
print *, ""
print *, " start const_ij_Hdet_kl_sparse"
call wall_time(t1)
na = n_det_alpha_unique
nb = n_det_beta_unique
ii = 0
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP PRIVATE(i,j,k,l,ii,h12,det1,det2,degree) &
!$OMP SHARED(na,nb,psi_det_alpha_unique,psi_det_beta_unique, &
!$OMP N_int,Hdet_ik,Hdet_jl,Hdet_v)
!$OMP DO
do l = 1, nb
det2(:,2) = psi_det_beta_unique(:,l)
do j = 1, nb
det1(:,2) = psi_det_beta_unique(:,j)
call get_excitation_degree_spin(det1(1,2),det2(1,2),degree,N_int)
if(degree .gt. 2) cycle
do k = 1, na
det2(:,1) = psi_det_alpha_unique(:,k)
do i = 1, na
det1(:,1) = psi_det_alpha_unique(:,i)
call get_excitation_degree(det1,det2,degree,N_int)
if(degree .gt. 2) cycle
call i_H_j(det1, det2, N_int, h12)
if(dabs(h12) .le. (1d-15)) cycle
ii = ii + 1
Hdet_ik(ii) = (i-1)*na + k
Hdet_jl(ii) = (j-1)*na + l
Hdet_v (ii) = h12
enddo
enddo
enddo
enddo
!$OMP END DO
!$OMP END PARALLEL
call wall_time(t2)
print *, " end const_ij_Hdet_kl_sparse after (min) ", (t2-t1)/60.
print *, ""
if( ii .ne. dim_Hdet) then
print*, ' error in const_ij_Hdet_kl_sparse'
print*, ' dim supposed = ', dim_Hdet
print*, ' dim foundedi = ', ii
stop
end if
return
end subroutine const_ij_Hdet_kl_sparse
! _________________________________________________________________________________________________
! _________________________________________________________________________________________________
! _________________________________________________________________________________________________
!
subroutine perform_RSVD(dim_U, dim_V, dim_RSVD, dim_Hdet, Hdet_ik, Hdet_jl, Hdet_v)
include 'constants.include.F'
implicit none
integer, intent(in) :: dim_U, dim_V, dim_RSVD
integer*8, intent(in) :: dim_Hdet
integer*8, intent(in) :: Hdet_ik(dim_Hdet), Hdet_jl(dim_Hdet)
double precision, intent(in) :: Hdet_v(dim_Hdet)
integer :: na, nb
integer :: iter, iter_max
integer :: ii, rr, ik, jl
double precision, allocatable :: GR(:,:)
double precision, allocatable :: Z(:,:), P(:,:), Yt(:,:), UYt(:,:)
double precision, allocatable :: U(:,:), V(:,:), D(:)
na = n_det_alpha_unique
nb = n_det_beta_unique
! Z = Hdet x G
! G: random gauss dist
allocate( Z(dim_U,dim_RSVD) )
Z(:,:) = 0
!$OMP PARALLEL DEFAULT(NONE) PRIVATE(ii, rr, ik, GR) &
!$OMP SHARED(dim_Hdet, dim_RSVD, Z, Hdet_ik, Hdet_v)
allocate( GR(dim_Hdet,2) )
!$OMP DO
do rr = 1, dim_RSVD
call random_number(GR)
GR(:,1) = dsqrt(-2.d0*dlog(GR(:,1)))
GR(:,1) = GR(:,1) * dcos(dtwo_pi*GR(:,2))
do ii = 1, dim_Hdet
ik = Hdet_ik(ii)
!jl = Hdet_jl(ii)
Z(ik,rr) = Z(ik,rr) + Hdet_v(ii) * GR(ii,1)
enddo
enddo
!$OMP END DO
deallocate(GR)
!$OMP END PARALLEL
! parameter
iter_max = 10
allocate( P(dim_V,dim_RSVD) )
! ------------------------------------------------------------------------------------------
! Power iterations
!
do iter = 1, iter_max
print *, ' power iteration ', iter, '/', iter_max
!$OMP PARALLEL DEFAULT(NONE) PRIVATE(ii, rr, ik, jl) &
!$OMP SHARED(dim_Hdet, dim_RSVD, Z, P, Hdet_ik, Hdet_jl, Hdet_v)
!$OMP DO
! P = Hdet.T x Z
do rr = 1, dim_RSVD
P(:,rr) = 0.d0
do ii = 1, dim_Hdet
ik = Hdet_ik(ii)
jl = Hdet_jl(ii)
P(jl,rr) = P(jl,rr) + Hdet_v(ii) * Z(ik,rr)
enddo
enddo
!$OMP END DO
!$OMP BARRIER
!$OMP DO
do rr = 1, dim_RSVD
Z(:,rr) = 0.d0
do ii = 1, dim_Hdet
ik = Hdet_ik(ii)
jl = Hdet_jl(ii)
Z(ik,rr) = Z(ik,rr) + Hdet_v(ii) * P(jl,rr)
enddo
enddo
!$OMP END DO
!$OMP END PARALLEL
call ortho_qr(Z, size(Z,1), dim_U, dim_RSVD)
enddo
!
! ------------------------------------------------------------------------------------------
! Y = Z.T x Hdet
! Yt = Hdet.T x Z
allocate( Yt(dim_V,dim_RSVD) )
!$OMP PARALLEL DEFAULT(NONE) PRIVATE(ii, rr, ik, jl) &
!$OMP SHARED(dim_Hdet, dim_RSVD, Z, Yt, Hdet_ik, Hdet_jl, Hdet_v)
!$OMP DO
do rr = 1, dim_RSVD
Yt(:,rr) = 0.d0
do ii = 1, dim_Hdet
ik = Hdet_ik(ii)
jl = Hdet_jl(ii)
Yt(jl,rr) = Yt(jl,rr) + Z(ik,rr) * Hdet_v(ii)
enddo
enddo
!$OMP END DO
!$OMP END PARALLEL
! Y = U x D x Vt
! Yt = V x D x Ut
allocate( D(dim_RSVD), V(dim_V,dim_RSVD), UYt(dim_RSVD,dim_RSVD) )
call svd(Yt, size(Yt,1), V, size(V,1), D, UYt, size(UYt,1), dim_V, dim_RSVD)
deallocate( Yt )
! U = Z x UY
allocate( U(dim_U,dim_RSVD) )
call dgemm('N', 'T', dim_U, dim_RSVD, dim_RSVD, 1.d0, Z, size(Z,1), UYt, size(UYt,1), 0.d0, U, size(U,1))
deallocate( UYt, Z )
open(unit=41, file='u_det.txt', action='write')
do rr = 1, dim_RSVD
do ii = 1, dim_U
write(41,*) U(ii,rr)
enddo
enddo
close(41)
! v = u because H is symmetric
!open(unit=41, file='v_det.txt', action='write')
! do rr = 1, dim_RSVD
! do ii = 1, dim_V
! write(41,*) V(ii,rr)
! enddo
! enddo
!close(41)
open(unit=41, file='d_det.txt', action='write')
do rr = 1, dim_RSVD
write(41,*) D(rr), sum( D(1:rr)**2 )
enddo
close(41)
deallocate( U, D, V )
end subroutine perform_RSVD
! _________________________________________________________________________________________________
! _________________________________________________________________________________________________

View File

@ -0,0 +1,511 @@
program SQ_klHkl_v1
implicit none
BEGIN_DOC
! perturbative approach to build psi_postsvd
END_DOC
read_wf = .True.
TOUCH read_wf
PROVIDE N_int
call run()
end
subroutine run
USE OMP_LIB
USE bitmasks
implicit none
integer(bit_kind) :: det1(N_int,2), det2(N_int,2)
integer :: degree, i_state
integer :: i, j, k, l, m, n
double precision :: x, y, h12
double precision, allocatable :: Uref(:,:), Dref(:), Vtref(:,:), Aref(:,:), Vref(:,:)
integer :: rank_max
double precision :: E0, overlop, Ept2
double precision, allocatable :: H0(:,:)
double precision, allocatable :: eigvec0(:,:), eigval0(:), coeff_psi(:), coeff_tmp(:)
integer :: ii, ia, ib
double precision, allocatable :: Hdiag(:), Hkl_save(:,:), Hkl_1d(:), Hkl_tmp(:,:), Hdiag_tmp(:)
integer :: na_new, nb_new, ind_new, ind_gs
double precision :: ctmp, coeff_new
double precision, allocatable :: epsil(:), epsil_energ(:), check_ov(:)
double precision, allocatable :: Uezfio(:,:,:), Dezfio(:,:), Vezfio(:,:,:)
integer :: ibeg_alpha, ibeg_beta, iend_alpha, iend_beta
integer :: n_toselect, na_max, nb_max
integer, allocatable :: numalpha_toselect(:), numbeta_toselect(:)
double precision :: t_beg, t_end, ti, tf
integer :: nb_taches
!$OMP PARALLEL
nb_taches = OMP_GET_NUM_THREADS()
!$OMP END PARALLEL
call wall_time(ti)
i_state = 1
det1(:,1) = psi_det_alpha_unique(:,1)
det2(:,1) = psi_det_alpha_unique(:,1)
det1(:,2) = psi_det_beta_unique(:,1)
det2(:,2) = psi_det_beta_unique(:,1)
call get_excitation_degree_spin(det1(1,1),det2(1,1),degree,N_int)
call get_excitation_degree(det1,det2,degree,N_int)
call i_H_j(det1, det2, N_int, h12)
! ---------------------------------------------------------------------------------------
! construct the initial CISD matrix
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
print *, ' CISD matrix:', n_det_alpha_unique,'x',n_det_beta_unique
print *, ' N det :', N_det
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
allocate( Aref(n_det_alpha_unique,n_det_beta_unique) )
Aref(:,:) = 0.d0
do k = 1, N_det
i = psi_bilinear_matrix_rows(k)
j = psi_bilinear_matrix_columns(k)
Aref(i,j) = psi_bilinear_matrix_values(k,i_state)
enddo
!
! ---------------------------------------------------------------------------------------
! ---------------------------------------------------------------------------------------
! perform a Full SVD
allocate( Uref(n_det_alpha_unique,n_det_alpha_unique) )
allocate( Dref(min(n_det_alpha_unique,n_det_beta_unique)) )
allocate( Vtref(n_det_beta_unique,n_det_beta_unique) )
call wall_time(t_beg)
call svd_s(Aref, size(Aref,1), Uref, size(Uref,1), Dref, Vtref &
, size(Vtref,1), n_det_alpha_unique, n_det_beta_unique)
call wall_time(t_end)
print *, " SVD is performed after (min)", (t_end-t_beg)/60.
deallocate( Aref , Dref )
allocate( Vref(n_det_beta_unique,n_det_beta_unique) )
do l = 1, n_det_beta_unique
do i = 1, n_det_beta_unique
Vref(i,l) = Vtref(l,i)
enddo
enddo
deallocate( Vtref )
!
! ---------------------------------------------------------------------------------------
! ---------------------------------------------------------------------------------------
! numerote | k l > toselect
ibeg_alpha = 1
iend_alpha = n_det_alpha_unique
na_max = iend_alpha - ibeg_alpha + 1
ibeg_beta = 1
iend_beta = n_det_beta_unique
nb_max = iend_beta - ibeg_beta + 1
n_toselect = na_max * nb_max
print *, ' na_max = ', na_max
print *, ' nb_max = ', nb_max
print *, ' n_toselect = ', n_toselect
allocate( numalpha_toselect(n_toselect) , numbeta_toselect(n_toselect) )
k = 0
do i = ibeg_alpha, iend_alpha
do j = ibeg_beta, iend_beta
k = k + 1
numalpha_toselect(k) = i
numbeta_toselect (k) = j
enddo
enddo
if( k.ne.n_toselect ) then
print *, " error in numbering"
stop
endif
!
! ---------------------------------------------------------------------------------------
double precision, allocatable :: A_ik(:,:), B_jl(:,:), T(:,:,:,:)
allocate( A_ik(n_det_alpha_unique,n_det_alpha_unique) , B_jl(n_det_beta_unique,n_det_beta_unique) )
allocate( T(n_det_alpha_unique,n_det_alpha_unique,n_det_beta_unique,n_det_beta_unique ) )
call const_AB(A_ik, B_jl)
call const_2b(T)
allocate( Hdiag(n_toselect) )
call const_Hdiag(n_toselect, Uref, Vref, numalpha_toselect, numbeta_toselect, A_ik, B_jl, T, Hdiag)
deallocate( A_ik, B_jl, T )
open(UNIT=11, FILE="SQ_klHkl_v1.dat", ACTION="WRITE")
do i = 1, n_toselect
write(11, '(2(I5,2X), 5X, E15.7)') numalpha_toselect(i), numbeta_toselect(i), Hdiag(i)
enddo
close(11)
deallocate( Hdiag )
deallocate( Uref, Vref )
deallocate( numalpha_toselect, numbeta_toselect )
call wall_time(tf)
print *, ' ___________________________________________________________________'
print *, ' '
!print *, " Execution avec ", nb_taches, " threads"
print *, " Execution avec 1 threads"
print *, " total elapsed time (min) = ", (tf-ti)/60.d0
print *, ' ___________________________________________________________________'
end
!/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\!
!---! !---! !---! !---! !---! !---! !---! !---! !---!
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
!___! !___! !___! !___! !___! !___! !___! !___! !___!
!___! !___! !___! !___! !___! !___! !___! !___! !___!
!/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\!
!---! !---! !---! !---! !---! !---! !---! !---! !---!
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
!___! !___! !___! !___! !___! !___! !___! !___! !___!
!___! !___! !___! !___! !___! !___! !___! !___! !___!
!/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\!
!---! !---! !---! !---! !---! !---! !---! !---! !---!
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
!___! !___! !___! !___! !___! !___! !___! !___! !___!
!___! !___! !___! !___! !___! !___! !___! !___! !___!
!/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\!
!---! !---! !---! !---! !---! !---! !---! !---! !---!
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
!___! !___! !___! !___! !___! !___! !___! !___! !___!
!___! !___! !___! !___! !___! !___! !___! !___! !___!
subroutine const_AB(A_ik, B_jl)
USE bitmasks
implicit none
! see one_e_dm_mo_alpha & one_e_dm_mo_beta in determinants/density_matrix.irp.f
double precision, intent(out) :: A_ik(n_det_alpha_unique,n_det_alpha_unique)
double precision, intent(out) :: B_jl(n_det_beta_unique ,n_det_beta_unique )
integer :: na, nb
integer :: i, k, j, l, e
integer(bit_kind) :: deti(N_int), detk(N_int), detj(N_int), detl(N_int)
double precision :: phase
integer :: degree, h1, h2, p1, p2
integer :: exc(0:2,2)
integer :: list(N_int*bit_kind_size), n_elements
na = n_det_alpha_unique
nb = n_det_beta_unique
A_ik(:,:) = 0.d0
B_jl(:,:) = 0.d0
! -----------------------------------------------------------------------------------------------------------
! Diagonal part
! -----------------------------------------------------------------------------------------------------------
do i = 1, na
deti(1:N_int) = psi_det_alpha_unique(1:N_int,i)
list = 0
call bitstring_to_list(deti, list, n_elements, N_int)
do e = 1, elec_alpha_num
A_ik(i,i) += mo_one_e_integrals(list(e),list(e))
enddo
enddo
do j = 1, nb
detj(1:N_int) = psi_det_beta_unique(1:N_int,j)
list = 0
call bitstring_to_list(detj, list, n_elements, N_int)
do e = 1, elec_beta_num
B_jl(j,j) += mo_one_e_integrals(list(e),list(e))
enddo
enddo
! -----------------------------------------------------------------------------------------------------------
! -----------------------------------------------------------------------------------------------------------
! -----------------------------------------------------------------------------------------------------------
! degree = 1
! -----------------------------------------------------------------------------------------------------------
do i = 1, na
deti(1:N_int) = psi_det_alpha_unique(1:N_int,i)
list = 0
call bitstring_to_list(deti, list, n_elements, N_int)
do k = 1, na
detk(1:N_int) = psi_det_alpha_unique(1:N_int,k)
call get_excitation_degree_spin(deti, detk, degree, N_int)
if(degree .eq. 1) then
exc = 0
call get_single_excitation_spin(deti, detk, exc, phase, N_int)
call decode_exc_spin(exc, h1, p1, h2, p2)
A_ik(i,k) += phase * mo_one_e_integrals(h1,p1)
!A_ik(i,k) += phase * mo_one_e_integrals(p1,h1)
endif
enddo
enddo
do j = 1, nb
detj(1:N_int) = psi_det_beta_unique(1:N_int,j)
list = 0
call bitstring_to_list(detj, list, n_elements, N_int)
do l = 1, nb
detl(1:N_int) = psi_det_beta_unique(1:N_int,l)
call get_excitation_degree_spin(detj, detl, degree, N_int)
if(degree .eq. 1) then
exc = 0
call get_single_excitation_spin(detj, detl, exc, phase, N_int)
call decode_exc_spin(exc, h1, p1, h2, p2)
B_jl(j,l) += phase * mo_one_e_integrals(h1,p1)
!B_jl(j,l) += phase * mo_one_e_integrals(p1,h1)
endif
enddo
enddo
! -----------------------------------------------------------------------------------------------------------
! -----------------------------------------------------------------------------------------------------------
return
end subroutine const_AB
subroutine const_2b(T)
USE bitmasks
implicit none
double precision, external :: get_two_e_integral
double precision, intent(out) :: T(n_det_alpha_unique,n_det_alpha_unique,n_det_beta_unique,n_det_beta_unique )
integer :: na, nb
integer :: i, k, j, l
integer(bit_kind) :: psi_ij(N_int,2), psi_kl(N_int,2)
double precision :: phase
integer :: degree, h1, h2, p1, p2, s1, s2, e1, e2
integer :: ii, jj
integer :: exc(0:2,2,2)
integer :: occ(N_int*bit_kind_size,2), n_occ_alpha
double precision :: two_body_fact
na = n_det_alpha_unique
nb = n_det_beta_unique
T(:,:,:,:) = 0.d0
! -----------------------------------------------------------------------------------------------------------------
do i = 1, na
psi_ij(1:N_int,1) = psi_det_alpha_unique(1:N_int,i)
do j = 1, nb
psi_ij(1:N_int,2) = psi_det_beta_unique(1:N_int,j)
call bitstring_to_list(psi_ij(1,1), occ(1,1), n_occ_alpha, N_int)
call bitstring_to_list(psi_ij(1,2), occ(1,2), n_occ_alpha, N_int)
do k = 1, na
psi_kl(1:N_int,1) = psi_det_alpha_unique(1:N_int,k)
do l = 1, nb
psi_kl(1:N_int,2) = psi_det_beta_unique(1:N_int,l)
call get_excitation_degree(psi_ij, psi_kl, degree, N_int)
two_body_fact = 0.d0
if(degree .eq. 2) then
call get_double_excitation(psi_ij, psi_kl, exc, phase, N_int)
call decode_exc(exc, degree, h1, p1, h2, p2, s1, s2)
select case(s1+s2)
case(2,4)
two_body_fact += phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map)
two_body_fact -= phase * get_two_e_integral(h1, h2, p2, p1, mo_integrals_map)
case(3)
two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map)
two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map)
end select
else if(degree .eq. 1) then
call get_single_excitation(psi_ij, psi_kl, exc, phase, N_int)
call decode_exc(exc, degree, h1, p1, h2, p2, s1, s2)
select case(s1)
case(1)
do ii = 1, elec_alpha_num
p2 = occ(ii,1)
h2 = p2
two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map)
two_body_fact -= 0.5d0 * phase * get_two_e_integral(h1, h2, p2, p1, mo_integrals_map)
two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map)
two_body_fact -= 0.5d0 * phase * get_two_e_integral(h2, h1, p1, p2, mo_integrals_map)
enddo
do ii = 1, elec_beta_num
p2 = occ(ii,2)
h2 = p2
two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map)
two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map)
enddo
case(2)
do ii = 1, elec_alpha_num
p2 = occ(ii,1)
h2 = p2
two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map)
two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map)
enddo
do ii = 1, elec_beta_num
p2 = occ(ii,2)
h2 = p2
two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map)
two_body_fact -= 0.5d0 * phase * get_two_e_integral(h1, h2, p2, p1, mo_integrals_map)
two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map)
two_body_fact -= 0.5d0 * phase * get_two_e_integral(h2, h1, p1, p2, mo_integrals_map)
enddo
end select
else if(degree .eq. 0) then
do ii = 1, elec_alpha_num
e1 = occ(ii,1)
do jj = 1, elec_alpha_num
e2 = occ(jj,1)
two_body_fact += 0.5d0 * get_two_e_integral(e1, e2, e1, e2, mo_integrals_map)
two_body_fact -= 0.5d0 * get_two_e_integral(e1, e2, e2, e1, mo_integrals_map)
enddo
do jj = 1, elec_beta_num
e2 = occ(jj,2)
two_body_fact += 0.5d0 * get_two_e_integral(e1, e2, e1, e2, mo_integrals_map)
two_body_fact += 0.5d0 * get_two_e_integral(e2, e1, e2, e1, mo_integrals_map)
enddo
enddo
do ii = 1, elec_beta_num
e1 = occ(ii,2)
do jj = 1, elec_beta_num
e2 = occ(jj,2)
two_body_fact += 0.5d0 * get_two_e_integral(e1, e2, e1, e2, mo_integrals_map)
two_body_fact -= 0.5d0 * get_two_e_integral(e1, e2, e2, e1, mo_integrals_map)
enddo
enddo
end if
T(i,k,j,l) = two_body_fact
enddo
enddo
enddo
enddo
! -----------------------------------------------------------------------------------------------------------------
return
end subroutine const_2b
subroutine const_Hdiag(n_toselect, Uref, Vref, numalpha_toselect, numbeta_toselect &
, A_ik, B_jl, T, Hdiag)
implicit none
integer, intent(in) :: n_toselect
integer, intent(in) :: numalpha_toselect(n_toselect), numbeta_toselect(n_toselect)
double precision, intent(in) :: Uref(n_det_alpha_unique,n_det_alpha_unique)
double precision, intent(in) :: Vref(n_det_beta_unique ,n_det_beta_unique)
double precision, intent(in) :: A_ik(n_det_alpha_unique,n_det_alpha_unique)
double precision, intent(in) :: B_jl(n_det_beta_unique ,n_det_beta_unique )
double precision, intent(in) :: T(n_det_alpha_unique,n_det_alpha_unique,n_det_beta_unique,n_det_beta_unique )
double precision, intent(out) :: Hdiag(n_toselect)
integer :: na, nb
integer :: i, j, k, l, ii, jj, n
na = n_det_alpha_unique
nb = n_det_beta_unique
Hdiag(:) = 0.d0
do n = 1, n_toselect
ii = numalpha_toselect(n)
jj = numbeta_toselect (n)
do i = 1, na
do k = 1, na
Hdiag(n) += Uref(i,ii) * Uref(k,ii) * A_ik(i,k)
enddo
enddo
do j = 1, nb
do l = 1, nb
Hdiag(n) += Vref(j,jj) * Vref(l,jj) * B_jl(j,l)
enddo
enddo
do i = 1, na
do k = 1, na
do j = 1, nb
do l = 1, nb
Hdiag(n) += Uref(i,ii) * Uref(k,ii) * Vref(j,jj) * Vref(l,jj) * T(i,k,j,l)
enddo
enddo
enddo
enddo
enddo
return
end subroutine const_Hdiag

24
devel/svdwf/SVD.slurm Normal file
View File

@ -0,0 +1,24 @@
#!/bin/bash
#
#SBATCH --job-name=SLURM_h2o_631g_SVD
#SBATCH --output=SLURM_h2o_631g_SVD.out
#
#SBATCH --mail-type=ALL
#SBATCH --mail-user=aammar@irsamc.ups-tlse.fr
#
#SBATCH -N 1
#SBATCH -n 1
#SBATCH -c 4
#SBATCH -t 0:10:00
##SBATCH --exclusive
#
#
srun hostname
echo "Running on `hostname`"
#
echo "Kicking off $SLURM_NPROCS compute servers on $SLURM_NNODES nodes"
echo "Nodes are\n `scontrol show hostname`"
#
~/qp2/bin/qpsh
qp_run Evar_TruncSVD h2o_631g >> h2o_631g_SVD.out
#

View File

@ -0,0 +1,62 @@
program SVD_rank
BEGIN_DOC
! rank SVD
END_DOC
implicit none
read_wf = .True.
TOUCH read_wf
call run()
end
subroutine run
implicit none
integer :: mm, nn, mn, i_state, low_r
double precision, allocatable :: Uezf_FSVD(:,:,:), Dezf_FSVD(:,:), Vezf_FSVD(:,:,:)
double precision, allocatable :: Uezf_TSVD(:,:,:), Dezf_TSVD(:,:), Vezf_TSVD(:,:,:)
i_state = 1
mm = n_det_alpha_unique
nn = n_det_beta_unique
mn = min(mm,nn)
! read TSVD
allocate( Uezf_FSVD(mm,mm,1), Dezf_FSVD(mn,1), Vezf_FSVD(nn,nn,1) )
call ezfio_get_spindeterminants_psi_svd_alpha(Uezf_FSVD)
call ezfio_get_spindeterminants_psi_svd_beta (Vezf_FSVD)
call ezfio_get_spindeterminants_psi_svd_coefs(Dezf_FSVD)
! new TSVD
low_r = 100
call ezfio_set_spindeterminants_n_svd_coefs(low_r)
Dezf_TSVD( 1:low_r,1) = Dezf_FSVD( 1:low_r,1)
Uezf_TSVD(1:mm,1:low_r,1) = Uezf_FSVD(1:mm,1:low_r,1)
Vezf_TSVD(1:nn,1:low_r,1) = Vezf_FSVD(1:nn,1:low_r,1)
deallocate( Uezf_FSVD, Dezf_FSVD, Vezf_FSVD )
call ezfio_set_spindeterminants_psi_svd_alpha(Uezf_TSVD)
call ezfio_set_spindeterminants_psi_svd_beta (Vezf_TSVD)
call ezfio_set_spindeterminants_psi_svd_coefs(Dezf_TSVD)
deallocate( Uezf_TSVD, Dezf_TSVD, Vezf_TSVD )
!call ezfio_set_spindeterminants_n_det(N_det)
!call ezfio_set_spindeterminants_n_states(N_states)
!call ezfio_set_spindeterminants_n_det_alpha(n_det_alpha_unique)
!call ezfio_set_spindeterminants_n_det_beta(n_det_beta_unique)
!call ezfio_set_spindeterminants_psi_coef_matrix_rows(psi_bilinear_matrix_rows)
!call ezfio_set_spindeterminants_psi_coef_matrix_columns(psi_bilinear_matrix_columns)
!call ezfio_set_spindeterminants_psi_coef_matrix_values(psi_bilinear_matrix_values)
end

116
devel/svdwf/TSVD_err.irp.f Normal file
View File

@ -0,0 +1,116 @@
program TSVD_err
BEGIN_DOC
! study precision variation with truncated SVD
END_DOC
implicit none
read_wf = .True.
TOUCH read_wf
call run()
end
subroutine run
implicit none
integer :: mm, nn, i_state, low_rank, lrank_min, lrank_max
integer :: i, j, k, l
double precision :: norm_psi, err_verif, err_tmp
double precision, allocatable :: U_FSVD(:,:), D_FSVD(:), Vt_FSVD(:,:), A_FSVD(:,:)
double precision, allocatable :: US(:,:), A_TSVD(:,:)
double precision :: tmp_acc
double precision, allocatable :: D2_FSVD(:)
double precision :: t0, t1, t2
call CPU_TIME(t0)
i_state = 1
mm = n_det_alpha_unique
nn = n_det_beta_unique
print *, ' matrix dimensions:', mm,'x',nn
print *, ' N det:', N_det
allocate( A_FSVD(mm,nn), U_FSVD(mm,mm), D_FSVD(min(mm,nn)), Vt_FSVD(nn,nn) )
norm_psi = 0.d0
A_FSVD(:,:) = 0.d0
do k = 1, N_det
i = psi_bilinear_matrix_rows(k)
j = psi_bilinear_matrix_columns(k)
A_FSVD(i,j) = psi_bilinear_matrix_values(k,i_state)
norm_psi += psi_bilinear_matrix_values(k,i_state) * psi_bilinear_matrix_values(k,i_state)
enddo
call svd_s( A_FSVD, size(A_FSVD,1), U_FSVD, size(U_FSVD,1), D_FSVD, Vt_FSVD, size(Vt_FSVD,1), mm, nn)
print *, ' --- Full SVD: ok after --- '
call CPU_TIME(t1)
print *, (t1-t0)/60.d0, 'min'
! ! US = U x SV :
! allocate( US(mm,min(mm,nn)) )
! US(:,:) = 0.d0
! do i = 1, mm
! do l = 1, min(mm,nn)
! US(i,l) = U_FSVD(i,l) * D_FSVD(l)
! enddo
! enddo
!
! allocate( A_TSVD(mm,nn) )
! A_TSVD(:,:) = 0.d0
! lrank_min = 1
! lrank_max = min(mm,nn)
! do low_rank = lrank_min, lrank_max, 1
!
! ! A_TSVD = US x Vt_FSVD
! call dgemm( 'N', 'N', mm, nn, low_rank, 1.d0 &
! , US , size(US ,1) &
! , Vt_FSVD, size(Vt_FSVD,1) &
! , 0.d0, A_TSVD, size(A_TSVD,1) )
! ! |A_FSVD-A_TSVD|
! err_verif = 0.d0
! do j = 1, nn
! do i = 1, mm
! err_tmp = A_FSVD(i,j) - A_TSVD(i,j)
! err_verif = err_verif + err_tmp * err_tmp
! enddo
! enddo
! print*, low_rank, 100.d0 * dsqrt(err_verif/norm_psi)
! enddo
! deallocate( A_TSVD , US )
deallocate( A_FSVD, U_FSVD, Vt_FSVD )
allocate( D2_FSVD(min(mm,nn)) )
do i = 1, min(mm,nn)
tmp_acc = 0.d0
do j = 1, i
tmp_acc = tmp_acc + D_FSVD(j) * D_FSVD(j)
enddo
D2_FSVD(i) = tmp_acc
enddo
open(unit=11, file='d_svd.txt',action='write')
do i = 1, min(mm,nn)
write(11, *) D_FSVD(i), D2_FSVD(i), 1.d0-D2_FSVD(i)
enddo
close(11)
deallocate( D2_FSVD )
deallocate( D_FSVD )
call CPU_TIME(t2)
print *, ''
print *, ' end after'
print *, (t2-t0)/60.d0, 'min'
end

View File

@ -0,0 +1,106 @@
program checkSVD_EZ
BEGIN_DOC
! save SVD manually
END_DOC
implicit none
read_wf = .True.
TOUCH read_wf
call run()
end
subroutine run
implicit none
integer :: mm, nn, i_state, low_rank, lrank_min, lrank_max
integer :: i, j, k, l
double precision :: norm_psi, err_verif, err_tmp
double precision, allocatable :: U_FSVD(:,:), D_FSVD(:), Vt_FSVD(:,:), V_FSVD(:,:), A_FSVD(:,:)
double precision, allocatable :: U_read(:,:), D_read(:), V_read(:,:)
double precision :: t0, t1, t2
call CPU_TIME(t0)
i_state = 1
mm = n_det_alpha_unique
nn = n_det_beta_unique
print *, ' matrix dimensions:', mm,'x',nn
print *, ' N det:', N_det
allocate( A_FSVD(mm,nn), U_FSVD(mm,mm), D_FSVD(min(mm,nn)), Vt_FSVD(nn,nn) )
norm_psi = 0.d0
A_FSVD(:,:) = 0.d0
do k = 1, N_det
i = psi_bilinear_matrix_rows(k)
j = psi_bilinear_matrix_columns(k)
A_FSVD(i,j) = psi_bilinear_matrix_values(k,i_state)
norm_psi += psi_bilinear_matrix_values(k,i_state) * psi_bilinear_matrix_values(k,i_state)
enddo
call svd_s( A_FSVD, size(A_FSVD,1), U_FSVD, size(U_FSVD,1), D_FSVD, Vt_FSVD, size(Vt_FSVD,1), mm, nn)
print *, ' --- Full SVD: ok --- '
call CPU_TIME(t1)
print *, (t1-t0)/60.d0, 'min'
deallocate( A_FSVD )
allocate( V_FSVD(nn,nn) )
do i = 1, nn
do j = 1, nn
V_FSVD(i,j) = Vt_FSVD(j,i)
enddo
enddo
deallocate(Vt_FSVD)
! ------------------------------------------
allocate( U_read(mm,mm), D_read(min(mm,nn)), V_read(nn,nn) )
call ezfio_get_spindeterminants_psi_svd_coefs(D_read)
call ezfio_get_spindeterminants_psi_svd_alpha(U_read)
call ezfio_get_spindeterminants_psi_svd_beta (V_read)
err_verif = 0.d0
do i = 1, min(mm,nn)
err_tmp = D_FSVD(i) - D_read(i)
err_verif += err_tmp * err_tmp
enddo
print *, ' error on D:', err_verif
deallocate( D_FSVD, D_read )
err_verif = 0.d0
do j = 1, nn
do i = 1, mm
err_tmp = U_FSVD(i,j) - U_read(i,j)
err_verif = err_verif + err_tmp * err_tmp
enddo
enddo
print *, ' error on U:', err_verif
deallocate( U_FSVD, U_read )
err_verif = 0.d0
do j = 1, nn
do i = 1, mm
err_tmp = V_FSVD(i,j) - V_read(i,j)
err_verif = err_verif + err_tmp * err_tmp
enddo
enddo
print *, ' error on V:', err_verif
deallocate( V_FSVD, V_read )
call CPU_TIME(t2)
print *, ''
print *, ' end after'
print *, (t2-t0)/60.d0, 'min'
end

View File

@ -0,0 +1,261 @@
# !!!
import sys, os
QMCCHEM_PATH=os.environ["QMCCHEM_PATH"]
sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/")
from ezfio import ezfio
from math import sqrt
from datetime import datetime
import time
import numpy as np
import subprocess
from scipy.linalg import eig, eigh
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_energy():
buffer = subprocess.check_output(['qmcchem', 'result', '-e', 'e_loc', EZFIO_file], encoding='UTF-8')
if buffer.strip() != "":
buffer = buffer.splitlines()[-1]
_, energy, error = [float(x) for x in buffer.split()]
return energy, error
else:
return None, None
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Ci_h_matrix_svd():
Ci_h_matrix_svd = np.zeros( (n_svd,n_svd) )
SErr_H = np.zeros( (n_svd,n_svd) )
beg_Ci_h_matrix_svd = results.find('Ci_h_matrix_svd : [ ') + len( 'Ci_h_matrix_svd : [ ' )
end_Ci_h_matrix_svd = len(results)
Ci_h_matrix_svd_buf = results[beg_Ci_h_matrix_svd:end_Ci_h_matrix_svd]
Ci_h_matrix_svd_buf = Ci_h_matrix_svd_buf.split( '\n' )
for iline in range(1, n_svd**2+1):
line = Ci_h_matrix_svd_buf[iline].split()
indc = int( line[0] )
errS = float( line[4] )
if( indc != iline ):
print(' Error in reading Ci_h_matrix_svd')
print(' indc = {}'.format(indc) )
print(' iline = {}'.format(iline) )
break
else:
irow = indc % n_svd
icol = indc // n_svd
if( irow!=0 ):
Ci_h_matrix_svd[irow-1][icol] = float( line[2] )
SErr_H [irow-1][icol] = float( line[4] )
#ci_tmp = Ci_h_matrix_svd[irow-1][icol]
#er_tmp = SErr_H [irow-1][icol]
#if(ci_tmp>0):
# Ci_h_matrix_svd[irow-1][icol] = max(0 , ci_tmp - er_tmp)
#else:
# Ci_h_matrix_svd[irow-1][icol] = min(0 , ci_tmp + er_tmp)
else:
Ci_h_matrix_svd[n_svd-1][icol-1] = float( line[2] )
SErr_H [n_svd-1][icol-1] = float( line[4] )
#ci_tmp = Ci_h_matrix_svd[n_svd-1][icol-1]
#er_tmp = SErr_H [n_svd-1][icol-1]
#if(ci_tmp>0):
# Ci_h_matrix_svd[n_svd-1][icol-1] = max(0 , ci_tmp - er_tmp)
#else:
# Ci_h_matrix_svd[n_svd-1][icol-1] = min(0 , ci_tmp + er_tmp)
return(Ci_h_matrix_svd,SErr_H)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Ci_overlap_matrix_svd():
Ci_overlap_matrix_svd = np.zeros( (n_svd,n_svd) )
SErr_O = np.zeros( (n_svd,n_svd) )
beg_Ci_overlap_matrix_svd = results.find('Ci_overlap_matrix_svd : [ ') + len( 'Ci_overlap_matrix_svd : [ ' )
end_Ci_overlap_matrix_svd = len(results)
Ci_overlap_matrix_svd_buf = results[beg_Ci_overlap_matrix_svd:end_Ci_overlap_matrix_svd]
Ci_overlap_matrix_svd_buf = Ci_overlap_matrix_svd_buf.split( '\n' )
for iline in range(1, n_svd**2+1):
line = Ci_overlap_matrix_svd_buf[iline].split()
indc = int( line[0] )
errS = float( line[4] )
if( indc != iline ):
print(' Error in reading Ci_overlap_matrix_svd')
print(' indc = {}'.format(indc))
print(' iline = {}'.format(iline))
break
else:
irow = indc % n_svd
icol = indc // n_svd
if( irow!=0 ):
Ci_overlap_matrix_svd[irow-1][icol] = float( line[2] )
SErr_O [irow-1][icol] = float( line[4] )
#ci_tmp = Ci_overlap_matrix_svd[irow-1][icol]
#er_tmp = SErr_O [irow-1][icol]
#if(ci_tmp>0):
# Ci_overlap_matrix_svd[irow-1][icol] = max(0 , ci_tmp - er_tmp)
#else:
# Ci_overlap_matrix_svd[irow-1][icol] = min(0 , ci_tmp + er_tmp)
else:
Ci_overlap_matrix_svd[n_svd-1][icol-1] = float( line[2] )
SErr_O [n_svd-1][icol-1] = float( line[4] )
#ci_tmp = Ci_overlap_matrix_svd[n_svd-1][icol-1]
#er_tmp = SErr_O [n_svd-1][icol-1]
#if(ci_tmp>0):
# Ci_overlap_matrix_svd[n_svd-1][icol-1] = max(0 , ci_tmp - er_tmp)
#else:
# Ci_overlap_matrix_svd[n_svd-1][icol-1] = min(0 , ci_tmp + er_tmp)
# !!!
# !!!
# !!!
return(Ci_overlap_matrix_svd,SErr_O)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def check_symmetric(a, tol=1e-3):
return np.all(np.abs(a-a.T) < tol)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Esvd():
# read CI_SVD matrices
Ci_h_matrix_svd , SErr_H = get_Ci_h_matrix_svd()
Ci_overlap_matrix_svd, SErr_O = get_Ci_overlap_matrix_svd()
#print( 'Ci_h_matrix_svd is symmetric ? {}' .format(check_symmetric(Ci_h_matrix_svd)) )
#print( 'Ci_overlap_matrix_svd is symmetric ? {}' .format(check_symmetric(Ci_overlap_matrix_svd)) )
if( save_SVD_QMCmat ):
with open('SVD_QMCmat.txt', 'a') as ff:
for i in range(n_svd):
for j in range(n_svd):
ff.write('{} {} {} {} {} {} \n'.format(i,j
, Ci_h_matrix_svd[i,j] , SErr_H[i,j]
, Ci_overlap_matrix_svd[i,j] , SErr_O[i,j] ))
# symmetrise and diagonalise
aa = Ci_h_matrix_svd
aa = 0.5*( aa + aa.T )
bb = Ci_overlap_matrix_svd
eigvals_svd, vr = eig(aa, bb, left=False, right=True, overwrite_a=True, overwrite_b=True,
check_finite=True, homogeneous_eigvals=False)
#print( eigvals_svd + E_toadd )
recouvre_svd = np.abs(psi_svd_coeff @ vr)
ind_gssvd = np.argmax(recouvre_svd)
E_svd = eigvals_svd[ind_gssvd] + E_toadd
return( E_svd, vr[:,ind_gssvd] )
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
if __name__ == '__main__':
t0 = time.time()
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
#EZFIO_file = "Cr2_TSVD30"
#EZFIO_file = "Cr2_TSVD100"
#EZFIO_file = "Cr2_TSVD200"
#EZFIO_file = "Cr2_TSVD924_0"
#EZFIO_file = "Cr2_TSVD924_1"
#EZFIO_file = "Cr2_TSVD924_2"
#EZFIO_file = "Cr2_TSVD30_it1"
#EZFIO_file = "Cr2_TSVD100_it1"
#EZFIO_file = "Cr2_TSVD200_it1"
#EZFIO_file = "Cr2_TSVD924_0_it1"
#EZFIO_file = "Cr2_TSVD924_1_it1"
EZFIO_file = "Cr2_TSVD924_2_it1"
#EZFIO_file = "Cr2_TSVD200_minmaxit1"
#EZFIO_file = "Cr2_TSVD30_it2"
E_toadd = 64.8242130309350
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
ezfio.set_file(EZFIO_file)
n_svd = ezfio.get_spindeterminants_n_svd_coefs()
psi_svd_coeff = np.array(ezfio.get_spindeterminants_psi_svd_coefs())
print(" ")
print(" Today's date:", datetime.now() )
print(" EZFIO file = {}".format(EZFIO_file))
print(" n_svd = {}\n".format(n_svd) )
t_read = time.time()
print(' getting QMCCHEM results from {}'.format(EZFIO_file) )
results = subprocess.check_output(['qmcchem', 'result', EZFIO_file], encoding='UTF-8')
print(' getting results after {} minutes \n'.format( (time.time()-t_read)/60. ))
if( len(results)<100):
print(' result is empty \n')
exit()
Eloc, ErrEloc = get_energy()
print(' Eloc = {} +/- {}'.format(Eloc, ErrEloc))
print(' {} <= Eloc <= {}'.format(Eloc-ErrEloc,Eloc+ErrEloc))
#print(' initial svd coeff = {}\n'.format(psi_svd_coeff))
save_SVD_QMCmat = True
#save_SVD_QMCmat = False
print('')
E_svd, sigma_svd = get_Esvd()
print(' svd enegry = {}'.format(E_svd) )
sigma_svd = sigma_svd * np.sign(sigma_svd[0])
#print(' svd coeff = {}'.format(sigma_svd))
print('')
# ___________________________________________________________________________
# ___________________________________________________________________________
#
save_to_EZFIO = 'svd_QMC'
#save_to_EZFIO = ''
if( save_to_EZFIO == 'svd_QMC' ):
ezfio.set_spindeterminants_psi_svd_coefs( sigma_svd )
direc_svdcoeff = EZFIO_file + '/spindeterminants/psi_svd_coefs.gz'
print(' {} is modified'.format(direc_svdcoeff) )
else:
print(' exit with no modifications in {} EZFIO'.format(EZFIO_file))
# ___________________________________________________________________________
# ___________________________________________________________________________
#
print("end after {:.3f} minutes".format((time.time()-t0)/60.) )
# !!!
# !!!
~

View File

@ -0,0 +1,225 @@
# !!!
import sys, os
QMCCHEM_PATH=os.environ["QMCCHEM_PATH"]
sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/")
from ezfio import ezfio
from math import sqrt
from datetime import datetime
import time
import numpy as np
import subprocess
from scipy.linalg import eig, eigh
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_energy():
buffer = subprocess.check_output(['qmcchem', 'result', '-e', 'e_loc', EZFIO_file], encoding='UTF-8')
if buffer.strip() != "":
buffer = buffer.splitlines()[-1]
_, energy, error = [float(x) for x in buffer.split()]
return energy, error
else:
return None, None
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Ci_h_matrix_modifsvd():
Ci_h_matrix_modifsvd = np.zeros( (n_modifsvd,n_modifsvd) )
SErr_H = np.zeros( (n_modifsvd,n_modifsvd) )
beg_Ci_h_matrix_modifsvd = results.find('Ci_h_matrix_modifsvd : [ ') + len( 'Ci_h_matrix_modifsvd : [ ' )
end_Ci_h_matrix_modifsvd = len(results)
Ci_h_matrix_modifsvd_buf = results[beg_Ci_h_matrix_modifsvd:end_Ci_h_matrix_modifsvd]
Ci_h_matrix_modifsvd_buf = Ci_h_matrix_modifsvd_buf.split( '\n' )
for iline in range(1, n_modifsvd**2+1):
line = Ci_h_matrix_modifsvd_buf[iline].split()
indc = int( line[0] )
errS = float( line[4] )
if( indc != iline ):
print(' Error in reading Ci_h_matrix_modifsvd')
print(' indc = {}'.format(indc) )
print(' iline = {}'.format(iline) )
break
else:
irow = indc % n_modifsvd
icol = indc // n_modifsvd
if( irow!=0 ):
Ci_h_matrix_modifsvd[irow-1][icol] = float( line[2] )
SErr_H [irow-1][icol] = float( line[4] )
else:
Ci_h_matrix_modifsvd[n_modifsvd-1][icol-1] = float( line[2] )
SErr_H [n_modifsvd-1][icol-1] = float( line[4] )
# !!!
# !!!
return(Ci_h_matrix_modifsvd,SErr_H)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Ci_overlap_matrix_modifsvd():
Ci_overlap_matrix_modifsvd = np.zeros( (n_modifsvd,n_modifsvd) )
SErr_O = np.zeros( (n_modifsvd,n_modifsvd) )
beg_Ci_overlap_matrix_modifsvd = results.find('Ci_overlap_matrix_modifsvd : [ ') + len( 'Ci_overlap_matrix_modifsvd : [ ' )
end_Ci_overlap_matrix_modifsvd = len(results)
Ci_overlap_matrix_modifsvd_buf = results[beg_Ci_overlap_matrix_modifsvd:end_Ci_overlap_matrix_modifsvd]
Ci_overlap_matrix_modifsvd_buf = Ci_overlap_matrix_modifsvd_buf.split( '\n' )
for iline in range(1, n_modifsvd**2+1):
line = Ci_overlap_matrix_modifsvd_buf[iline].split()
indc = int( line[0] )
errS = float( line[4] )
if( indc != iline ):
print(' Error in reading Ci_overlap_matrix_modifsvd')
print(' indc = {}'.format(indc))
print(' iline = {}'.format(iline))
break
else:
irow = indc % n_modifsvd
icol = indc // n_modifsvd
if( irow!=0 ):
Ci_overlap_matrix_modifsvd[irow-1][icol] = float( line[2] )
SErr_O [irow-1][icol] = float( line[4] )
else:
Ci_overlap_matrix_modifsvd[n_modifsvd-1][icol-1] = float( line[2] )
SErr_O [n_modifsvd-1][icol-1] = float( line[4] )
return(Ci_overlap_matrix_modifsvd,SErr_O)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def check_symmetric(a, tol=1e-3):
return np.all(np.abs(a-a.T) < tol)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Esvd():
Ci_h_matrix_modifsvd , SErr_H = get_Ci_h_matrix_modifsvd()
Ci_overlap_matrix_modifsvd, SErr_O = get_Ci_overlap_matrix_modifsvd()
if( save_compactSVD_QMCmat ):
with open('compactSVD_QMCmat.txt', 'a') as ff:
for i in range(n_modifsvd):
for j in range(n_modifsvd):
ff.write('{} {} {} {} {} {} \n'.format(i,j
, Ci_h_matrix_modifsvd[i,j] , SErr_H[i,j]
, Ci_overlap_matrix_modifsvd[i,j] , SErr_O[i,j] ))
# symmetrise and diagonalise
aa = Ci_h_matrix_modifsvd
aa = 0.5*( aa + aa.T )
bb = Ci_overlap_matrix_modifsvd
eigvals_modifsvd, vr = eig(aa, bb, left=False, right=True, overwrite_a=True, overwrite_b=True,
check_finite=True, homogeneous_eigvals=False)
psi_tmp = psi_svd_coefs[0,0:n_modifsvd]
recouvre_modifsvd = np.abs(psi_tmp @ vr)
ind_gssvd = np.argmax(recouvre_modifsvd)
E_modifsvd = eigvals_modifsvd[ind_gssvd] + E_toadd
return( E_modifsvd, vr[:,ind_gssvd] )
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
if __name__ == '__main__':
t0 = time.time()
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
#EZFIO_file = "Cr2_compactSVD30"
EZFIO_file = "Cr2_compactSVD30_it1"
E_toadd = 64.8242130309350
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
ezfio.set_file(EZFIO_file)
n_svd = ezfio.get_spindeterminants_n_svd_coefs()
n_modifsvd = ezfio.get_spindeterminants_n_modifsvd_coefs()
psi_svd_coefs = np.array(ezfio.get_spindeterminants_psi_svd_coefs())
print(" ")
print(" Today's date:", datetime.now() )
print(" EZFIO file = {}".format(EZFIO_file))
print(" n_svd = {}".format(n_svd) )
print(" n_modifsvd = {}\n".format(n_modifsvd) )
t_read = time.time()
print(' getting QMCCHEM results from {}'.format(EZFIO_file) )
results = subprocess.check_output(['qmcchem', 'result', EZFIO_file], encoding='UTF-8')
print(' getting results after {} minutes \n'.format( (time.time()-t_read)/60. ))
if( len(results)<100):
print(' result is empty \n')
exit()
Eloc, ErrEloc = get_energy()
print(' Eloc = {} +/- {}'.format(Eloc, ErrEloc))
print(' {} <= Eloc <= {}'.format(Eloc-ErrEloc,Eloc+ErrEloc))
#print(' initial svd coeff = {}\n'.format(psi_svd_coefs))
save_compactSVD_QMCmat = True
print('')
E_compactsvd, sigma_compactsvd = get_Esvd()
print(' compact svd enegry = {}'.format(E_compactsvd) )
sigma_compactsvd = sigma_compactsvd * np.sign(sigma_compactsvd[0])
print(' compact svd coeff = {}\n'.format(sigma_compactsvd))
#print(' compact svd factor = {}\n'.format(sigma_compactsvd[n_modifsvd-1]))
# ___________________________________________________________________________
# ___________________________________________________________________________
#
#save_to_EZFIO = 'compactsvd_QMC'
save_to_EZFIO = ''
if( save_to_EZFIO == 'compactsvd_QMC' ):
ezfio_sigma_svd = np.zeros((n_svd))
for i in range(n_modifsvd-1):
ezfio_sigma_svd[i] = sigma_compactsvd[i]
for i in range(n_modifsvd-1, n_svd):
ezfio_sigma_svd[i] = psi_svd_coefs[0,i] * sigma_compactsvd[n_modifsvd-1]
#print(' new svd coeff = {}\n'.format(ezfio_sigma_svd))
ezfio.set_spindeterminants_psi_svd_coefs( ezfio_sigma_svd )
direc_svdcoeff = EZFIO_file + '/spindeterminants/psi_svd_coefs.gz'
print(' {} is modified'.format(direc_svdcoeff) )
else:
print(' no modifications has been done in {}'.format(EZFIO_file))
# ___________________________________________________________________________
# ___________________________________________________________________________
print("end after {:.3f} minutes".format((time.time()-t0)/60.) )
# !!!
# !!!
~
~

View File

@ -0,0 +1,175 @@
# !!!
import sys, os
QMCCHEM_PATH=os.environ["QMCCHEM_PATH"]
sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/")
from ezfio import ezfio
from math import sqrt
from datetime import datetime
import time
import numpy as np
import subprocess
from scipy.linalg import eig, eigh
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_energy():
buffer = subprocess.check_output(['qmcchem', 'result', '-e', 'e_loc', EZFIO_file], encoding='UTF-8')
if buffer.strip() != "":
buffer = buffer.splitlines()[-1]
_, energy, error = [float(x) for x in buffer.split()]
return energy, error
else:
return None, None
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Ci_h_matrix_svd():
Ci_h_matrix_svd = np.zeros( (n_svd,n_svd) )
SErr_H = np.zeros( (n_svd,n_svd) )
f = open(VMCmat_file, 'r')
Lines = f.readlines()
for line in Lines:
line = line.split()
ii = int ( line[0] )
jj = int ( line[1] )
Ci_h_matrix_svd[ii][jj] = float( line[2] )
SErr_H [ii][jj] = float( line[3] )
return(Ci_h_matrix_svd,SErr_H)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Ci_overlap_matrix_svd():
Ci_overlap_matrix_svd = np.zeros( (n_svd,n_svd) )
SErr_O = np.zeros( (n_svd,n_svd) )
f = open(VMCmat_file, 'r')
Lines = f.readlines()
for line in Lines:
line = line.split()
ii = int ( line[0] )
jj = int ( line[1] )
Ci_overlap_matrix_svd[ii][jj] = float( line[4] )
SErr_O [ii][jj] = float( line[5] )
return(Ci_overlap_matrix_svd,SErr_O)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def check_symmetric(a, tol=1e-3):
return np.all(np.abs(a-a.T) < tol)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Esvd():
# read CI_SVD matrices
Ci_h_matrix_svd , SErr_H = get_Ci_h_matrix_svd()
Ci_overlap_matrix_svd, SErr_O = get_Ci_overlap_matrix_svd()
#print( 'Ci_h_matrix_svd is symmetric ? {}' .format(check_symmetric(Ci_h_matrix_svd)) )
#print( 'Ci_overlap_matrix_svd is symmetric ? {}' .format(check_symmetric(Ci_overlap_matrix_svd)) )
# symmetrise and diagonalise
aa = Ci_h_matrix_svd
aa = 0.5*( aa + aa.T )
bb = Ci_overlap_matrix_svd
eigvals_svd, vr = eig(aa, bb, left=False, right=True, overwrite_a=True, overwrite_b=True,
check_finite=True, homogeneous_eigvals=False)
#print( eigvals_svd + E_toadd )
recouvre_svd = np.abs(psi_svd_coeff @ vr)
ind_gssvd = np.argmax(recouvre_svd)
E_svd = eigvals_svd[ind_gssvd] + E_toadd
return( E_svd, vr[:,ind_gssvd] )
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
if __name__ == '__main__':
t0 = time.time()
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
#EZFIO_file = "Cr2_TSVD30"
#EZFIO_file = "Cr2_TSVD100"
#EZFIO_file = "Cr2_TSVD200"
#EZFIO_file = "Cr2_TSVD924"
#EZFIO_file = "Cr2_TSVD924_1"
#EZFIO_file = "Cr2_TSVD30_it1"
#EZFIO_file = "Cr2_TSVD100_it1"
#EZFIO_file = "Cr2_TSVD200_it1"
EZFIO_file = "Cr2_TSVD924_1_it1"
#EZFIO_file = "Cr2_TSVD200_minmaxit1"
#EZFIO_file = "Cr2_TSVD30_it2"
E_toadd = 64.8242130309350
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
ezfio.set_file(EZFIO_file)
n_svd = ezfio.get_spindeterminants_n_svd_coefs()
psi_svd_coeff = np.array(ezfio.get_spindeterminants_psi_svd_coefs())
print(" ")
print(" Today's date:", datetime.now() )
print(" EZFIO file = {}".format(EZFIO_file))
print(" n_svd = {}\n".format(n_svd) )
#VMCmat_list = [ 'SVD_QMCmat_FSVD_2b.txt' , 'SVD_QMCmat_FSVD_3b.txt' , 'SVD_QMCmat_FSVD_0.txt' ]
#VMCmat_list = [ 'SVD_QMCmat_FSVD_2b_1.txt', 'SVD_QMCmat_FSVD_3b_1.txt'
# , 'SVD_QMCmat_FSVD_4b_1.txt', 'SVD_QMCmat_FSVD_5b_1.txt'
# , 'SVD_QMCmat_FSVD_1.txt' ]
#for VMCmat_file in VMCmat_list:
# print(" SVD matrices file = {}".format(VMCmat_file))
# E_svd, sigma_svd = get_Esvd()
# print(' svd enegry = {} \n'.format(E_svd) )
VMCmat_file = 'SVD_QMCmat_FSVD_4b_1.txt'
print(" SVD matrices file = {}".format(VMCmat_file))
E_svd, sigma_svd = get_Esvd()
sigma_svd = sigma_svd * np.sign(sigma_svd[0])
print(' svd coeff = {}'.format(sigma_svd))
# ___________________________________________________________________________
# ___________________________________________________________________________
#
#save_to_EZFIO = 'svd_QMC'
save_to_EZFIO = ''
if( save_to_EZFIO == 'svd_QMC' ):
ezfio.set_spindeterminants_psi_svd_coefs( sigma_svd )
direc_svdcoeff = EZFIO_file + '/spindeterminants/psi_svd_coefs.gz'
print(' {} is modified'.format(direc_svdcoeff) )
else:
pass
# ___________________________________________________________________________
# ___________________________________________________________________________
print("end after {:.3f} minutes".format((time.time()-t0)/60.) )
# !!!
# !!!
~

View File

@ -0,0 +1,173 @@
# !!!
import sys, os
QMCCHEM_PATH=os.environ["QMCCHEM_PATH"]
sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/")
from ezfio import ezfio
from math import sqrt
from datetime import datetime
import time
import numpy as np
import subprocess
from scipy.linalg import eig, eigh
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_energy():
buffer = subprocess.check_output(['qmcchem', 'result', '-e', 'e_loc', EZFIO_file], encoding='UTF-8')
if buffer.strip() != "":
buffer = buffer.splitlines()[-1]
_, energy, error = [float(x) for x in buffer.split()]
return energy, error
else:
return None, None
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Ci_h_matrix_modifsvd():
Ci_h_matrix_modifsvd = np.zeros( (n_modifsvd,n_modifsvd) )
SErr_H = np.zeros( (n_modifsvd,n_modifsvd) )
f = open(compactVMCmat_file, 'r')
Lines = f.readlines()
for line in Lines:
line = line.split()
ii = int ( line[0] )
jj = int ( line[1] )
Ci_h_matrix_modifsvd[ii][jj] = float( line[2] )
SErr_H [ii][jj] = float( line[3] )
return(Ci_h_matrix_modifsvd,SErr_H)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Ci_overlap_matrix_modifsvd():
Ci_overlap_matrix_modifsvd = np.zeros( (n_modifsvd,n_modifsvd) )
SErr_O = np.zeros( (n_modifsvd,n_modifsvd) )
f = open(compactVMCmat_file, 'r')
Lines = f.readlines()
for line in Lines:
line = line.split()
ii = int ( line[0] )
jj = int ( line[1] )
Ci_overlap_matrix_modifsvd[ii][jj] = float( line[4] )
SErr_O [ii][jj] = float( line[5] )
return(Ci_overlap_matrix_modifsvd,SErr_O)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def check_symmetric(a, tol=1e-3):
return np.all(np.abs(a-a.T) < tol)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Esvd():
Ci_h_matrix_modifsvd , SErr_H = get_Ci_h_matrix_modifsvd()
Ci_overlap_matrix_modifsvd, SErr_O = get_Ci_overlap_matrix_modifsvd()
# symmetrise and diagonalise
aa = Ci_h_matrix_modifsvd
aa = 0.5*( aa + aa.T )
bb = Ci_overlap_matrix_modifsvd
eigvals_modifsvd, vr = eig(aa, bb, left=False, right=True, overwrite_a=True, overwrite_b=True,
check_finite=True, homogeneous_eigvals=False)
psi_tmp = psi_svd_coefs[0,0:n_modifsvd]
recouvre_modifsvd = np.abs(psi_tmp @ vr)
ind_gssvd = np.argmax(recouvre_modifsvd)
E_modifsvd = eigvals_modifsvd[ind_gssvd] + E_toadd
return( E_modifsvd, vr[:,ind_gssvd] )
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
if __name__ == '__main__':
t0 = time.time()
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
#EZFIO_file = "Cr2_compactSVD30"
#EZFIO_file = "Cr2_compactSVD30_it1"
EZFIO_file = "Cr2_compactSVD30_it1_1"
E_toadd = 64.8242130309350
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
ezfio.set_file(EZFIO_file)
n_svd = ezfio.get_spindeterminants_n_svd_coefs()
n_modifsvd = ezfio.get_spindeterminants_n_modifsvd_coefs()
psi_svd_coefs = np.array(ezfio.get_spindeterminants_psi_svd_coefs())
print(" ")
print(" Today's date:", datetime.now() )
print(" EZFIO file = {}".format(EZFIO_file))
print(" n_svd = {}".format(n_svd) )
print(" n_modifsvd = {}\n".format(n_modifsvd) )
#print(' initial svd coeff = {}\n'.format(psi_svd_coefs))
compactVMCmat_list = [ 'compactSVD_QMCmat_1.txt' , 'compactSVD_QMCmat_2.txt' ]
for compactVMCmat_file in compactVMCmat_list:
print(" compactSVD matrices file = {}".format(compactVMCmat_file))
E_compactsvd, sigma_compactsvd = get_Esvd()
print(' compact svd enegry = {}'.format(E_compactsvd) )
print('')
compactVMCmat_file = 'compactSVD_QMCmat_1.txt'
print(" compactSVD matrices file = {}".format(compactVMCmat_file))
E_compactsvd, sigma_compactsvd = get_Esvd()
sigma_compactsvd = sigma_compactsvd * np.sign(sigma_compactsvd[0])
print(' compact svd enegry = {}'.format(E_compactsvd) )
print(' compact svd coeff = {}\n'.format(sigma_compactsvd))
print(' compact svd factor = {}\n'.format(sigma_compactsvd[n_modifsvd-1]))
# ___________________________________________________________________________
# ___________________________________________________________________________
#
#save_to_EZFIO = 'compactsvd_QMC'
save_to_EZFIO = ''
if( save_to_EZFIO == 'compactsvd_QMC' ):
ezfio_sigma_svd = np.zeros((n_svd))
for i in range(n_modifsvd-1):
ezfio_sigma_svd[i] = sigma_compactsvd[i]
for i in range(n_modifsvd-1, n_svd):
ezfio_sigma_svd[i] = psi_svd_coefs[0,i] * sigma_compactsvd[n_modifsvd-1]
#print(' new svd coeff = {}\n'.format(ezfio_sigma_svd))
ezfio.set_spindeterminants_psi_svd_coefs( ezfio_sigma_svd )
direc_svdcoeff = EZFIO_file + '/spindeterminants/psi_svd_coefs.gz'
print(' {} is modified'.format(direc_svdcoeff) )
else:
print(' no modifications has been done in {}'.format(EZFIO_file))
# ___________________________________________________________________________
# ___________________________________________________________________________
print("end after {:.3f} minutes".format((time.time()-t0)/60.) )
# !!!
# !!!
~

View File

@ -0,0 +1,131 @@
#!/usr/bin/env python
import numpy as np
import subprocess
import sys, os
import time
from datetime import datetime
QP_PATH=os.environ["QP_ROOT"]+"/external/ezfio/Python/"
sys.path.insert(0,QP_PATH)
from ezfio import ezfio
#____________________________________________________________________________________
#
def read_ci_dress_svd():
Ci_dress_svd_val = np.zeros((n_svd))
Ci_dress_svd_err = np.zeros((n_svd))
beg_read = results.find('Ci_dress_svd : [ ') + len( 'Ci_dress_svd : [ ' )
end_read = len(results)
vect_buf = results[beg_read:end_read]
vect_buf = vect_buf.split( '\n' )
for iline in range(1, n_svd+1):
line = vect_buf[iline].split()
# check
indc = int( line[0] )
if( indc != iline ):
print(' Error in reading Ci_dress_svd')
print(' indc = {}'.format(indc) )
print(' iline = {}'.format(iline) )
break
else:
Ci_dress_svd_val[indc-1] = float( line[2] )
Ci_dress_svd_err[indc-1] = float( line[4] )
# !!!
# !!!
# !!!
return(Ci_dress_svd_val,Ci_dress_svd_err)
#____________________________________________________________________________________
#____________________________________________________________________________________
#
def SVD_to_C():
d_svd = np.array(ezfio.get_spindeterminants_psi_svd_coefs())
U_svd = np.array(ezfio.get_spindeterminants_psi_svd_alpha())
V_svd = np.array(ezfio.get_spindeterminants_psi_svd_beta())
d_svd = d_svd[0,:]
U_svd = U_svd[0,:,:].T
V_svd = V_svd[0,:,:].T
C_mat_val = np.dot(U_svd,np.dot(np.diagflat(d_svd),V_svd.T))
n_det = ezfio.get_spindeterminants_n_det()
i_row = np.array(ezfio.get_spindeterminants_psi_coef_matrix_rows())
j_col = np.array(ezfio.get_spindeterminants_psi_coef_matrix_columns())
C_val = np.zeros((n_det))
for k in range(n_det):
i = i_row[k] - 1
j = j_col[k] - 1
C_val[k] = C_mat_val[i,j]
return(C_val)
#____________________________________________________________________________________
#____________________________________________________________________________________
#
def save_to_file(v_val, name_f):
with open(name_f, 'a') as ff:
for i in range(len(v_val)):
ff.write(' {} {}\n'.format(i, v_val[i]))
#____________________________________________________________________________________
if __name__ == '__main__':
t0 = time.time()
# _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
#
#EZFIO_file = sys.argv[1]
#EZFIO_file = "/home/aammar/qp2/src/svdwf/cr2_work/cr2_1p6_compactSVD50_DMC_fast"
EZFIO_file = "/home/aammar/qp2/src/svdwf/cr2_work/cr2_1p6_compactSVD50_DMC_fast_2"
#EZFIO_file = "/home/aammar/qp2/src/svdwf/cr2_work/cr2_1p6_compactSVD50_it1_DMC_fast"
#EZFIO_file = "/home/aammar/qp2/src/svdwf/cr2_work/cr2_1p6_TSVD50_DMC_fast"
#EZFIO_file = "/home/aammar/qp2/src/svdwf/cr2_work/cr2_1p6_TSVD50_it1_DMC_fast"
# _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ezfio.set_file(EZFIO_file)
n_svd = ezfio.get_spindeterminants_n_svd_coefs()
print(" ")
print(" Today's date:", datetime.now() )
print(" EZFIO file = {}".format(EZFIO_file))
print(" n_svd = {}\n".format(n_svd) )
if(n_svd <= 0):
print(" n_svd <=0")
break
C_val = SVD_to_C()
print(C_val)
#save_to_file(C_val, 'C_val.txt')
# _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
#
# SAVE TO EZFIO
#
ezfio.set_spindeterminants_psi_coef_matrix_values( C_val )
ezfio.set_spindeterminants_n_svd_coefs(-1)
# _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
#
print("end after {:.3f} minutes".format((time.time()-t0)/60.) )
# !!!
# !!!

View File

@ -0,0 +1,203 @@
program delta_2bTSVD_v0
BEGIN_DOC
! !!!
END_DOC
implicit none
read_wf = .True.
touch read_wf
call run()
end
subroutine run()
implicit none
integer :: ii, ii_i, ii_j, k, l
integer :: na, nb, nsvd
integer :: n_TSVD
integer :: n_tmp
double precision, allocatable :: U(:,:), V(:,:)
double precision, allocatable :: delta0_det(:), delta1_det(:)
double precision, allocatable :: delta_O(:,:), delta_D(:)
double precision, allocatable :: delta_tmp(:)
double precision :: t1, t2
na = n_det_alpha_unique
nb = n_det_beta_unique
call ezfio_get_spindeterminants_n_svd_coefs(nsvd)
allocate( u(na,nsvd) , v(nb,nsvd) )
print *, ' start read SVD vectors'
call wall_time(t1)
call ezfio_get_spindeterminants_psi_svd_alpha(U)
call ezfio_get_spindeterminants_psi_svd_beta (V)
call wall_time(t2)
print *, ' end read SVD vectors after (min)', (t2-t1)/60.d0
allocate( delta0_det(N_det) )
call ezfio_get_dmc_dress_dmc_delta_h(delta0_det)
! ---------------------------------------------
! ---------------------------------------------
! parameters
!
!n_TSVD = 100
read *, n_TSVD
print *, " --- delta_2bTSVD_v0 ---"
print *, " n_TSVD =", n_TSVD
print *, " tot =", n_TSVD * n_TSVD + &
nsvd - n_TSVD
!
! ---------------------------------------------
! ---------------------------------------------
! ---------------------------------------------
n_tmp = n_TSVD + 1
allocate( delta_O(1:n_TSVD,1:n_TSVD) )
allocate( delta_D(n_tmp:nsvd) )
call obtenir_deltaSVD_2b(nsvd, n_TSVD, U, V, delta0_det, delta_O, delta_D)
deallocate( delta0_det )
allocate( delta1_det(N_det) )
delta1_det(1:N_det) = 0.d0
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(nsvd, n_TSVD, n_tmp, N_det, U, V, delta1_det, delta_O, delta_D &
!$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) &
!$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp)
allocate( delta_tmp(N_det) )
delta_tmp(1:N_det) = 0.d0
!$OMP DO
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
do l = 1, n_TSVD
delta_tmp(ii) = delta_tmp(ii) + U(ii_i,l) * V(ii_j,l) * delta_D(l)
do k = 1, n_TSVD
delta_tmp(ii) = delta_tmp(ii) + U(ii_i,k) * V(ii_j,l) * delta_O(k,l)
enddo
enddo
enddo
!$OMP END DO
!$OMP CRITICAL
do ii = 1, N_det
delta1_det(ii) = delta1_det(ii) + delta_tmp(ii)
enddo
!$OMP END CRITICAL
deallocate( delta_tmp )
!$OMP END PARALLEL
deallocate( U , V )
deallocate( delta_O , delta_D )
call ezfio_set_dmc_dress_dmc_delta_h(delta1_det)
deallocate( delta1_det )
end
! _______________________________________________________________________________________________________
!
! [ delta_SVD ]_kl = < dup_SVD ddn_SVD | H_tilde - H | psi >
! = \sum_{i,j} U_{i,k} V_{j,l} < dup_i ddn_j | H_tilde - H | psi >
!
subroutine obtenir_deltaSVD_2b(nsvd, n_TSVD, U, V, delta0_det, delta_O, delta_D)
implicit none
integer, intent(in) :: nsvd, n_TSVD
double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd)
double precision, intent(in) :: delta0_det(N_det)
double precision, intent(out) :: delta_O(1:n_TSVD,1:n_TSVD)
double precision, intent(out) :: delta_D(n_TSVD+1:nsvd)
integer :: n_tmp
integer :: k, l, ii, ii_i, ii_j
double precision, allocatable :: delta_tmp(:,:), delta1d_tmp(:)
n_tmp = n_TSVD + 1
! --------------------------------------------------------------------------------
!
delta_O(1:n_TSVD,1:n_TSVD) = 0.d0
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(n_TSVD, N_det, U, V, delta0_det, delta_O &
!$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) &
!$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp)
allocate( delta_tmp(1:n_TSVD,1:n_TSVD) )
delta_tmp(1:n_TSVD,1:n_TSVD) = 0.d0
!$OMP DO
do l = 1, n_TSVD
do k = 1, n_TSVD
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
delta_tmp(k,l) = delta_tmp(k,l) + U(ii_i,k) * V(ii_j,l) * delta0_det(ii)
enddo
enddo
enddo
!$OMP END DO
!$OMP CRITICAL
do l = 1, n_TSVD
do k = 1, n_TSVD
delta_O(k,l) = delta_O(k,l) + delta_tmp(k,l)
enddo
enddo
!$OMP END CRITICAL
deallocate(delta_tmp)
!$OMP END PARALLEL
!
! --------------------------------------------------------------------------------
! --------------------------------------------------------------------------------
!
delta_D(n_tmp:nsvd) = 0.d0
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(nsvd, n_tmp, N_det, U, V, delta0_det, delta_D &
!$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) &
!$OMP PRIVATE(l, ii, ii_i, ii_j, delta1d_tmp)
allocate( delta1d_tmp(n_tmp:nsvd) )
delta1d_tmp(n_tmp:nsvd) = 0.d0
!$OMP DO
do l = n_tmp, nsvd
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
delta1d_tmp(l) = delta1d_tmp(l) + U(ii_i,l) * V(ii_j,l) * delta0_det(ii)
enddo
enddo
!$OMP END DO
!$OMP CRITICAL
do l = n_tmp, nsvd
delta_D(l) = delta_D(l) + delta1d_tmp(l)
enddo
!$OMP END CRITICAL
deallocate(delta1d_tmp)
!$OMP END PARALLEL
!
! --------------------------------------------------------------------------------
return
end subroutine obtenir_deltaSVD_2b
! _______________________________________________________________________________________________________
! _______________________________________________________________________________________________________

View File

@ -0,0 +1,164 @@
program delta_3bSVD_v0
BEGIN_DOC
! !!!
END_DOC
implicit none
read_wf = .True.
touch read_wf
call run()
end
subroutine run()
implicit none
integer :: ii, ii_i, ii_j, k, l
integer :: na, nb, nsvd
integer :: n_tmp, n_TSVD
double precision, allocatable :: U(:,:), V(:,:), S(:)
double precision, allocatable :: delta0_det(:), delta1_det(:), deltaSVD_kl(:,:)
double precision, allocatable :: delta_tmp(:)
na = n_det_alpha_unique
nb = n_det_beta_unique
! read SVD vectors
call ezfio_get_spindeterminants_n_svd_coefs(nsvd)
allocate( U(na,nsvd), S(nsvd), V(nb,nsvd) )
call ezfio_get_spindeterminants_psi_svd_alpha(U)
call ezfio_get_spindeterminants_psi_svd_beta (V)
call ezfio_get_spindeterminants_psi_svd_coefs(S)
allocate( delta0_det(N_det) )
call ezfio_get_dmc_dress_dmc_delta_h(delta0_det)
allocate( deltaSVD_kl(nsvd,nsvd) )
deltaSVD_kl(1:nsvd,1:nsvd) = 0.d0
call obtenir_deltaSVD_kl(nsvd, U, V, delta0_det, deltaSVD_kl)
! ---------------------------------------------
! parameters
n_TSVD = 4
! ---------------------------------------------
n_tmp = n_TSVD + 1
! [ delta ]_mn = \sum_{k,l} U_{m,k} delta_SVD_{k,l} V_{n,l}
allocate( delta1_det(N_det) )
delta1_det(1:N_det) = 0.d0
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(nsvd, n_TSVD, n_tmp, N_det, U, V, deltaSVD_kl, delta1_det &
!$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) &
!$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp)
allocate( delta_tmp(N_det) )
delta_tmp(1:N_det) = 0.d0
!$OMP DO
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
do l = 1, n_TSVD
do k = 1, nsvd
delta_tmp(ii) = delta_tmp(ii) + U(ii_i,k) * V(ii_j,l) * deltaSVD_kl(k,l)
enddo
enddo
do l = n_tmp, nsvd
do k = 1, n_TSVD
delta_tmp(ii) = delta_tmp(ii) + U(ii_i,k) * V(ii_j,l) * deltaSVD_kl(k,l)
enddo
enddo
enddo
!$OMP END DO
!$OMP CRITICAL
do ii = 1, N_det
delta1_det(ii) = delta1_det(ii) + delta_tmp(ii)
enddo
!$OMP END CRITICAL
deallocate( delta_tmp )
!$OMP END PARALLEL
call ezfio_set_dmc_dress_dmc_delta_h(delta1_det)
deallocate( U , S , V )
deallocate( deltaSVD_kl )
deallocate( delta0_det , delta1_det )
end
! _______________________________________________________________________________________________________
!
! [ delta_SVD ]_kl = < dup_SVD ddn_SVD | H_tilde - H | psi >
! = \sum_{i,j} U_{i,k} V_{j,l} < dup_i ddn_j | H_tilde - H | psi >
!
subroutine obtenir_deltaSVD_kl(nsvd, U, V, delta0_det, deltaSVD_kl)
implicit none
integer, intent(in) :: nsvd
double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd)
double precision, intent(in) :: delta0_det(N_det)
double precision, intent(out) :: deltaSVD_kl(nsvd,nsvd)
integer :: k, l, ii, ii_i, ii_j
double precision, allocatable :: delta_tmp(:,:)
deltaSVD_kl(1:nsvd,1:nsvd) = 0.d0
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(nsvd, N_det, U, V, delta0_det, deltaSVD_kl &
!$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) &
!$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp)
allocate( delta_tmp(nsvd,nsvd) )
delta_tmp(1:nsvd,1:nsvd) = 0.d0
!$OMP DO
do l = 1, nsvd
do k = 1, nsvd
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
delta_tmp(k,l) = delta_tmp(k,l) + U(ii_i,k) * V(ii_j,l) * delta0_det(ii)
enddo
enddo
enddo
!$OMP END DO
!$OMP CRITICAL
do l = 1, nsvd
do k = 1, nsvd
deltaSVD_kl(k,l) = deltaSVD_kl(k,l) + delta_tmp(k,l)
enddo
enddo
!$OMP END CRITICAL
deallocate(delta_tmp)
!$OMP END PARALLEL
return
end subroutine obtenir_deltaSVD_kl
! _______________________________________________________________________________________________________
! _______________________________________________________________________________________________________

View File

@ -0,0 +1,195 @@
program delta_3bSVD_v1
BEGIN_DOC
! !!!
END_DOC
implicit none
read_wf = .True.
touch read_wf
call run()
end
subroutine run()
implicit none
integer :: ii, ii_i, ii_j, k, l
integer :: na, nb, nsvd
integer :: n_tmp, n_TSVD
double precision, allocatable :: U(:,:), V(:,:), S(:)
double precision, allocatable :: delta0_det(:), delta1_det(:)
double precision, allocatable :: deltaSVD1_kl(:,:), deltaSVD2_kl(:,:)
double precision, allocatable :: delta_tmp(:)
na = n_det_alpha_unique
nb = n_det_beta_unique
call ezfio_get_spindeterminants_n_svd_coefs(nsvd)
! read SVD vectors
allocate( u(na,nsvd) , v(nb,nsvd) )
call ezfio_get_spindeterminants_psi_svd_alpha(U)
call ezfio_get_spindeterminants_psi_svd_beta (V)
! allocate( s(nsvd) )
! call ezfio_get_spindeterminants_psi_svd_coefs(S)
allocate( delta0_det(N_det) )
call ezfio_get_dmc_dress_dmc_delta_h(delta0_det)
! ---------------------------------------------
! parameters
n_TSVD = 50
print *, " --- delta_3bSVD_v1 ---"
print *, " n_TSVD =", n_TSVD
print *, " tot =", nsvd * n_TSVD + &
(nsvd-n_TSVD)*n_TSVD
!
! ---------------------------------------------
n_tmp = n_TSVD + 1
allocate( deltaSVD1_kl(1:nsvd,1:n_TSVD) , deltaSVD2_kl(1:n_TSVD,n_tmp:nsvd) )
call obtenir_deltaSVD_3b(nsvd, n_TSVD, U, V, delta0_det, deltaSVD1_kl, deltaSVD2_kl)
deallocate( delta0_det )
! [ delta ]_mn = \sum_{k,l} U_{m,k} delta_SVD_{k,l} V_{n,l}
allocate( delta1_det(N_det) )
delta1_det(1:N_det) = 0.d0
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(nsvd, n_TSVD, n_tmp, N_det, U, V, delta1_det, deltaSVD1_kl &
!$OMP , deltaSVD2_kl, psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) &
!$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp)
allocate( delta_tmp(N_det) )
delta_tmp(1:N_det) = 0.d0
!$OMP DO
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
do l = 1, n_TSVD
do k = 1, nsvd
delta_tmp(ii) = delta_tmp(ii) + U(ii_i,k) * V(ii_j,l) * deltaSVD1_kl(k,l)
enddo
enddo
do l = n_tmp, nsvd
do k = 1, n_TSVD
delta_tmp(ii) = delta_tmp(ii) + U(ii_i,k) * V(ii_j,l) * deltaSVD2_kl(k,l)
enddo
enddo
enddo
!$OMP END DO
!$OMP CRITICAL
do ii = 1, N_det
delta1_det(ii) = delta1_det(ii) + delta_tmp(ii)
enddo
!$OMP END CRITICAL
deallocate( delta_tmp )
!$OMP END PARALLEL
! deallocate( S )
deallocate( U , V )
deallocate( deltaSVD1_kl, deltaSVD2_kl )
call ezfio_set_dmc_dress_dmc_delta_h(delta1_det)
deallocate( delta1_det )
end
! _______________________________________________________________________________________________________
!
! [ delta_SVD ]_kl = < dup_SVD ddn_SVD | H_tilde - H | psi >
! = \sum_{i,j} U_{i,k} V_{j,l} < dup_i ddn_j | H_tilde - H | psi >
!
subroutine obtenir_deltaSVD_3b(nsvd, n_TSVD, U, V, delta0_det, deltaSVD1_kl, deltaSVD2_kl)
implicit none
integer, intent(in) :: nsvd, n_TSVD
double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd)
double precision, intent(in) :: delta0_det(N_det)
double precision, intent(out) :: deltaSVD1_kl(1:nsvd,1:n_TSVD)
double precision, intent(out) :: deltaSVD2_kl(1:n_TSVD,n_TSVD+1:nsvd)
integer :: n_tmp
integer :: k, l, ii, ii_i, ii_j
double precision, allocatable :: delta_tmp(:,:)
n_tmp = n_TSVD + 1
deltaSVD1_kl(1:nsvd,1:n_TSVD) = 0.d0
deltaSVD2_kl(1:n_TSVD,n_tmp:nsvd) = 0.d0
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(nsvd, n_TSVD, N_det, U, V, delta0_det, deltaSVD1_kl &
!$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) &
!$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp)
allocate( delta_tmp(1:nsvd,1:n_TSVD) )
delta_tmp(1:nsvd,1:n_TSVD) = 0.d0
!$OMP DO
do l = 1, n_TSVD
do k = 1, nsvd
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
delta_tmp(k,l) = delta_tmp(k,l) + U(ii_i,k) * V(ii_j,l) * delta0_det(ii)
enddo
enddo
enddo
!$OMP END DO
!$OMP CRITICAL
do l = 1, n_TSVD
do k = 1, nsvd
deltaSVD1_kl(k,l) = deltaSVD1_kl(k,l) + delta_tmp(k,l)
enddo
enddo
!$OMP END CRITICAL
deallocate(delta_tmp)
!$OMP END PARALLEL
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(nsvd, n_TSVD, n_tmp, N_det, U, V, delta0_det, deltaSVD2_kl &
!$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) &
!$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp)
allocate( delta_tmp(1:n_TSVD,n_tmp:nsvd) )
delta_tmp(1:n_TSVD,n_tmp:nsvd) = 0.d0
!$OMP DO
do l = n_tmp, nsvd
do k = 1, n_TSVD
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
delta_tmp(k,l) = delta_tmp(k,l) + U(ii_i,k) * V(ii_j,l) * delta0_det(ii)
enddo
enddo
enddo
!$OMP END DO
!$OMP CRITICAL
do l = n_tmp, nsvd
do k = 1, n_TSVD
deltaSVD2_kl(k,l) = deltaSVD2_kl(k,l) + delta_tmp(k,l)
enddo
enddo
!$OMP END CRITICAL
deallocate(delta_tmp)
!$OMP END PARALLEL
return
end subroutine obtenir_deltaSVD_3b
! _______________________________________________________________________________________________________
! _______________________________________________________________________________________________________

View File

@ -0,0 +1,305 @@
program delta_4bTSVD_v0
BEGIN_DOC
! !!!
END_DOC
implicit none
read_wf = .True.
touch read_wf
call run()
end
subroutine run()
implicit none
integer :: ii, ii_i, ii_j, k, l
integer :: na, nb, nsvd
integer :: n_TSVD, La, lla, Lb, llb
integer :: n_tmp
double precision, allocatable :: U(:,:), V(:,:)
double precision, allocatable :: delta0_det(:), delta1_det(:)
double precision, allocatable :: delta_O(:,:), delta_D(:), delta_A(:,:), delta_B(:,:)
double precision, allocatable :: delta_tmp(:)
double precision :: t1, t2
na = n_det_alpha_unique
nb = n_det_beta_unique
call ezfio_get_spindeterminants_n_svd_coefs(nsvd)
allocate( u(na,nsvd) , v(nb,nsvd) )
print *, ' start read SVD vectors'
call wall_time(t1)
call ezfio_get_spindeterminants_psi_svd_alpha(U)
call ezfio_get_spindeterminants_psi_svd_beta (V)
call wall_time(t2)
print *, ' end read SVD vectors after (min)', (t2-t1)/60.d0
allocate( delta0_det(N_det) )
call ezfio_get_dmc_dress_dmc_delta_h(delta0_det)
! ---------------------------------------------
! ---------------------------------------------
! parameters
!
!n_TSVD = 100
read *, n_TSVD
!La = nsvd
!lla = 3
read *, La
read *, lla
!Lb = nsvd
!llb = 3
read *, Lb
read *, llb
print *, " --- delta_4bTSVD_v0 ---"
print *, " n_TSVD =", n_TSVD
print *, " La =", La
print *, " lla =", lla
print *, " Lb =", Lb
print *, " llb =", llb
print *, " tot =", (La-n_TSVD)*lla + &
(Lb-n_TSVD)*llb + &
n_TSVD * n_TSVD + &
nsvd - n_TSVD
!
! ---------------------------------------------
! ---------------------------------------------
! ---------------------------------------------
n_tmp = n_TSVD + 1
allocate( delta_O(1:n_TSVD,1:n_TSVD) )
allocate( delta_A(n_tmp:La,1:lla) )
allocate( delta_B(1:llb,n_tmp:Lb) )
allocate( delta_D(n_tmp:nsvd) )
call obtenir_deltaSVD_4b( nsvd, n_TSVD, La, lla, Lb, llb, U, V, delta0_det &
, delta_O, delta_A, delta_B, delta_D )
deallocate( delta0_det )
allocate( delta1_det(N_det) )
delta1_det(1:N_det) = 0.d0
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(nsvd, n_TSVD, n_tmp, La, lla, Lb, llb, N_det, U, V &
!$OMP , delta1_det, delta_O, delta_D, delta_A, delta_B &
!$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) &
!$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp)
allocate( delta_tmp(N_det) )
delta_tmp(1:N_det) = 0.d0
!$OMP DO
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
do l = 1, n_TSVD
delta_tmp(ii) = delta_tmp(ii) + U(ii_i,l) * V(ii_j,l) * delta_D(l)
do k = 1, n_TSVD
delta_tmp(ii) = delta_tmp(ii) + U(ii_i,k) * V(ii_j,l) * delta_O(k,l)
enddo
enddo
do l = 1, lla
do k = n_tmp, La
delta_tmp(ii) = delta_tmp(ii) + U(ii_i,k) * V(ii_j,l) * delta_A(k,l)
enddo
enddo
do l = n_tmp, Lb
do k = 1, llb
delta_tmp(ii) = delta_tmp(ii) + U(ii_i,k) * V(ii_j,l) * delta_B(k,l)
enddo
enddo
enddo
!$OMP END DO
!$OMP CRITICAL
do ii = 1, N_det
delta1_det(ii) = delta1_det(ii) + delta_tmp(ii)
enddo
!$OMP END CRITICAL
deallocate( delta_tmp )
!$OMP END PARALLEL
deallocate( U , V )
deallocate( delta_O, delta_A, delta_B, delta_D )
call ezfio_set_dmc_dress_dmc_delta_h(delta1_det)
deallocate( delta1_det )
end
! _______________________________________________________________________________________________________
!
! [ delta_SVD ]_kl = < dup_SVD ddn_SVD | H_tilde - H | psi >
! = \sum_{i,j} U_{i,k} V_{j,l} < dup_i ddn_j | H_tilde - H | psi >
!
subroutine obtenir_deltaSVD_4b( nsvd, n_TSVD, La, lla, Lb, llb, U, V, delta0_det &
, delta_O, delta_A, delta_B, delta_D )
implicit none
integer, intent(in) :: nsvd, n_TSVD, La, lla, Lb, llb
double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd)
double precision, intent(in) :: delta0_det(N_det)
double precision, intent(out) :: delta_O(1:n_TSVD,1:n_TSVD)
double precision, intent(out) :: delta_A(n_TSVD+1:La,1:lla)
double precision, intent(out) :: delta_B(1:llb,n_TSVD+1:Lb)
double precision, intent(out) :: delta_D(n_TSVD+1:nsvd)
integer :: n_tmp
integer :: k, l, ii, ii_i, ii_j
double precision, allocatable :: delta_tmp(:,:), delta1d_tmp(:)
n_tmp = n_TSVD + 1
! --------------------------------------------------------------------------------
!
delta_O(1:n_TSVD,1:n_TSVD) = 0.d0
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(n_TSVD, N_det, U, V, delta0_det, delta_O &
!$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) &
!$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp)
allocate( delta_tmp(1:n_TSVD,1:n_TSVD) )
delta_tmp(1:n_TSVD,1:n_TSVD) = 0.d0
!$OMP DO
do l = 1, n_TSVD
do k = 1, n_TSVD
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
delta_tmp(k,l) = delta_tmp(k,l) + U(ii_i,k) * V(ii_j,l) * delta0_det(ii)
enddo
enddo
enddo
!$OMP END DO
!$OMP CRITICAL
do l = 1, n_TSVD
do k = 1, n_TSVD
delta_O(k,l) = delta_O(k,l) + delta_tmp(k,l)
enddo
enddo
!$OMP END CRITICAL
deallocate(delta_tmp)
!$OMP END PARALLEL
!
! --------------------------------------------------------------------------------
! --------------------------------------------------------------------------------
!
delta_D(n_tmp:nsvd) = 0.d0
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(nsvd, n_tmp, N_det, U, V, delta0_det, delta_D &
!$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) &
!$OMP PRIVATE(l, ii, ii_i, ii_j, delta1d_tmp)
allocate( delta1d_tmp(n_tmp:nsvd) )
delta1d_tmp(n_tmp:nsvd) = 0.d0
!$OMP DO
do l = n_tmp, nsvd
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
delta1d_tmp(l) = delta1d_tmp(l) + U(ii_i,l) * V(ii_j,l) * delta0_det(ii)
enddo
enddo
!$OMP END DO
!$OMP CRITICAL
do l = n_tmp, nsvd
delta_D(l) = delta_D(l) + delta1d_tmp(l)
enddo
!$OMP END CRITICAL
deallocate(delta1d_tmp)
!$OMP END PARALLEL
!
! --------------------------------------------------------------------------------
! --------------------------------------------------------------------------------
!
delta_A(n_tmp:La,1:lla) = 0.d0
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(n_tmp, La, lla, N_det, U, V, delta0_det, delta_A &
!$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) &
!$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp)
allocate( delta_tmp(n_tmp:La,1:lla) )
delta_tmp(n_tmp:La,1:lla) = 0.d0
!$OMP DO
do l = 1, lla
do k = n_tmp, La
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
delta_tmp(k,l) = delta_tmp(k,l) + U(ii_i,k) * V(ii_j,l) * delta0_det(ii)
enddo
enddo
enddo
!$OMP END DO
!$OMP CRITICAL
do l = 1, lla
do k = n_tmp, La
delta_A(k,l) = delta_A(k,l) + delta_tmp(k,l)
enddo
enddo
!$OMP END CRITICAL
deallocate(delta_tmp)
!$OMP END PARALLEL
!
! --------------------------------------------------------------------------------
! --------------------------------------------------------------------------------
!
delta_B(1:llb,n_tmp:Lb) = 0.d0
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(n_tmp, Lb, llb, N_det, U, V, delta0_det, delta_B &
!$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) &
!$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp)
allocate( delta_tmp(1:llb,n_tmp:Lb) )
delta_tmp(1:llb,n_tmp:Lb) = 0.d0
!$OMP DO
do l = n_tmp, Lb
do k = 1, llb
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
delta_tmp(k,l) = delta_tmp(k,l) + U(ii_i,k) * V(ii_j,l) * delta0_det(ii)
enddo
enddo
enddo
!$OMP END DO
!$OMP CRITICAL
do l = n_tmp, Lb
do k = 1, llb
delta_B(k,l) = delta_B(k,l) + delta_tmp(k,l)
enddo
enddo
!$OMP END CRITICAL
deallocate(delta_tmp)
!$OMP END PARALLEL
!
! --------------------------------------------------------------------------------
return
end subroutine obtenir_deltaSVD_4b
! _______________________________________________________________________________________________________
! _______________________________________________________________________________________________________

View File

@ -0,0 +1,250 @@
program delta_FSVD_v0
BEGIN_DOC
! !!!
END_DOC
implicit none
read_wf = .True.
touch read_wf
my_grid_becke = .True.
my_n_pt_r_grid = 30
my_n_pt_a_grid = 170
touch my_grid_becke my_n_pt_r_grid my_n_pt_a_grid
extra_grid_type_sgn = 1
touch extra_grid_type_sgn
my_extra_grid_becke = .False.
touch my_extra_grid_becke
print*,'Warning : the Becke grid parameters are automatically set to '
print*,'my_n_pt_a_grid = ',my_n_pt_a_grid
print*,'my_n_pt_r_grid = ',my_n_pt_r_grid
if(linear_tc) then
three_body_h_tc = .False.
touch three_body_h_tc
grad_squared = .False.
touch grad_squared
endif
if(read_tc_ints) then
call read_fcidump_1_tc
endif
call run()
end
subroutine run()
implicit none
integer :: ii, ii_i, ii_j, k, l
integer :: na, nb, nsvd
double precision, allocatable :: U(:,:), V(:,:), S(:)
double precision, allocatable :: deltaDet_ex(:), deltaDet_ap(:), deltaSVD_kl(:,:)
na = n_det_alpha_unique
nb = n_det_beta_unique
! read SVD vectors
call ezfio_get_spindeterminants_n_svd_coefs(nsvd)
allocate( U(na,nsvd), S(nsvd), V(nb,nsvd) )
call ezfio_get_spindeterminants_psi_svd_alpha(U)
call ezfio_get_spindeterminants_psi_svd_beta (V)
call ezfio_get_spindeterminants_psi_svd_coefs(S)
!allocate( deltaSVD_kk(nsvd) )
!call obtenir_deltaSVD_kk(nsvd, U, V, deltaSVD_kk)
allocate( deltaSVD_kl(nsvd,nsvd) )
call obtenir_deltaSVD_kl(nsvd, U, V, deltaSVD_kl)
allocate( deltaDet_ex(N_det) , deltaDet_ap(N_det) )
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
deltaDet_ex(ii) = 0.d0
deltaDet_ap(ii) = 0.d0
do k = 1, nsvd
deltaDet_ap(ii) = deltaDet_ap(ii) + U(ii_i,k) * V(ii_j,k) * deltaSVD_kl(k,k)
do l = 1, nsvd
deltaDet_ex(ii) = deltaDet_ex(ii) + U(ii_i,k) * V(ii_j,l) * deltaSVD_kl(k,l)
enddo
enddo
print *, deltaDet_ex(ii) , deltaDet_ap(ii)
enddo
!call ezfio_set_dmc_dress_dmc_delta_h(delta_Det_ex)
deallocate( U , S , V )
deallocate( deltaSVD_kl )
deallocate( deltaDet_ex , deltaDet_ap )
end
! _______________________________________________________________________________________________________
!
! [ delta_SVD ]_kk = < dup_SVD ddn_SVD | H_tilde - H | psi >
! = \sum_{i,j} U_{i,k} V_{j,k} < dup_i ddn_j | H_tilde - H | psi >
!
subroutine obtenir_deltaSVD_kk(nsvd, U, V, deltaSVD_kk)
implicit none
integer, intent(in) :: nsvd
double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd)
double precision, intent(out) :: deltaSVD_kk(nsvd)
integer :: i_state, na, nb
integer :: k, ii, jj, ii_i, ii_j, jj_i, jj_j
double precision :: tmp_k, tmp_ij, coef_jj
integer(bit_kind) :: det_ii(N_int,2), det_jj(N_int,2)
double precision :: hmono, heff, hderiv, hthree, htilde_ij, hij, delta_mat
PROVIDE scalar_mu_r_pot_physicist_mo deriv_mu_r_pot_physicist_mo
PROVIDE three_body_3_index three_body_3_index_exch_12 three_body_3_index_exch_13 three_body_3_index_exch_23
PROVIDE three_body_5_index three_body_5_index_exch_13 three_body_5_index_exch_32
PROVIDE three_body_4_index three_body_4_index_exch_12 three_body_4_index_exch_12_part
i_state = 1
na = n_det_alpha_unique
nb = n_det_beta_unique
deltaSVD_kk(:) = 0.d0
do k = 1, nsvd
tmp_k = 0.d0
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
det_ii(:,1) = psi_det_alpha_unique(:,ii_i)
det_ii(:,2) = psi_det_beta_unique (:,ii_j)
!tmp_ij = < dup_i ddn_j | H_tilde - H | psi >
tmp_ij = 0.d0
do jj = 1, N_det
jj_i = psi_bilinear_matrix_rows (jj)
jj_j = psi_bilinear_matrix_columns(jj)
coef_jj = psi_bilinear_matrix_values(jj,i_state)
det_jj(:,1) = psi_det_alpha_unique(:,jj_i)
det_jj(:,2) = psi_det_beta_unique (:,jj_j)
call htilde_mat(det_ii, det_jj, hmono, heff, hderiv, hthree, htilde_ij)
call i_H_j(det_ii, det_jj, N_int, hij)
delta_mat = htilde_ij - hij
tmp_ij = tmp_ij + coef_jj * delta_mat
enddo
tmp_k = tmp_k + U(ii_i,k) * V(ii_j,k) * tmp_ij
enddo
deltaSVD_kk(k) = tmp_k
enddo
return
end subroutine obtenir_deltaSVD_kk
! _______________________________________________________________________________________________________
! _______________________________________________________________________________________________________
! _______________________________________________________________________________________________________
!
! [ delta_SVD ]_kl = < dup_SVD ddn_SVD | H_tilde - H | psi >
! = \sum_{i,j} U_{i,k} V_{j,l} < dup_i ddn_j | H_tilde - H | psi >
!
subroutine obtenir_deltaSVD_kl(nsvd, U, V, deltaSVD_kl)
implicit none
integer, intent(in) :: nsvd
double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd)
double precision, intent(out) :: deltaSVD_kl(nsvd,nsvd)
integer :: i_state, na, nb
integer :: k, l, ii, jj, ii_i, ii_j, jj_i, jj_j
double precision :: tmp_kl, tmp_ij, coef_jj
integer(bit_kind) :: det_ii(N_int,2), det_jj(N_int,2)
double precision :: hmono, heff, hderiv, hthree, htilde_ij, hij, delta_mat
PROVIDE scalar_mu_r_pot_physicist_mo deriv_mu_r_pot_physicist_mo
PROVIDE three_body_3_index three_body_3_index_exch_12 three_body_3_index_exch_13 three_body_3_index_exch_23
PROVIDE three_body_5_index three_body_5_index_exch_13 three_body_5_index_exch_32
PROVIDE three_body_4_index three_body_4_index_exch_12 three_body_4_index_exch_12_part
i_state = 1
na = n_det_alpha_unique
nb = n_det_beta_unique
! ! !
det_ii(:,1) = psi_det_alpha_unique(:,1)
det_ii(:,2) = psi_det_beta_unique (:,1)
det_jj(:,1) = psi_det_alpha_unique(:,1)
det_jj(:,2) = psi_det_beta_unique (:,1)
call htilde_mat(det_ii, det_jj, hmono, heff, hderiv, hthree, htilde_ij)
call i_H_j(det_ii, det_jj, N_int, hij)
! ! !
print *, ' --- start delta SVD calcul ---'
deltaSVD_kl(:,:) = 0.d0
do k = 1, nsvd
do l = 1, nsvd
tmp_kl = 0.d0
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
det_ii(:,1) = psi_det_alpha_unique(:,ii_i)
det_ii(:,2) = psi_det_beta_unique (:,ii_j)
!tmp_ij = < dup_i ddn_j | H_tilde - H | psi >
tmp_ij = 0.d0
do jj = 1, N_det
jj_i = psi_bilinear_matrix_rows (jj)
jj_j = psi_bilinear_matrix_columns(jj)
coef_jj = psi_bilinear_matrix_values(jj,i_state)
det_jj(:,1) = psi_det_alpha_unique(:,jj_i)
det_jj(:,2) = psi_det_beta_unique (:,jj_j)
call htilde_mat(det_ii, det_jj, hmono, heff, hderiv, hthree, htilde_ij)
call i_H_j(det_ii, det_jj, N_int, hij)
delta_mat = htilde_ij - hij
tmp_ij = tmp_ij + coef_jj * delta_mat
enddo
tmp_kl = tmp_kl + U(ii_i,k) * V(ii_j,l) * tmp_ij
enddo
deltaSVD_kl(k,l) = tmp_kl
enddo
enddo
print *, ' --- end delta SVD calcul ---'
return
end subroutine obtenir_deltaSVD_kl
! _______________________________________________________________________________________________________
! _______________________________________________________________________________________________________

View File

@ -0,0 +1,197 @@
program delta_FSVD_v1
BEGIN_DOC
! !!!
END_DOC
implicit none
read_wf = .True.
touch read_wf
my_grid_becke = .True.
my_n_pt_r_grid = 30
my_n_pt_a_grid = 170
touch my_grid_becke my_n_pt_r_grid my_n_pt_a_grid
extra_grid_type_sgn = 1
touch extra_grid_type_sgn
my_extra_grid_becke = .False.
touch my_extra_grid_becke
print*,'Warning : the Becke grid parameters are automatically set to '
print*,'my_n_pt_a_grid = ',my_n_pt_a_grid
print*,'my_n_pt_r_grid = ',my_n_pt_r_grid
if(linear_tc) then
three_body_h_tc = .False.
touch three_body_h_tc
grad_squared = .False.
touch grad_squared
endif
if(read_tc_ints) then
call read_fcidump_1_tc
endif
call run()
end
subroutine run()
implicit none
integer :: ii, ii_i, ii_j, k, l
integer :: na, nb, nsvd
double precision, allocatable :: U(:,:), V(:,:), S(:)
double precision, allocatable :: deltaDet_ex(:), deltaDet_ap(:), deltaSVD_kl(:,:)
na = n_det_alpha_unique
nb = n_det_beta_unique
! read SVD vectors
call ezfio_get_spindeterminants_n_svd_coefs(nsvd)
allocate( U(na,nsvd), S(nsvd), V(nb,nsvd) )
call ezfio_get_spindeterminants_psi_svd_alpha(U)
call ezfio_get_spindeterminants_psi_svd_beta (V)
call ezfio_get_spindeterminants_psi_svd_coefs(S)
!allocate( deltaSVD_kk(nsvd) )
!call obtenir_deltaSVD_kk(nsvd, U, V, deltaSVD_kk)
allocate( deltaSVD_kl(nsvd,nsvd) )
call obtenir_deltaSVD_kl(nsvd, U, V, deltaSVD_kl)
allocate( deltaDet_ex(N_det) , deltaDet_ap(N_det) )
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
deltaDet_ex(ii) = 0.d0
! deltaDet_ap(ii) = 0.d0
do k = 1, nsvd
! deltaDet_ap(ii) = deltaDet_ap(ii) + U(ii_i,k) * V(ii_j,k) * deltaSVD_kl(k,k)
do l = 1, nsvd
deltaDet_ex(ii) = deltaDet_ex(ii) + U(ii_i,k) * V(ii_j,l) * deltaSVD_kl(k,l)
enddo
enddo
! print *, deltaDet_ex(ii) , deltaDet_ap(ii)
enddo
call ezfio_set_dmc_dress_dmc_delta_h(deltaDet_ex)
deallocate( U , S , V )
deallocate( deltaSVD_kl )
deallocate( deltaDet_ex , deltaDet_ap )
end
! _______________________________________________________________________________________________________
!
! [ delta_SVD ]_kl = < dup_SVD ddn_SVD | H_tilde - H | psi >
! = \sum_{i,j} U_{i,k} V_{j,l} < dup_i ddn_j | H_tilde - H | psi >
!
subroutine obtenir_deltaSVD_kl(nsvd, U, V, deltaSVD_kl)
use bitmasks
implicit none
integer, intent(in) :: nsvd
double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd)
double precision, intent(out) :: deltaSVD_kl(nsvd,nsvd)
integer :: i_state
integer :: k, l, ii, jj, ii_i, ii_j, jj_i, jj_j
integer(bit_kind) :: det_ii(N_int,2), det_jj(N_int,2)
double precision :: hmono, heff, hderiv, hthree, htilde_ij, hij, delta_mat
double precision, allocatable :: delta_det(:)
PROVIDE scalar_mu_r_pot_physicist_mo deriv_mu_r_pot_physicist_mo
PROVIDE three_body_3_index three_body_3_index_exch_12 three_body_3_index_exch_13 three_body_3_index_exch_23
PROVIDE three_body_5_index three_body_5_index_exch_13 three_body_5_index_exch_32
PROVIDE three_body_4_index three_body_4_index_exch_12 three_body_4_index_exch_12_part
i_state = 1
! ! !
det_ii(:,1) = psi_det_alpha_unique(:,1)
det_ii(:,2) = psi_det_beta_unique (:,1)
det_jj(:,1) = psi_det_alpha_unique(:,1)
det_jj(:,2) = psi_det_beta_unique (:,1)
call htilde_mat(det_ii, det_jj, hmono, heff, hderiv, hthree, htilde_ij)
call i_H_j(det_ii, det_jj, N_int, hij)
! ! !
print *, ' --- start delta SVD calcul ---'
! -------------------------------------------------------------------------
! < dup_i ddn_j | H_tilde - H | psi >
allocate( delta_det(N_det) )
delta_det(:) = 0.d0
!$OMP PARALLEL DO DEFAULT(NONE) SCHEDULE(dynamic,8) &
!$OMP SHARED(N_det, i_state, N_int, psi_bilinear_matrix_rows &
!$OMP , psi_bilinear_matrix_columns, psi_bilinear_matrix_values &
!$OMP , psi_det_alpha_unique, psi_det_beta_unique, delta_det) &
!$OMP PRIVATE(ii, ii_i, ii_j, jj, jj_i, jj_j, det_ii, det_jj &
!$OMP , hmono, heff, hderiv, hthree, htilde_ij, hij)
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
det_ii(:,1) = psi_det_alpha_unique(:,ii_i)
det_ii(:,2) = psi_det_beta_unique (:,ii_j)
do jj = 1, N_det
jj_i = psi_bilinear_matrix_rows (jj)
jj_j = psi_bilinear_matrix_columns(jj)
det_jj(:,1) = psi_det_alpha_unique(:,jj_i)
det_jj(:,2) = psi_det_beta_unique (:,jj_j)
call htilde_mat(det_ii, det_jj, hmono, heff, hderiv, hthree, htilde_ij)
call i_H_j(det_ii, det_jj, N_int, hij)
delta_det(ii) = delta_det(ii) + (htilde_ij-hij) * psi_bilinear_matrix_values(jj,i_state)
enddo
enddo
!$OMP END PARALLEL DO
! -------------------------------------------------------------------------
!call dset_order(delta_det, psi_bilinear_matrix_order, N_det)
deltaSVD_kl(:,:) = 0.d0
!$OMP PARALLEL DO DEFAULT(NONE) SCHEDULE(dynamic,8) &
!$OMP SHARED(nsvd, N_det, U, V, delta_det, deltaSVD_kl &
!$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) &
!$OMP PRIVATE(k, l, ii, ii_i, ii_j)
do l = 1, nsvd
do k = 1, nsvd
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
deltaSVD_kl(k,l) = deltaSVD_kl(k,l) + U(ii_i,k) * V(ii_j,l) * delta_det(ii)
enddo
enddo
enddo
!$OMP END PARALLEL DO
deallocate( delta_det )
print *, ' --- end delta SVD calcul ---'
return
end subroutine obtenir_deltaSVD_kl
! _______________________________________________________________________________________________________
! _______________________________________________________________________________________________________

View File

@ -0,0 +1,145 @@
program delta_FSVD_v2
BEGIN_DOC
! !!!
END_DOC
implicit none
read_wf = .True.
touch read_wf
call run()
end
subroutine run()
implicit none
integer :: ii, ii_i, ii_j, k, l
integer :: na, nb, nsvd
double precision, allocatable :: U(:,:), V(:,:), S(:)
double precision, allocatable :: delta0_det(:), delta1_det(:), deltaSVD_kl(:,:)
double precision, allocatable :: delta_tmp(:)
na = n_det_alpha_unique
nb = n_det_beta_unique
! read SVD vectors
call ezfio_get_spindeterminants_n_svd_coefs(nsvd)
allocate( U(na,nsvd), S(nsvd), V(nb,nsvd) )
call ezfio_get_spindeterminants_psi_svd_alpha(U)
call ezfio_get_spindeterminants_psi_svd_beta (V)
call ezfio_get_spindeterminants_psi_svd_coefs(S)
allocate( delta0_det(N_det) )
call ezfio_get_dmc_dress_dmc_delta_h(delta0_det)
allocate( deltaSVD_kl(nsvd,nsvd) )
deltaSVD_kl(:,:) = 0.d0
call obtenir_deltaSVD_kl(nsvd, U, V, delta0_det, deltaSVD_kl)
! [ delta ]_mn = \sum_{k,l} U_{m,k} delta_SVD_{k,l} V_{n,l}
allocate( delta1_det(N_det) )
delta1_det(1:N_det) = 0.d0
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(nsvd, N_det, U, V, deltaSVD_kl, delta1_det &
!$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) &
!$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp)
allocate( delta_tmp(N_det) )
delta_tmp(1:N_det) = 0.d0
!$OMP DO
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
do l = 1, nsvd
do k = 1, nsvd
delta_tmp(ii) = delta_tmp(ii) + U(ii_i,k) * V(ii_j,l) * deltaSVD_kl(k,l)
enddo
enddo
enddo
!$OMP END DO
!$OMP CRITICAL
do ii = 1, N_det
delta1_det(ii) = delta1_det(ii) + delta_tmp(ii)
enddo
!$OMP END CRITICAL
deallocate( delta_tmp )
!$OMP END PARALLEL
call ezfio_set_dmc_dress_dmc_delta_h(delta1_det)
deallocate( U , S , V )
deallocate( deltaSVD_kl )
deallocate( delta0_det , delta1_det )
end
! _______________________________________________________________________________________________________
!
! [ delta_SVD ]_kl = < dup_SVD ddn_SVD | H_tilde - H | psi >
! = \sum_{i,j} U_{i,k} V_{j,l} < dup_i ddn_j | H_tilde - H | psi >
!
subroutine obtenir_deltaSVD_kl(nsvd, U, V, delta0_det, deltaSVD_kl)
implicit none
integer, intent(in) :: nsvd
double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd)
double precision, intent(in) :: delta0_det(N_det)
double precision, intent(out) :: deltaSVD_kl(nsvd,nsvd)
integer :: k, l, ii, ii_i, ii_j
double precision, allocatable :: delta_tmp(:,:)
deltaSVD_kl(1:nsvd,1:nsvd) = 0.d0
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(nsvd, N_det, U, V, delta0_det, deltaSVD_kl &
!$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) &
!$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp)
allocate( delta_tmp(nsvd,nsvd) )
delta_tmp(1:nsvd,1:nsvd) = 0.d0
!$OMP DO
do l = 1, nsvd
do k = 1, nsvd
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
delta_tmp(k,l) = delta_tmp(k,l) + U(ii_i,k) * V(ii_j,l) * delta0_det(ii)
enddo
enddo
enddo
!$OMP END DO
!$OMP CRITICAL
do l = 1, nsvd
do k = 1, nsvd
deltaSVD_kl(k,l) = deltaSVD_kl(k,l) + delta_tmp(k,l)
enddo
enddo
!$OMP END CRITICAL
deallocate(delta_tmp)
!$OMP END PARALLEL
return
end subroutine obtenir_deltaSVD_kl
! _______________________________________________________________________________________________________
! _______________________________________________________________________________________________________

View File

@ -0,0 +1,147 @@
program delta_diagSVD_v0
BEGIN_DOC
! !!!
END_DOC
implicit none
read_wf = .True.
touch read_wf
call run()
end
subroutine run()
implicit none
integer :: ii, ii_i, ii_j, k
integer :: na, nb, nsvd, n_TSVD
double precision, allocatable :: U(:,:), V(:,:), S(:)
double precision, allocatable :: delta0_det(:), delta1_det(:), deltaSVD_kk(:)
double precision, allocatable :: delta_tmp(:)
na = n_det_alpha_unique
nb = n_det_beta_unique
! read SVD vectors
call ezfio_get_spindeterminants_n_svd_coefs(nsvd)
allocate( U(na,nsvd) , V(nb,nsvd) )
call ezfio_get_spindeterminants_psi_svd_alpha(U)
call ezfio_get_spindeterminants_psi_svd_beta (V)
allocate( delta0_det(N_det) )
call ezfio_get_dmc_dress_dmc_delta_h(delta0_det)
allocate( deltaSVD_kk(nsvd) )
deltaSVD_kk(1:nsvd) = 0.d0
call obtenir_deltaSVD_kk(nsvd, U, V, delta0_det, deltaSVD_kk)
deallocate( delta0_det )
! ---------------------------------------------
! parameters
n_TSVD = nsvd
print *, " --- delta_diagSVD_v0 ---"
print *, " n_TSVD =", n_TSVD
print *, " tot =", n_TSVD
!
! ---------------------------------------------
! [ delta ]_mn = \sum_{k} U_{m,k} delta_SVD_{k,k} V_{n,k}
allocate( delta1_det(N_det) )
delta1_det(:) = 0.d0
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(n_TSVD, N_det, U, V, deltaSVD_kk, delta1_det &
!$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) &
!$OMP PRIVATE(k, ii, ii_i, ii_j, delta_tmp)
allocate( delta_tmp(N_det) )
delta_tmp(:) = 0.d0
!$OMP DO
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
do k = 1, n_TSVD
delta_tmp(ii) = delta_tmp(ii) + U(ii_i,k) * V(ii_j,k) * deltaSVD_kk(k)
enddo
enddo
!$OMP END DO
!$OMP CRITICAL
do ii = 1, N_det
delta1_det(ii) = delta1_det(ii) + delta_tmp(ii)
enddo
!$OMP END CRITICAL
deallocate( delta_tmp )
!$OMP END PARALLEL
deallocate( U , V )
deallocate( deltaSVD_kk )
call ezfio_set_dmc_dress_dmc_delta_h(delta1_det)
deallocate( delta1_det )
end
! _______________________________________________________________________________________________________
!
! [ delta_SVD ]_kk = < dup_SVD ddn_SVD | H_tilde - H | psi >
! = \sum_{i,j} U_{i,k} V_{j,k} < dup_i ddn_j | H_tilde - H | psi >
!
subroutine obtenir_deltaSVD_kk(nsvd, U, V, delta0_det, deltaSVD_kk)
implicit none
integer, intent(in) :: nsvd
double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd)
double precision, intent(in) :: delta0_det(N_det)
double precision, intent(out) :: deltaSVD_kk(nsvd)
integer :: k, ii, ii_i, ii_j
double precision, allocatable :: delta_tmp(:)
deltaSVD_kk(1:nsvd) = 0.d0
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(nsvd, N_det, U, V, delta0_det, deltaSVD_kk &
!$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) &
!$OMP PRIVATE(k, ii, ii_i, ii_j, delta_tmp)
allocate( delta_tmp(nsvd) )
delta_tmp(1:nsvd) = 0.d0
!$OMP DO
do k = 1, nsvd
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
delta_tmp(k) = delta_tmp(k) + U(ii_i,k) * V(ii_j,k) * delta0_det(ii)
enddo
enddo
!$OMP END DO
!$OMP CRITICAL
do k = 1, nsvd
deltaSVD_kk(k) = deltaSVD_kk(k) + delta_tmp(k)
enddo
!$OMP END CRITICAL
deallocate(delta_tmp)
!$OMP END PARALLEL
return
end subroutine obtenir_deltaSVD_kk
! _______________________________________________________________________________________________________
! _______________________________________________________________________________________________________

View File

@ -0,0 +1,221 @@
program delta_svd_v1
BEGIN_DOC
! !!!
END_DOC
implicit none
read_wf = .true.
TOUCH read_wf
call run()
end
subroutine run()
implicit none
integer :: ii, ii_i, ii_j, k, l
integer :: na, nb, nsvd
double precision, allocatable :: U(:,:), V(:,:), S(:)
double precision, allocatable :: deltaDet_ex(:), deltaDet_ap(:), deltaSVD_kl(:,:)
na = n_det_alpha_unique
nb = n_det_beta_unique
! read SVD vectors
call ezfio_get_spindeterminants_n_svd_coefs(nsvd)
allocate( U(na,nsvd), S(nsvd), V(nb,nsvd) )
call ezfio_get_spindeterminants_psi_svd_alpha(U)
call ezfio_get_spindeterminants_psi_svd_beta (V)
call ezfio_get_spindeterminants_psi_svd_coefs(S)
!allocate( deltaSVD_kk(nsvd) )
!call obtenir_deltaSVD_kk(nsvd, U, V, deltaSVD_kk)
allocate( deltaSVD_kl(nsvd,nsvd) )
call obtenir_deltaSVD_kl(nsvd, U, V, deltaSVD_kl)
allocate( deltaDet_ex(N_det) , deltaDet_ap(N_det) )
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
deltaDet_ex(ii) = 0.d0
deltaDet_ap(ii) = 0.d0
do k = 1, nsvd
deltaDet_ap(ii) = deltaDet_ap(ii) + U(ii_i,k) * V(ii_j,k) * deltaSVD_kl(k,k)
do l = 1, nsvd
deltaDet_ex(ii) = deltaDet_ex(ii) + U(ii_i,k) * V(ii_j,l) * deltaSVD_kl(k,l)
enddo
enddo
print *, deltaDet_ex(ii) , deltaDet_ap(ii)
enddo
!call ezfio_set_dmc_dress_dmc_delta_h(delta_Det_ex)
deallocate( U , S , V )
deallocate( deltaSVD_kl )
deallocate( deltaDet_ex , deltaDet_ap )
end
! _______________________________________________________________________________________________________
!
! [ delta_SVD ]_kk = < dup_SVD ddn_SVD | H_tilde - H | psi >
! = \sum_{i,j} U_{i,k} V_{j,k} < dup_i ddn_j | H_tilde - H | psi >
!
subroutine obtenir_deltaSVD_kk(nsvd, U, V, deltaSVD_kk)
implicit none
integer, intent(in) :: nsvd
double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd)
double precision, intent(out) :: deltaSVD_kk(nsvd)
integer :: i_state, na, nb
integer :: k, ii, jj, ii_i, ii_j, jj_i, jj_j
double precision :: tmp_k, tmp_ij, coef_jj
integer(bit_kind) :: det_ii(N_int,2), det_jj(N_int,2)
double precision :: hmono, heff, hderiv, hthree, htilde_ij, hij, delta_mat
PROVIDE scalar_mu_r_pot_physicist_mo deriv_mu_r_pot_physicist_mo
PROVIDE three_body_3_index three_body_3_index_exch_12 three_body_3_index_exch_13 three_body_3_index_exch_23
PROVIDE three_body_5_index three_body_5_index_exch_13 three_body_5_index_exch_32
PROVIDE three_body_4_index three_body_4_index_exch_12 three_body_4_index_exch_12_part
i_state = 1
na = n_det_alpha_unique
nb = n_det_beta_unique
deltaSVD_kk(:) = 0.d0
do k = 1, nsvd
tmp_k = 0.d0
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
det_ii(:,1) = psi_det_alpha_unique(:,ii_i)
det_ii(:,2) = psi_det_beta_unique (:,ii_j)
!tmp_ij = < dup_i ddn_j | H_tilde - H | psi >
tmp_ij = 0.d0
do jj = 1, N_det
jj_i = psi_bilinear_matrix_rows (jj)
jj_j = psi_bilinear_matrix_columns(jj)
coef_jj = psi_bilinear_matrix_values(jj,i_state)
det_jj(:,1) = psi_det_alpha_unique(:,jj_i)
det_jj(:,2) = psi_det_beta_unique (:,jj_j)
call htilde_mat(det_ii, det_jj, hmono, heff, hderiv, hthree, htilde_ij)
call i_H_j(det_ii, det_jj, N_int, hij)
delta_mat = htilde_ij - hij
tmp_ij = tmp_ij + coef_jj * delta_mat
enddo
tmp_k = tmp_k + U(ii_i,k) * V(ii_j,k) * tmp_ij
enddo
deltaSVD_kk(k) = tmp_k
enddo
return
end subroutine obtenir_deltaSVD_kk
! _______________________________________________________________________________________________________
! _______________________________________________________________________________________________________
! _______________________________________________________________________________________________________
!
! [ delta_SVD ]_kl = < dup_SVD ddn_SVD | H_tilde - H | psi >
! = \sum_{i,j} U_{i,k} V_{j,l} < dup_i ddn_j | H_tilde - H | psi >
!
subroutine obtenir_deltaSVD_kl(nsvd, U, V, deltaSVD_kl)
implicit none
integer, intent(in) :: nsvd
double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd)
double precision, intent(out) :: deltaSVD_kl(nsvd,nsvd)
integer :: i_state, na, nb
integer :: k, l, ii, jj, ii_i, ii_j, jj_i, jj_j
double precision :: tmp_kl, tmp_ij, coef_jj
integer(bit_kind) :: det_ii(N_int,2), det_jj(N_int,2)
double precision :: hmono, heff, hderiv, hthree, htilde_ij, hij, delta_mat
PROVIDE scalar_mu_r_pot_physicist_mo deriv_mu_r_pot_physicist_mo
PROVIDE three_body_3_index three_body_3_index_exch_12 three_body_3_index_exch_13 three_body_3_index_exch_23
PROVIDE three_body_5_index three_body_5_index_exch_13 three_body_5_index_exch_32
PROVIDE three_body_4_index three_body_4_index_exch_12 three_body_4_index_exch_12_part
i_state = 1
na = n_det_alpha_unique
nb = n_det_beta_unique
! ! !
det_ii(:,1) = psi_det_alpha_unique(:,1)
det_ii(:,2) = psi_det_beta_unique (:,1)
det_jj(:,1) = psi_det_alpha_unique(:,1)
det_jj(:,2) = psi_det_beta_unique (:,1)
call htilde_mat(det_ii, det_jj, hmono, heff, hderiv, hthree, htilde_ij)
call i_H_j(det_ii, det_jj, N_int, hij)
! ! !
deltaSVD_kl(:,:) = 0.d0
do k = 1, nsvd
do l = 1, nsvd
tmp_kl = 0.d0
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
det_ii(:,1) = psi_det_alpha_unique(:,ii_i)
det_ii(:,2) = psi_det_beta_unique (:,ii_j)
!tmp_ij = < dup_i ddn_j | H_tilde - H | psi >
tmp_ij = 0.d0
do jj = 1, N_det
jj_i = psi_bilinear_matrix_rows (jj)
jj_j = psi_bilinear_matrix_columns(jj)
coef_jj = psi_bilinear_matrix_values(jj,i_state)
det_jj(:,1) = psi_det_alpha_unique(:,jj_i)
det_jj(:,2) = psi_det_beta_unique (:,jj_j)
call htilde_mat(det_ii, det_jj, hmono, heff, hderiv, hthree, htilde_ij)
call i_H_j(det_ii, det_jj, N_int, hij)
delta_mat = htilde_ij - hij
tmp_ij = tmp_ij + coef_jj * delta_mat
enddo
tmp_kl = tmp_kl + U(ii_i,k) * V(ii_j,l) * tmp_ij
enddo
deltaSVD_kl(k,l) = tmp_kl
enddo
enddo
return
end subroutine obtenir_deltaSVD_kl
! _______________________________________________________________________________________________________
! _______________________________________________________________________________________________________

View File

@ -0,0 +1,167 @@
program delta_svd_v2
BEGIN_DOC
! !!!
END_DOC
implicit none
read_wf = .true.
TOUCH read_wf
call run()
end
subroutine run()
implicit none
integer :: ii, ii_i, ii_j, k, l
integer :: na, nb, nsvd
double precision, allocatable :: U(:,:), V(:,:), S(:)
double precision, allocatable :: deltaDet_ex(:), deltaDet_ap(:), deltaSVD_kl(:,:)
na = n_det_alpha_unique
nb = n_det_beta_unique
! read SVD vectors
call ezfio_get_spindeterminants_n_svd_coefs(nsvd)
allocate( U(na,nsvd), S(nsvd), V(nb,nsvd) )
call ezfio_get_spindeterminants_psi_svd_alpha(U)
call ezfio_get_spindeterminants_psi_svd_beta (V)
call ezfio_get_spindeterminants_psi_svd_coefs(S)
!allocate( deltaSVD_kk(nsvd) )
!call obtenir_deltaSVD_kk(nsvd, U, V, deltaSVD_kk)
allocate( deltaSVD_kl(nsvd,nsvd) )
call obtenir_deltaSVD_kl(nsvd, U, V, deltaSVD_kl)
allocate( deltaDet_ex(N_det) , deltaDet_ap(N_det) )
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
deltaDet_ex(ii) = 0.d0
deltaDet_ap(ii) = 0.d0
do k = 1, nsvd
deltaDet_ap(ii) = deltaDet_ap(ii) + U(ii_i,k) * V(ii_j,k) * deltaSVD_kl(k,k)
do l = 1, nsvd
deltaDet_ex(ii) = deltaDet_ex(ii) + U(ii_i,k) * V(ii_j,l) * deltaSVD_kl(k,l)
enddo
enddo
print *, deltaDet_ex(ii) , deltaDet_ap(ii)
enddo
!call ezfio_set_dmc_dress_dmc_delta_h(delta_Det_ex)
deallocate( U , S , V )
deallocate( deltaSVD_kl )
deallocate( deltaDet_ex , deltaDet_ap )
end
! _______________________________________________________________________________________________________
!
! [ delta_SVD ]_kl = < dup_SVD ddn_SVD | H_tilde - H | psi >
! = \sum_{i,j} U_{i,k} V_{j,l} < dup_i ddn_j | H_tilde - H | psi >
!
subroutine obtenir_deltaSVD_kl(nsvd, U, V, deltaSVD_kl)
implicit none
integer, intent(in) :: nsvd
double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd)
double precision, intent(out) :: deltaSVD_kl(nsvd,nsvd)
integer :: i_state
integer :: k, l, ii, jj, ii_i, ii_j, jj_i, jj_j
integer(bit_kind) :: det_ii(N_int,2), det_jj(N_int,2)
double precision :: hmono, heff, hderiv, hthree, htilde_ij, hij, delta_mat
double precision, allocatable :: delta_det(:)
PROVIDE scalar_mu_r_pot_physicist_mo deriv_mu_r_pot_physicist_mo
PROVIDE three_body_3_index three_body_3_index_exch_12 three_body_3_index_exch_13 three_body_3_index_exch_23
PROVIDE three_body_5_index three_body_5_index_exch_13 three_body_5_index_exch_32
PROVIDE three_body_4_index three_body_4_index_exch_12 three_body_4_index_exch_12_part
i_state = 1
! ! !
det_ii(:,1) = psi_det_alpha_unique(:,1)
det_ii(:,2) = psi_det_beta_unique (:,1)
det_jj(:,1) = psi_det_alpha_unique(:,1)
det_jj(:,2) = psi_det_beta_unique (:,1)
call htilde_mat(det_ii, det_jj, hmono, heff, hderiv, hthree, htilde_ij)
call i_H_j(det_ii, det_jj, N_int, hij)
! ! !
! -------------------------------------------------------------------------
! < dup_i ddn_j | H_tilde - H | psi >
allocate( delta_det(N_det) )
delta_det(:) = 0.d0
!$OMP PARALLEL DO DEFAULT(NONE) SCHEDULE(dynamic,8) &
!$OMP SHARED(N_det, i_state, N_int, psi_bilinear_matrix_rows &
!$OMP , psi_bilinear_matrix_columns, psi_bilinear_matrix_values &
!$OMP , psi_det_alpha_unique, psi_det_beta_unique, delta_det) &
!$OMP PRIVATE(ii, ii_i, ii_j, jj, jj_i, jj_j, det_ii, det_jj &
!$OMP , hmono, heff, hderiv, hthree, htilde_ij, hij)
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
det_ii(:,1) = psi_det_alpha_unique(:,ii_i)
det_ii(:,2) = psi_det_beta_unique (:,ii_j)
do jj = 1, N_det
jj_i = psi_bilinear_matrix_rows (jj)
jj_j = psi_bilinear_matrix_columns(jj)
det_jj(:,1) = psi_det_alpha_unique(:,jj_i)
det_jj(:,2) = psi_det_beta_unique (:,jj_j)
call htilde_mat(det_ii, det_jj, hmono, heff, hderiv, hthree, htilde_ij)
call i_H_j(det_ii, det_jj, N_int, hij)
delta_det(ii) = delta_det(ii) + (htilde_ij-hij) * psi_bilinear_matrix_values(jj,i_state)
enddo
enddo
!$OMP END PARALLEL DO
! -------------------------------------------------------------------------
deltaSVD_kl(:,:) = 0.d0
!$OMP PARALLEL DO DEFAULT(NONE) SCHEDULE(dynamic,8) &
!$OMP SHARED(nsvd, N_det, U, V, delta_det, deltaSVD_kl &
!$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) &
!$OMP PRIVATE(k, l, ii, ii_i, ii_j)
do l = 1, nsvd
do k = 1, nsvd
do ii = 1, N_det
ii_i = psi_bilinear_matrix_rows (ii)
ii_j = psi_bilinear_matrix_columns(ii)
deltaSVD_kl(k,l) = deltaSVD_kl(k,l) + U(ii_i,k) * V(ii_j,l) * delta_det(ii)
enddo
enddo
enddo
!$OMP END PARALLEL DO
deallocate( delta_det )
return
end subroutine obtenir_deltaSVD_kl
! _______________________________________________________________________________________________________
! _______________________________________________________________________________________________________

View File

@ -0,0 +1,347 @@
#!/usr/bin/env python
from ezfio import ezfio
import numpy as np
import sys
import time
from datetime import datetime
import matplotlib.pyplot as plt
#import seaborn as sns
from matplotlib.colors import LogNorm
# ____________________________________________________________________________________________
#
def read_AO_2eCoulomb():
lines = []
with open(ao_file) as f_in:
for line in f_in:
lines.append( float(line) )
J = np.zeros((ao_num2,ao_num2))
i_l = 0
for mu in range(ao_num):
for nu in range(ao_num):
ii = nu + ao_num * mu
for sig in range(ao_num):
for lam in range(ao_num):
jj = lam + ao_num * sig
J[ii,jj] = lines[i_l]
i_l += 1
return(J)
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
#
def read_H_det():
H_det = np.zeros((n_det_alpha*n_det_beta,n_det_alpha*n_det_beta))
with open("fort.7000") as f_in:
for line in f_in:
ll = line.split()
i = int( ll[0] ) - 1
j = int( ll[1] ) - 1
ii = j + n_det_beta * i
k = int( ll[2] ) - 1
l = int( ll[3] ) - 1
jj = l + n_det_beta * k
H_det[ii,jj] = float(ll[4])
return(H_det)
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
#
def read_T():
lines = []
with open("ij_T_kl.dat") as f_in:
for line in f_in:
lines.append( float(line) )
T = np.zeros( (n_det_alpha*n_det_beta,n_det_alpha*n_det_beta) )
i_l = 0
for i in range(n_det_alpha):
for j in range(n_det_beta):
ii = j + n_det_beta * i
for k in range(n_det_alpha):
for l in range(n_det_beta):
jj = l + n_det_beta * k
T[ii,jj] = lines[i_l]
i_l += 1
return(T)
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
#
def check_symmetric(a, rtol=1e-05, atol=1e-08):
return( np.allclose(a, a.T, rtol=rtol, atol=atol) )
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
#
def plot_mat(M, xstep, ystep, namefile):
Mp = np.abs(M) + 1e-15
ax = sns.heatmap(Mp, linewidths=0.0, rasterized=True, norm=LogNorm())
# x axis
ax.xaxis.tick_top()
xgrid = np.arange(1, M.shape[1]+1, xstep-1)
plt.xticks( np.arange(0, M.shape[1], xstep-1) + .5, xgrid )
# y axis
ygrid = np.arange(1, M.shape[0]+1, ystep-1)
plt.yticks( np.arange(0, M.shape[0], ystep-1) + .5, ygrid )
plt.savefig(namefile)
plt.clf()
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
#
def incomplete_Cholesky(M, ma, mb, theta_CD):
D = np.zeros((ma,mb))
for lam in range(ma):
for sig in range(mb):
ii = sig + mb * lam
D[sig,lam] = M[ii,ii]
# find the maximum
val_max = np.amax(D)
ind_max = np.where(D == val_max)
sig_max = ind_max[0][0]
lam_max = ind_max[1][0]
ii_max = sig_max + mb * lam_max
#print( sig_max, lam_max, D[sig_max,lam_max], val_max )
# define the initial resudual
mab = ma * mb
R = np.zeros((mab))
R[:] = M[:,ii_max]
m = 0
L = np.zeros((mab))
List_vec = []
while(val_max>theta_CD):
if(m>0):
# update the residual
for ii in range(mab):
sumii = 0
for i in range(m):
sumii += List_vec[i][ii] * List_vec[i][ii_max]
R[ii] = M[ii,ii_max] - sumii
# compute Cholesky vector
L = R / np.sqrt(val_max)
List_vec.append(L)
# update diagonals
for lam in range(ma):
for sig in range(mb):
ii = sig + mb * lam
D[sig,lam] = D[sig,lam] - L[ii]*L[ii]
m += 1
# find the new maximum
val_max = np.amax(D)
ind_max = np.where(D == val_max)
sig_max = ind_max[0][0]
lam_max = ind_max[1][0]
ii_max = sig_max + mb * lam_max
return(m, List_vec)
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
#
def err_p_estim(M, List_vec):
mM = M.shape[0]
mL = len(List_vec)
normM = np.linalg.norm(M)
L_CD = np.zeros((mM,mL))
for i in range(mL):
L_CD[:,i] = List_vec[i]
print(" size of L_CD: {} MB\n".format( sys.getsizeof(L_CD) / 1024. ) )
err_p = 100. * np.linalg.norm( M - np.dot(L_CD, L_CD.T) ) / normM
return( L_CD, err_p , normM)
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________________________________________________
# ____________________________________________________________________________________________________________________________________
#
if __name__=="__main__":
t_beg = time.time()
print("")
print(" date and time = {} \n".format(datetime.now().strftime("%d/%m/%Y %H:%M:%S")))
EZFIO_name = "/home/aammar/qp2/src/svdwf/f2_work/f2_fci"
ezfio.set_file(EZFIO_name)
# ------------------------------------------------------------------------------------------------------
# 2-e integrals in AO basis
# ------------------------------------------------------------------------------------------------------
ao_num = ezfio.get_ao_basis_ao_num()
ao_num2 = ao_num * ao_num
print(" nb of AO = {} \n".format(ao_num))
ao_file = "/home/aammar/qp2/src/svdwf/f2_work/ao_2eCoulombIntegrals.txt"
J = read_AO_2eCoulomb()
print(" size of J: {} MB ".format( sys.getsizeof(J) / 1024. ) )
print(" J is symmetric ? {} ".format(check_symmetric(J)) )
#plot_mat(J, ao_num, ao_num, 'J.pdf')
# pivoted incomplete Cholesky decomposition
theta_CD_J = 1e-02
m_J, List_vec_J = incomplete_Cholesky(J, ao_num, ao_num, theta_CD_J)
print(" nb of L_CD vectors = {} for theta = {}".format(m_J,theta_CD_J))
# check error
L_CD_J, err_p_J, normJ = err_p_estim(J, List_vec_J)
print(" norm of J = {} \n".format(normJ))
print(" error estimation on J = {} % \n".format(err_p_J))
#plot_mat(L_CD_J, 2, ao_num, 'L_CD_J.pdf')
# ------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------
print('\n \n \n')
# ------------------------------------------------------------------------------------------------------
# < d_i d_j | T | d_k d_l >
# ------------------------------------------------------------------------------------------------------
# n_det_alpha = ezfio.get_spindeterminants_n_det_alpha()
# n_det_beta = ezfio.get_spindeterminants_n_det_beta ()
# n_ab = n_det_alpha * n_det_beta
# print(" n_det_alpha = {} ".format(n_det_alpha))
# print(" n_det_beta = {} \n".format(n_det_beta ))
#
# T = read_T()
# print(" T is symmetric ? {} \n".format(check_symmetric(T)) )
#
# plot_mat(T, 50, 50, 'T.pdf')
#
#
# # pivoted incomplete Cholesky decomposition
# theta_CD_T = 1.5
# m_T, List_vec_T = incomplete_Cholesky(T, n_det_alpha, n_det_beta, theta_CD_T)
# print(" nb of L_CD vectors = {} for theta = {}".format(m_T,theta_CD_T))
#
# # check error
# L_CD_T, err_p_T, normT = err_p_estim(T, List_vec_T)
# print(" norm of T = {} ".format(normT))
# print(" error estimation on T = {} % \n".format(err_p_T))
#
# plot_mat(L_CD_T, 2, n_det_beta, 'L_CD_T.pdf')
# ------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------
print('\n \n \n')
# ------------------------------------------------------------------------------------------------------
# < d_i d_j | H | d_k d_l >
#
# WARNING: this isn't semipositive definite
# ------------------------------------------------------------------------------------------------------
#
# # get H_det
# n_det_alpha = ezfio.get_spindeterminants_n_det_alpha()
# n_det_beta = ezfio.get_spindeterminants_n_det_beta ()
# n_ab = n_det_alpha * n_det_beta
# print(" n_det_alpha = {} ".format(n_det_alpha))
# print(" n_det_beta = {} \n".format(n_det_beta ))
#
# H_det = read_H_det()
# print(" size of H_det: {} MB ".format( sys.getsizeof(H_det) / 1024. ) )
# print(" H_det is symmetric ? {} \n".format(check_symmetric(H_det)) )
#
# # plot H_det
# H_det = H_det + 1e-15
# plot_mat(H_det, 50, 50, 'H_det.pdf')
#
#
# # pivoted incomplete Cholesky decomposition
# theta_CD_H_det = 1e-02
# m_H_det, List_vec_H_det = incomplete_Cholesky(H_det, n_det_alpha, n_det_beta, theta_CD_H_det)
# print(" nb of L_CD_H_det vectors = {} for a precision of {}".format(m_H_det,theta_CD_H_det))
# #print(" size of L_CD_H_det: {} MB\n".format( sys.getsizeof(List_vec_H_det) / 1024. ) )
#
# # check error
# L_CD_H_det, err_p_H_det, normH_det = err_p_estim(H_det, List_vec_H_det)
# print(" norm of H_det = {} \n".format(normH_det))
# print(" error estimation on H_det = {} % \n".format(err_p_H_det))
#
# plot_mat(L_CD_H_det, 2, n_det_beta, 'L_CD_H_det.pdf')
# ------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------
print('\n\n')
t_end = time.time()
print(' end after {} min'.format((t_end-t_beg)/60.))
# ____________________________________________________________________________________________________________________________________
# ____________________________________________________________________________________________________________________________________
# ____________________________________________________________________________________________________________________________________

View File

@ -0,0 +1,348 @@
#!/usr/bin/env python
from ezfio import ezfio
import numpy as np
import sys
import time
from datetime import datetime
import matplotlib.pyplot as plt
#import seaborn as sns
from matplotlib.colors import LogNorm
# ____________________________________________________________________________________________
#
def read_Hsvd():
Hsvd = np.zeros((n_det_alpha*n_det_beta,n_det_alpha*n_det_beta))
n_zero = 0
with open("fort.7070") as f_in:
#with open("fort.7071") as f_in:
for line in f_in:
ll = line.split()
i = int( ll[0] ) - 1
j = int( ll[1] ) - 1
ii = j + n_det_beta * i
k = int( ll[2] ) - 1
l = int( ll[3] ) - 1
jj = l + n_det_beta * k
Hsvd[ii,jj] = float(ll[4])
if( abs(Hsvd[ii,jj]) <= 1e-12):
n_zero += 1
print(' nb of zero element in Hsvd = {}/{}'.format(
n_zero, n_det_alpha*n_det_beta*n_det_alpha*n_det_beta ))
print(' % of zero element in Hsvd = {}\n'.format(
100. * n_zero / (n_det_alpha*n_det_beta*n_det_alpha*n_det_beta) ))
return(Hsvd)
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
#
def read_Hdet():
Hdet = np.zeros((n_ab,n_ab))
n_zero = 0
with open("hdet_file") as f_in:
for line in f_in:
ll = line.split()
i = int( ll[0] ) - 1
j = int( ll[1] ) - 1
ii = j + n_det_beta * i
k = int( ll[2] ) - 1
l = int( ll[3] ) - 1
jj = l + n_det_beta * k
Hdet[ii,jj] = float(ll[4])
if( abs(Hdet[ii,jj]) <= 1e-12):
n_zero += 1
print(' nb of zero element in Hdet = {}/{}'.format(n_zero, n_ab*n_ab))
print(' % of zero element in Hdet = {} \n'.format(100.*n_zero/(n_ab*n_ab)))
return(Hdet)
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
#
def read_Tdet():
lines = []
with open("ij_T_kl.dat") as f_in:
for line in f_in:
lines.append( float(line) )
Tdet = np.zeros( (n_det_alpha*n_det_beta,n_det_alpha*n_det_beta) )
i_l = 0
n_zero = 0
for i in range(n_det_alpha):
for j in range(n_det_beta):
ii = j + n_det_beta * i
for k in range(n_det_alpha):
for l in range(n_det_beta):
jj = l + n_det_beta * k
Tdet[ii,jj] = lines[i_l]
i_l += 1
if( abs(Tdet[ii,jj]) <= 1e-12):
n_zero += 1
print(' nb of zero element in Tdet = {}/{}'.format(
n_zero, n_det_alpha*n_det_beta*n_det_alpha*n_det_beta ))
print(' % of zero element in Tdet = {}\n'.format(
100. * n_zero / (n_det_alpha*n_det_beta*n_det_alpha*n_det_beta) ))
return(Tdet)
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
#
def read_Tsvd():
lines = []
with open("ab_T_gd_v0.dat") as f_in:
for line in f_in:
lines.append( float(line) )
Tsvd = np.zeros( (n_det_alpha*n_det_beta,n_det_alpha*n_det_beta) )
i_l = 0
n_zero = 0
for i in range(n_det_alpha):
for j in range(n_det_beta):
ii = j + n_det_beta * i
for k in range(n_det_alpha):
for l in range(n_det_beta):
jj = l + n_det_beta * k
Tsvd[ii,jj] = lines[i_l]
i_l += 1
if( abs(Tsvd[ii,jj]) <= 1e-12):
n_zero += 1
print(' nb of zero element in Tsvd = {}/{}'.format(
n_zero, n_det_alpha*n_det_beta*n_det_alpha*n_det_beta ))
print(' % of zero element in Tsvd = {}\n'.format(
100. * n_zero / (n_det_alpha*n_det_beta*n_det_alpha*n_det_beta) ))
return(Tsvd)
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
#
def read_AO_2eCoulomb():
lines = []
with open(ao_file) as f_in:
for line in f_in:
lines.append( float(line) )
J = np.zeros((ao_num2,ao_num2))
i_l = 0
n_zero = 0
for mu in range(ao_num):
for nu in range(ao_num):
ii = nu + ao_num * mu
for sig in range(ao_num):
for lam in range(ao_num):
jj = lam + ao_num * sig
J[ii,jj] = lines[i_l]
i_l += 1
if( abs(J[ii,jj]) <= 1e-12):
n_zero += 1
print(' nb of zero element in J = {}/{}'.format(n_zero, ao_num2*ao_num2))
print(' % of zero element in J = {}\n'.format(100.*n_zero/(ao_num2*ao_num2)))
return(J)
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
#
def check_symmetric(a, rtol=1e-05, atol=1e-08):
if( np.allclose(a, a.T, rtol=rtol, atol=atol) ):
return( True )
else:
print(' | a - aT | / | a | = {} %'.format(
100. * np.linalg.norm(a-a.T) / np.linalg.norm(a) ))
return( False )
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
#
def plot_mat(M, xstep, ystep, namefile):
Mp = np.abs(M) + 1e-15
ax = sns.heatmap(Mp, linewidths=0.0, rasterized=True, norm=LogNorm())
# x axis
ax.xaxis.tick_top()
xgrid = np.arange(1, M.shape[1]+1, xstep-1)
plt.xticks( np.arange(0, M.shape[1], xstep-1) + .5, xgrid )
# y axis
ygrid = np.arange(1, M.shape[0]+1, ystep-1)
plt.yticks( np.arange(0, M.shape[0], ystep-1) + .5, ygrid )
plt.savefig(namefile)
plt.clf()
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
#
def save_SVs():
with open('sing_val.txt', 'w') as ff:
for i in range(s.shape[0]):
ff.write("{:+e}\n".format(s[i]))
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
#
if __name__=="__main__":
t0 = time.time()
print("")
print(" date and time = {} \n".format(datetime.now().strftime("%d/%m/%Y %H:%M:%S")))
EZFIO_name = "/home/aammar/qp2/src/svdwf/f2_work/f2_fci"
ezfio.set_file(EZFIO_name)
# -------------------- read M ------------------------------
n_det_alpha = ezfio.get_spindeterminants_n_det_alpha()
n_det_beta = ezfio.get_spindeterminants_n_det_beta ()
n_ab = n_det_alpha * n_det_beta
print(" n_det_alpha = {} ".format(n_det_alpha))
print(" n_det_beta = {} \n".format(n_det_beta ))
# < i j | H | k l > in det basis
hdet_file = "/home/aammar/qp2/src/svdwf/f2_work/fort.7000"
M = read_Hdet()
#M = read_Hsvd()
#M = read_Tdet()
#M = read_Tsvd()
#ao_num = ezfio.get_ao_basis_ao_num()
#ao_num2 = ao_num * ao_num
#print(" nb of AO = {} \n".format(ao_num))
# 2-e integrals in AO basis
#ao_file = "/home/aammar/qp2/src/svdwf/f2_work/ao_2eCoulombIntegrals.txt"
#M = read_AO_2eCoulomb()
#plot_mat(M, 50, 50, 'Hdet.pdf')
#plot_mat(M, 50, 50, 'Hsvd.pdf')
#plot_mat(M, 50, 50, 'Tdet.pdf')
#plot_mat(M, 50, 50, 'Tsvd.pdf')
# --------------------------------------------------------------------
# --------------------------------------------------------------------
# -------------------- perform SVD ------------------------------
norm_M = np.linalg.norm(M)
print(" size of M: {} MB ".format( sys.getsizeof(M) / 1024. ) )
print(" M is symmetric ? {} \n".format(check_symmetric(M)) )
u, s, vt = np.linalg.svd(M, full_matrices=False)
n_FSVD = s.shape[0]
err_p = 100. * np.linalg.norm(
M - np.dot( u, np.dot(np.diag(s),vt) )
) / norm_M
print(' n_FSVD = {}, err(%) = {}\n'.format(n_FSVD,err_p))
# --------------------------------------------------------------------
# --------------------------------------------------------------------
save_SVs()
# -------------------- T SVD -----------------------------
# truncatad SVD
print(' n_FSVD err(%)')
for n_TSVD in range(1,n_FSVD):
u_T, s_T, vt_T = u[:,0:n_TSVD], s[0:n_TSVD], vt[0:n_TSVD,:]
err_p = 100. * np.linalg.norm(
M - np.dot( u_T, np.dot(np.diag(s_T),vt_T) )
) / norm_M
print(' {} {:+e}'.format(n_TSVD,err_p))
# --------------------------------------------------------------------
# --------------------------------------------------------------------
print("")
print(" end after {} min".format((-t0+time.time())/60.))
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________
# ____________________________________________________________________________________________

View File

@ -0,0 +1,251 @@
# !!!
import sys, os
QMCCHEM_PATH=os.environ["QMCCHEM_PATH"]
sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/")
from ezfio import ezfio
from math import sqrt
from datetime import datetime
import time
import numpy as np
import subprocess
from scipy.linalg import eig, eigh
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_energy():
buffer = subprocess.check_output(['qmcchem', 'result', '-e', 'e_loc', EZFIO_file], encoding='UTF-8')
if buffer.strip() != "":
buffer = buffer.splitlines()[-1]
_, energy, error = [float(x) for x in buffer.split()]
return energy, error
else:
return None, None
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Ci_h_matrix_svd():
Ci_h_matrix_svd = np.zeros( (n_svd,n_svd) )
SErr_H = np.zeros( (n_svd,n_svd) )
beg_Ci_h_matrix_svd = results.find('Ci_h_matrix_svd : [ ') + len( 'Ci_h_matrix_svd : [ ' )
end_Ci_h_matrix_svd = len(results)
Ci_h_matrix_svd_buf = results[beg_Ci_h_matrix_svd:end_Ci_h_matrix_svd]
Ci_h_matrix_svd_buf = Ci_h_matrix_svd_buf.split( '\n' )
for iline in range(1, n_svd**2+1):
line = Ci_h_matrix_svd_buf[iline].split()
indc = int( line[0] )
errS = float( line[4] )
if( indc != iline ):
print(' Error in reading Ci_h_matrix_svd')
print(' indc = {}'.format(indc) )
print(' iline = {}'.format(iline) )
break
else:
irow = indc % n_svd
icol = indc // n_svd
if( irow!=0 ):
Ci_h_matrix_svd[irow-1][icol] = float( line[2] )
SErr_H [irow-1][icol] = float( line[4] )
else:
Ci_h_matrix_svd[n_svd-1][icol-1] = float( line[2] )
SErr_H [n_svd-1][icol-1] = float( line[4] )
return(Ci_h_matrix_svd,SErr_H)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Ci_overlap_matrix_svd():
Ci_overlap_matrix_svd = np.zeros( (n_svd,n_svd) )
SErr_O = np.zeros( (n_svd,n_svd) )
beg_Ci_overlap_matrix_svd = results.find('Ci_overlap_matrix_svd : [ ') + len( 'Ci_overlap_matrix_svd : [ ' )
end_Ci_overlap_matrix_svd = len(results)
Ci_overlap_matrix_svd_buf = results[beg_Ci_overlap_matrix_svd:end_Ci_overlap_matrix_svd]
Ci_overlap_matrix_svd_buf = Ci_overlap_matrix_svd_buf.split( '\n' )
for iline in range(1, n_svd**2+1):
line = Ci_overlap_matrix_svd_buf[iline].split()
indc = int( line[0] )
errS = float( line[4] )
if( indc != iline ):
print(' Error in reading Ci_overlap_matrix_svd')
print(' indc = {}'.format(indc))
print(' iline = {}'.format(iline))
break
else:
irow = indc % n_svd
icol = indc // n_svd
if( irow!=0 ):
Ci_overlap_matrix_svd[irow-1][icol] = float( line[2] )
SErr_O [irow-1][icol] = float( line[4] )
else:
Ci_overlap_matrix_svd[n_svd-1][icol-1] = float( line[2] )
SErr_O [n_svd-1][icol-1] = float( line[4] )
return(Ci_overlap_matrix_svd,SErr_O)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def check_symmetric(a, tol=1e-3):
return np.all(np.abs(a-a.T) < tol)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def save_QMCmat():
with open('SVD_QMCmat.txt', 'a') as ff:
for i in range(n_svd):
for j in range(n_svd):
ff.write('{} {} {} {} {} {} \n'.format(i,j
, Ci_h_matrix_svd[i,j] , SErr_H[i,j]
, Ci_overlap_matrix_svd[i,j] , SErr_O[i,j] ))
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Esvd():
# symmetrise and diagonalise
aa = Ci_h_matrix_svd
aa = 0.5*( aa + aa.T )
bb = Ci_overlap_matrix_svd
eigvals_svd, vr = eig(aa, bb, left=False, right=True, overwrite_a=True, overwrite_b=True,
check_finite=True, homogeneous_eigvals=False)
#print( eigvals_svd + E_toadd )
recouvre_svd = np.abs(psi_svd_coeff @ vr)
ind_gssvd = np.argmax(recouvre_svd)
E_svd = eigvals_svd[ind_gssvd] + E_toadd
return( E_svd, vr[:,ind_gssvd] )
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def Evmc_Tsvd(n_Tsvd):
# symmetrise and diagonalise
aa = Ci_h_matrix_svd[0:n_Tsvd,0:n_Tsvd]
aa = 0.5*( aa + aa.T )
bb = Ci_overlap_matrix_svd[0:n_Tsvd,0:n_Tsvd]
bb = 0.5*( bb + bb.T )
eig_Tsvd, vr_Tsvd = eig(aa, bb, left=False, right=True, overwrite_a=True, overwrite_b=True,
check_finite=True, homogeneous_eigvals=False)
recouvre_Tsvd = np.abs(psi_svd_coeff[0:n_Tsvd] @ vr_Tsvd)
ind_gssvd = np.argmax(recouvre_Tsvd)
E_Tsvd = eig_Tsvd[ind_gssvd] + E_toadd
return( E_Tsvd, vr_Tsvd[:,ind_gssvd] )
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# _________________________________________________________________________________________________
# _________________________________________________________________________________________________
#
if __name__ == '__main__':
t0 = time.time()
print(" ")
print(" Today's date: \n", datetime.now() )
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
#EZFIO_file = "/home/aammar/qp2/src/svdwf/f2_work/f2_opt/SVD_opt/f2_cisd"
E_toadd = 30.35863309325590
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
ezfio.set_file(EZFIO_file)
n_svd = ezfio.get_spindeterminants_n_svd_coefs()
psi_svd_coeff = np.array(ezfio.get_spindeterminants_psi_svd_coefs())
print(" EZFIO file = {}".format(EZFIO_file))
print(" n_svd = {}\n".format(n_svd) )
t_read = time.time()
print(' getting QMCCHEM results from {}'.format(EZFIO_file) )
results = subprocess.check_output(['qmcchem', 'result', EZFIO_file], encoding='UTF-8')
print(' getting results after {} minutes \n'.format( (time.time()-t_read)/60. ))
if( len(results)<100):
print(' result is empty \n')
exit()
Eloc, ErrEloc = get_energy()
print(' Eloc = {} +/- {}'.format(Eloc, ErrEloc))
print(' {} <= Eloc <= {}\n'.format(Eloc-ErrEloc,Eloc+ErrEloc))
#print(' initial svd coeff = {}\n'.format(psi_svd_coeff))
# read CI_SVD matrices
Ci_h_matrix_svd , SErr_H = get_Ci_h_matrix_svd()
Ci_overlap_matrix_svd, SErr_O = get_Ci_overlap_matrix_svd()
#print( 'Ci_h_matrix_svd is symmetric ? {}' .format(check_symmetric(Ci_h_matrix_svd)) )
#print( 'Ci_overlap_matrix_svd is symmetric ? {}' .format(check_symmetric(Ci_overlap_matrix_svd)) )
#save_QMCmat()
for n_Tsvd in range(n_svd):
E_Tsvd, _ = Evmc_Tsvd(n_Tsvd)
print(' n_Tsvd = {}, E_Tsvd = {}'.format(n_Tsvd,E_Tsvd) )
print('')
# ___________________________________________________________________________
# ___________________________________________________________________________
#
save_to_EZFIO = ''
#save_to_EZFIO = 'svd_QMC'
#n_TSVD = ...
#_, sigma_svd = Evmc_Tsvd(n_Tsvd)
if( save_to_EZFIO == 'svd_QMC' ):
ezfio.set_spindeterminants_psi_svd_coefs( sigma_svd )
direc_svdcoeff = EZFIO_file + '/spindeterminants/psi_svd_coefs.gz'
print(' {} is modified'.format(direc_svdcoeff) )
else:
print(' exit with no modifications in {} EZFIO'.format(EZFIO_file))
# ___________________________________________________________________________
# ___________________________________________________________________________
print("end after {:.3f} minutes".format((time.time()-t0)/60.) )
# _________________________________________________________________________________________________~
# _________________________________________________________________________________________________
# _________________________________________________________________________________________________

View File

@ -0,0 +1,216 @@
# !!!
import sys, os
QMCCHEM_PATH=os.environ["QMCCHEM_PATH"]
sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/")
from ezfio import ezfio
from math import sqrt
from datetime import datetime
import time
import numpy as np
import subprocess
from scipy.linalg import eig, eigh
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_energy():
buffer = subprocess.check_output(['qmcchem', 'result', '-e', 'e_loc', EZFIO_file], encoding='UTF-8')
if buffer.strip() != "":
buffer = buffer.splitlines()[-1]
_, energy, error = [float(x) for x in buffer.split()]
return energy, error
else:
return None, None
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Ci_h_matrix_svd():
Ci_h_matrix_svd = np.zeros( (n_svd,n_svd) )
SErr_H = np.zeros( (n_svd,n_svd) )
beg_Ci_h_matrix_svd = results.find('Ci_h_matrix_svd : [ ') + len( 'Ci_h_matrix_svd : [ ' )
end_Ci_h_matrix_svd = len(results)
Ci_h_matrix_svd_buf = results[beg_Ci_h_matrix_svd:end_Ci_h_matrix_svd]
Ci_h_matrix_svd_buf = Ci_h_matrix_svd_buf.split( '\n' )
for iline in range(1, n_svd**2+1):
line = Ci_h_matrix_svd_buf[iline].split()
indc = int( line[0] )
errS = float( line[4] )
if( indc != iline ):
print(' Error in reading Ci_h_matrix_svd')
print(' indc = {}'.format(indc) )
print(' iline = {}'.format(iline) )
break
else:
irow = indc % n_svd
icol = indc // n_svd
if( irow!=0 ):
Ci_h_matrix_svd[irow-1][icol] = float( line[2] )
SErr_H [irow-1][icol] = float( line[4] )
else:
Ci_h_matrix_svd[n_svd-1][icol-1] = float( line[2] )
SErr_H [n_svd-1][icol-1] = float( line[4] )
return(Ci_h_matrix_svd,SErr_H)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Ci_overlap_matrix_svd():
Ci_overlap_matrix_svd = np.zeros( (n_svd,n_svd) )
SErr_O = np.zeros( (n_svd,n_svd) )
beg_Ci_overlap_matrix_svd = results.find('Ci_overlap_matrix_svd : [ ') + len( 'Ci_overlap_matrix_svd : [ ' )
end_Ci_overlap_matrix_svd = len(results)
Ci_overlap_matrix_svd_buf = results[beg_Ci_overlap_matrix_svd:end_Ci_overlap_matrix_svd]
Ci_overlap_matrix_svd_buf = Ci_overlap_matrix_svd_buf.split( '\n' )
for iline in range(1, n_svd**2+1):
line = Ci_overlap_matrix_svd_buf[iline].split()
indc = int( line[0] )
errS = float( line[4] )
if( indc != iline ):
print(' Error in reading Ci_overlap_matrix_svd')
print(' indc = {}'.format(indc))
print(' iline = {}'.format(iline))
break
else:
irow = indc % n_svd
icol = indc // n_svd
if( irow!=0 ):
Ci_overlap_matrix_svd[irow-1][icol] = float( line[2] )
SErr_O [irow-1][icol] = float( line[4] )
else:
Ci_overlap_matrix_svd[n_svd-1][icol-1] = float( line[2] )
SErr_O [n_svd-1][icol-1] = float( line[4] )
return(Ci_overlap_matrix_svd,SErr_O)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def check_symmetric(a, tol=1e-3):
return np.all(np.abs(a-a.T) < tol)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Esvd():
# read CI_SVD matrices
Ci_h_matrix_svd , SErr_H = get_Ci_h_matrix_svd()
Ci_overlap_matrix_svd, SErr_O = get_Ci_overlap_matrix_svd()
#print( 'Ci_h_matrix_svd is symmetric ? {}' .format(check_symmetric(Ci_h_matrix_svd)) )
#print( 'Ci_overlap_matrix_svd is symmetric ? {}' .format(check_symmetric(Ci_overlap_matrix_svd)) )
if( save_SVD_QMCmat ):
with open('SVD_QMCmat.txt', 'a') as ff:
for i in range(n_svd):
for j in range(n_svd):
ff.write('{} {} {} {} {} {} \n'.format(i,j
, Ci_h_matrix_svd[i,j] , SErr_H[i,j]
, Ci_overlap_matrix_svd[i,j] , SErr_O[i,j] ))
# symmetrise and diagonalise
aa = Ci_h_matrix_svd
aa = 0.5*( aa + aa.T )
bb = Ci_overlap_matrix_svd
eigvals_svd, vr = eig(aa, bb, left=False, right=True, overwrite_a=True, overwrite_b=True,
check_finite=True, homogeneous_eigvals=False)
#print( eigvals_svd + E_toadd )
recouvre_svd = np.abs(psi_svd_coeff @ vr)
ind_gssvd = np.argmax(recouvre_svd)
E_svd = eigvals_svd[ind_gssvd] + E_toadd
return( E_svd, vr[:,ind_gssvd] )
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# _________________________________________________________________________________________________
# _________________________________________________________________________________________________
#
if __name__ == '__main__':
t0 = time.time()
print(" ")
print(" Today's date: \n", datetime.now() )
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
#EZFIO_file = "/home/aammar/qp2/src/svdwf/f2_work/f2_opt/SVD_opt/f2_cisd"
E_toadd = 30.35863309325590
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
ezfio.set_file(EZFIO_file)
n_svd = ezfio.get_spindeterminants_n_svd_coefs()
psi_svd_coeff = np.array(ezfio.get_spindeterminants_psi_svd_coefs())
print(" EZFIO file = {}".format(EZFIO_file))
print(" n_svd = {}\n".format(n_svd) )
t_read = time.time()
print(' getting QMCCHEM results from {}'.format(EZFIO_file) )
results = subprocess.check_output(['qmcchem', 'result', EZFIO_file], encoding='UTF-8')
print(' getting results after {} minutes \n'.format( (time.time()-t_read)/60. ))
if( len(results)<100):
print(' result is empty \n')
exit()
Eloc, ErrEloc = get_energy()
print(' Eloc = {} +/- {}'.format(Eloc, ErrEloc))
print(' {} <= Eloc <= {}'.format(Eloc-ErrEloc,Eloc+ErrEloc))
#print(' initial svd coeff = {}\n'.format(psi_svd_coeff))
save_SVD_QMCmat = True
#save_SVD_QMCmat = False
print('')
E_svd, sigma_svd = get_Esvd()
print(' svd enegry = {}'.format(E_svd) )
sigma_svd = sigma_svd * np.sign(sigma_svd[0])
#print(' svd coeff = {}'.format(sigma_svd))
print('')
# ___________________________________________________________________________
# ___________________________________________________________________________
#
#save_to_EZFIO = 'svd_QMC'
save_to_EZFIO = ''
if( save_to_EZFIO == 'svd_QMC' ):
ezfio.set_spindeterminants_psi_svd_coefs( sigma_svd )
direc_svdcoeff = EZFIO_file + '/spindeterminants/psi_svd_coefs.gz'
print(' {} is modified'.format(direc_svdcoeff) )
else:
print(' exit with no modifications in {} EZFIO'.format(EZFIO_file))
# ___________________________________________________________________________
# ___________________________________________________________________________
print("end after {:.3f} minutes".format((time.time()-t0)/60.) )
# _________________________________________________________________________________________________~
# _________________________________________________________________________________________________
# _________________________________________________________________________________________________

View File

@ -0,0 +1,225 @@
# !!!
import sys, os
QMCCHEM_PATH=os.environ["QMCCHEM_PATH"]
sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/")
from ezfio import ezfio
from math import sqrt
from datetime import datetime
import time
import numpy as np
import subprocess
from scipy.linalg import eig, eigh
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_energy():
buffer = subprocess.check_output(['qmcchem', 'result', '-e', 'e_loc', EZFIO_file], encoding='UTF-8')
if buffer.strip() != "":
buffer = buffer.splitlines()[-1]
_, energy, error = [float(x) for x in buffer.split()]
return energy, error
else:
return None, None
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Ci_h_matrix_modifsvd():
Ci_h_matrix_modifsvd = np.zeros( (n_modifsvd,n_modifsvd) )
SErr_H = np.zeros( (n_modifsvd,n_modifsvd) )
beg_Ci_h_matrix_modifsvd = results.find('Ci_h_matrix_modifsvd : [ ') + len( 'Ci_h_matrix_modifsvd : [ ' )
end_Ci_h_matrix_modifsvd = len(results)
Ci_h_matrix_modifsvd_buf = results[beg_Ci_h_matrix_modifsvd:end_Ci_h_matrix_modifsvd]
Ci_h_matrix_modifsvd_buf = Ci_h_matrix_modifsvd_buf.split( '\n' )
for iline in range(1, n_modifsvd**2+1):
line = Ci_h_matrix_modifsvd_buf[iline].split()
indc = int( line[0] )
errS = float( line[4] )
if( indc != iline ):
print(' Error in reading Ci_h_matrix_modifsvd')
print(' indc = {}'.format(indc) )
print(' iline = {}'.format(iline) )
break
else:
irow = indc % n_modifsvd
icol = indc // n_modifsvd
if( irow!=0 ):
Ci_h_matrix_modifsvd[irow-1][icol] = float( line[2] )
SErr_H [irow-1][icol] = float( line[4] )
else:
Ci_h_matrix_modifsvd[n_modifsvd-1][icol-1] = float( line[2] )
SErr_H [n_modifsvd-1][icol-1] = float( line[4] )
# !!!
# !!!
return(Ci_h_matrix_modifsvd,SErr_H)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Ci_overlap_matrix_modifsvd():
Ci_overlap_matrix_modifsvd = np.zeros( (n_modifsvd,n_modifsvd) )
SErr_O = np.zeros( (n_modifsvd,n_modifsvd) )
beg_Ci_overlap_matrix_modifsvd = results.find('Ci_overlap_matrix_modifsvd : [ ') + len( 'Ci_overlap_matrix_modifsvd : [ ' )
end_Ci_overlap_matrix_modifsvd = len(results)
Ci_overlap_matrix_modifsvd_buf = results[beg_Ci_overlap_matrix_modifsvd:end_Ci_overlap_matrix_modifsvd]
Ci_overlap_matrix_modifsvd_buf = Ci_overlap_matrix_modifsvd_buf.split( '\n' )
for iline in range(1, n_modifsvd**2+1):
line = Ci_overlap_matrix_modifsvd_buf[iline].split()
indc = int( line[0] )
errS = float( line[4] )
if( indc != iline ):
print(' Error in reading Ci_overlap_matrix_modifsvd')
print(' indc = {}'.format(indc))
print(' iline = {}'.format(iline))
break
else:
irow = indc % n_modifsvd
icol = indc // n_modifsvd
if( irow!=0 ):
Ci_overlap_matrix_modifsvd[irow-1][icol] = float( line[2] )
SErr_O [irow-1][icol] = float( line[4] )
else:
Ci_overlap_matrix_modifsvd[n_modifsvd-1][icol-1] = float( line[2] )
SErr_O [n_modifsvd-1][icol-1] = float( line[4] )
return(Ci_overlap_matrix_modifsvd,SErr_O)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def check_symmetric(a, tol=1e-3):
return np.all(np.abs(a-a.T) < tol)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Esvd():
Ci_h_matrix_modifsvd , SErr_H = get_Ci_h_matrix_modifsvd()
Ci_overlap_matrix_modifsvd, SErr_O = get_Ci_overlap_matrix_modifsvd()
if( save_compactSVD_QMCmat ):
with open('compactSVD_QMCmat.txt', 'a') as ff:
for i in range(n_modifsvd):
for j in range(n_modifsvd):
ff.write('{} {} {} {} {} {} \n'.format(i,j
, Ci_h_matrix_modifsvd[i,j] , SErr_H[i,j]
, Ci_overlap_matrix_modifsvd[i,j] , SErr_O[i,j] ))
# symmetrise and diagonalise
aa = Ci_h_matrix_modifsvd
aa = 0.5*( aa + aa.T )
bb = Ci_overlap_matrix_modifsvd
eigvals_modifsvd, vr = eig(aa, bb, left=False, right=True, overwrite_a=True, overwrite_b=True,
check_finite=True, homogeneous_eigvals=False)
psi_tmp = psi_svd_coefs[0,0:n_modifsvd]
recouvre_modifsvd = np.abs(psi_tmp @ vr)
ind_gssvd = np.argmax(recouvre_modifsvd)
E_modifsvd = eigvals_modifsvd[ind_gssvd] + E_toadd
return( E_modifsvd, vr[:,ind_gssvd] )
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
if __name__ == '__main__':
t0 = time.time()
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
#EZFIO_file = "Cr2_compactSVD30"
EZFIO_file = "Cr2_compactSVD30_it1"
E_toadd = 64.8242130309350
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
ezfio.set_file(EZFIO_file)
n_svd = ezfio.get_spindeterminants_n_svd_coefs()
n_modifsvd = ezfio.get_spindeterminants_n_modifsvd_coefs()
psi_svd_coefs = np.array(ezfio.get_spindeterminants_psi_svd_coefs())
print(" ")
print(" Today's date:", datetime.now() )
print(" EZFIO file = {}".format(EZFIO_file))
print(" n_svd = {}".format(n_svd) )
print(" n_modifsvd = {}\n".format(n_modifsvd) )
t_read = time.time()
print(' getting QMCCHEM results from {}'.format(EZFIO_file) )
results = subprocess.check_output(['qmcchem', 'result', EZFIO_file], encoding='UTF-8')
print(' getting results after {} minutes \n'.format( (time.time()-t_read)/60. ))
if( len(results)<100):
print(' result is empty \n')
exit()
Eloc, ErrEloc = get_energy()
print(' Eloc = {} +/- {}'.format(Eloc, ErrEloc))
print(' {} <= Eloc <= {}'.format(Eloc-ErrEloc,Eloc+ErrEloc))
#print(' initial svd coeff = {}\n'.format(psi_svd_coefs))
save_compactSVD_QMCmat = True
print('')
E_compactsvd, sigma_compactsvd = get_Esvd()
print(' compact svd enegry = {}'.format(E_compactsvd) )
sigma_compactsvd = sigma_compactsvd * np.sign(sigma_compactsvd[0])
print(' compact svd coeff = {}\n'.format(sigma_compactsvd))
#print(' compact svd factor = {}\n'.format(sigma_compactsvd[n_modifsvd-1]))
# ___________________________________________________________________________
# ___________________________________________________________________________
#
#save_to_EZFIO = 'compactsvd_QMC'
save_to_EZFIO = ''
if( save_to_EZFIO == 'compactsvd_QMC' ):
ezfio_sigma_svd = np.zeros((n_svd))
for i in range(n_modifsvd-1):
ezfio_sigma_svd[i] = sigma_compactsvd[i]
for i in range(n_modifsvd-1, n_svd):
ezfio_sigma_svd[i] = psi_svd_coefs[0,i] * sigma_compactsvd[n_modifsvd-1]
#print(' new svd coeff = {}\n'.format(ezfio_sigma_svd))
ezfio.set_spindeterminants_psi_svd_coefs( ezfio_sigma_svd )
direc_svdcoeff = EZFIO_file + '/spindeterminants/psi_svd_coefs.gz'
print(' {} is modified'.format(direc_svdcoeff) )
else:
print(' no modifications has been done in {}'.format(EZFIO_file))
# ___________________________________________________________________________
# ___________________________________________________________________________
print("end after {:.3f} minutes".format((time.time()-t0)/60.) )
# !!!
# !!!
~
~

View File

@ -0,0 +1,166 @@
# !!!
import sys, os
QMCCHEM_PATH=os.environ["QMCCHEM_PATH"]
sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/")
from ezfio import ezfio
from math import sqrt
from datetime import datetime
import time
import numpy as np
import subprocess
from scipy.linalg import eig, eigh
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_energy():
buffer = subprocess.check_output(['qmcchem', 'result', '-e', 'e_loc', EZFIO_file], encoding='UTF-8')
if buffer.strip() != "":
buffer = buffer.splitlines()[-1]
_, energy, error = [float(x) for x in buffer.split()]
return energy, error
else:
return None, None
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Ci_h_matrix_svd():
Ci_h_matrix_svd = np.zeros( (n_svd,n_svd) )
SErr_H = np.zeros( (n_svd,n_svd) )
f = open(VMCmat_file, 'r')
Lines = f.readlines()
for line in Lines:
line = line.split()
ii = int ( line[0] )
jj = int ( line[1] )
Ci_h_matrix_svd[ii][jj] = float( line[2] )
SErr_H [ii][jj] = float( line[3] )
return(Ci_h_matrix_svd,SErr_H)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Ci_overlap_matrix_svd():
Ci_overlap_matrix_svd = np.zeros( (n_svd,n_svd) )
SErr_O = np.zeros( (n_svd,n_svd) )
f = open(VMCmat_file, 'r')
Lines = f.readlines()
for line in Lines:
line = line.split()
ii = int ( line[0] )
jj = int ( line[1] )
Ci_overlap_matrix_svd[ii][jj] = float( line[4] )
SErr_O [ii][jj] = float( line[5] )
return(Ci_overlap_matrix_svd,SErr_O)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def check_symmetric(a, tol=1e-3):
return np.all(np.abs(a-a.T) < tol)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Esvd():
# read CI_SVD matrices
Ci_h_matrix_svd , SErr_H = get_Ci_h_matrix_svd()
Ci_overlap_matrix_svd, SErr_O = get_Ci_overlap_matrix_svd()
#print( 'Ci_h_matrix_svd is symmetric ? {}' .format(check_symmetric(Ci_h_matrix_svd)) )
#print( 'Ci_overlap_matrix_svd is symmetric ? {}' .format(check_symmetric(Ci_overlap_matrix_svd)) )
# symmetrise and diagonalise
aa = Ci_h_matrix_svd
aa = 0.5*( aa + aa.T )
bb = Ci_overlap_matrix_svd
eigvals_svd, vr = eig(aa, bb, left=False, right=True, overwrite_a=True, overwrite_b=True,
check_finite=True, homogeneous_eigvals=False)
#print( eigvals_svd + E_toadd )
recouvre_svd = np.abs(psi_svd_coeff @ vr)
ind_gssvd = np.argmax(recouvre_svd)
E_svd = eigvals_svd[ind_gssvd] + E_toadd
return( E_svd, vr[:,ind_gssvd] )
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# _________________________________________________________________________________________________
# _________________________________________________________________________________________________
#
if __name__ == '__main__':
t0 = time.time()
print(" ")
print(" Today's date:\n", datetime.now() )
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
#EZFIO_file = "Cr2_TSVD30_it2"
E_toadd = 30.35863309325590
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
ezfio.set_file(EZFIO_file)
n_svd = ezfio.get_spindeterminants_n_svd_coefs()
psi_svd_coeff = np.array(ezfio.get_spindeterminants_psi_svd_coefs())
print(" EZFIO file = {}".format(EZFIO_file))
print(" n_svd = {}\n".format(n_svd) )
#VMCmat_list = [ 'SVD_QMCmat_FSVD_2b.txt' , 'SVD_QMCmat_FSVD_3b.txt' , 'SVD_QMCmat_FSVD_0.txt' ]
#VMCmat_list = [ 'SVD_QMCmat_FSVD_2b_1.txt', 'SVD_QMCmat_FSVD_3b_1.txt'
# , 'SVD_QMCmat_FSVD_4b_1.txt', 'SVD_QMCmat_FSVD_5b_1.txt'
# , 'SVD_QMCmat_FSVD_1.txt' ]
#for VMCmat_file in VMCmat_list:
# print(" SVD matrices file = {}".format(VMCmat_file))
# E_svd, sigma_svd = get_Esvd()
# print(' svd enegry = {} \n'.format(E_svd) )
VMCmat_file = 'SVD_QMCmat_FSVD_4b_1.txt'
print(" SVD matrices file = {}".format(VMCmat_file))
E_svd, sigma_svd = get_Esvd()
sigma_svd = sigma_svd * np.sign(sigma_svd[0])
print(' svd coeff = {}'.format(sigma_svd))
# ___________________________________________________________________________
# ___________________________________________________________________________
#
#save_to_EZFIO = 'svd_QMC'
save_to_EZFIO = ''
if( save_to_EZFIO == 'svd_QMC' ):
ezfio.set_spindeterminants_psi_svd_coefs( sigma_svd )
direc_svdcoeff = EZFIO_file + '/spindeterminants/psi_svd_coefs.gz'
print(' {} is modified'.format(direc_svdcoeff) )
else:
pass
# ___________________________________________________________________________
# ___________________________________________________________________________
print("end after {:.3f} minutes".format((time.time()-t0)/60.) )
# _________________________________________________________________________________________________
# _________________________________________________________________________________________________
# _________________________________________________________________________________________________
~

View File

@ -0,0 +1,173 @@
# !!!
import sys, os
QMCCHEM_PATH=os.environ["QMCCHEM_PATH"]
sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/")
from ezfio import ezfio
from math import sqrt
from datetime import datetime
import time
import numpy as np
import subprocess
from scipy.linalg import eig, eigh
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_energy():
buffer = subprocess.check_output(['qmcchem', 'result', '-e', 'e_loc', EZFIO_file], encoding='UTF-8')
if buffer.strip() != "":
buffer = buffer.splitlines()[-1]
_, energy, error = [float(x) for x in buffer.split()]
return energy, error
else:
return None, None
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Ci_h_matrix_modifsvd():
Ci_h_matrix_modifsvd = np.zeros( (n_modifsvd,n_modifsvd) )
SErr_H = np.zeros( (n_modifsvd,n_modifsvd) )
f = open(compactVMCmat_file, 'r')
Lines = f.readlines()
for line in Lines:
line = line.split()
ii = int ( line[0] )
jj = int ( line[1] )
Ci_h_matrix_modifsvd[ii][jj] = float( line[2] )
SErr_H [ii][jj] = float( line[3] )
return(Ci_h_matrix_modifsvd,SErr_H)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Ci_overlap_matrix_modifsvd():
Ci_overlap_matrix_modifsvd = np.zeros( (n_modifsvd,n_modifsvd) )
SErr_O = np.zeros( (n_modifsvd,n_modifsvd) )
f = open(compactVMCmat_file, 'r')
Lines = f.readlines()
for line in Lines:
line = line.split()
ii = int ( line[0] )
jj = int ( line[1] )
Ci_overlap_matrix_modifsvd[ii][jj] = float( line[4] )
SErr_O [ii][jj] = float( line[5] )
return(Ci_overlap_matrix_modifsvd,SErr_O)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def check_symmetric(a, tol=1e-3):
return np.all(np.abs(a-a.T) < tol)
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Esvd():
Ci_h_matrix_modifsvd , SErr_H = get_Ci_h_matrix_modifsvd()
Ci_overlap_matrix_modifsvd, SErr_O = get_Ci_overlap_matrix_modifsvd()
# symmetrise and diagonalise
aa = Ci_h_matrix_modifsvd
aa = 0.5*( aa + aa.T )
bb = Ci_overlap_matrix_modifsvd
eigvals_modifsvd, vr = eig(aa, bb, left=False, right=True, overwrite_a=True, overwrite_b=True,
check_finite=True, homogeneous_eigvals=False)
psi_tmp = psi_svd_coefs[0,0:n_modifsvd]
recouvre_modifsvd = np.abs(psi_tmp @ vr)
ind_gssvd = np.argmax(recouvre_modifsvd)
E_modifsvd = eigvals_modifsvd[ind_gssvd] + E_toadd
return( E_modifsvd, vr[:,ind_gssvd] )
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
if __name__ == '__main__':
t0 = time.time()
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
#EZFIO_file = "Cr2_compactSVD30"
#EZFIO_file = "Cr2_compactSVD30_it1"
EZFIO_file = "Cr2_compactSVD30_it1_1"
E_toadd = 64.8242130309350
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
ezfio.set_file(EZFIO_file)
n_svd = ezfio.get_spindeterminants_n_svd_coefs()
n_modifsvd = ezfio.get_spindeterminants_n_modifsvd_coefs()
psi_svd_coefs = np.array(ezfio.get_spindeterminants_psi_svd_coefs())
print(" ")
print(" Today's date:", datetime.now() )
print(" EZFIO file = {}".format(EZFIO_file))
print(" n_svd = {}".format(n_svd) )
print(" n_modifsvd = {}\n".format(n_modifsvd) )
#print(' initial svd coeff = {}\n'.format(psi_svd_coefs))
compactVMCmat_list = [ 'compactSVD_QMCmat_1.txt' , 'compactSVD_QMCmat_2.txt' ]
for compactVMCmat_file in compactVMCmat_list:
print(" compactSVD matrices file = {}".format(compactVMCmat_file))
E_compactsvd, sigma_compactsvd = get_Esvd()
print(' compact svd enegry = {}'.format(E_compactsvd) )
print('')
compactVMCmat_file = 'compactSVD_QMCmat_1.txt'
print(" compactSVD matrices file = {}".format(compactVMCmat_file))
E_compactsvd, sigma_compactsvd = get_Esvd()
sigma_compactsvd = sigma_compactsvd * np.sign(sigma_compactsvd[0])
print(' compact svd enegry = {}'.format(E_compactsvd) )
print(' compact svd coeff = {}\n'.format(sigma_compactsvd))
print(' compact svd factor = {}\n'.format(sigma_compactsvd[n_modifsvd-1]))
# ___________________________________________________________________________
# ___________________________________________________________________________
#
#save_to_EZFIO = 'compactsvd_QMC'
save_to_EZFIO = ''
if( save_to_EZFIO == 'compactsvd_QMC' ):
ezfio_sigma_svd = np.zeros((n_svd))
for i in range(n_modifsvd-1):
ezfio_sigma_svd[i] = sigma_compactsvd[i]
for i in range(n_modifsvd-1, n_svd):
ezfio_sigma_svd[i] = psi_svd_coefs[0,i] * sigma_compactsvd[n_modifsvd-1]
#print(' new svd coeff = {}\n'.format(ezfio_sigma_svd))
ezfio.set_spindeterminants_psi_svd_coefs( ezfio_sigma_svd )
direc_svdcoeff = EZFIO_file + '/spindeterminants/psi_svd_coefs.gz'
print(' {} is modified'.format(direc_svdcoeff) )
else:
print(' no modifications has been done in {}'.format(EZFIO_file))
# ___________________________________________________________________________
# ___________________________________________________________________________
print("end after {:.3f} minutes".format((time.time()-t0)/60.) )
# !!!
# !!!
~

View File

@ -0,0 +1,188 @@
#!/usr/bin/env python
import numpy as np
import subprocess
import sys, os
import time
from datetime import datetime
QP_PATH=os.environ["QP_ROOT"]+"/external/ezfio/Python/"
sys.path.insert(0,QP_PATH)
from ezfio import ezfio
#____________________________________________________________________________________
#
def get_energy():
energy_buffer = subprocess.check_output(
['qmcchem', 'result', '-e', 'e_loc', EZFIO_file]
, encoding='UTF-8')
if energy_buffer.strip() != "":
energy_buffer = energy_buffer.splitlines()[-1]
_, energy, error = [float(x) for x in energy_buffer.split()]
return energy, error
else:
return None, None
#____________________________________________________________________________________
#____________________________________________________________________________________
#
def read_scalar(scalar):
scal_txt = scalar + ' : '
beg_read = results.find(scal_txt) + len(scal_txt)
scal_buf = results[beg_read:beg_read+100].split('\n')[0].split()
scal_val , scal_err = float( scal_buf[0] ) , float( scal_buf[2] )
return(scal_val,scal_err)
#____________________________________________________________________________________
#____________________________________________________________________________________
#
def read_ci_dress_svd():
Ci_dress_svd_val = np.zeros((n_svd))
Ci_dress_svd_err = np.zeros((n_svd))
beg_read = results.find('Ci_dress_svd : [ ') + len( 'Ci_dress_svd : [ ' )
end_read = len(results)
vect_buf = results[beg_read:end_read]
vect_buf = vect_buf.split( '\n' )
for iline in range(1, n_svd+1):
line = vect_buf[iline].split()
# check
indc = int( line[0] )
if( indc != iline ):
print(' Error in reading Ci_dress_svd')
print(' indc = {}'.format(indc) )
print(' iline = {}'.format(iline) )
break
else:
Ci_dress_svd_val[indc-1] = float( line[2] )
Ci_dress_svd_err[indc-1] = float( line[4] )
return(Ci_dress_svd_val,Ci_dress_svd_err)
#____________________________________________________________________________________
#____________________________________________________________________________________
#
def get_ci_dress():
U_svd = np.array(ezfio.get_spindeterminants_psi_svd_alpha())
V_svd = np.array(ezfio.get_spindeterminants_psi_svd_beta())
U_svd = U_svd[0,:,:].T
V_svd = V_svd[0,:,:].T
ci_dress_mat_val = np.dot(U_svd,np.dot(np.diagflat(Ci_dress_svd_val),V_svd.T))
ci_dress_mat_err = np.dot(U_svd,np.dot(np.diagflat(Ci_dress_svd_err),V_svd.T))
n_det = ezfio.get_spindeterminants_n_det()
i_row = np.array(ezfio.get_spindeterminants_psi_coef_matrix_rows())
j_col = np.array(ezfio.get_spindeterminants_psi_coef_matrix_columns())
Ci_dress_val = np.zeros((n_det))
Ci_dress_err = np.zeros((n_det))
for k in range(n_det):
i = i_row[k] - 1
j = j_col[k] - 1
Ci_dress_val[k] = ci_dress_mat_val[i,j]
Ci_dress_err[k] = ci_dress_mat_err[i,j]
Ci_dress_val = Ci_dress_val / psi_norm
Ci_dress_err = Ci_dress_err / psi_norm
return(Ci_dress_val,Ci_dress_err)
#____________________________________________________________________________________
#____________________________________________________________________________________
#
def save_to_file(v_val,v_err, name_f):
with open(name_f, 'w') as ff:
for i in range(len(v_val)):
ff.write(' {} {} {}\n'.format(i, v_val[i], v_err[i]))
#____________________________________________________________________________________
# _________________________________________________________________________________________________
# _________________________________________________________________________________________________
#
if __name__ == '__main__':
t0 = time.time()
print(" ")
print(" Today's date:\n", datetime.now() )
# _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
#
#EZFIO_file = sys.argv[1]
EZFIO_file = "/home/aammar/qp2/src/svdwf/f2_work/f2_opt/dress_opt/f2_cisd"
# _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ezfio.set_file(EZFIO_file)
n_svd = ezfio.get_spindeterminants_n_svd_coefs()
print(" EZFIO file = {}".format(EZFIO_file))
print(" n_svd = {}\n".format(n_svd) )
t_read = time.time()
print(' getting QMCCHEM results from {}'.format(EZFIO_file) )
results = subprocess.check_output(['qmcchem', 'result', EZFIO_file], encoding='UTF-8')
print(' getting results after {} minutes \n'.format( (time.time()-t_read)/60. ))
# --------------------
# read QMC results
E_loc, ErrE_loc = get_energy()
print(' E_loc = {} +/- {}'.format(E_loc, ErrE_loc))
print(' {} <= E_loc <= {}\n'.format(E_loc-ErrE_loc,E_loc+ErrE_loc))
E_loc_qmcvar, ErrE_loc_qmcvar = read_scalar('E_loc_qmcvar')
print(' E_loc_qmcvar = {} +/- {} \n'.format(E_loc_qmcvar,ErrE_loc_qmcvar))
psi_norm, Errpsi_norm = read_scalar('Psi_norm')
print(' psi_norm = {} +/- {}\n'.format(psi_norm,Errpsi_norm))
psi_norm_qmcvar, Errpsi_norm_qmcvar = read_scalar('Psi_norm_qmcvar')
print(' Psi_norm_qmcvar = {} +/- {} \n'.format(psi_norm_qmcvar, Errpsi_norm_qmcvar))
Ci_dress_svd_val, Ci_dress_svd_err = read_ci_dress_svd()
# --------------------
# --------------------
Ci_dress_val, Ci_dress_err = get_ci_dress()
save_to_file(Ci_dress_svd_val,Ci_dress_svd_err, 'ci_dress_svd.txt')
save_to_file(Ci_dress_val,Ci_dress_err, 'ci_dress.txt')
# _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
#
# SAVE TO EZFIO
#
#ezfio.set_dmc_dress_dmc_delta_h(Ci_dress_val)
# _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
#
print("end after {:.3f} minutes".format((time.time()-t0)/60.) )
# _________________________________________________________________________________________________
# _________________________________________________________________________________________________
# _________________________________________________________________________________________________

View File

@ -0,0 +1,25 @@
1- prepare the dressing vector in EZFIO/dmc_dress/dmc_delta_h with:
[aammar@lcpq-curie dress_opt]$ python dress_SVD.py
2- run:
[aammar@lcpq-curie dress_opt]$ qp run dmc_dress
3- update the wavefunction in the EZFIO with:
[aammar@lcpq-curie dress_opt]$ qp run dmc_dress
4- to do the calculation without SVD, put -1 for n_SVD
in EZFIO/spindeterminants/n_svd_coefs. Otherwise, run:
[aammar@lcpq-curie dress_opt]$ qp run FSVD_trunc

View File

@ -0,0 +1,504 @@
# ******NOTICE***************
# optimize.py module by Travis E. Oliphant
#
# You may copy and use this module as you see fit with no
# guarantee implied provided you keep this notice in all copies.
# *****END NOTICE************
import numpy
from numpy import asarray, eye, squeeze, sum
class Brent:
#need to rethink design of __init__
def __init__(self, func, args=(), tol=1.48e-8, maxiter=500,
full_output=0):
self.func = func
self.args = args
self.tol = tol
self.maxiter = maxiter
self._mintol = 1.0e-11
self._cg = 0.3819660
self.xmin = None
self.fval = None
self.iter = 0
self.funcalls = 0
#need to rethink design of set_bracket (new options, etc)
def set_bracket(self, brack = None):
self.brack = brack
def get_bracket_info(self):
#set up
func = self.func
args = self.args
brack = self.brack
### BEGIN core bracket_info code ###
### carefully DOCUMENT any CHANGES in core ##
if brack is None:
xa,xb,xc,fa,fb,fc,funcalls = bracket(func, args=args)
elif len(brack) == 2:
xa,xb,xc,fa,fb,fc,funcalls = bracket(func, xa=brack[0],
xb=brack[1], args=args)
elif len(brack) == 3:
xa,xb,xc = brack
if (xa > xc): # swap so xa < xc can be assumed
dum = xa; xa=xc; xc=dum
assert ((xa < xb) and (xb < xc)), "Not a bracketing interval."
fa = func(*((xa,)+args))
fb = func(*((xb,)+args))
fc = func(*((xc,)+args))
assert ((fb<fa) and (fb < fc)), "Not a bracketing interval."
funcalls = 3
else:
raise ValueError("Bracketing interval must be " \
"length 2 or 3 sequence.")
### END core bracket_info code ###
return xa,xb,xc,fa,fb,fc,funcalls
def optimize(self):
#set up for optimization
func = self.func
xa,xb,xc,fa,fb,fc,funcalls = self.get_bracket_info()
_mintol = self._mintol
_cg = self._cg
#################################
#BEGIN CORE ALGORITHM
#we are making NO CHANGES in this
#################################
x=w=v=xb
fw=fv=fx=func(*((x,)+self.args))
if (xa < xc):
a = xa; b = xc
else:
a = xc; b = xa
deltax= 0.0
funcalls = 1
iter = 0
while (iter < self.maxiter):
tol1 = self.tol*abs(x) + _mintol
tol2 = 2.0*tol1
xmid = 0.5*(a+b)
if abs(x-xmid) < (tol2-0.5*(b-a)): # check for convergence
xmin=x; fval=fx
break
if (abs(deltax) <= tol1):
if (x>=xmid): deltax=a-x # do a golden section step
else: deltax=b-x
rat = _cg*deltax
else: # do a parabolic step
tmp1 = (x-w)*(fx-fv)
tmp2 = (x-v)*(fx-fw)
p = (x-v)*tmp2 - (x-w)*tmp1;
tmp2 = 2.0*(tmp2-tmp1)
if (tmp2 > 0.0): p = -p
tmp2 = abs(tmp2)
dx_temp = deltax
deltax= rat
# check parabolic fit
if ((p > tmp2*(a-x)) and (p < tmp2*(b-x)) and (abs(p) < abs(0.5*tmp2*dx_temp))):
rat = p*1.0/tmp2 # if parabolic step is useful.
u = x + rat
if ((u-a) < tol2 or (b-u) < tol2):
if xmid-x >= 0: rat = tol1
else: rat = -tol1
else:
if (x>=xmid): deltax=a-x # if it's not do a golden section step
else: deltax=b-x
rat = _cg*deltax
if (abs(rat) < tol1): # update by at least tol1
if rat >= 0: u = x + tol1
else: u = x - tol1
else:
u = x + rat
fu = func(*((u,)+self.args)) # calculate new output value
funcalls += 1
if (fu > fx): # if it's bigger than current
if (u<x): a=u
else: b=u
if (fu<=fw) or (w==x):
v=w; w=u; fv=fw; fw=fu
elif (fu<=fv) or (v==x) or (v==w):
v=u; fv=fu
else:
if (u >= x): a = x
else: b = x
v=w; w=x; x=u
fv=fw; fw=fx; fx=fu
iter += 1
#################################
#END CORE ALGORITHM
#################################
self.xmin = x
self.fval = fx
self.iter = iter
self.funcalls = funcalls
def get_result(self, full_output=False):
if full_output:
return self.xmin, self.fval, self.iter, self.funcalls
else:
return self.xmin
def wrap_function(function, args):
ncalls = [0]
def function_wrapper(x):
ncalls[0] += 1
return function(x, *args)
return ncalls, function_wrapper
def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500):
"""Given a function of one-variable and a possible bracketing interval,
return the minimum of the function isolated to a fractional precision of
tol.
Parameters
----------
func : callable f(x,*args)
Objective function.
args
Additional arguments (if present).
brack : tuple
Triple (a,b,c) where (a<b<c) and func(b) <
func(a),func(c). If bracket consists of two numbers (a,c)
then they are assumed to be a starting interval for a
downhill bracket search (see `bracket`); it doesn't always
mean that the obtained solution will satisfy a<=x<=c.
full_output : bool
If True, return all output args (xmin, fval, iter,
funcalls).
Returns
-------
xmin : ndarray
Optimum point.
fval : float
Optimum value.
iter : int
Number of iterations.
funcalls : int
Number of objective function evaluations made.
Notes
-----
Uses inverse parabolic interpolation when possible to speed up
convergence of golden section method.
"""
brent = Brent(func=func, args=args, tol=tol,
full_output=full_output, maxiter=maxiter)
brent.set_bracket(brack)
brent.optimize()
return brent.get_result(full_output=full_output)
def bracket(func, xa=0.0, xb=1.0, args=(), grow_limit=110.0, maxiter=1000):
"""Given a function and distinct initial points, search in the
downhill direction (as defined by the initital points) and return
new points xa, xb, xc that bracket the minimum of the function
f(xa) > f(xb) < f(xc). It doesn't always mean that obtained
solution will satisfy xa<=x<=xb
Parameters
----------
func : callable f(x,*args)
Objective function to minimize.
xa, xb : float
Bracketing interval.
args : tuple
Additional arguments (if present), passed to `func`.
grow_limit : float
Maximum grow limit.
maxiter : int
Maximum number of iterations to perform.
Returns
-------
xa, xb, xc : float
Bracket.
fa, fb, fc : float
Objective function values in bracket.
funcalls : int
Number of function evaluations made.
"""
_gold = 1.618034
_verysmall_num = 1e-21
fa = func(*(xa,)+args)
fb = func(*(xb,)+args)
if (fa < fb): # Switch so fa > fb
dum = xa; xa = xb; xb = dum
dum = fa; fa = fb; fb = dum
xc = xb + _gold*(xb-xa)
fc = func(*((xc,)+args))
funcalls = 3
iter = 0
while (fc < fb):
tmp1 = (xb - xa)*(fb-fc)
tmp2 = (xb - xc)*(fb-fa)
val = tmp2-tmp1
if abs(val) < _verysmall_num:
denom = 2.0*_verysmall_num
else:
denom = 2.0*val
w = xb - ((xb-xc)*tmp2-(xb-xa)*tmp1)/denom
wlim = xb + grow_limit*(xc-xb)
if iter > maxiter:
#raise RuntimeError, "Too many iterations."
raise RuntimeError("Too many iterations.")
iter += 1
if (w-xc)*(xb-w) > 0.0:
fw = func(*((w,)+args))
funcalls += 1
if (fw < fc):
xa = xb; xb=w; fa=fb; fb=fw
return xa, xb, xc, fa, fb, fc, funcalls
elif (fw > fb):
xc = w; fc=fw
return xa, xb, xc, fa, fb, fc, funcalls
w = xc + _gold*(xc-xb)
fw = func(*((w,)+args))
funcalls += 1
elif (w-wlim)*(wlim-xc) >= 0.0:
w = wlim
fw = func(*((w,)+args))
funcalls += 1
elif (w-wlim)*(xc-w) > 0.0:
fw = func(*((w,)+args))
funcalls += 1
if (fw < fc):
xb=xc; xc=w; w=xc+_gold*(xc-xb)
fb=fc; fc=fw; fw=func(*((w,)+args))
funcalls += 1
else:
w = xc + _gold*(xc-xb)
fw = func(*((w,)+args))
funcalls += 1
xa=xb; xb=xc; xc=w
fa=fb; fb=fc; fc=fw
return xa, xb, xc, fa, fb, fc, funcalls
def _linesearch_powell(func, p, xi, tol=1e-3):
"""Line-search algorithm using fminbound.
Find the minimium of the function ``func(x0+ alpha*direc)``.
"""
def myfunc(alpha):
return func(p + alpha * xi)
alpha_min, fret, iter, num = brent(myfunc, full_output=1, tol=tol)
xi = alpha_min*xi
return squeeze(fret), p+xi, xi
def fmin_powell(func, x0, args=(), xtol=1e-4, ftol=1e-4, maxiter=None,
maxfun=None, full_output=0, disp=1, retall=0, callback=None,
direc=None):
"""Minimize a function using modified Powell's method.
Parameters
----------
func : callable f(x,*args)
Objective function to be minimized.
x0 : ndarray
Initial guess.
args : tuple
Eextra arguments passed to func.
callback : callable
An optional user-supplied function, called after each
iteration. Called as ``callback(xk)``, where ``xk`` is the
current parameter vector.
direc : ndarray
Initial direction set.
Returns
-------
xopt : ndarray
Parameter which minimizes `func`.
fopt : number
Value of function at minimum: ``fopt = func(xopt)``.
direc : ndarray
Current direction set.
iter : int
Number of iterations.
funcalls : int
Number of function calls made.
warnflag : int
Integer warning flag:
1 : Maximum number of function evaluations.
2 : Maximum number of iterations.
allvecs : list
List of solutions at each iteration.
Other Parameters
----------------
xtol : float
Line-search error tolerance.
ftol : float
Relative error in ``func(xopt)`` acceptable for convergence.
maxiter : int
Maximum number of iterations to perform.
maxfun : int
Maximum number of function evaluations to make.
full_output : bool
If True, fopt, xi, direc, iter, funcalls, and
warnflag are returned.
disp : bool
If True, print convergence messages.
retall : bool
If True, return a list of the solution at each iteration.
Notes
-----
Uses a modification of Powell's method to find the minimum of
a function of N variables.
"""
# we need to use a mutable object here that we can update in the
# wrapper function
fcalls, func = wrap_function(func, args)
x = asarray(x0).flatten()
if retall:
allvecs = [x]
N = len(x)
rank = len(x.shape)
if not -1 < rank < 2:
#raise ValueError, "Initial guess must be a scalar or rank-1 sequence."
raise ValueError("Initial guess must be a scalar or rank-1 sequence.")
if maxiter is None:
maxiter = N * 1000
if maxfun is None:
maxfun = N * 1000
if direc is None:
direc = eye(N, dtype=float)
else:
direc = asarray(direc, dtype=float)
fval = squeeze(func(x))
x1 = x.copy()
iter = 0;
ilist = range(N)
while True:
fx = fval
bigind = 0
delta = 0.0
for i in ilist:
direc1 = direc[i]
fx2 = fval
fval, x, direc1 = _linesearch_powell(func, x, direc1, tol=xtol*100)
if (fx2 - fval) > delta:
delta = fx2 - fval
bigind = i
iter += 1
if callback is not None:
callback(x)
if retall:
allvecs.append(x)
if (2.0*(fx - fval) <= ftol*(abs(fx)+abs(fval))+1e-20): break
if fcalls[0] >= maxfun: break
if iter >= maxiter: break
# Construct the extrapolated point
direc1 = x - x1
x2 = 2*x - x1
x1 = x.copy()
fx2 = squeeze(func(x2))
if (fx > fx2):
t = 2.0*(fx+fx2-2.0*fval)
temp = (fx-fval-delta)
t *= temp*temp
temp = fx-fx2
t -= delta*temp*temp
if t < 0.0:
fval, x, direc1 = _linesearch_powell(func, x, direc1,
tol=xtol*100)
direc[bigind] = direc[-1]
direc[-1] = direc1
warnflag = 0
if fcalls[0] >= maxfun:
warnflag = 1
if disp:
print("Warning: Maximum number of function evaluations has been exceeded.")
elif iter >= maxiter:
warnflag = 2
if disp:
print("Warning: Maximum number of iterations has been exceeded")
else:
if disp:
print("Optimization terminated successfully.")
print(" Current function value: %f" % fval)
print(" Iterations: %d" % iter)
print(" Function evaluations: %d" % fcalls[0])
x = squeeze(x)
if full_output:
retlist = x, fval, direc, iter, fcalls[0], warnflag
if retall:
retlist += (allvecs,)
else:
retlist = x
if retall:
retlist = (x, allvecs)
return retlist
#
# Scipy powell optimization method does not have xmin, xmax. The following
# is just a simple wrapper on the optimization method.
#
def my_fmin_powell( fcn, x0, xmin, xmax, args=(), xtol=1e-4, ftol=1e-4,
maxiter=None, maxfev=None, full_output=0, verbose=0,
retall=0, callback=None, direc=None):
FUNC_MAX = numpy.float_(numpy.finfo(numpy.float_).max)
N = len( x0 )
if maxiter is None:
maxiter = N * 1000
if maxfev is None:
maxfev = N * 1000
def _outside_limits(x, xmin, xmax):
return (numpy.any(x < xmin) or numpy.any(x > xmax))
myxmin = asarray( xmin )
myxmax = asarray( xmax )
orig_fcn = fcn
def fcn(x_new):
if _outside_limits(x_new, myxmin, myxmax):
return FUNC_MAX
return orig_fcn(x_new)
result = fmin_powell( fcn, asarray(x0), args=args, xtol=xtol, ftol=ftol,
maxiter=maxiter, full_output=1, disp=verbose,
retall=retall, callback=callback, direc=direc )
xpar = result[ 0 ]
fval = result[ 1 ]
nfev = result[ 4 ]
warnflag = result[ 5 ]
key = {
0: (True, 'Optimization terminated successfully.'),
1: (False,
'number of function evaluations has exceeded maxfev=%d' % maxfev),
2: (False,
'number of iterations has exceeded maxiter=%d' % maxiter)
}
status, msg = key.get(warnflag, (False, 'unknown status flag (%d)' % warnflag))
retlist = (status, xpar, fval )
retlist += ( msg, { 'info' : warnflag, 'nfev': nfev } )
return retlist

View File

@ -0,0 +1,254 @@
import sys, os
QMCCHEM_PATH=os.environ["QMCCHEM_PATH"]
sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/")
from ezfio import ezfio
from datetime import datetime
import time
import numpy as np
import subprocess
import atexit
import scipy as sp
import scipy.optimize
from math import sqrt
from modif_powell_imp import my_fmin_powell
#------------------------------------------------------------------------------
def make_atom_map():
labels = {}
dimension = 0
# i: label of nuclei
# k: counter of nuclei
for i,k in enumerate(ezfio.nuclei_nucl_label):
if k in labels:
labels[k].append(i)
else:
labels[k] = [dimension, i]
dimension += 1
atom_map = [[] for i in range(dimension)]
for atom in labels.keys():
l = labels[atom]
atom_map[l[0]] = l[1:]
return atom_map
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
def get_params_pen():
d = ezfio.jastrow_jast_pen
return np.array([d[m[0]] for m in atom_map])
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
def set_params_pen(x):
y = list(ezfio.jastrow_jast_pen)
for i,m in enumerate(atom_map):
for j in m:
y[j] = x[i]
ezfio.set_jastrow_jast_pen(y)
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
def get_params_b():
b = ezfio.get_jastrow_jast_b_up_up()
return b
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
def set_params_b(b):
ezfio.set_jastrow_jast_b_up_up(b)
ezfio.set_jastrow_jast_b_up_dn(b)
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
def get_energy():
buffer = subprocess.check_output(
['qmcchem', 'result', '-e', 'e_loc', EZFIO_file], encoding='UTF-8')
if buffer.strip() != "":
buffer = buffer.splitlines()[-1]
_, energy, error = [float(x) for x in buffer.split()]
return energy, error
else:
return None, None
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
def get_variance():
buffer = subprocess.check_output(
['qmcchem', 'result', '-e', 'e_loc_qmcvar', EZFIO_file], encoding='UTF-8')
if buffer.strip() != "":
buffer = buffer.splitlines()[-1]
_, variance, error = [float(x) for x in buffer.split()]
return variance, error
else:
return None, None
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
def set_vmc_params(block_time,total_time):
subprocess.check_output(['qmcchem', 'edit', '-c', '-j', 'Simple',
'-t', str(total_time),
'-l', str(block_time), EZFIO_file])
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
def run_qmc():
return subprocess.check_output(['qmcchem', 'run', EZFIO_file])
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
def stop_qmc():
subprocess.check_output(['qmcchem', 'stop', EZFIO_file])
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
def f(x):
global i_fev
global memo_energy
print(' eval {} of f on:'.format(i_fev))
print(' nuc param Jast = {}'.format(x[:-1]))
print(' b param Jast = {}'.format(x[-1]))
h = str(x)
if h in memo_energy:
return memo_energy[h]
i_fev = i_fev + 1
set_params_pen(x[:-1])
set_params_b(x[-1])
block_time_f = 300
total_time_f = 1000
set_vmc_params(block_time_f, total_time_f)
loc_err = 10.
ii = 0
ii_max = 5
energy = None
err = None
while( thresh < loc_err ):
run_qmc()
energy, err = get_energy()
if( (energy is None) or (err is None) ):
continue
elif( memo_energy['fmin'] < (energy-2.*err) ):
print(" %d energy: %f %f "%(ii, energy, err))
break
else:
loc_err = err
ii = ii + 1
print(" %d energy: %f %f "%(ii, energy, err))
if( ii_max < ii ):
break
print(" ")
memo_energy[h] = energy + err
memo_energy['fmin'] = min(energy, memo_energy['fmin'])
return energy
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
#_____________________________________________________________________________________________________________
#
if __name__ == '__main__':
t0 = time.time()
# # # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # # #
EZFIO_file = "/home/aammar/qp2/src/svdwf/f2_work/f2_opt/opt_Jas/f2_Jastopt"
ezfio.set_file(EZFIO_file)
# PARAMETERS
thresh = 1.e-2
# maximum allowed number of function evaluations
N_fev = 50
# # # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # # #
print(" Today's date:", datetime.now() )
print(" EZFIO file = {}".format(EZFIO_file))
# map nuclei to a list
# for f2 this will give: atom_map = [[0, 1]]
atom_map = make_atom_map()
n_par = len(atom_map) # nb of nclear parameters
n_par = n_par + 1 # e-e parameter b
print(' nb of parameters = {}'.format(n_par))
x = get_params_pen()
print(' initial pen: {}'.format(x))
b_par = get_params_b()
print(' initial b: {}'.format(b_par))
x = np.append(x, b_par)
i_fev = 1
memo_energy = {'fmin': 100.}
x_min = [ (0.001) for _ in range(n_par) ]
x_max = [ (9.999) for _ in range(n_par) ]
opt = my_fmin_powell( f, x, x_min, x_max
, xtol = 0.02
, ftol = thresh
, maxfev = N_fev
, full_output = 1
, verbose = 1 )
print(" x = "+str(opt))
#set_params_pen(opt['x'])
print(' number of function evaluations = {}'.format(i_fev))
print(' memo_energy: {}'.format(memo_energy))
print(" end after {:.3f} minutes".format((time.time()-t0)/60.) )
#_____________________________________________________________________________________________________________
#_____________________________________________________________________________________________________________
#_____________________________________________________________________________________________________________

View File

@ -0,0 +1,176 @@
import sys, os
QMCCHEM_PATH=os.environ["QMCCHEM_PATH"]
sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/")
from ezfio import ezfio
from datetime import datetime
import time
import numpy as np
import subprocess
from scipy.linalg import eig, eigh
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_energy():
buffer = subprocess.check_output( ['qmcchem', 'result', '-e', 'e_loc', EZFIO_file]
, encoding='UTF-8' )
if buffer.strip() != "":
buffer = buffer.splitlines()[-1]
_, energy, error = [float(x) for x in buffer.split()]
return energy, error
else:
return None, None
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def run_qmc():
return subprocess.check_output(['qmcchem', 'run', EZFIO_file])
def stop_qmc():
subprocess.check_output(['qmcchem', 'stop', EZFIO_file])
def set_vmc_params():
subprocess.check_output(['qmcchem', 'edit', '-c', '-j', 'None'
, '-m', 'SRMC'
, '-s', 'Brownian'
, '-l', str(block_time)
, '--time-step=0.0005'
, '-t', str(total_time)
, EZFIO_file])
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def get_Aref():
Aref = np.zeros( (n_alpha, n_beta) )
for k in range(n_det):
i = A_rows[k] - 1
j = A_cols[k] - 1
Aref[i,j] = A_vals[0][k]
return( Aref )
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def check_svd_error( A, U, S, Vt ):
norm_A = np.linalg.norm(A, ord='fro')
A_SVD = np.linalg.multi_dot([ U, np.diag(S), Vt ])
err_SVD = 100. * np.linalg.norm( A - A_SVD, ord="fro") / norm_A
print(' error between A_SVD and Aref = {} %\n'.format(err_SVD) )
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
def TSVD_save_EZFIO():
U_toEZFIO = np.zeros( ( 1, U_TSVD.shape[1], U_TSVD.shape[0] ) )
V_toEZFIO = np.zeros( ( 1, V_TSVD.shape[1], V_TSVD.shape[0] ) )
U_toEZFIO[0,:,:] = U_TSVD.T
V_toEZFIO[0,:,:] = V_TSVD.T
ezfio.set_spindeterminants_n_svd_coefs( low_rank )
ezfio.set_spindeterminants_psi_svd_alpha( U_toEZFIO )
ezfio.set_spindeterminants_psi_svd_beta ( V_toEZFIO )
ezfio.set_spindeterminants_psi_svd_coefs( S_TSVD )
print(' SVD vectors & coeff are saved to EZFIO ')
# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ !
if __name__ == '__main__':
t0 = time.time()
print(" Today's date:", datetime.now() )
# EZFIO file
EZFIO_file = "/home/aammar/qp2/src/svdwf/h2o_work/FN_test/cc_pCVDZ/h2o_dz_nsvd"
ezfio.set_file(EZFIO_file)
print(" filename = {}".format(EZFIO_file))
# parameters
energ_nuc = 9.194966082434476
# get spindeterminant data from EZFIO
n_alpha = ezfio.get_spindeterminants_n_det_alpha()
n_beta = ezfio.get_spindeterminants_n_det_beta()
A_rows = np.array(ezfio.get_spindeterminants_psi_coef_matrix_rows() )
A_cols = np.array(ezfio.get_spindeterminants_psi_coef_matrix_columns())
A_vals = np.array(ezfio.get_spindeterminants_psi_coef_matrix_values() )
n_det = A_rows.shape[0]
print(' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~')
print(' matrix: {} x {}'.format(n_alpha,n_beta))
print(' n_det = {}'.format(n_det))
print(' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~')
# construct intial dense matrix
Aref = get_Aref()
# perform initial Full SVD
print(' ----- Performing Full SVD ----- ')
U_FSVD, S_FSVD, Vt_FSVD = np.linalg.svd(Aref, full_matrices=False)
V_FSVD = Vt_FSVD.T
#print(' initial psi coeff = {}\n'.format(S_FSVD))
check_svd_error( Aref, U_FSVD, S_FSVD, Vt_FSVD )
# run QMC before SVD
block_time = 500 # in sec
total_time = 3000 # in sec
set_vmc_params()
run_qmc()
t_read = time.time()
print(' getting QMCCHEM results from {}'.format(EZFIO_file) )
results = subprocess.check_output(['qmcchem', 'result', EZFIO_file], encoding='UTF-8')
print(' getting results after {} minutes \n'.format( (time.time()-t_read)/60. ))
Eloc, ErrEloc = get_energy()
print(' Eloc = {} +/- {}'.format(Eloc, ErrEloc))
print(' {} <= Eloc <= {} \n'.format(Eloc-ErrEloc,Eloc+ErrEloc))
#_________________________________________________________________________________________
#
# loop over truncated rank
#_________________________________________________________________________________________
low_rank_min = 5
low_rank_max = 31
for low_rank in range( low_rank_min, low_rank_max+1, 2 ):
t_it = time.time()
print(" SVD iteration rank = {}".format(low_rank))
# SVD naive truncation
U_TSVD = U_FSVD[:, 0:low_rank+1]
V_TSVD = V_FSVD[:, 0:low_rank+1]
Vt_TSVD = V_TSVD.T
S_TSVD = S_FSVD[0:low_rank+1]
# check truncated SVD error
check_svd_error( Aref, U_TSVD, S_TSVD, Vt_TSVD )
# save new coefficients to EZFIO
TSVD_save_EZFIO()
# set QMC settings and run
block_time = 500 # in sec
total_time = 3000 # in sec
set_vmc_params()
run_qmc()
# read QMC=CHEM results
t_read = time.time()
print(' getting QMCCHEM results from {}'.format(EZFIO_file) )
results = subprocess.check_output(['qmcchem', 'result', EZFIO_file], encoding='UTF-8')
print(' getting results after {} minutes \n'.format( (time.time()-t_read)/60. ))
# < E_loc >
Eloc, ErrEloc = get_energy()
print(' Eloc = {} +/- {}'.format(Eloc, ErrEloc))
print(' {} <= Eloc <= {} \n'.format(Eloc-ErrEloc,Eloc+ErrEloc))
print(" iteration time = {:.3f} minutes \n".format((time.time()-t_it)/60.) )
#_________________________________________________________________________________________
print(" end after {:.3f} minutes".format((time.time()-t0)/60.) )
# end

View File

@ -0,0 +1,62 @@
import numpy as np
from ezfio import ezfio
from datetime import datetime
import time
from matplotlib import pyplot as plt
from scipy.sparse import coo_matrix
def plot_coo_matrix(m):
if not isinstance(m, coo_matrix):
m = coo_matrix(m)
fig = plt.figure()
ax = fig.add_subplot(111, facecolor='black')
ax.plot(m.col, m.row, 's', color='white', ms=1)
ax.set_xlim(0, m.shape[1])
ax.set_ylim(0, m.shape[0])
ax.set_aspect('equal')
for spine in ax.spines.values():
spine.set_visible(False)
ax.invert_yaxis()
ax.set_aspect('equal')
ax.set_xticks([])
ax.set_yticks([])
return ax
if __name__ == "__main__":
t0 = time.time()
EZFIO_file = "/home/aammar/qp2/src/svdwf/h2o_work/FN_test/cc_pCVDZ/h2o_dz"
ezfio.set_file(EZFIO_file)
print(" EZFIO = {}\n".format(EZFIO_file))
n_alpha = ezfio.get_spindeterminants_n_det_alpha()
n_beta = ezfio.get_spindeterminants_n_det_beta()
print(' matrix: {} x {}\n'.format(n_alpha,n_beta))
n_selected = 15 * 15
# selected with v2
f = open("fort.222", "r")
lines = f.readlines()
f.close()
E_v2 = float(lines[-1].split()[4])
deltaE_v2 = np.zeros((n_alpha,n_beta))
rows, cols, vals = [], [], []
print("E_v2 = {}\n".format(E_v2))
for i in range(n_selected):
line = lines[i].split()
ia, ib = int(line[1]), int(line[2])
deltaE_v2[ia,ib] = float(line[3])/E_v2
rows.append(ia)
cols.append(ib)
vals.append(deltaE_v2[ia,ib])
m = coo_matrix((vals, (rows, cols)), shape=(n_alpha,n_beta))
ax = plot_coo_matrix(m)
ax.figure.savefig("selected_SVD.pdf")

View File

@ -0,0 +1,199 @@
program invFSVD_det
BEGIN_DOC
! build CI matrix from SVD vectors
END_DOC
implicit none
read_wf = .True.
TOUCH read_wf
call run()
end
subroutine run
implicit none
integer :: mm, nn, i_state, low_rank
integer :: i, j, k, l
double precision :: tmp1, eps_det
double precision, allocatable :: U_SVD(:,:), D_SVD(:), V_SVD(:,:), A_SVD(:,:), US(:,:)
double precision, allocatable :: newpsi_rows(:), newpsi_columns(:), newpsi_values(:)
double precision :: t0, t1, t2
call CPU_TIME(t0)
i_state = 1
mm = n_det_alpha_unique
nn = n_det_beta_unique
print *, ' matrix dimensions:', mm,'x',nn
print *, ' N det:', N_det
call ezfio_get_spindeterminants_n_svd_coefs(low_rank)
print *, ' SVD rank:', low_rank
allocate( U_SVD(mm,low_rank), D_SVD(low_rank), V_SVD(nn,low_rank) )
call ezfio_get_spindeterminants_psi_svd_alpha(U_SVD)
call ezfio_get_spindeterminants_psi_svd_beta (V_SVD)
call ezfio_get_spindeterminants_psi_svd_coefs(D_SVD)
print *, ' read EZFIO SVD vectors OK'
! US = U x S :
allocate( US(mm,low_rank) )
US(:,:) = 0.d0
do i = 1, mm
do l = 1, low_rank
US(i,l) = U_SVD(i,l) * D_SVD(l)
enddo
enddo
print *, ' U x D: ok'
deallocate( U_SVD , D_SVD )
! A_TSVD = US x V.T
allocate( A_SVD(mm,nn) )
A_SVD(:,:) = 0.d0
call dgemm( 'N', 'T', mm, nn, low_rank, 1.d0 &
, US , size(US ,1) &
, V_SVD , size(V_SVD,1) &
, 0.d0, A_SVD, size(A_SVD,1) )
print *, ' U x D x Vt: ok'
deallocatE(US)
call ezfio_set_spindeterminants_n_states(N_states)
call ezfio_set_spindeterminants_n_det_alpha(n_det_alpha_unique)
call ezfio_set_spindeterminants_n_det_beta(n_det_beta_unique)
print *, 'EZFIO set n_det_alpha and n_det_beta'
! ---------------
eps_det = 1d-13
print *, ' det coeff thresh for consideration =', eps_det
! ---------------
k = 0
do j = 1, nn
do i = 1, mm
tmp1 = A_SVD(i,j)
if( dabs(tmp1) .lt. (eps_det) ) cycle
k = k + 1
enddo
enddo
print *, ' non zero elements = ', k
! call generate_all_alpha_beta_det_products
! call save_wavefunction
call all_ab_det(eps_det, A_SVD)
call update_SVDWF(eps_det, k, A_SVD)
deallocate( A_SVD )
call CPU_TIME(t2)
print *, ''
print *, ' end after'
print *, (t2-t0)/60.d0, 'min'
end
subroutine update_SVDWF(eps_det, n_ab, A_SVD)
implicit none
integer , intent(in) :: n_ab
double precision, intent(in) :: eps_det
double precision, intent(in) :: A_SVD(n_det_alpha_unique,n_det_beta_unique)
integer :: i, j, l
integer(bit_kind), allocatable :: tmp_det(:,:,:)
double precision, allocatable :: tmp_coef(:)
PROVIDE H_apply_buffer_allocated
allocate( tmp_coef(n_ab) )
allocate (tmp_det(N_int,2,n_ab))
l = 0
do j = 1, N_det_beta_unique
do i = 1, N_det_alpha_unique
if( (dabs(A_SVD(i,j)) .ge. eps_det) .and. (l.le.n_ab) ) then
l = l + 1
tmp_det(1:N_int,1,l) = psi_det_alpha_unique(1:N_int,i)
tmp_det(1:N_int,2,l) = psi_det_beta_unique (1:N_int,j)
tmp_coef(l) = A_SVD(i,j)
endif
enddo
enddo
print *, ' l_max =', l
print *, ' n_ab =', n_ab
!call save_wavefunction_general(ndet,nstates ,psidet ,dim_psicoef,psicoef )
call save_wavefunction_general(l ,n_states,tmp_det,l ,tmp_coef)
deallocate(tmp_coef)
deallocate(tmp_det)
end subroutine update_SVDWF
subroutine all_ab_det(eps_det, A_SVD)
implicit none
double precision, intent(in) :: eps_det
double precision, intent(in) :: A_SVD(n_det_alpha_unique,n_det_beta_unique)
integer :: i, j, k, l
integer :: iproc
integer(bit_kind), allocatable :: tmp_det(:,:,:)
integer, external :: get_index_in_psi_det_sorted_bit
logical, external :: is_in_wavefunction
PROVIDE H_apply_buffer_allocated
!$OMP PARALLEL DEFAULT(NONE) SHARED(psi_coef_sorted_bit, N_det_beta_unique, &
!$OMP N_det_alpha_unique, N_int, psi_det_alpha_unique, psi_det_beta_unique, &
!$OMP eps_det, A_SVD ) &
!$OMP PRIVATE(i,j,k,l,tmp_det,iproc)
!$ iproc = omp_get_thread_num()
allocate (tmp_det(N_int,2,N_det_alpha_unique))
!$OMP DO SCHEDULE(static,8)
do j=1,N_det_beta_unique
l = 1
do i=1,N_det_alpha_unique
do k=1,N_int
tmp_det(k,1,l) = psi_det_alpha_unique(k,i)
tmp_det(k,2,l) = psi_det_beta_unique (k,j)
enddo
if( (.not.is_in_wavefunction(tmp_det(1,1,l),N_int)) .and. (dabs(A_SVD(i,j)) .ge. eps_det) ) then
l = l + 1
endif
enddo
call fill_H_apply_buffer_no_selection(l-1, tmp_det, N_int, iproc)
enddo
!$OMP END DO
deallocate(tmp_det)
!$OMP END PARALLEL
call copy_H_apply_buffer_to_wf
SOFT_TOUCH psi_det psi_coef N_det N_det_beta_unique N_det_alpha_unique psi_det_alpha_unique psi_det_beta_unique
print *, ' new n_det =', N_det
end subroutine all_ab_det()

View File

@ -0,0 +1,120 @@
program invFSVD_spindet
BEGIN_DOC
! build CI matrix from SVD vectors
END_DOC
implicit none
read_wf = .True.
TOUCH read_wf
call run()
end
subroutine run
implicit none
integer :: mm, nn, i_state, low_rank
integer :: i, j, k, l
double precision :: tmp1, eps_det
double precision, allocatable :: U_SVD(:,:), D_SVD(:), V_SVD(:,:), A_SVD(:,:), US(:,:)
double precision, allocatable :: newpsi_rows(:), newpsi_columns(:), newpsi_values(:)
double precision :: t0, t1, t2
call CPU_TIME(t0)
i_state = 1
mm = n_det_alpha_unique
nn = n_det_beta_unique
print *, ' matrix dimensions:', mm,'x',nn
print *, ' N det:', N_det
call ezfio_get_spindeterminants_n_svd_coefs(low_rank)
print *, ' SVD rank:', low_rank
allocate( U_SVD(mm,low_rank), D_SVD(low_rank), V_SVD(nn,low_rank) )
call ezfio_get_spindeterminants_psi_svd_alpha(U_SVD)
call ezfio_get_spindeterminants_psi_svd_beta (V_SVD)
call ezfio_get_spindeterminants_psi_svd_coefs(D_SVD)
print *, ' read EZFIO SVD vectors OK'
! US = U x S :
allocate( US(mm,low_rank) )
US(:,:) = 0.d0
do i = 1, mm
do l = 1, low_rank
US(i,l) = U_SVD(i,l) * D_SVD(l)
enddo
enddo
print *, ' U x D: ok'
deallocate( U_SVD , D_SVD )
! A_TSVD = US x V.T
allocate( A_SVD(mm,nn) )
A_SVD(:,:) = 0.d0
call dgemm( 'N', 'T', mm, nn, low_rank, 1.d0 &
, US , size(US ,1) &
, V_SVD , size(V_SVD,1) &
, 0.d0, A_SVD, size(A_SVD,1) )
print *, ' U x D x Vt: ok'
deallocatE(US)
call ezfio_set_spindeterminants_n_states(N_states)
call ezfio_set_spindeterminants_n_det_alpha(n_det_alpha_unique)
call ezfio_set_spindeterminants_n_det_beta(n_det_beta_unique)
print *, 'EZFIO set n_det_alpha and n_det_beta'
! ---------------
eps_det = 1d-15
print *, ' det coeff thresh for consideration =', eps_det
! ---------------
k = 0
do j = 1, nn
do i = 1, mm
tmp1 = A_SVD(i,j)
if( dabs(tmp1) .lt. (eps_det) ) cycle
k = k + 1
enddo
enddo
print *, ' non zero elements = ', k
allocate( newpsi_rows(k), newpsi_columns(k), newpsi_values(k) )
k = 0
do j = 1, nn
do i = 1, mm
tmp1 = A_SVD(i,j)
if( dabs(tmp1) .lt. (eps_det) ) cycle
k = k + 1
newpsi_rows (k) = i
newpsi_columns(k) = j
newpsi_values (k) = tmp1
enddo
enddo
call ezfio_set_spindeterminants_n_det(N_det)
call ezfio_set_spindeterminants_psi_coef_matrix_columns(psi_bilinear_matrix_columns)
call ezfio_set_spindeterminants_psi_coef_matrix_values(psi_bilinear_matrix_values)
call ezfio_set_spindeterminants_psi_coef_matrix_rows(psi_bilinear_matrix_rows)
deallocate( A_SVD )
deallocate( newpsi_rows, newpsi_columns, newpsi_values )
call CPU_TIME(t2)
print *, ''
print *, ' end after'
print *, (t2-t0)/60.d0, 'min'
end

View File

@ -25,34 +25,19 @@ subroutine run
integer :: degree, i_state integer :: degree, i_state
integer :: i, j, k, l, m, n integer :: i, j, k, l, m, n
integer :: ii, ia, ib
double precision :: x, y, h12 double precision :: x, y, h12
double precision, allocatable :: Uref(:,:), Dref(:), Vtref(:,:), Aref(:,:), Vref(:,:) double precision, allocatable :: Uref(:,:), Dref(:), Vref(:,:), Vtref(:,:), Aref(:,:)
double precision, allocatable :: Hdiag(:)
integer :: rank_max
double precision :: E0, overlop, Ept2
double precision, allocatable :: H0(:,:)
double precision, allocatable :: eigvec0(:,:), eigval0(:), coeff_psi(:), coeff_tmp(:)
integer :: ii, ia, ib
double precision, allocatable :: Hdiag(:), Hkl_save(:,:), Hkl_1d(:), Hkl_tmp(:,:), Hdiag_tmp(:)
integer :: na_new, nb_new, ind_new, ind_gs
double precision :: ctmp, coeff_new
double precision, allocatable :: epsil(:), epsil_energ(:), check_ov(:)
double precision, allocatable :: Uezfio(:,:,:), Dezfio(:,:), Vezfio(:,:,:)
integer :: ibeg_alpha, ibeg_beta, iend_alpha, iend_beta integer :: ibeg_alpha, ibeg_beta, iend_alpha, iend_beta
integer :: n_toselect, na_max, nb_max integer :: n_toselect, na_max, nb_max
integer, allocatable :: numalpha_toselect(:), numbeta_toselect(:) integer, allocatable :: numalpha_toselect(:), numbeta_toselect(:)
integer :: cantor_pairing_ij, cantor_pairing_new
integer, allocatable :: cantor_pairing(:), cantor_pairing_tmp(:)
double precision :: t_beg, t_end double precision :: t_beg, t_end
integer(kind=8) :: W_tbeg, W_tend, W_tbeg_it, W_tend_it, W_ir integer(kind=8) :: W_tbeg, W_tend, W_ir
real(kind=8) :: W_tot_time, W_tot_time_it real(kind=8) :: W_tot_time
integer :: nb_taches integer :: nb_taches
!$OMP PARALLEL !$OMP PARALLEL
@ -71,14 +56,36 @@ subroutine run
call get_excitation_degree(det1,det2,degree,N_int) call get_excitation_degree(det1,det2,degree,N_int)
call i_H_j(det1, det2, N_int, h12) call i_H_j(det1, det2, N_int, h12)
! ---------------------------------------------------------------------------------------
! construct the initial CISD matrix
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
print *, ' CISD matrix:', n_det_alpha_unique,'x',n_det_beta_unique print *, ' CI matrix:', n_det_alpha_unique,'x',n_det_beta_unique
print *, ' N det :', N_det print *, ' N det :', N_det
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
ibeg_alpha = 1
!iend_alpha = 10
iend_alpha = n_det_alpha_unique
ibeg_beta = 1
!iend_beta = 10
iend_beta = n_det_beta_unique
na_max = iend_alpha - ibeg_alpha + 1
nb_max = iend_beta - ibeg_beta + 1
n_toselect = na_max * nb_max
print *, ' na_max = ', na_max
print *, ' nb_max = ', nb_max
print *, ' n_toselect = ', n_toselect
! ---------------------------------------------------------------------------------------
! perform a Full SVD
call cpu_time(t_beg)
allocate( Uref(n_det_alpha_unique,n_det_alpha_unique) )
allocate( Dref(min(n_det_alpha_unique,n_det_beta_unique)) )
allocate( Vtref(n_det_beta_unique,n_det_beta_unique) )
! construct the initial CI matrix
allocate( Aref(n_det_alpha_unique,n_det_beta_unique) ) allocate( Aref(n_det_alpha_unique,n_det_beta_unique) )
Aref(:,:) = 0.d0 Aref(:,:) = 0.d0
do k = 1, N_det do k = 1, N_det
@ -86,26 +93,10 @@ subroutine run
j = psi_bilinear_matrix_columns(k) j = psi_bilinear_matrix_columns(k)
Aref(i,j) = psi_bilinear_matrix_values(k,i_state) Aref(i,j) = psi_bilinear_matrix_values(k,i_state)
enddo enddo
! perform a FSVD
! ---------------------------------------------------------------------------------------
! ---------------------------------------------------------------------------------------
! perform a Full SVD
allocate( Uref(n_det_alpha_unique,n_det_alpha_unique) )
allocate( Dref(min(n_det_alpha_unique,n_det_beta_unique)) )
allocate( Vtref(n_det_beta_unique,n_det_beta_unique) )
call cpu_time(t_beg)
call svd_s(Aref, size(Aref,1), Uref, size(Uref,1), Dref, Vtref & call svd_s(Aref, size(Aref,1), Uref, size(Uref,1), Dref, Vtref &
, size(Vtref,1), n_det_alpha_unique, n_det_beta_unique) , size(Vtref,1), n_det_alpha_unique, n_det_beta_unique)
call cpu_time(t_end)
print *, " SVD is performed after (min)", (t_end-t_beg)/60.
deallocate( Aref , Dref ) deallocate( Aref , Dref )
allocate( Vref(n_det_beta_unique,n_det_beta_unique) ) allocate( Vref(n_det_beta_unique,n_det_beta_unique) )
do l = 1, n_det_beta_unique do l = 1, n_det_beta_unique
do i = 1, n_det_beta_unique do i = 1, n_det_beta_unique
@ -114,20 +105,33 @@ subroutine run
enddo enddo
deallocate( Vtref ) deallocate( Vtref )
ibeg_alpha = 1 ! ! read SVD vectors
iend_alpha = n_det_alpha_unique ! allocate( Uref(n_det_alpha_unique,iend_alpha) )
na_max = iend_alpha - ibeg_alpha + 1 ! allocate( Vref(n_det_beta_unique ,iend_beta ) )
! allocate( Dref( min(iend_alpha,iend_beta) ) )
! open(unit=15, file="d_svd.txt", action='read')
! do i = 1, min(iend_alpha,iend_beta)
! read(15,*) Dref(i)
! enddo
! close(15)
! open(unit=15, file="u_svd.txt", action='read')
! do j = 1, iend_alpha
! do i = 1, n_det_alpha_unique
! read(15,*) Uref(i,j)
! enddo
! enddo
! close(15)
! open(unit=15, file="v_svd.txt", action='read')
! do j = 1, iend_beta
! do i = 1, n_det_beta_unique
! read(15,*) Vref(i,j)
! enddo
! enddo
! close(15)
ibeg_beta = 1 call cpu_time(t_end)
iend_beta = n_det_beta_unique print *, " SVD is performed after (min)", (t_end-t_beg)/60.
nb_max = iend_beta - ibeg_beta + 1 ! ---------------------------------------------------------------------------------------
n_toselect = na_max * nb_max
print *, ' na_max = ', na_max
print *, ' nb_max = ', nb_max
print *, ' n_toselect = ', n_toselect
allocate( numalpha_toselect(n_toselect) , numbeta_toselect(n_toselect) ) allocate( numalpha_toselect(n_toselect) , numbeta_toselect(n_toselect) )
k = 0 k = 0
@ -160,29 +164,6 @@ subroutine run
deallocate( numalpha_toselect, numbeta_toselect, Hdiag ) deallocate( numalpha_toselect, numbeta_toselect, Hdiag )
! ***************************************************************************************************
! save to ezfion
!allocate( Uezfio(n_det_alpha_unique,rank0,1), Dezfio(rank0,1), Vezfio(n_det_beta_unique,rank0,1) )
!do l = 1, rank0
! Dezfio(l,1) = coeff_psi(l)
! Uezfio(:,l,1) = U0(:,l)
! Vezfio(:,l,1) = V0(:,l)
!enddo
!call ezfio_set_spindeterminants_n_det(N_det)
!call ezfio_set_spindeterminants_n_states(N_states)
!call ezfio_set_spindeterminants_n_det_alpha(n_det_alpha_unique)
!call ezfio_set_spindeterminants_n_det_beta(n_det_beta_unique)
!call ezfio_set_spindeterminants_psi_coef_matrix_rows(psi_bilinear_matrix_rows)
!call ezfio_set_spindeterminants_psi_coef_matrix_columns(psi_bilinear_matrix_columns)
!call ezfio_set_spindeterminants_psi_coef_matrix_values(psi_bilinear_matrix_values)
!call ezfio_set_spindeterminants_n_svd_coefs(rank0)
!call ezfio_set_spindeterminants_psi_svd_alpha(Uezfio)
!call ezfio_set_spindeterminants_psi_svd_beta(Vezfio )
!call ezfio_set_spindeterminants_psi_svd_coefs(Dezfio)
!deallocate( Uezfio, Dezfio, Vezfio )
! ***************************************************************************************************
call SYSTEM_CLOCK(COUNT=W_tend, COUNT_RATE=W_ir) call SYSTEM_CLOCK(COUNT=W_tend, COUNT_RATE=W_ir)
@ -193,7 +174,6 @@ subroutine run
print *, " total elapsed time (min) = ", W_tot_time/60.d0 print *, " total elapsed time (min) = ", W_tot_time/60.d0
print *, ' ___________________________________________________________________' print *, ' ___________________________________________________________________'
end end

View File

@ -25,31 +25,17 @@ subroutine run
integer :: degree, i_state integer :: degree, i_state
integer :: i, j, k, l, m, n integer :: i, j, k, l, m, n
integer :: ii, ia, ib
double precision :: x, y, h12 double precision :: x, y, h12
double precision, allocatable :: Uref(:,:), Dref(:), Vtref(:,:), Aref(:,:), Vref(:,:) double precision, allocatable :: Uref(:,:), Dref(:), Vtref(:,:), Aref(:,:), Vref(:,:)
integer :: rank_max double precision, allocatable :: Hdiag(:)
double precision :: E0, overlop, Ept2
double precision, allocatable :: H0(:,:)
double precision, allocatable :: eigvec0(:,:), eigval0(:), coeff_psi(:), coeff_tmp(:)
integer :: ii, ia, ib
double precision, allocatable :: Hdiag(:), Hkl_save(:,:), Hkl_1d(:), Hkl_tmp(:,:), Hdiag_tmp(:)
integer :: na_new, nb_new, ind_new, ind_gs
double precision :: ctmp, coeff_new
double precision, allocatable :: epsil(:), epsil_energ(:), check_ov(:)
double precision, allocatable :: Uezfio(:,:,:), Dezfio(:,:), Vezfio(:,:,:)
integer :: ibeg_alpha, ibeg_beta, iend_alpha, iend_beta integer :: ibeg_alpha, ibeg_beta, iend_alpha, iend_beta
integer :: n_toselect, na_max, nb_max integer :: n_toselect, na_max, nb_max
integer, allocatable :: numalpha_toselect(:), numbeta_toselect(:) integer, allocatable :: numalpha_toselect(:), numbeta_toselect(:)
integer :: cantor_pairing_ij, cantor_pairing_new
integer, allocatable :: cantor_pairing(:), cantor_pairing_tmp(:)
double precision :: t_beg, t_end double precision :: t_beg, t_end
integer(kind=8) :: W_tbeg, W_tend, W_tbeg_it, W_tend_it, W_ir integer(kind=8) :: W_tbeg, W_tend, W_tbeg_it, W_tend_it, W_ir
real(kind=8) :: W_tot_time, W_tot_time_it real(kind=8) :: W_tot_time, W_tot_time_it
@ -115,13 +101,15 @@ subroutine run
deallocate( Vtref ) deallocate( Vtref )
ibeg_alpha = 1 ibeg_alpha = 1
iend_alpha = n_det_alpha_unique iend_alpha = 100
na_max = iend_alpha - ibeg_alpha + 1 !iend_alpha = n_det_alpha_unique
ibeg_beta = 1 ibeg_beta = 1
iend_beta = n_det_beta_unique iend_beta = 100
nb_max = iend_beta - ibeg_beta + 1 !iend_beta = n_det_beta_unique
na_max = iend_alpha - ibeg_alpha + 1
nb_max = iend_beta - ibeg_beta + 1
n_toselect = na_max * nb_max n_toselect = na_max * nb_max
print *, ' na_max = ', na_max print *, ' na_max = ', na_max
@ -155,36 +143,10 @@ subroutine run
enddo enddo
close(11) close(11)
deallocate( Uref, Vref ) deallocate( Uref, Vref )
deallocate( numalpha_toselect, numbeta_toselect, Hdiag ) deallocate( numalpha_toselect, numbeta_toselect, Hdiag )
! ***************************************************************************************************
! save to ezfion
!allocate( Uezfio(n_det_alpha_unique,rank0,1), Dezfio(rank0,1), Vezfio(n_det_beta_unique,rank0,1) )
!do l = 1, rank0
! Dezfio(l,1) = coeff_psi(l)
! Uezfio(:,l,1) = U0(:,l)
! Vezfio(:,l,1) = V0(:,l)
!enddo
!call ezfio_set_spindeterminants_n_det(N_det)
!call ezfio_set_spindeterminants_n_states(N_states)
!call ezfio_set_spindeterminants_n_det_alpha(n_det_alpha_unique)
!call ezfio_set_spindeterminants_n_det_beta(n_det_beta_unique)
!call ezfio_set_spindeterminants_psi_coef_matrix_rows(psi_bilinear_matrix_rows)
!call ezfio_set_spindeterminants_psi_coef_matrix_columns(psi_bilinear_matrix_columns)
!call ezfio_set_spindeterminants_psi_coef_matrix_values(psi_bilinear_matrix_values)
!call ezfio_set_spindeterminants_n_svd_coefs(rank0)
!call ezfio_set_spindeterminants_psi_svd_alpha(Uezfio)
!call ezfio_set_spindeterminants_psi_svd_beta(Vezfio )
!call ezfio_set_spindeterminants_psi_svd_coefs(Dezfio)
!deallocate( Uezfio, Dezfio, Vezfio )
! ***************************************************************************************************
call SYSTEM_CLOCK(COUNT=W_tend, COUNT_RATE=W_ir) call SYSTEM_CLOCK(COUNT=W_tend, COUNT_RATE=W_ir)
W_tot_time = real(W_tend - W_tbeg, kind=8) / real(W_ir, kind=8) W_tot_time = real(W_tend - W_tbeg, kind=8) / real(W_ir, kind=8)
print *, ' ___________________________________________________________________' print *, ' ___________________________________________________________________'
@ -193,7 +155,6 @@ subroutine run
print *, " total elapsed time (min) = ", W_tot_time/60.d0 print *, " total elapsed time (min) = ", W_tot_time/60.d0
print *, ' ___________________________________________________________________' print *, ' ___________________________________________________________________'
end end

View File

@ -0,0 +1,402 @@
program printSQ_ab_T_gd_v0
implicit none
BEGIN_DOC
! perturbative approach to build psi_postsvd
END_DOC
read_wf = .True.
TOUCH read_wf
PROVIDE N_int
call run()
end
subroutine run
USE OMP_LIB
USE bitmasks
implicit none
integer(bit_kind) :: det1(N_int,2), det2(N_int,2)
integer :: degree, i_state
double precision :: h12
integer :: i, j, k, l
double precision, allocatable :: T(:,:,:,:)
double precision, allocatable :: Uref(:,:), Dref(:), Vtref(:,:), Aref(:,:), Vref(:,:)
double precision :: ti, tf
integer :: nb_taches
!$OMP PARALLEL
nb_taches = OMP_GET_NUM_THREADS()
!$OMP END PARALLEL
call wall_time(ti)
i_state = 1
det1(:,1) = psi_det_alpha_unique(:,1)
det2(:,1) = psi_det_alpha_unique(:,1)
det1(:,2) = psi_det_beta_unique(:,1)
det2(:,2) = psi_det_beta_unique(:,1)
call get_excitation_degree_spin(det1(1,1),det2(1,1),degree,N_int)
call get_excitation_degree(det1,det2,degree,N_int)
call i_H_j(det1, det2, N_int, h12)
! ---------------------------------------------------------------------------------------
! ---------------------------------------------------------------------------------------
! ---------------------------------------------------------------------------------------
! construct the initial CI matrix
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
print *, ' CI matrix :', n_det_alpha_unique,'x',n_det_beta_unique
print *, ' N det :', N_det
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
allocate( Aref(n_det_alpha_unique,n_det_beta_unique) )
Aref(:,:) = 0.d0
do k = 1, N_det
i = psi_bilinear_matrix_rows(k)
j = psi_bilinear_matrix_columns(k)
Aref(i,j) = psi_bilinear_matrix_values(k,i_state)
enddo
allocate( Uref(n_det_alpha_unique,n_det_alpha_unique) )
allocate( Dref(min(n_det_alpha_unique,n_det_beta_unique)) )
allocate( Vtref(n_det_beta_unique,n_det_beta_unique) )
call svd_s(Aref, size(Aref,1), Uref, size(Uref,1), Dref, Vtref &
, size(Vtref,1), n_det_alpha_unique, n_det_beta_unique)
print *, " ---------- Full SVD is performed ----------------- "
allocate( Vref(n_det_beta_unique,n_det_beta_unique) )
do l = 1, n_det_beta_unique
do i = 1, n_det_beta_unique
Vref(i,l) = Vtref(l,i)
enddo
enddo
deallocate( Aref , Vtref , Dref )
! ---------------------------------------------------------------------------------------
! ---------------------------------------------------------------------------------------
! ---------------------------------------------------------------------------------------
! ---------------------------------------------------------------------------------------
allocate( T(n_det_alpha_unique,n_det_beta_unique,n_det_alpha_unique,n_det_beta_unique) )
call const_2b(T)
call const_ab_T_gd(Uref, Vref, T)
deallocate( T )
deallocate( Uref , Vref )
call wall_time(tf)
print *, ' ___________________________________________________________________'
print *, ' '
!print *, " Execution avec ", nb_taches, " threads"
print *, " Execution avec 1 threads"
print *, " total elapsed time (min) = ", (tf-ti)/60.d0
print *, ' ___________________________________________________________________'
end
!/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\!
!---! !---! !---! !---! !---! !---! !---! !---! !---!
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
!___! !___! !___! !___! !___! !___! !___! !___! !___!
!___! !___! !___! !___! !___! !___! !___! !___! !___!
!/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\!
!---! !---! !---! !---! !---! !---! !---! !---! !---!
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
!___! !___! !___! !___! !___! !___! !___! !___! !___!
!___! !___! !___! !___! !___! !___! !___! !___! !___!
!/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\!
!---! !---! !---! !---! !---! !---! !---! !---! !---!
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
!___! !___! !___! !___! !___! !___! !___! !___! !___!
!___! !___! !___! !___! !___! !___! !___! !___! !___!
!/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\!
!---! !---! !---! !---! !---! !---! !---! !---! !---!
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
!___! !___! !___! !___! !___! !___! !___! !___! !___!
!___! !___! !___! !___! !___! !___! !___! !___! !___!
subroutine const_2b(T)
USE bitmasks
implicit none
double precision, external :: get_two_e_integral
double precision, intent(out) :: T(n_det_alpha_unique,n_det_beta_unique,n_det_alpha_unique,n_det_beta_unique )
integer :: na, nb
integer :: i, k, j, l
integer(bit_kind) :: psi_ij(N_int,2), psi_kl(N_int,2)
double precision :: phase
integer :: degree, h1, h2, p1, p2, s1, s2, e1, e2
integer :: ii, jj
integer :: exc(0:2,2,2)
integer :: occ(N_int*bit_kind_size,2), n_occ_alpha
double precision :: two_body_fact
na = n_det_alpha_unique
nb = n_det_beta_unique
T(:,:,:,:) = 0.d0
! -----------------------------------------------------------------------------------------------------------------
do i = 1, na
psi_ij(1:N_int,1) = psi_det_alpha_unique(1:N_int,i)
do j = 1, nb
psi_ij(1:N_int,2) = psi_det_beta_unique(1:N_int,j)
call bitstring_to_list(psi_ij(1,1), occ(1,1), n_occ_alpha, N_int)
call bitstring_to_list(psi_ij(1,2), occ(1,2), n_occ_alpha, N_int)
do k = 1, na
psi_kl(1:N_int,1) = psi_det_alpha_unique(1:N_int,k)
do l = 1, nb
psi_kl(1:N_int,2) = psi_det_beta_unique(1:N_int,l)
call get_excitation_degree(psi_ij, psi_kl, degree, N_int)
two_body_fact = 0.d0
if(degree .eq. 2) then
call get_double_excitation(psi_ij, psi_kl, exc, phase, N_int)
call decode_exc(exc, degree, h1, p1, h2, p2, s1, s2)
select case(s1+s2)
case(2,4)
two_body_fact += phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map)
two_body_fact -= phase * get_two_e_integral(h1, h2, p2, p1, mo_integrals_map)
case(3)
two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map)
two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map)
end select
else if(degree .eq. 1) then
call get_single_excitation(psi_ij, psi_kl, exc, phase, N_int)
call decode_exc(exc, degree, h1, p1, h2, p2, s1, s2)
select case(s1)
case(1)
do ii = 1, elec_alpha_num
p2 = occ(ii,1)
h2 = p2
two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map)
two_body_fact -= 0.5d0 * phase * get_two_e_integral(h1, h2, p2, p1, mo_integrals_map)
two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map)
two_body_fact -= 0.5d0 * phase * get_two_e_integral(h2, h1, p1, p2, mo_integrals_map)
enddo
do ii = 1, elec_beta_num
p2 = occ(ii,2)
h2 = p2
two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map)
two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map)
enddo
case(2)
do ii = 1, elec_alpha_num
p2 = occ(ii,1)
h2 = p2
two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map)
two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map)
enddo
do ii = 1, elec_beta_num
p2 = occ(ii,2)
h2 = p2
two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map)
two_body_fact -= 0.5d0 * phase * get_two_e_integral(h1, h2, p2, p1, mo_integrals_map)
two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map)
two_body_fact -= 0.5d0 * phase * get_two_e_integral(h2, h1, p1, p2, mo_integrals_map)
enddo
end select
else if(degree .eq. 0) then
do ii = 1, elec_alpha_num
e1 = occ(ii,1)
do jj = 1, elec_alpha_num
e2 = occ(jj,1)
two_body_fact += 0.5d0 * get_two_e_integral(e1, e2, e1, e2, mo_integrals_map)
two_body_fact -= 0.5d0 * get_two_e_integral(e1, e2, e2, e1, mo_integrals_map)
enddo
do jj = 1, elec_beta_num
e2 = occ(jj,2)
two_body_fact += 0.5d0 * get_two_e_integral(e1, e2, e1, e2, mo_integrals_map)
two_body_fact += 0.5d0 * get_two_e_integral(e2, e1, e2, e1, mo_integrals_map)
enddo
enddo
do ii = 1, elec_beta_num
e1 = occ(ii,2)
do jj = 1, elec_beta_num
e2 = occ(jj,2)
two_body_fact += 0.5d0 * get_two_e_integral(e1, e2, e1, e2, mo_integrals_map)
two_body_fact -= 0.5d0 * get_two_e_integral(e1, e2, e2, e1, mo_integrals_map)
enddo
enddo
end if
T(i,j,k,l) = two_body_fact
enddo
enddo
enddo
enddo
! -----------------------------------------------------------------------------------------------------------------
return
end subroutine const_2b
subroutine const_ab_T_gd(Uref, Vref, T)
implicit none
double precision, intent(in) :: Uref(n_det_alpha_unique,n_det_alpha_unique)
double precision, intent(in) :: Vref(n_det_beta_unique ,n_det_beta_unique)
double precision, intent(in) :: T(n_det_alpha_unique,n_det_beta_unique,n_det_alpha_unique,n_det_beta_unique )
integer :: na, nb
integer :: i, j, k, l, ii, jj, kk, ll
double precision :: h12, T_abgd, sum_i, sum_j, sum_k, sum_l
double precision, allocatable :: tmp1(:,:,:,:), tmp2(:,:,:,:)
double precision :: t1, t2
print *, ""
print *, " start const_ab_T_gd"
call wall_time(t1)
na = n_det_alpha_unique
nb = n_det_beta_unique
allocate( tmp1(na,nb,na,nb) )
tmp1(:,:,:,:) = 0.d0
do ii = 1, na
do l = 1, nb
do j = 1, nb
do k = 1, na
sum_i = 0.d0
do i = 1, na
sum_i = sum_i + T(i,j,k,l) * Uref(i,ii)
enddo
tmp1(ii,j,k,l) = sum_i
enddo
enddo
enddo
enddo
allocate( tmp2(na,nb,na,nb) )
tmp2(:,:,:,:) = 0.d0
do ii = 1, na
do jj = 1, nb
do k = 1, na
do l = 1, nb
sum_j = 0.d0
do j = 1, nb
sum_j = sum_j + tmp1(ii,j,k,l) * Vref(j,jj)
enddo
tmp2(ii,jj,k,l) = sum_j
enddo
enddo
enddo
enddo
deallocate(tmp1)
allocate( tmp1(na,nb,na,nb) )
tmp1(:,:,:,:) = 0.d0
do ii = 1, na
do jj = 1, nb
do kk = 1, na
do l = 1, nb
sum_k = 0.d0
do k = 1, na
sum_k = sum_k + tmp2(ii,jj,k,l) * Uref(k,kk)
enddo
tmp1(ii,jj,kk,l) = sum_k
enddo
enddo
enddo
enddo
deallocate(tmp2)
allocate( tmp2(na,nb,na,nb) )
tmp2(:,:,:,:) = 0.d0
do ii = 1, na
do jj = 1, nb
do kk = 1, na
do ll = 1, nb
sum_l = 0.d0
do l = 1, nb
sum_l = sum_l + tmp1(ii,jj,kk,l) * Vref(l,ll)
enddo
tmp2(ii,jj,kk,ll) = sum_l
enddo
enddo
enddo
enddo
deallocate(tmp1)
open(UNIT=11, FILE="ab_T_gd_v0.dat", ACTION="WRITE")
do ii = 1, na
do jj = 1, nb
do kk = 1, na
do ll = 1, nb
T_abgd = tmp2(ii,jj,kk,ll)
write(11, '((F15.8))') T_abgd
enddo
enddo
enddo
enddo
close(11)
deallocate(tmp2)
call wall_time(t2)
print *, " end const_ab_T_gd after (min) ", (t2-t1)/60.
print *, ""
return
end subroutine const_ab_T_gd

View File

@ -0,0 +1,257 @@
program printSQ_ij_T_kl
implicit none
BEGIN_DOC
! perturbative approach to build psi_postsvd
END_DOC
read_wf = .True.
TOUCH read_wf
PROVIDE N_int
call run()
end
subroutine run
USE OMP_LIB
USE bitmasks
implicit none
integer(bit_kind) :: det1(N_int,2), det2(N_int,2)
integer :: degree, i_state
double precision :: h12
integer :: i, j, k, l
double precision, allocatable :: T(:,:,:,:)
double precision :: ti, tf
integer :: nb_taches
!$OMP PARALLEL
nb_taches = OMP_GET_NUM_THREADS()
!$OMP END PARALLEL
call wall_time(ti)
i_state = 1
det1(:,1) = psi_det_alpha_unique(:,1)
det2(:,1) = psi_det_alpha_unique(:,1)
det1(:,2) = psi_det_beta_unique(:,1)
det2(:,2) = psi_det_beta_unique(:,1)
call get_excitation_degree_spin(det1(1,1),det2(1,1),degree,N_int)
call get_excitation_degree(det1,det2,degree,N_int)
call i_H_j(det1, det2, N_int, h12)
! ---------------------------------------------------------------------------------------
! construct the initial CI matrix
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
print *, ' CI matrix :', n_det_alpha_unique,'x',n_det_beta_unique
print *, ' N det :', N_det
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
! ---------------------------------------------------------------------------------------
! ---------------------------------------------------------------------------------------
allocate( T(n_det_alpha_unique,n_det_beta_unique,n_det_alpha_unique,n_det_beta_unique) )
call const_2b(T)
open(UNIT=11, FILE="ij_T_kl.dat", ACTION="WRITE")
do i = 1, n_det_alpha_unique
do j = 1, n_det_beta_unique
do k = 1, n_det_alpha_unique
do l = 1, n_det_beta_unique
write(11, '(E15.7)') T(i,j,k,l)
!write(11, '(4(I5,2X), 5X, E15.7)') i, j, k, l, T(i,j,k,l)
enddo
enddo
enddo
enddo
close(11)
deallocate( T )
call wall_time(tf)
print *, ' ___________________________________________________________________'
print *, ' '
!print *, " Execution avec ", nb_taches, " threads"
print *, " Execution avec 1 threads"
print *, " total elapsed time (min) = ", (tf-ti)/60.d0
print *, ' ___________________________________________________________________'
end
!/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\!
!---! !---! !---! !---! !---! !---! !---! !---! !---!
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
!___! !___! !___! !___! !___! !___! !___! !___! !___!
!___! !___! !___! !___! !___! !___! !___! !___! !___!
!/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\!
!---! !---! !---! !---! !---! !---! !---! !---! !---!
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
!___! !___! !___! !___! !___! !___! !___! !___! !___!
!___! !___! !___! !___! !___! !___! !___! !___! !___!
!/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\!
!---! !---! !---! !---! !---! !---! !---! !---! !---!
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
!___! !___! !___! !___! !___! !___! !___! !___! !___!
!___! !___! !___! !___! !___! !___! !___! !___! !___!
!/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\!
!---! !---! !---! !---! !---! !---! !---! !---! !---!
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
!___! !___! !___! !___! !___! !___! !___! !___! !___!
!___! !___! !___! !___! !___! !___! !___! !___! !___!
subroutine const_2b(T)
USE bitmasks
implicit none
double precision, external :: get_two_e_integral
double precision, intent(out) :: T(n_det_alpha_unique,n_det_beta_unique,n_det_alpha_unique,n_det_beta_unique )
integer :: na, nb
integer :: i, k, j, l
integer(bit_kind) :: psi_ij(N_int,2), psi_kl(N_int,2)
double precision :: phase
integer :: degree, h1, h2, p1, p2, s1, s2, e1, e2
integer :: ii, jj
integer :: exc(0:2,2,2)
integer :: occ(N_int*bit_kind_size,2), n_occ_alpha
double precision :: two_body_fact
na = n_det_alpha_unique
nb = n_det_beta_unique
T(:,:,:,:) = 0.d0
! -----------------------------------------------------------------------------------------------------------------
do i = 1, na
psi_ij(1:N_int,1) = psi_det_alpha_unique(1:N_int,i)
do j = 1, nb
psi_ij(1:N_int,2) = psi_det_beta_unique(1:N_int,j)
call bitstring_to_list(psi_ij(1,1), occ(1,1), n_occ_alpha, N_int)
call bitstring_to_list(psi_ij(1,2), occ(1,2), n_occ_alpha, N_int)
do k = 1, na
psi_kl(1:N_int,1) = psi_det_alpha_unique(1:N_int,k)
do l = 1, nb
psi_kl(1:N_int,2) = psi_det_beta_unique(1:N_int,l)
call get_excitation_degree(psi_ij, psi_kl, degree, N_int)
two_body_fact = 0.d0
if(degree .eq. 2) then
call get_double_excitation(psi_ij, psi_kl, exc, phase, N_int)
call decode_exc(exc, degree, h1, p1, h2, p2, s1, s2)
select case(s1+s2)
case(2,4)
two_body_fact += phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map)
two_body_fact -= phase * get_two_e_integral(h1, h2, p2, p1, mo_integrals_map)
case(3)
two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map)
two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map)
end select
else if(degree .eq. 1) then
call get_single_excitation(psi_ij, psi_kl, exc, phase, N_int)
call decode_exc(exc, degree, h1, p1, h2, p2, s1, s2)
select case(s1)
case(1)
do ii = 1, elec_alpha_num
p2 = occ(ii,1)
h2 = p2
two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map)
two_body_fact -= 0.5d0 * phase * get_two_e_integral(h1, h2, p2, p1, mo_integrals_map)
two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map)
two_body_fact -= 0.5d0 * phase * get_two_e_integral(h2, h1, p1, p2, mo_integrals_map)
enddo
do ii = 1, elec_beta_num
p2 = occ(ii,2)
h2 = p2
two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map)
two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map)
enddo
case(2)
do ii = 1, elec_alpha_num
p2 = occ(ii,1)
h2 = p2
two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map)
two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map)
enddo
do ii = 1, elec_beta_num
p2 = occ(ii,2)
h2 = p2
two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map)
two_body_fact -= 0.5d0 * phase * get_two_e_integral(h1, h2, p2, p1, mo_integrals_map)
two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map)
two_body_fact -= 0.5d0 * phase * get_two_e_integral(h2, h1, p1, p2, mo_integrals_map)
enddo
end select
else if(degree .eq. 0) then
do ii = 1, elec_alpha_num
e1 = occ(ii,1)
do jj = 1, elec_alpha_num
e2 = occ(jj,1)
two_body_fact += 0.5d0 * get_two_e_integral(e1, e2, e1, e2, mo_integrals_map)
two_body_fact -= 0.5d0 * get_two_e_integral(e1, e2, e2, e1, mo_integrals_map)
enddo
do jj = 1, elec_beta_num
e2 = occ(jj,2)
two_body_fact += 0.5d0 * get_two_e_integral(e1, e2, e1, e2, mo_integrals_map)
two_body_fact += 0.5d0 * get_two_e_integral(e2, e1, e2, e1, mo_integrals_map)
enddo
enddo
do ii = 1, elec_beta_num
e1 = occ(ii,2)
do jj = 1, elec_beta_num
e2 = occ(jj,2)
two_body_fact += 0.5d0 * get_two_e_integral(e1, e2, e1, e2, mo_integrals_map)
two_body_fact -= 0.5d0 * get_two_e_integral(e1, e2, e2, e1, mo_integrals_map)
enddo
enddo
end if
T(i,j,k,l) = two_body_fact
enddo
enddo
enddo
enddo
! -----------------------------------------------------------------------------------------------------------------
return
end subroutine const_2b

View File

@ -0,0 +1,48 @@
program print_2e_integrals
BEGIN_DOC
! script to print 2-electron Coulomb integrals
END_DOC
implicit none
read_wf = .true.
TOUCH read_wf
call run()
end
subroutine run()
implicit none
integer :: i, j, k, l
double precision, external :: get_ao_two_e_integral
print *, ' ao_num = ', ao_num
! provide ao_two_e_integrals_in_map
! print *, hf_energy
! Map of Atomic integrals
! i(r1) j(r2) 1/r12 k(r1) l(r2)
! https://quantum-package.readthedocs.io/en/master/modules/ao_two_e_ints.html
open(unit=11, file='ao_2eCoulombIntegrals.txt', action='write')
do i = 1, ao_num
do k = 1, ao_num
do j = 1, ao_num
do l = 1, ao_num
! write(11, '(e15.8)') get_two_e_integral(i, j, k, l, ao_integrals_map)
write(11, *) get_ao_two_e_integral(i, j, k, l, ao_integrals_map)
enddo
enddo
enddo
enddo
close(11)
end

View File

@ -0,0 +1,129 @@
program print_ij_H_kl_det
implicit none
BEGIN_DOC
! perturbative approach to build psi_postsvd
! without OMP
END_DOC
read_wf = .True.
TOUCH read_wf
PROVIDE N_int
call run()
end
subroutine run
USE OMP_LIB
implicit none
integer(bit_kind) :: det1(N_int,2), det2(N_int,2)
integer :: degree, i_state
double precision :: h12
integer(kind=8) :: W_tbeg, W_tend, W_tbeg_it, W_tend_it, W_ir
real(kind=8) :: W_tot_time
integer :: nb_taches
!$OMP PARALLEL
nb_taches = OMP_GET_NUM_THREADS()
!$OMP END PARALLEL
call SYSTEM_CLOCK(COUNT=W_tbeg, COUNT_RATE=W_ir)
i_state = 1
det1(:,1) = psi_det_alpha_unique(:,1)
det2(:,1) = psi_det_alpha_unique(:,1)
det1(:,2) = psi_det_beta_unique(:,1)
det2(:,2) = psi_det_beta_unique(:,1)
call get_excitation_degree_spin(det1(1,1),det2(1,1),degree,N_int)
call get_excitation_degree(det1,det2,degree,N_int)
call i_H_j(det1, det2, N_int, h12)
! ---------------------------------------------------------------------------------------
! construct the initial CI matrix
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
print *, ' CISD matrix:', n_det_alpha_unique,'x',n_det_beta_unique
print *, ' N det :', N_det
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
! ---------------------------------------------------------------------------------------
! get < d_i d_j | H | d_k d_l > in det basis
call const_ij_H_kl_det()
call SYSTEM_CLOCK(COUNT=W_tend, COUNT_RATE=W_ir)
W_tot_time = real(W_tend - W_tbeg, kind=8) / real(W_ir, kind=8)
print *, ' ___________________________________________________________________'
print *, ' '
!print *, " Execution avec ", nb_taches, "threads"
print *, " Execution avec 1 threads"
print *, " total elapsed time (min) = ", W_tot_time/60.d0
print *, ' ___________________________________________________________________'
end
subroutine const_ij_H_kl_det()
implicit none
integer(bit_kind) :: det1(N_int,2)
integer(bit_kind) :: det2(N_int,2)
integer :: degree, na, nb
integer :: i, j, k, l
double precision :: h12
double precision :: t1, t2
print *, ""
print *, " start const_ij_H_kl_det"
call wall_time(t1)
na = n_det_alpha_unique
nb = n_det_beta_unique
do l = 1, nb
det2(:,2) = psi_det_beta_unique(:,l)
do j = 1, nb
det1(:,2) = psi_det_beta_unique(:,j)
call get_excitation_degree_spin(det1(1,2),det2(1,2),degree,N_int)
if(degree .gt. 2) cycle
do k = 1, na
det2(:,1) = psi_det_alpha_unique(:,k)
do i = 1, na
det1(:,1) = psi_det_alpha_unique(:,i)
call get_excitation_degree(det1,det2,degree,N_int)
if(degree .gt. 2) cycle
call i_H_j(det1, det2, N_int, h12)
if(h12 .eq. 0.d0) cycle
write(7000, '(4(I4,2X),(F15.8))') i, j, k, l, h12
enddo
enddo
enddo
enddo
call wall_time(t2)
print *, " end const_ij_H_kl_det after (min) ", (t2-t1)/60.
print *, ""
return
end subroutine const_ij_H_kl_det

View File

@ -0,0 +1,144 @@
program print_ij_H_kl_det_v0
implicit none
BEGIN_DOC
! perturbative approach to build psi_postsvd
! without OMP
END_DOC
read_wf = .True.
TOUCH read_wf
PROVIDE N_int
call run()
end
subroutine run
USE OMP_LIB
implicit none
integer(bit_kind) :: det1(N_int,2), det2(N_int,2)
integer :: degree, i_state
double precision :: h12
integer(kind=8) :: W_tbeg, W_tend, W_tbeg_it, W_tend_it, W_ir
real(kind=8) :: W_tot_time
integer :: nb_taches
!$OMP PARALLEL
nb_taches = OMP_GET_NUM_THREADS()
!$OMP END PARALLEL
call SYSTEM_CLOCK(COUNT=W_tbeg, COUNT_RATE=W_ir)
i_state = 1
det1(:,1) = psi_det_alpha_unique(:,1)
det2(:,1) = psi_det_alpha_unique(:,1)
det1(:,2) = psi_det_beta_unique(:,1)
det2(:,2) = psi_det_beta_unique(:,1)
call get_excitation_degree_spin(det1(1,1),det2(1,1),degree,N_int)
call get_excitation_degree(det1,det2,degree,N_int)
call i_H_j(det1, det2, N_int, h12)
! ---------------------------------------------------------------------------------------
! construct the initial CI matrix
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
print *, ' CISD matrix:', n_det_alpha_unique,'x',n_det_beta_unique
print *, ' N det :', N_det
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
! ---------------------------------------------------------------------------------------
! get < d_i d_j | H | d_k d_l > in det basis
call const_ij_H_kl_det()
call SYSTEM_CLOCK(COUNT=W_tend, COUNT_RATE=W_ir)
W_tot_time = real(W_tend - W_tbeg, kind=8) / real(W_ir, kind=8)
print *, ' ___________________________________________________________________'
print *, ' '
!print *, " Execution avec ", nb_taches, "threads"
print *, " Execution avec 1 threads"
print *, " total elapsed time (min) = ", W_tot_time/60.d0
print *, ' ___________________________________________________________________'
end
subroutine const_ij_H_kl_det()
implicit none
integer(bit_kind) :: det1(N_int,2)
integer(bit_kind) :: det2(N_int,2)
integer :: degree, na, nb
integer :: i, j, k, l
double precision :: h12
double precision :: nb_nz, n_tot
double precision :: t1, t2
print *, ""
print *, " start const_ij_H_kl_det"
call wall_time(t1)
na = n_det_alpha_unique
nb = n_det_beta_unique
nb_nz = 0.d0
do l = 1, nb
det2(:,2) = psi_det_beta_unique(:,l)
do j = 1, nb
det1(:,2) = psi_det_beta_unique(:,j)
call get_excitation_degree_spin(det1(1,2),det2(1,2),degree,N_int)
if(degree .gt. 2) cycle
do k = 1, na
det2(:,1) = psi_det_alpha_unique(:,k)
do i = 1, na
det1(:,1) = psi_det_alpha_unique(:,i)
call get_excitation_degree(det1,det2,degree,N_int)
if(degree .gt. 2) cycle
call i_H_j(det1, det2, N_int, h12)
if(dabs(h12).le.(1d-12)) cycle
! need nbs
nb_nz = nb_nz + 1.d0
write(7000, '(4(I8,2X),(F20.13))') i, j, k, l, h12
enddo
enddo
enddo
enddo
n_tot = dble(na)**2 * dble(nb)**2
print *, ' na = ', na
print *, ' nb = ', nb
print *, ' nb non zero elemenets = ', nb_nz
print *, ' n_tot = ', n_tot
print *, ' % non zero elemenets = ', 100.d0 * dexp( dlog(nb_nz) - dlog(n_tot) )
call wall_time(t2)
print *, " end const_ij_H_kl_det after (min) ", (t2-t1)/60.
print *, ""
return
end subroutine const_ij_H_kl_det

View File

@ -0,0 +1,110 @@
program print_ij_H_kl_det_v1
implicit none
BEGIN_DOC
! perturbative approach to build psi_postsvd
! without OMP
END_DOC
read_wf = .True.
TOUCH read_wf
PROVIDE N_int
call run()
end
subroutine run
implicit none
integer(bit_kind) :: det1(N_int,2), det2(N_int,2)
integer :: degree
double precision :: h12
det1(:,1) = psi_det_alpha_unique(:,1)
det2(:,1) = psi_det_alpha_unique(:,1)
det1(:,2) = psi_det_beta_unique(:,1)
det2(:,2) = psi_det_beta_unique(:,1)
call get_excitation_degree_spin(det1(1,1),det2(1,1),degree,N_int)
call get_excitation_degree(det1,det2,degree,N_int)
call i_H_j(det1, det2, N_int, h12)
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
print *, ' CI matrix:', n_det_alpha_unique,'x',n_det_beta_unique
print *, ' N det :', N_det
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
! get < d_i d_j | H | d_k d_l > in det basis
call const_ij_Hdet_kl_sparse()
end
! _________________________________________________________________________________________________
!
subroutine const_ij_Hdet_kl_sparse()
implicit none
integer(bit_kind) :: det1(N_int,2), det2(N_int,2)
integer :: degree
integer :: na, nb, i, j, k, l, ii
double precision :: h12
double precision :: t1, t2
print *, ""
print *, " start const_ij_Hdet_kl_sparse"
call wall_time(t1)
na = n_det_alpha_unique
nb = n_det_beta_unique
ii = 0
!$OMP PARALLEL DEFAULT(NONE) PRIVATE(i,j,k,l,h12,det1,det2,degree) &
!$OMP SHARED(na,nb,psi_det_alpha_unique,psi_det_beta_unique,N_int)
!$OMP DO
do l = 1, nb
det2(:,2) = psi_det_beta_unique(:,l)
do j = 1, nb
det1(:,2) = psi_det_beta_unique(:,j)
call get_excitation_degree_spin(det1(1,2),det2(1,2),degree,N_int)
if(degree .gt. 2) cycle
do k = 1, na
det2(:,1) = psi_det_alpha_unique(:,k)
do i = 1, na
det1(:,1) = psi_det_alpha_unique(:,i)
call get_excitation_degree(det1,det2,degree,N_int)
if(degree .gt. 2) cycle
call i_H_j(det1, det2, N_int, h12)
if(dabs(h12) .le. (1d-9)) cycle
write(7001, '(4(I8,2X),(F15.8))') i, j, k, l, h12
enddo
enddo
enddo
enddo
!$OMP END DO
!$OMP END PARALLEL
call wall_time(t2)
print *, " end const_ij_Hdet_kl_sparse after (min) ", (t2-t1)/60.
print *, ""
return
end subroutine const_ij_Hdet_kl_sparse
! _________________________________________________________________________________________________
! _________________________________________________________________________________________________

View File

@ -0,0 +1,225 @@
program print_ij_H_kl_v0
implicit none
BEGIN_DOC
! perturbative approach to build psi_postsvd
! without OMP
END_DOC
read_wf = .True.
TOUCH read_wf
PROVIDE N_int
call run()
end
subroutine run
USE OMP_LIB
implicit none
integer(bit_kind) :: det1(N_int,2), det2(N_int,2)
integer :: degree, i_state
integer :: i, j, k, l, m, n
double precision :: x, y, h12
double precision, allocatable :: Uref(:,:), Dref(:), Vtref(:,:), Aref(:,:), Vref(:,:)
integer :: rank_max
double precision :: E0, overlop, Ept2
double precision, allocatable :: H0(:,:)
double precision, allocatable :: eigvec0(:,:), eigval0(:), coeff_psi(:), coeff_tmp(:)
integer :: ii, ia, ib
double precision, allocatable :: Hdiag(:), Hkl_save(:,:), Hkl_1d(:), Hkl_tmp(:,:), Hdiag_tmp(:)
integer :: na_new, nb_new, ind_new, ind_gs
double precision :: ctmp, coeff_new
double precision, allocatable :: epsil(:), epsil_energ(:), check_ov(:)
double precision, allocatable :: Uezfio(:,:,:), Dezfio(:,:), Vezfio(:,:,:)
integer :: ibeg_alpha, ibeg_beta, iend_alpha, iend_beta
integer :: n_toselect, na_max, nb_max
integer, allocatable :: numalpha_toselect(:), numbeta_toselect(:)
integer :: cantor_pairing_ij, cantor_pairing_new
integer, allocatable :: cantor_pairing(:), cantor_pairing_tmp(:)
double precision :: t_beg, t_end
integer(kind=8) :: W_tbeg, W_tend, W_tbeg_it, W_tend_it, W_ir
real(kind=8) :: W_tot_time, W_tot_time_it
integer :: nb_taches
!$OMP PARALLEL
nb_taches = OMP_GET_NUM_THREADS()
!$OMP END PARALLEL
call SYSTEM_CLOCK(COUNT=W_tbeg, COUNT_RATE=W_ir)
i_state = 1
det1(:,1) = psi_det_alpha_unique(:,1)
det2(:,1) = psi_det_alpha_unique(:,1)
det1(:,2) = psi_det_beta_unique(:,1)
det2(:,2) = psi_det_beta_unique(:,1)
call get_excitation_degree_spin(det1(1,1),det2(1,1),degree,N_int)
call get_excitation_degree(det1,det2,degree,N_int)
call i_H_j(det1, det2, N_int, h12)
! ---------------------------------------------------------------------------------------
! construct the initial CISD matrix
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
print *, ' CISD matrix:', n_det_alpha_unique,'x',n_det_beta_unique
print *, ' N det :', N_det
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
allocate( Aref(n_det_alpha_unique,n_det_beta_unique) )
Aref(:,:) = 0.d0
do k = 1, N_det
i = psi_bilinear_matrix_rows(k)
j = psi_bilinear_matrix_columns(k)
Aref(i,j) = psi_bilinear_matrix_values(k,i_state)
enddo
! ---------------------------------------------------------------------------------------
! ---------------------------------------------------------------------------------------
! perform a Full SVD
allocate( Uref(n_det_alpha_unique,n_det_alpha_unique) )
allocate( Dref(min(n_det_alpha_unique,n_det_beta_unique)) )
allocate( Vtref(n_det_beta_unique,n_det_beta_unique) )
call cpu_time(t_beg)
call svd_s(Aref, size(Aref,1), Uref, size(Uref,1), Dref, Vtref &
, size(Vtref,1), n_det_alpha_unique, n_det_beta_unique)
call cpu_time(t_end)
print *, " SVD is performed after (min)", (t_end-t_beg)/60.
deallocate( Aref , Dref )
allocate( Vref(n_det_beta_unique,n_det_beta_unique) )
do l = 1, n_det_beta_unique
do i = 1, n_det_beta_unique
Vref(i,l) = Vtref(l,i)
enddo
enddo
deallocate( Vtref )
! get < u_i v_j | H | u_k v_l > for all vectors
call const_ij_H_kl(Uref, Vref)
deallocate( Uref, Vref )
call SYSTEM_CLOCK(COUNT=W_tend, COUNT_RATE=W_ir)
W_tot_time = real(W_tend - W_tbeg, kind=8) / real(W_ir, kind=8)
print *, ' ___________________________________________________________________'
print *, ' '
!print *, " Execution avec ", nb_taches, "threads"
print *, " Execution avec 1 threads"
print *, " total elapsed time (min) = ", W_tot_time/60.d0
print *, ' ___________________________________________________________________'
end
subroutine const_ij_H_kl(Uref, Vref)
implicit none
double precision, intent(in) :: Uref(n_det_alpha_unique,n_det_alpha_unique)
double precision, intent(in) :: Vref(n_det_beta_unique ,n_det_beta_unique)
integer(bit_kind) :: det1(N_int,2)
integer(bit_kind) :: det2(N_int,2)
integer :: degree, na, nb
integer :: i, j, k, l, ii, jj, kk, ll
double precision :: h12, h_abgd, sum_i, sum_j, sum_k, sum_l
double precision :: t1, t2
print *, ""
print *, " start const_ij_H_kl"
call wall_time(t1)
na = n_det_alpha_unique
nb = n_det_beta_unique
do ii = 1, na
do jj = 1, nb
do kk = 1, na
do ll = 1, nb
sum_l = 0.d0
do l = 1, nb
det2(:,2) = psi_det_beta_unique(:,l)
sum_j = 0.d0
do j = 1, nb
det1(:,2) = psi_det_beta_unique(:,j)
call get_excitation_degree_spin(det1(1,2),det2(1,2),degree,N_int)
if(degree .gt. 2) cycle
sum_k = 0.d0
do k = 1, na
det2(:,1) = psi_det_alpha_unique(:,k)
sum_i = 0.d0
do i = 1, na
det1(:,1) = psi_det_alpha_unique(:,i)
call get_excitation_degree(det1,det2,degree,N_int)
if(degree .gt. 2) cycle
call i_H_j(det1, det2, N_int, h12)
if(h12 .eq. 0.d0) cycle
sum_i = sum_i + h12 * Uref(i,ii)
enddo
sum_k = sum_k + sum_i * Uref(k,kk)
enddo
sum_j = sum_j + sum_k * Vref(j,jj)
enddo
sum_l = sum_l + sum_j * Vref(l,ll)
enddo
h_abgd = sum_l
write(7070, '(4(I4,2X),(F15.8))') ii, jj, kk, ll, h_abgd
enddo
enddo
enddo
enddo
call wall_time(t2)
print *, " end const_ij_H_kl after (min) ", (t2-t1)/60.
print *, ""
return
end subroutine const_ij_H_kl

View File

@ -0,0 +1,280 @@
program print_ij_H_kl_v1
implicit none
BEGIN_DOC
! perturbative approach to build psi_postsvd
! without OMP
END_DOC
read_wf = .True.
TOUCH read_wf
PROVIDE N_int
call run()
end
subroutine run
USE OMP_LIB
implicit none
integer(bit_kind) :: det1(N_int,2), det2(N_int,2)
integer :: degree, i_state
integer :: i, j, k, l, m, n
double precision :: x, y, h12
double precision, allocatable :: Uref(:,:), Dref(:), Vtref(:,:), Aref(:,:), Vref(:,:)
integer :: rank_max
double precision :: E0, overlop, Ept2
double precision, allocatable :: H0(:,:)
double precision, allocatable :: eigvec0(:,:), eigval0(:), coeff_psi(:), coeff_tmp(:)
integer :: ii, ia, ib
double precision, allocatable :: Hdiag(:), Hkl_save(:,:), Hkl_1d(:), Hkl_tmp(:,:), Hdiag_tmp(:)
integer :: na_new, nb_new, ind_new, ind_gs
double precision :: ctmp, coeff_new
double precision, allocatable :: epsil(:), epsil_energ(:), check_ov(:)
double precision, allocatable :: Uezfio(:,:,:), Dezfio(:,:), Vezfio(:,:,:)
integer :: ibeg_alpha, ibeg_beta, iend_alpha, iend_beta
integer :: n_toselect, na_max, nb_max
integer, allocatable :: numalpha_toselect(:), numbeta_toselect(:)
integer :: cantor_pairing_ij, cantor_pairing_new
integer, allocatable :: cantor_pairing(:), cantor_pairing_tmp(:)
double precision :: t_beg, t_end
integer(kind=8) :: W_tbeg, W_tend, W_tbeg_it, W_tend_it, W_ir
real(kind=8) :: W_tot_time, W_tot_time_it
integer :: nb_taches
!$OMP PARALLEL
nb_taches = OMP_GET_NUM_THREADS()
!$OMP END PARALLEL
call SYSTEM_CLOCK(COUNT=W_tbeg, COUNT_RATE=W_ir)
i_state = 1
det1(:,1) = psi_det_alpha_unique(:,1)
det2(:,1) = psi_det_alpha_unique(:,1)
det1(:,2) = psi_det_beta_unique(:,1)
det2(:,2) = psi_det_beta_unique(:,1)
call get_excitation_degree_spin(det1(1,1),det2(1,1),degree,N_int)
call get_excitation_degree(det1,det2,degree,N_int)
call i_H_j(det1, det2, N_int, h12)
! ---------------------------------------------------------------------------------------
! construct the initial CISD matrix
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
print *, ' CISD matrix:', n_det_alpha_unique,'x',n_det_beta_unique
print *, ' N det :', N_det
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
allocate( Aref(n_det_alpha_unique,n_det_beta_unique) )
Aref(:,:) = 0.d0
do k = 1, N_det
i = psi_bilinear_matrix_rows(k)
j = psi_bilinear_matrix_columns(k)
Aref(i,j) = psi_bilinear_matrix_values(k,i_state)
enddo
! ---------------------------------------------------------------------------------------
! ---------------------------------------------------------------------------------------
! perform a Full SVD
allocate( Uref(n_det_alpha_unique,n_det_alpha_unique) )
allocate( Dref(min(n_det_alpha_unique,n_det_beta_unique)) )
allocate( Vtref(n_det_beta_unique,n_det_beta_unique) )
call cpu_time(t_beg)
call svd_s(Aref, size(Aref,1), Uref, size(Uref,1), Dref, Vtref &
, size(Vtref,1), n_det_alpha_unique, n_det_beta_unique)
call cpu_time(t_end)
print *, " SVD is performed after (min)", (t_end-t_beg)/60.
deallocate( Aref , Dref )
allocate( Vref(n_det_beta_unique,n_det_beta_unique) )
do l = 1, n_det_beta_unique
do i = 1, n_det_beta_unique
Vref(i,l) = Vtref(l,i)
enddo
enddo
deallocate( Vtref )
! get < u_i v_j | H | u_k v_l > for all vectors
call const_ij_H_kl(Uref, Vref)
deallocate( Uref, Vref )
call SYSTEM_CLOCK(COUNT=W_tend, COUNT_RATE=W_ir)
W_tot_time = real(W_tend - W_tbeg, kind=8) / real(W_ir, kind=8)
print *, ' ___________________________________________________________________'
print *, ' '
!print *, " Execution avec ", nb_taches, "threads"
print *, " Execution avec 1 threads"
print *, " total elapsed time (min) = ", W_tot_time/60.d0
print *, ' ___________________________________________________________________'
end
subroutine const_ij_H_kl(Uref, Vref)
implicit none
double precision, intent(in) :: Uref(n_det_alpha_unique,n_det_alpha_unique)
double precision, intent(in) :: Vref(n_det_beta_unique ,n_det_beta_unique)
integer(bit_kind) :: det1(N_int,2)
integer(bit_kind) :: det2(N_int,2)
integer :: degree, na, nb
integer :: i, j, k, l, ii, jj, kk, ll
double precision :: h12, h_abgd, sum_i, sum_j, sum_k, sum_l
double precision, allocatable :: tmp1(:,:,:,:), tmp2(:,:,:,:)
double precision :: t1, t2
print *, ""
print *, " start const_ij_H_kl"
call wall_time(t1)
na = n_det_alpha_unique
nb = n_det_beta_unique
allocate( tmp1(na,nb,na,nb) )
tmp1(:,:,:,:) = 0.d0
do ii = 1, na
do l = 1, nb
det2(:,2) = psi_det_beta_unique(:,l)
do j = 1, nb
det1(:,2) = psi_det_beta_unique(:,j)
call get_excitation_degree_spin(det1(1,2),det2(1,2),degree,N_int)
if(degree .gt. 2) cycle
do k = 1, na
det2(:,1) = psi_det_alpha_unique(:,k)
sum_i = 0.d0
do i = 1, na
det1(:,1) = psi_det_alpha_unique(:,i)
call get_excitation_degree(det1,det2,degree,N_int)
if(degree .gt. 2) cycle
call i_H_j(det1, det2, N_int, h12)
if(h12 .eq. 0.d0) cycle
sum_i = sum_i + h12 * Uref(i,ii)
!sum_i = sum_i + h12 * Uref(ii,i)
enddo
tmp1(ii,j,k,l) = sum_i
enddo
enddo
enddo
enddo
allocate( tmp2(na,nb,na,nb) )
tmp2(:,:,:,:) = 0.d0
do ii = 1, na
do jj = 1, nb
do k = 1, na
do l = 1, nb
sum_j = 0.d0
do j = 1, nb
sum_j = sum_j + tmp1(ii,j,k,l) * Vref(j,jj)
!sum_j = sum_j + tmp1(ii,j,k,l) * Vref(jj,j)
enddo
tmp2(ii,jj,k,l) = sum_j
enddo
enddo
enddo
enddo
deallocate(tmp1)
allocate( tmp1(na,nb,na,nb) )
tmp1(:,:,:,:) = 0.d0
do ii = 1, na
do jj = 1, nb
do kk = 1, na
do l = 1, nb
sum_k = 0.d0
do k = 1, na
sum_k = sum_k + tmp2(ii,jj,k,l) * Uref(k,kk)
!sum_k = sum_k + tmp2(ii,jj,k,l) * Uref(kk,k)
enddo
tmp1(ii,jj,kk,l) = sum_k
enddo
enddo
enddo
enddo
deallocate(tmp2)
allocate( tmp2(na,nb,na,nb) )
tmp2(:,:,:,:) = 0.d0
do ii = 1, na
do jj = 1, nb
do kk = 1, na
do ll = 1, nb
sum_l = 0.d0
do l = 1, nb
sum_l = sum_l + tmp1(ii,jj,kk,l) * Vref(l,ll)
!sum_l = sum_l + tmp1(ii,jj,kk,l) * Vref(ll,l)
enddo
tmp2(ii,jj,kk,ll) = sum_l
enddo
enddo
enddo
enddo
deallocate(tmp1)
do ii = 1, na
do jj = 1, nb
do kk = 1, na
do ll = 1, nb
h_abgd = tmp2(ii,jj,kk,ll)
write(7071, '(4(I4,2X),(F15.8))') ii, jj, kk, ll, h_abgd
enddo
enddo
enddo
enddo
deallocate(tmp2)
call wall_time(t2)
print *, " end const_ij_H_kl after (min) ", (t2-t1)/60.
print *, ""
return
end subroutine const_ij_H_kl

View File

@ -72,7 +72,7 @@ subroutine run
! construct the initial CISD matrix ! construct the initial CISD matrix
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
print *, ' CISD matrix:', n_det_alpha_unique,'x',n_det_beta_unique print *, ' CI matrix:', n_det_alpha_unique,'x',n_det_beta_unique
print *, ' N det :', N_det print *, ' N det :', N_det
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
@ -317,23 +317,23 @@ subroutine run
ind_gs = MAXLOC( check_ov, DIM=1 ) ind_gs = MAXLOC( check_ov, DIM=1 )
overlop = check_ov(ind_gs) overlop = check_ov(ind_gs)
E0 = eigval0(ind_gs)+nuclear_repulsion E0 = eigval0(ind_gs)+nuclear_repulsion
coeff_psi(:) = eigvec0(:,ind_gs)
deallocate( check_ov, eigval0, eigvec0 )
! ---------------------------------------------------------------------------------------
print*, ' space dimen = ', n_selected print*, ' space dimen = ', n_selected
print*, ' E bef diag = ', Em print*, ' E bef diag = ', Em
print*, ' E aft diag = ', E0 print*, ' E aft diag = ', E0
print*, ' overlop = ', overlop print*, ' overlop = ', overlop
print*, ' index = ', ind_gs print*, ' index = ', ind_gs
do i = 1, n_selected
print *, eigvec0(i,ind_gs)
enddo
!coeff_psi(:) = eigvec0(:,ind_gs)
deallocate( check_ov, eigval0, eigvec0 )
! ---------------------------------------------------------------------------------------
write(211, '( 3(I5,3X), 4(F15.8,3X) )') n_selected, na_new, nb_new, Em, E0, overlop write(211, '( 3(I5,3X), 4(F15.8,3X) )') n_selected, na_new, nb_new, Em, E0, overlop
! --------------------------------------------------------------------------------------- ! ---------------------------------------------------------------------------------------
! remove selected pair | na_new nb_new > ! remove selected pair | na_new nb_new >
@ -355,30 +355,6 @@ subroutine run
!________________________________________________________________________________________________________ !________________________________________________________________________________________________________
! ***************************************************************************************************
! save to ezfion
!allocate( Uezfio(n_det_alpha_unique,rank0,1), Dezfio(rank0,1), Vezfio(n_det_beta_unique,rank0,1) )
!do l = 1, rank0
! Dezfio(l,1) = coeff_psi(l)
! Uezfio(:,l,1) = U0(:,l)
! Vezfio(:,l,1) = V0(:,l)
!enddo
!call ezfio_set_spindeterminants_n_det(N_det)
!call ezfio_set_spindeterminants_n_states(N_states)
!call ezfio_set_spindeterminants_n_det_alpha(n_det_alpha_unique)
!call ezfio_set_spindeterminants_n_det_beta(n_det_beta_unique)
!call ezfio_set_spindeterminants_psi_coef_matrix_rows(psi_bilinear_matrix_rows)
!call ezfio_set_spindeterminants_psi_coef_matrix_columns(psi_bilinear_matrix_columns)
!call ezfio_set_spindeterminants_psi_coef_matrix_values(psi_bilinear_matrix_values)
!call ezfio_set_spindeterminants_n_svd_coefs(rank0)
!call ezfio_set_spindeterminants_psi_svd_alpha(Uezfio)
!call ezfio_set_spindeterminants_psi_svd_beta(Vezfio )
!call ezfio_set_spindeterminants_psi_svd_coefs(Dezfio)
!deallocate( Uezfio, Dezfio, Vezfio )
! ***************************************************************************************************
call SYSTEM_CLOCK(COUNT=W_tend, COUNT_RATE=W_ir) call SYSTEM_CLOCK(COUNT=W_tend, COUNT_RATE=W_ir)
W_tot_time = real(W_tend - W_tbeg, kind=8) / real(W_ir, kind=8) W_tot_time = real(W_tend - W_tbeg, kind=8) / real(W_ir, kind=8)
print *, ' ___________________________________________________________________' print *, ' ___________________________________________________________________'
@ -392,7 +368,7 @@ subroutine run
deallocate( Dref ) deallocate( Dref )
deallocate( Uref, Vref ) deallocate( Uref, Vref )
deallocate( coeff_psi ) !deallocate( coeff_psi )
deallocate( numalpha_selected, numbeta_selected ) deallocate( numalpha_selected, numbeta_selected )
deallocate( H0, Hdiag ) deallocate( H0, Hdiag )

View File

@ -0,0 +1,334 @@
program psiSVD_naivBbyB_v2
BEGIN_DOC
! diagonal H in the FSVD space
END_DOC
implicit none
read_wf = .True.
TOUCH read_wf
PROVIDE N_int
call run()
end
subroutine run
implicit none
integer(bit_kind) :: det1(N_int,2), det2(N_int,2)
integer :: degree, i_state
double precision :: h12, tol_h
integer :: na, nb
integer :: n_FSVD, n_TSVD
integer :: i, j, k, l
double precision, allocatable :: Uref(:,:), Dref(:), Vtref(:,:), Aref(:,:), Vref(:,:)
double precision :: t_beg, t_end
call wall_time(t_beg)
i_state = 1
det1(:,1) = psi_det_alpha_unique(:,1)
det2(:,1) = psi_det_alpha_unique(:,1)
det1(:,2) = psi_det_beta_unique(:,1)
det2(:,2) = psi_det_beta_unique(:,1)
call get_excitation_degree_spin(det1(1,1),det2(1,1),degree,N_int)
call get_excitation_degree(det1,det2,degree,N_int)
call i_H_j(det1, det2, N_int, h12)
na = n_det_alpha_unique
nb = n_det_beta_unique
n_FSVD = min(na,nb)
! ---------------------------------------------------------------------------------------
! construct the initial CI matrix
!
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
print *, ' CI matrix:', na, 'x', nb
print *, ' N det :', N_det
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
allocate( Aref(na,nb) )
Aref(:,:) = 0.d0
do k = 1, N_det
i = psi_bilinear_matrix_rows(k)
j = psi_bilinear_matrix_columns(k)
Aref(i,j) = psi_bilinear_matrix_values(k,i_state)
enddo
!
! ---------------------------------------------------------------------------------------
! ---------------------------------------------------------------------------------------
! perform a Full SVD
!
allocate( Uref(na,na), Dref(n_FSVD), Vtref(nb,nb) )
call svd_s(Aref, size(Aref,1), Uref, size(Uref,1), Dref, Vtref, size(Vtref,1), na, nb)
deallocate( Aref )
allocate( Vref(n_det_beta_unique,n_det_beta_unique) )
do l = 1, nb
do i = 1, nb
Vref(i,l) = Vtref(l,i)
enddo
enddo
deallocate( Vtref )
!
! ---------------------------------------------------------------------------------------
tol_h = 1d-12
do i = 2, n_FSVD, 10
call diag_hsvd(i, n_FSVD, tol_h, Uref, Vref, Dref)
enddo
call diag_hsvd(n_FSVD, n_FSVD, tol_h, Uref, Vref, Dref)
deallocate( Dref, Uref, Vref )
call wall_time(t_end)
print *, ' '
print *, " total elapsed time (min) = ", (t_end-t_beg)/60.d0
end
! ____________________________________________________________________________________________________________
!
! H_svd(a,b,c,d) = sum_{i,j,k,l} H_det(i,j,k,l) U(i,a) V(j,b) U(k,c) V(l,d)
!
subroutine diag_hsvd(n_TSVD, n_FSVD, tol_h, Uref, Vref, Dref)
implicit none
integer, intent(in) :: n_TSVD, n_FSVD
double precision, intent(in) :: tol_h
double precision, intent(in) :: Uref(n_det_alpha_unique,n_det_alpha_unique)
double precision, intent(in) :: Vref(n_det_beta_unique ,n_det_beta_unique)
double precision, intent(in) :: Dref(n_FSVD)
integer(bit_kind) :: det1(N_int,2), det2(N_int,2)
integer :: degree
double precision :: h12, x
integer :: na, nb, n_selec
integer :: i, j, k, l
integer :: a, b, c, d
double precision, allocatable :: H_SVD(:,:,:,:)
double precision, allocatable :: tmp1(:,:,:,:), tmp2(:,:,:,:)
integer :: ii, ind_gs
double precision :: E0, overlop
double precision, allocatable :: eigvec(:,:), eigval(:), check_ov(:)
double precision :: t1, t2, t3
na = n_det_alpha_unique
nb = n_det_beta_unique
n_selec = n_TSVD * n_TSVD
! ---------------------------------------------------------------------------------------
!
call wall_time(t1)
print *, ''
print *, ' start const psiHpsi in SVD space ...'
allocate( tmp1(nb,nb,n_TSVD,n_TSVD) )
tmp1(:,:,:,:) = 0.d0
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP PRIVATE(a, c, i, j, k, l, h12, x, det1, det2, degree, tmp2) &
!$OMP SHARED(na, nb, psi_det_alpha_unique, psi_det_beta_unique, &
!$OMP N_int, n_TSVD, tol_h, Uref, tmp1)
allocate( tmp2(nb,nb,n_TSVD,n_TSVD) )
tmp2(:,:,:,:) = 0.d0
!$OMP DO COLLAPSE(2) SCHEDULE(DYNAMIC,8)
do l = 1, nb
do j = 1, nb
det2(:,2) = psi_det_beta_unique(:,l)
det1(:,2) = psi_det_beta_unique(:,j)
call get_excitation_degree_spin(det1(1,2),det2(1,2),degree,N_int)
if(degree .gt. 2) cycle
do k = 1, na
det2(:,1) = psi_det_alpha_unique(:,k)
do i = 1, na
det1(:,1) = psi_det_alpha_unique(:,i)
call get_excitation_degree(det1,det2,degree,N_int)
if(degree .gt. 2) cycle
call i_H_j(det1, det2, N_int, h12)
if(dabs(h12) .lt. tol_h) cycle
! tmp2(j,l,a,c) = sum_{i,k} H(i,j,k,l) U(i,a) U(k,c)
do c = 1, n_TSVD
x = Uref(k,c) * h12
if(dabs(x) .lt. tol_h) cycle
do a = 1, n_TSVD
tmp2(j,l,a,c) += Uref(i,a) * x
enddo
enddo
enddo
enddo
enddo
enddo
!$OMP END DO
! tmp1 = tmp2
!$OMP CRITICAL
do a = 1, n_TSVD
do c = 1, n_TSVD
do l = 1, nb
do j = 1, nb
tmp1(j,l,a,c) += tmp2(j,l,a,c)
enddo
enddo
enddo
enddo
!$OMP END CRITICAL
deallocate( tmp2 )
!$OMP END PARALLEL
! tmp2_{l,a,c,b} = sum_{j} tmp1_{j,l,a,c} V_{j,b}
allocate( tmp2(nb,n_TSVD,n_TSVD,n_TSVD) )
call DGEMM('T', 'N', nb*n_TSVD*n_TSVD, n_TSVD, nb, 1.d0 &
, tmp1, size(tmp1,1) &
, Vref, size(Vref,1) &
, 0.d0, tmp2, size(tmp2,1)*size(tmp2,2)*size(tmp2,3) )
deallocate(tmp1)
! tmp1_{d,a,c,b} = sum_{l} tmp2_{l,a,c,b} V_{l,d}
allocate( tmp1(n_TSVD,n_TSVD,n_TSVD,n_TSVD) )
call DGEMM('T', 'N', n_TSVD*n_TSVD*n_TSVD, n_TSVD, nb, 1.d0 &
, tmp2, size(tmp2,1) &
, Vref, size(Vref,1) &
, 0.d0, tmp1, size(tmp1,1)*size(tmp1,2)*size(tmp1,3) )
deallocate( tmp2 )
allocate( H_SVD(n_TSVD,n_TSVD,n_TSVD,n_TSVD) )
H_SVD(:,:,:,:) = 0.d0
do d = 1, n_TSVD
do c = 1, n_TSVD
do b = 1, n_TSVD
do a = 1, n_TSVD
H_SVD(a,b,c,d) = tmp1(d,a,c,b)
enddo
enddo
enddo
enddo
deallocate( tmp1 )
call wall_time(t2)
print *, ' end const psiHpsi in SVD space after (min)', (t2-t1)/60.d0
print *, ''
!
! ---------------------------------------------------------------------------------------
! ---------------------------------------------------------------------------------------
!
print *, ''
print *, ' diagonalize psiHpsi in SVD space ...'
allocate( eigvec(n_selec,n_selec), eigval(n_selec) )
call lapack_diag(eigval, eigvec, H_SVD, n_selec, n_selec)
deallocate(H_SVD)
! get the postsvd ground state
allocate( check_ov(n_selec) )
do l = 1, n_selec
overlop = 0.d0
do i = 1, n_TSVD
ii = i + (i-1) * n_TSVD
overlop = overlop + eigvec(ii,l) * Dref(i)
enddo
check_ov(l) = dabs(overlop)
enddo
ind_gs = MAXLOC( check_ov, DIM=1 )
overlop = check_ov(ind_gs)
E0 = eigval(ind_gs) + nuclear_repulsion
print *, ' - - - - - - - - - - - - '
print *, ' n_TSVD = ', n_TSVD
print *, ' space dimen = ', n_selec
print *, ' gs num = ', ind_gs
print *, ' overlop = ', overlop
print *, ' diag energy = ', E0
print *, ' eigen vector: '
do i = 1, n_selec
print *, eigvec(i,ind_gs)
enddo
print *, ' - - - - - - - - - - - - '
write(222, *) n_TSVD, n_selec, E0, overlop
deallocate( check_ov, eigval, eigvec )
call wall_time(t3)
print *, ' end diag in SVD space after (min)', (t3-t2)/60.d0
print *, ''
!
! ---------------------------------------------------------------------------------------
return
end subroutine diag_hsvd
! ____________________________________________________________________________________________________________
! ____________________________________________________________________________________________________________
! ! ---------------------------------------------------------------------------------------
! ! H0 in det basis
!
! call wall_time(ti)
! print *, ''
! print *, ' start const psiHpsi in det space ...'
!
! tol_h = 1d-15
! allocate( H0_det(na,nb,na,nb) )
! H0_det(:,:,:,:) = 0.d0
!
! !$OMP PARALLEL DEFAULT(NONE) &
! !$OMP PRIVATE(i, j, k, l, h12, det1, det2, degree) &
! !$OMP SHARED(na, nb, psi_det_alpha_unique,psi_det_beta_unique, &
! !$OMP N_int, H0, tol_h)
! !$OMP DO COLLAPSE(2) SCHEDULE(DYNAMIC,8)
! do l = 1, nb
! do j = 1, nb
! det2(:,2) = psi_det_beta_unique(:,l)
! det1(:,2) = psi_det_beta_unique(:,j)
! call get_excitation_degree_spin(det1(1,2),det2(1,2),degree,N_int)
! if(degree .gt. 2) cycle
! do k = 1, na
! det2(:,1) = psi_det_alpha_unique(:,k)
! do i = 1, na
! det1(:,1) = psi_det_alpha_unique(:,i)
! call get_excitation_degree(det1,det2,degree,N_int)
! if(degree .gt. 2) cycle
! call i_H_j(det1, det2, N_int, h12)
! if(dabs(h12) .lt. tol_h) cycle
! H0(i,j,k,l) = h12
! enddo
! enddo
! enddo
! enddo
! !$OMP END DO
! !$OMP END PARALLEL
!
! call wall_time(tf)
! print *, ' end const psiHpsi in det space after (min)', (ti-tf)/60.d0
! print *, ''
! ! ---------------------------------------------------------------------------------------

View File

@ -77,7 +77,7 @@ subroutine run
! construct the initial CISD matrix ! construct the initial CISD matrix
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
print *, ' CISD matrix:', n_det_alpha_unique,'x',n_det_beta_unique print *, ' CI matrix:', n_det_alpha_unique,'x',n_det_beta_unique
print *, ' N det :', N_det print *, ' N det :', N_det
print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
@ -440,30 +440,6 @@ subroutine run
!________________________________________________________________________________________________________ !________________________________________________________________________________________________________
! ***************************************************************************************************
! save to ezfion
!allocate( Uezfio(n_det_alpha_unique,rank0,1), Dezfio(rank0,1), Vezfio(n_det_beta_unique,rank0,1) )
!do l = 1, rank0
! Dezfio(l,1) = coeff_psi(l)
! Uezfio(:,l,1) = U0(:,l)
! Vezfio(:,l,1) = V0(:,l)
!enddo
!call ezfio_set_spindeterminants_n_det(N_det)
!call ezfio_set_spindeterminants_n_states(N_states)
!call ezfio_set_spindeterminants_n_det_alpha(n_det_alpha_unique)
!call ezfio_set_spindeterminants_n_det_beta(n_det_beta_unique)
!call ezfio_set_spindeterminants_psi_coef_matrix_rows(psi_bilinear_matrix_rows)
!call ezfio_set_spindeterminants_psi_coef_matrix_columns(psi_bilinear_matrix_columns)
!call ezfio_set_spindeterminants_psi_coef_matrix_values(psi_bilinear_matrix_values)
!call ezfio_set_spindeterminants_n_svd_coefs(rank0)
!call ezfio_set_spindeterminants_psi_svd_alpha(Uezfio)
!call ezfio_set_spindeterminants_psi_svd_beta(Vezfio )
!call ezfio_set_spindeterminants_psi_svd_coefs(Dezfio)
!deallocate( Uezfio, Dezfio, Vezfio )
! ***************************************************************************************************
call SYSTEM_CLOCK(COUNT=W_tend, COUNT_RATE=W_ir) call SYSTEM_CLOCK(COUNT=W_tend, COUNT_RATE=W_ir)
W_tot_time = real(W_tend - W_tbeg, kind=8) / real(W_ir, kind=8) W_tot_time = real(W_tend - W_tbeg, kind=8) / real(W_ir, kind=8)
print *, ' ___________________________________________________________________' print *, ' ___________________________________________________________________'
@ -473,7 +449,6 @@ subroutine run
print *, ' ___________________________________________________________________' print *, ' ___________________________________________________________________'
deallocate( Dref ) deallocate( Dref )
deallocate( Uref, Vref ) deallocate( Uref, Vref )

View File

@ -0,0 +1,31 @@
#!/bin/bash
#
#SBATCH --job-name=QMC_n20_2h2
#SBATCH --output=%x_%j.out
#
#SBATCH --mail-type=ALL
#SBATCH --mail-user=aammar@irsamc.ups-tlse.fr
#
#SBATCH -N 1
#SBATCH -n 32
#SBATCH -c 1
#SBATCH -t 24:00:00
#SBATCH -p xeonv4
#SBATCH --exclusive
#
#
#
srun hostname
echo "Running on `hostname`"
#
echo "Kicking off $SLURM_NPROCS compute servers on $SLURM_NNODES nodes"
echo "Nodes are\n `scontrol show hostname`"
#
source ~/qmcchem/qmcchemrc
#
##qmcchem edit -c -j None -l 10 -t 120 h2o_631g >> qmcchem_h2o_631g.out
#qmcchem edit -c -j None -l 600 -t 10000 h2o_631g >> qmcchem_h2o_631g.out
#qmcchem run h2o_631g_frez_Jopt_nsvd10_iter2postsvd >> qmcchem_h2o_631g_frez_Jopt_nsvd10_iter2postsvd.out
#
qmcchem run 2h2_work/2h2_cisd_nsvd20 >> QMC_2h2_nsvd20.out
#

35
devel/svdwf/qpRun.slurm Normal file
View File

@ -0,0 +1,35 @@
#!/bin/bash
#
##SBATCH --job-name=buildpsi_h2o_pv
#SBATCH --job-name=diag_f2
#SBATCH --output=%x_%j.out
#SBATCH --mail-type=ALL
#SBATCH --mail-user=aammar@irsamc.ups-tlse.fr
#
#SBATCH -N 1
#SBATCH -n 1
#SBATCH -c 32
##SBATCH -c 1
#SBATCH -t 72:00:00
#SBATCH -p xeonv2
#SBATCH --exclusive
#
srun hostname
echo "Running on `hostname`"
echo "Kicking off $SLURM_NPROCS compute servers on $SLURM_NNODES nodes"
echo "Nodes are\n `scontrol show hostname`"
#
#qp create_ezfio -b 6-31g h2o.xyz -o h2o_631g
#qp create_ezfio -p bfd -b cc-pvdz_ecp_bfd h2o.xyz -o h2o_pseudo
#
~/qp2/bin/qpsh
#
#qp_run scf h2o_631g >> scf_h2o_631g.out
#qp_run cisd h2o_631g >> cisd_h2o_631g.out
#
#qp_run buildpsi_postsvd_pv h2o_work/h2o_631g_frez_cisd >> buildpsi_postsvd_h2o_631g_frez_cisd.dat
#
#qp_run diag_H_npostsvd h2o_work/h2o_631g_frez_fci >> diag_H_npostsvd.dat
qp_run diag_H_npostsvd_pv f2_work/f2_cisd >> diag_H_npostsvd_pv_f2.dat
#qp_run diag_H_npostsvd_pv h2o_work/h2o_631g_frez_cisd >> diag_H_npostsvd_pv_h2o.dat
#

26
devel/svdwf/run_py.slurm Normal file
View File

@ -0,0 +1,26 @@
#!/bin/bash
#SBATCH --job-name=RSVD
#SBATCH --output=%x_%j.out
#
#SBATCH --mail-type=ALL
#SBATCH --mail-user=aammar@irsamc.ups-tlse.fr
#
#SBATCH -N 1
#SBATCH -n 1
#SBATCH -c 1
#SBATCH -t 250:00:00
#SBATCH -p xeonv2
###SBATCH --exclusive
#
#
#
srun hostname
echo "Running on `hostname`"
#
echo "Kicking off $SLURM_NPROCS compute servers on $SLURM_NNODES nodes"
echo "Nodes are\n `scontrol show hostname`"
#
source ~/qmcchem/qmcchemrc
#
python perform_RSVD.py >> RSVD_py.out

View File

@ -0,0 +1,150 @@
program saveSVD_asEZ
BEGIN_DOC
! save SVD manually
END_DOC
implicit none
read_wf = .True.
TOUCH read_wf
call run()
end
subroutine run
implicit none
integer :: mm, nn, i_state, low_rank, lrank_min, lrank_max
integer :: i, j, k, l
double precision :: norm_psi, err_verif, err_tmp
double precision, allocatable :: U_FSVD(:,:), D_FSVD(:), Vt_FSVD(:,:), A_FSVD(:,:)
double precision, allocatable :: Uezfio(:,:,:), Dezfio(:,:), Vezfio(:,:,:)
double precision, allocatable :: US(:,:), A_TSVD(:,:)
double precision :: t0, t1, t2
call CPU_TIME(t0)
i_state = 1
mm = n_det_alpha_unique
nn = n_det_beta_unique
print *, ' matrix dimensions:', mm,'x',nn
print *, ' N det:', N_det
allocate( A_FSVD(mm,nn), U_FSVD(mm,mm), D_FSVD(min(mm,nn)), Vt_FSVD(nn,nn) )
norm_psi = 0.d0
A_FSVD(:,:) = 0.d0
do k = 1, N_det
i = psi_bilinear_matrix_rows(k)
j = psi_bilinear_matrix_columns(k)
A_FSVD(i,j) = psi_bilinear_matrix_values(k,i_state)
norm_psi += psi_bilinear_matrix_values(k,i_state) * psi_bilinear_matrix_values(k,i_state)
enddo
call svd_s( A_FSVD, size(A_FSVD,1), U_FSVD, size(U_FSVD,1), D_FSVD, Vt_FSVD, size(Vt_FSVD,1), mm, nn)
print *, ' --- Full SVD: ok --- '
call CPU_TIME(t1)
print *, (t1-t0)/60.d0, 'min'
! ------------------------------------------
!low_rank = 24
low_rank = min(mm,nn)
! US = U x SV :
allocate( US(mm,low_rank) )
US(:,:) = 0.d0
do i = 1, mm
do l = 1, low_rank
US(i,l) = U_FSVD(i,l) * D_FSVD(l)
enddo
enddo
! A_TSVD = US x Vt_FSVD
allocate( A_TSVD(mm,nn) )
A_TSVD(:,:) = 0.d0
call dgemm( 'N', 'N', mm, nn, low_rank, 1.d0 &
, US , size(US ,1) &
, Vt_FSVD, size(Vt_FSVD,1) &
, 0.d0, A_TSVD, size(A_TSVD,1) )
deallocatE(US)
! |A_FSVD-A_TSVD|
err_verif = 0.d0
do j = 1, nn
do i = 1, mm
err_tmp = A_FSVD(i,j) - A_TSVD(i,j)
err_verif = err_verif + err_tmp * err_tmp
enddo
enddo
print*, ' rank = ', low_rank
print*, ' err verif (%) = ', 100.d0 * dsqrt(err_verif/norm_psi)
deallocate( A_FSVD , A_TSVD )
! ------------------------------------------------------------------------------------------------
! set to EZFIO for a fixed low rank
allocate( Uezfio(mm,low_rank,1), Dezfio(low_rank,1), Vezfio(nn,low_rank,1))
do l = 1, low_rank
Dezfio(l,1) = D_FSVD(l)
do j = 1, mm
Uezfio(j,l,1) = U_FSVD(j,l)
enddo
do j = 1, nn
Vezfio(j,l,1) = Vt_FSVD(l,j)
enddo
enddo
deallocate( U_FSVD, D_FSVD, Vt_FSVD )
!call ezfio_set_spindeterminants_n_det(N_det)
!call ezfio_set_spindeterminants_n_states(N_states)
!call ezfio_set_spindeterminants_n_det_alpha(n_det_alpha_unique)
!call ezfio_set_spindeterminants_n_det_beta(n_det_beta_unique)
!call ezfio_set_spindeterminants_psi_coef_matrix_rows(psi_bilinear_matrix_rows)
!call ezfio_set_spindeterminants_psi_coef_matrix_columns(psi_bilinear_matrix_columns)
!call ezfio_set_spindeterminants_psi_coef_matrix_values(psi_bilinear_matrix_values)
call ezfio_set_spindeterminants_n_svd_coefs(low_rank)
call ezfio_set_spindeterminants_psi_svd_coefs(Dezfio)
deallocate( Dezfio)
! does not work for big matrices
!call ezfio_set_spindeterminants_psi_svd_alpha(Uezfio)
!call ezfio_set_spindeterminants_psi_svd_beta(Vezfio )
open(unit=11, file="u_svd.txt", action='write')
do l = 1, low_rank
do i = 1, mm
write(11,*) Uezfio(i,l,1)
enddo
enddo
close(11)
deallocate( Uezfio )
open(unit=11, file="v_svd.txt", action='write')
do l = 1, low_rank
do i = 1, nn
write(11,*) Vezfio(i,l,1)
enddo
enddo
close(11)
deallocate( Vezfio )
! ------------------------------------------------------------------------------------------------
call CPU_TIME(t2)
print *, ''
print *, ' end after'
print *, (t2-t0)/60.d0, 'min'
end