10
1
mirror of https://gitlab.com/scemama/qmcchem.git synced 2024-06-02 03:15:19 +02:00

Fixed exploding energies with pseudos

This commit is contained in:
Anthony Scemama 2020-05-11 13:49:07 +02:00
parent f41412658e
commit e9706cee7a
4 changed files with 110 additions and 49 deletions

View File

@ -8,18 +8,25 @@ import os
import time import time
import subprocess import subprocess
sys.path.insert(0,"/home/scemama/qmcchem/EZFIO/Python/") QMCCHEM_PATH=os.environ["QMCCHEM_PATH"]
sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/")
from ezfio import ezfio from ezfio import ezfio
# PARAMETERS # PARAMETERS
thresh = 1.e-3 thresh = 1.e-3
block_time = 30 block_time = 20
def main(): def main():
if len(sys.argv) != 2:
print("Usage: %s <EZFIO_DIRECTORY>"%sys.argv[0])
sys.exti(1)
filename = sys.argv[1] filename = sys.argv[1]
ezfio.set_file(filename) ezfio.set_file(filename)
def make_atom_map(): def make_atom_map():
labels = {} labels = {}
dimension = 0 dimension = 0
@ -36,10 +43,12 @@ def main():
return atom_map return atom_map
atom_map = make_atom_map() atom_map = make_atom_map()
def get_params_pen(): def get_params_pen():
d = ezfio.jastrow_jast_pen d = ezfio.jastrow_jast_pen
return np.array([d[m[0]] for m in atom_map]) return np.array([d[m[0]] for m in atom_map])
def get_energy(): def get_energy():
buffer = subprocess.check_output(['qmcchem', 'result', '-e', 'e_loc', filename], buffer = subprocess.check_output(['qmcchem', 'result', '-e', 'e_loc', filename],
encoding='UTF-8') encoding='UTF-8')
@ -50,6 +59,7 @@ def main():
else: else:
return None, None return None, None
def set_params_pen(x): def set_params_pen(x):
x = np.abs(x) x = np.abs(x)
y=list(ezfio.jastrow_jast_pen) y=list(ezfio.jastrow_jast_pen)
@ -58,23 +68,30 @@ def main():
y[j] = x[i] y[j] = x[i]
ezfio.set_jastrow_jast_pen(y) ezfio.set_jastrow_jast_pen(y)
def run_qmc(): def run_qmc():
subprocess.check_output(['qmcchem', 'run', filename]) subprocess.check_output(['qmcchem', 'run', filename])
def stop_qmc(): def stop_qmc():
subprocess.check_output(['qmcchem', 'stop', filename]) subprocess.check_output(['qmcchem', 'stop', filename])
def set_vmc_params(): def set_vmc_params():
# subprocess.check_output(['qmcchem', 'edit', '-c', '-j', 'Simple',
# '-m', 'VMC',
# '-l', str(block_time),
# '--time-step=0.3',
# '--stop-time=36000',
# '--norm=1.e-5',
# '-w', '10',
# filename])
subprocess.check_output(['qmcchem', 'edit', '-c', '-j', 'Simple', subprocess.check_output(['qmcchem', 'edit', '-c', '-j', 'Simple',
'-m', 'VMC',
'-l', str(block_time), '-l', str(block_time),
'--time-step=0.3',
'--stop-time=3600',
'--norm=1.e-5',
'-w', '10',
filename]) filename])
memo_energy = {}
memo_energy = {'fmin': 100000000.}
def f(x): def f(x):
print ("x = %s"%str(x)) print ("x = %s"%str(x))
h = str(x) h = str(x)
@ -92,13 +109,16 @@ def main():
err = thresh+1. err = thresh+1.
time.sleep(block_time/2) time.sleep(block_time/2)
while err > thresh: local_thresh = thresh
while err > local_thresh:
time.sleep(block_time) time.sleep(block_time)
energy, err = get_energy() energy, err = get_energy()
if energy is not None: if energy is not None:
print(" %f %f"%(energy, err)) print(" %f %f"%(energy, err))
if (energy-2.*err) > memo_energy['fmin']+thresh:
local_thresh = 10.*thresh
else: else:
err = thresh+1. err = local_thresh+1.
# Check if PID is still running # Check if PID is still running
try: os.kill(pid,0) try: os.kill(pid,0)
@ -106,6 +126,7 @@ def main():
stop_qmc() stop_qmc()
os.wait() os.wait()
memo_energy[h] = energy memo_energy[h] = energy
memo_energy['fmin'] = min(energy, memo_energy['fmin'])
return energy return energy
@ -115,6 +136,7 @@ def main():
options= {'disp':True, 'ftol':thresh,'xtol':0.02}) options= {'disp':True, 'ftol':thresh,'xtol':0.02})
print("x = "+str(opt)) print("x = "+str(opt))
set_params_pen(opt['x']) set_params_pen(opt['x'])
run() run()
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -6,7 +6,10 @@ type t =
let to_string = function let to_string = function
| Srun -> "srun" | Srun -> "srun"
| Bash -> "env" | Bash -> "env"
| MPI -> Lazy.force Qmcchem_config.mpirun | MPI -> String.concat " " [ Lazy.force Qmcchem_config.mpirun ;
try Sys.getenv "QMCCHEM_MPIRUN_FLAGS" with Not_found -> ""
]
(* (*
let to_string = function let to_string = function
| MPI | MPI
@ -16,7 +19,8 @@ let to_string = function
| Some p -> p | Some p -> p
] ]
| Bash -> "env" | Bash -> "env"
*) *)
(** Find the launcher for the current job scheduler *) (** Find the launcher for the current job scheduler *)

View File

@ -183,6 +183,20 @@ END_SHELL
E_loc_save(2,i_walk) = E_loc_save(1,i_walk) E_loc_save(2,i_walk) = E_loc_save(1,i_walk)
E_loc_save(1,i_walk) = E_loc E_loc_save(1,i_walk) = E_loc
if (do_print_dmc_data) then
do k=1,walk_num
double precision, external :: qmc_ranf
if (qmc_ranf() < 0.001) then
print *, '--'
do i=1,elec_num
print *, elec_coord_full(i,1:3,k)
enddo
print *, 'w=', pdmc_pop_weight_mult(pdmc_n_diag) * pdmc_weight(i_walk)
endif
enddo
endif
if (dabs(pdmc_weight(i_walk)*pdmc_pop_weight_mult(pdmc_n_diag)) > 1.d-15) then if (dabs(pdmc_weight(i_walk)*pdmc_pop_weight_mult(pdmc_n_diag)) > 1.d-15) then
dmc_zv_weight = 1.d0/(pdmc_weight(i_walk)*pdmc_pop_weight_mult(pdmc_n_diag)) dmc_zv_weight = 1.d0/(pdmc_weight(i_walk)*pdmc_pop_weight_mult(pdmc_n_diag))
dmc_zv_weight_half = 1.d0/(pdmc_weight(i_walk)*pdmc_pop_weight_mult(pdmc_n_diag/2)) dmc_zv_weight_half = 1.d0/(pdmc_weight(i_walk)*pdmc_pop_weight_mult(pdmc_n_diag/2))
@ -248,7 +262,6 @@ END_SHELL
! pdmc_pop_weight_mult(:) = 1.d0 ! pdmc_pop_weight_mult(:) = 1.d0
! endif ! endif
do k=1,pdmc_n_diag do k=1,pdmc_n_diag
! Move to the next projection step ! Move to the next projection step
if (pdmc_projection(pdmc_n_diag) > 0) then if (pdmc_projection(pdmc_n_diag) > 0) then

View File

@ -1,5 +1,14 @@
! Providers of *_srmc_block_walk ! Providers of *_srmc_block_walk
!============================== !==============================
BEGIN_PROVIDER [ logical, do_print_dmc_data ]
implicit none
BEGIN_DOC
! If true, print in stdout the data to fit a Jastrow
END_DOC
do_print_dmc_data = .False.
END_PROVIDER
BEGIN_SHELL [ /usr/bin/env python2 ] BEGIN_SHELL [ /usr/bin/env python2 ]
from properties import * from properties import *
@ -155,12 +164,12 @@ END_SHELL
if (delta >= 0.d0) then if (delta >= 0.d0) then
srmc_weight(i_walk) = dexp(-dtime_step*delta) srmc_weight(i_walk) = dexp(-dtime_step*delta)
else else
srmc_weight(i_walk) = 2.d0-dexp(dtime_step*delta) srmc_weight(i_walk) = max(2.d0-dexp(dtime_step*delta), 0.d0)
endif endif
! Trick to avoid holes in DMC PES. ! Trick to avoid holes in DMC PES.
if (dabs(delta/E_ref) * time_step_sq > p ) then if (dabs(delta/E_ref) * time_step_sq > p * 0.5d0 ) then
srmc_weight(i_walk) = 1.d-1 srmc_weight(i_walk) = 0.d0
endif endif
@ -294,6 +303,19 @@ END_SHELL
! Update the running population weight ! Update the running population weight
srmc_pop_weight_mult *= srmc_pop_weight(srmc_projection_step) srmc_pop_weight_mult *= srmc_pop_weight(srmc_projection_step)
if (do_print_dmc_data) then
do k=1,walk_num
double precision, external :: qmc_ranf
if (qmc_ranf() < 0.001) then
print *, '--'
do i=1,elec_num
print *, elec_coord_full(i,1:3,k)
enddo
print *, 'w=', srmc_weight(k)
endif
enddo
endif
! Reconfiguration ! Reconfiguration
integer :: ipos(walk_num) integer :: ipos(walk_num)