10
1
mirror of https://gitlab.com/scemama/qmcchem.git synced 2024-12-22 04:13:31 +01:00

Smaller time step errors

- Implemented SRMC and DMC
- Using (E_new+E_old)/2 in DMC weight reduces time step errors
- Branching weight is present in E_loc accumulation
- Introduces Error in Message.ml
This commit is contained in:
Anthony Scemama 2016-01-18 20:17:37 +01:00
parent 55d3c7b68a
commit c56c3ea851
22 changed files with 389 additions and 330 deletions

View File

@ -65,7 +65,7 @@ simulation
ci_threshold double precision
md5_key character*(32)
E_ref double precision
dmc_projection_time real
srmc_projection_time real
jastrow
jast_type character*(32)

View File

@ -17,7 +17,7 @@ let simulation_method = lazy ( "VMC" )
let simulation_sampling = lazy ( "Langevin" )
let simulation_stop_time = lazy ( 3600 )
let simulation_time_step = lazy ( 0.15 )
let simulation_dmc_projection_time = lazy ( 1. )
let simulation_srmc_projection_time = lazy ( 1. )
let reset_defaults () =
List.iter ~f:(fun x -> Sys.remove ( (Lazy.force Qputils.ezfio_filename) ^ x))

View File

@ -399,7 +399,7 @@ end
module Method : sig
type t = VMC | DMC
type t = VMC | DMC | SRMC
val doc : string
val read : unit -> t
val write : t -> unit
@ -408,19 +408,21 @@ module Method : sig
end = struct
type t = VMC | DMC
type t = VMC | DMC | SRMC
let doc = "QMC Method : [ VMC | DMC ]"
let doc = "QMC Method : [ VMC | DMC | SRMC ]"
let of_string = function
| "VMC" | "vmc" -> VMC
| "DMC" | "dmc" -> DMC
| x -> failwith ("Method should be [ VMC | DMC ], not "^x^".")
| "SRMC" | "srmc" -> SRMC
| x -> failwith ("Method should be [ VMC | DMC | SRMC ], not "^x^".")
let to_string = function
| VMC -> "VMC"
| DMC -> "DMC"
| SRMC -> "SRMC"
let read () =
@ -611,7 +613,7 @@ contribution to the norm less than t (au)"
end
module DMC_projection_time : sig
module SRMC_projection_time : sig
type t = float
val doc : string
@ -625,13 +627,13 @@ module DMC_projection_time : sig
end = struct
type t = float
let doc = "DMC projection time (au)"
let doc = "SRMC projection time (au)"
let of_float x =
if (x >= 100.) then
failwith "DMC Projection time should be < 100.";
failwith "SRMC Projection time should be < 100.";
if (x <= 0.) then
failwith "DMC Projection time should be positive.";
failwith "SRMC Projection time should be positive.";
x
@ -641,10 +643,10 @@ end = struct
let _ =
Lazy.force Qputils.ezfio_filename
in
if (not (Ezfio.has_simulation_dmc_projection_time())) then
Lazy.force Default.simulation_dmc_projection_time
|> Ezfio.set_simulation_dmc_projection_time ;
Ezfio.get_simulation_dmc_projection_time ()
if (not (Ezfio.has_simulation_srmc_projection_time())) then
Lazy.force Default.simulation_srmc_projection_time
|> Ezfio.set_simulation_srmc_projection_time ;
Ezfio.get_simulation_srmc_projection_time ()
|> of_float
@ -653,7 +655,7 @@ end = struct
Lazy.force Qputils.ezfio_filename
in
to_float t
|> Ezfio.set_simulation_dmc_projection_time
|> Ezfio.set_simulation_srmc_projection_time
let of_string x =
@ -862,27 +864,31 @@ let validate () =
(* Check sampling and time steps *)
let () =
match (sampling, meth, Pseudo.to_bool do_pseudo) with
| (Sampling.Brownian, Method.DMC, true) ->
| (Sampling.Brownian, Method.DMC, true)
| (Sampling.Brownian, Method.SRMC, true) ->
if ( (Time_step.to_float ts) >= 0.5 ) then
warn "Time step seems large for DMC.";
warn ( "Time step seems large for "^(Method.to_string meth) )
| (Sampling.Brownian, Method.SRMC, false)
| (Sampling.Brownian, Method.DMC, false) ->
if ( (Time_step.to_float ts) >= 0.01 ) then
warn "Time step seems large for DMC.";
warn ( "Time step seems large for "^(Method.to_string meth) )
| (Sampling.Brownian, Method.VMC, _) ->
if ( (Time_step.to_float ts) >= 10. ) then
warn "Time step seems large for VMC.";
warn "Time step seems large for VMC."
| (Sampling.Langevin, Method.VMC, _) ->
if ( (Time_step.to_float ts) <= 0.01 ) then
warn "Time step seems small for Langevin sampling."
| (Sampling.Langevin, Method.SRMC, _)
| (Sampling.Langevin, Method.DMC, _) ->
failwith "Lanvegin sampling is incompatible with DMC"
failwith "Lanvegin sampling is incompatible with DMC/SRMC"
in
(* Check E_ref is not zero *)
let () =
match (meth, Ref_energy.(read () |> to_float) ) with
| (Method.DMC,0.) -> failwith "E_ref should not be zero in DMC"
| (Method.SRMC,0.)
| (Method.DMC,0.) -> failwith ("E_ref should not be zero in "^(Method.to_string meth) )
| _ -> ()
in
@ -895,7 +901,8 @@ let validate () =
(* Check if E_loc if computed *)
let () =
match (meth, Property.(calc E_loc)) with
| (Method.DMC, false) -> failwith "E_loc should be sampled in DMC"
| (Method.SRMC, false)
| (Method.DMC, false) -> failwith ( "E_loc should be sampled in "^(Method.to_string meth) )
| (Method.VMC, false) -> warn "Sampling of E_loc is not activated in input"
| _ -> ()
in

View File

@ -9,9 +9,12 @@ type t =
| Test
| GetWalkers of Strictly_positive_int.t
| Ezfio of string
| Error of string
let create = function
let create m =
try
match m with
| [ "cpu" ; c ; pid ; b ; "1" ; v ] ->
let open Block in
Property
@ -103,11 +106,10 @@ let create = function
block_id = Block_id.of_int (Int.of_string b);
}
end
| l ->
begin
List.iter ~f:(Printf.printf ":%s:") l;
failwith "Message not understood"
end
| l -> Error (String.concat ~sep:":" l)
with
| Assert_failure (l,_,_) -> Error l
| _ -> Error "Unknown error"
let to_string = function
@ -122,5 +124,6 @@ let to_string = function
(Compute_node.to_string h) (Pid.to_string p)
| Test -> "Test"
| Ezfio msg -> "Ezfio "^msg
| Error msg -> "Error "^msg

View File

@ -28,7 +28,7 @@ let bind_socket ~socket_type ~socket ~address =
let run ?(daemon=true) ezfio_filename =
Ezfio.set_file ezfio_filename ;
Qputils.set_ezfio_filename ezfio_filename;
(** Measures the time difference between [t0] and [Time.now ()] *)
let delta_t t0 =
@ -126,9 +126,9 @@ let run ?(daemon=true) ezfio_filename =
Printf.sprintf "tcp://*:%d" (port+4)
in
bind_socket "XPUB" debug_socket address;
ZMQ.Socket.set_linger_period debug_socket 100 ;
let close_debug_socket () =
ZMQ.Socket.set_linger_period debug_socket 1000 ;
ZMQ.Socket.close debug_socket
in
@ -475,7 +475,7 @@ let run ?(daemon=true) ezfio_filename =
;
done;
ZMQ.Socket.send socket (Status.to_string !status);
ZMQ.Socket.set_linger_period socket 1000 ;
ZMQ.Socket.set_linger_period socket 1_000 ;
ZMQ.Socket.close socket
)
in
@ -564,9 +564,10 @@ let run ?(daemon=true) ezfio_filename =
Printf.sprintf "tcp://*:%d" port
in
bind_socket "REP" rep_socket address;
ZMQ.Socket.set_receive_high_water_mark rep_socket 100000;
ZMQ.Socket.set_send_high_water_mark rep_socket 100000;
ZMQ.Socket.set_receive_high_water_mark rep_socket 100_000;
ZMQ.Socket.set_send_high_water_mark rep_socket 100_000;
ZMQ.Socket.set_immediate rep_socket true;
ZMQ.Socket.set_linger_period rep_socket 600_000 ;
(** EZFIO Cache *)
let ezfio_cache =
@ -630,6 +631,7 @@ let run ?(daemon=true) ezfio_filename =
List.fold ~init:0 ~f:(fun accu x -> accu + (String.length x)) raw_msg
in
let handle = function
| Message.Error _ -> ()
| Message.Ezfio ezfio_msg ->
let result =
handle_ezfio ezfio_msg
@ -718,6 +720,7 @@ let run ?(daemon=true) ezfio_filename =
in
let handle = function
| Message.Error _ -> ()
| Message.Walkers (h,pid,w) ->
begin
if (status = Status.Running) then

View File

@ -1,9 +1,9 @@
open Core.Std
let run ~t filename=
let run ~t ezfio_filename=
Ezfio.set_file filename;
Qputils.set_ezfio_filename ezfio_filename;
if (not (Ezfio.has_simulation_http_server ())) then
failwith "QMC=Chem is not running"
@ -13,7 +13,7 @@ let run ~t filename=
ZMQ.Context.create ()
in
Printf.printf "Debugging %s\n%!" filename;
Printf.printf "Debugging %s\n%!" ezfio_filename;
let socket =
ZMQ.Socket.create zmq_context ZMQ.Socket.sub
in
@ -70,7 +70,7 @@ let spec =
empty
+> flag "t" no_arg
~doc:"Measure the throughput"
+> anon ("filename" %: string)
+> anon ("ezfio_file" %: string)
let command =
@ -78,7 +78,7 @@ let command =
~summary: "Debug ZeroMQ communications"
~readme:(fun () -> "Gets debug information from the ZMQ debug sockets.")
spec
(fun t filename () -> run t filename)
(fun t ezfio_file () -> run t ezfio_file)

View File

@ -26,7 +26,7 @@ type field =
| Ref_energy
| CI_threshold
| Time_step
| DMC_projection_time
| SRMC_projection_time
| Jastrow_type
| Properties
@ -66,8 +66,8 @@ let get field =
option_to_string CI_threshold.read CI_threshold.to_string CI_threshold.doc
| Time_step ->
option_to_string Time_step.read Time_step.to_string Time_step.doc
| DMC_projection_time ->
option_to_string DMC_projection_time.read DMC_projection_time.to_string DMC_projection_time.doc
| SRMC_projection_time ->
option_to_string SRMC_projection_time.read SRMC_projection_time.to_string SRMC_projection_time.doc
| Jastrow_type ->
option_to_string Jastrow_type.read Jastrow_type.to_string Jastrow_type.doc
| Properties ->
@ -116,10 +116,7 @@ let run ~c ?f ?t ?l ?m ?e ?s ?ts ?w ?wt ?n ?j ?p ?input ezfio_filename =
in
(* Open EZFIO *)
if (not (Sys.file_exists_exn ezfio_filename)) then
failwith (ezfio_filename^" does not exist");
Ezfio.set_file ezfio_filename;
Qputils.set_ezfio_filename ezfio_filename;
let handle_option (type_conv, write) x =
let () =
@ -144,7 +141,7 @@ let run ~c ?f ?t ?l ?m ?e ?s ?ts ?w ?wt ?n ?j ?p ?input ezfio_filename =
handle_option Input.Walk_num.(of_int , write) w;
handle_option Input.Walk_num_tot.(of_int , write) wt;
handle_option Input.CI_threshold.(of_float , write) n;
handle_option Input.DMC_projection_time.(of_float , write) p;
handle_option Input.SRMC_projection_time.(of_float , write) p;
let fields =
@ -154,7 +151,7 @@ let run ~c ?f ?t ?l ?m ?e ?s ?ts ?w ?wt ?n ?j ?p ?input ezfio_filename =
Method ;
Sampling ;
Time_step ;
DMC_projection_time ;
SRMC_projection_time ;
Ref_energy ;
Walk_num ;
Walk_num_tot ;
@ -223,7 +220,7 @@ let run ~c ?f ?t ?l ?m ?e ?s ?ts ?w ?wt ?n ?j ?p ?input ezfio_filename =
| Ref_energy -> Ref_energy.(of_string s |> write)
| Sampling -> Sampling.(of_string s |> write)
| Time_step -> Time_step.(of_string s |> write)
| DMC_projection_time -> DMC_projection_time.(of_string s |> write)
| SRMC_projection_time -> SRMC_projection_time.(of_string s |> write)
| Walk_num -> Walk_num.(of_string s |> write)
| Walk_num_tot -> Walk_num_tot.(of_string s |> write)
| CI_threshold -> CI_threshold.(of_string s |> write)
@ -297,7 +294,7 @@ let spec =
+> flag "j" (optional string)
~doc:("jastrow_type "^Input.Jastrow_type.doc)
+> flag "p" (optional float)
~doc:("projection_time "^Input.DMC_projection_time.doc)
~doc:("projection_time "^Input.SRMC_projection_time.doc)
+> anon ("ezfio_file" %: string)
+> anon (maybe ("input" %: string))
;;

View File

@ -226,16 +226,17 @@ let run ezfio_filename dataserver =
ZMQ.Socket.create zmq_context ZMQ.Socket.req
in
ZMQ.Socket.connect req_socket dataserver;
ZMQ.Socket.set_receive_timeout req_socket 180_000;
ZMQ.Socket.set_receive_timeout req_socket 600_000;
let dealer_socket =
ZMQ.Socket.create zmq_context ZMQ.Socket.dealer
in
bind_socket "PROXY" dealer_socket "inproc://dealer";
ZMQ.Socket.set_receive_high_water_mark dealer_socket 100000;
ZMQ.Socket.set_send_high_water_mark dealer_socket 100000;
ZMQ.Socket.set_receive_high_water_mark dealer_socket 100_000;
ZMQ.Socket.set_send_high_water_mark dealer_socket 100_000;
ZMQ.Socket.set_immediate dealer_socket true;
ZMQ.Socket.set_linger_period dealer_socket 600_000;
let fetch_walkers () =
ZMQ.Socket.send_all req_socket ["get_walkers" ; Int.to_string !walk_num ];
@ -293,7 +294,7 @@ let run ezfio_filename dataserver =
let result =
handle_ezfio ezfio_msg
in
ZMQ.Socket.send_all dealer_socket (header @ result) ;
ZMQ.Socket.send_all dealer_socket (header @ result)
| Message.GetWalkers n_walks ->
begin
if (!walk_num = 0) then
@ -305,7 +306,8 @@ let run ezfio_filename dataserver =
walkers := fetch_walkers ();
end
| Message.Test ->
ZMQ.Socket.send_all dealer_socket (header @ [ "OK" ]);
ZMQ.Socket.send_all dealer_socket (header @ [ "OK" ])
| Message.Error _ -> ()
| Message.Register _
| Message.Unregister _
| Message.Walkers _
@ -315,8 +317,8 @@ let run ezfio_filename dataserver =
end;
done;
ZMQ.Socket.set_linger_period dealer_socket 1000 ;
ZMQ.Socket.close dealer_socket;
ZMQ.Socket.set_linger_period req_socket 1000 ;
ZMQ.Socket.close dealer_socket;
ZMQ.Socket.close req_socket;
in
Thread.create f
@ -330,6 +332,7 @@ let run ezfio_filename dataserver =
ZMQ.Socket.create zmq_context ZMQ.Socket.dealer
in
ZMQ.Socket.connect dealer_socket dataserver;
ZMQ.Socket.set_linger_period dealer_socket 600_000;
let proxy_socket =
ZMQ.Socket.create zmq_context ZMQ.Socket.dealer
@ -345,6 +348,7 @@ let run ezfio_filename dataserver =
ZMQ.Socket.set_receive_high_water_mark router_socket 100000;
ZMQ.Socket.set_send_high_water_mark router_socket 100000;
ZMQ.Socket.set_immediate router_socket true;
ZMQ.Socket.set_linger_period router_socket 600_000;
(* Pull socket for computed data *)
let push_socket =
@ -353,6 +357,7 @@ let run ezfio_filename dataserver =
Printf.sprintf "tcp://%s:%d" dataserver_address (port+2-10)
in
ZMQ.Socket.connect push_socket address;
ZMQ.Socket.set_linger_period push_socket 600_000;
let pull_socket =
ZMQ.Socket.create zmq_context ZMQ.Socket.pull
@ -380,13 +385,14 @@ let run ezfio_filename dataserver =
| Message.GetWalkers _
| Message.Ezfio _
| Message.Test ->
ZMQ.Socket.send_all proxy_socket raw_msg;
ZMQ.Socket.send_all proxy_socket raw_msg
| Message.Register _
| Message.Unregister _ ->
ZMQ.Socket.send_all dealer_socket raw_msg;
ZMQ.Socket.send_all dealer_socket raw_msg
| Message.Walkers (_, _, _)
| Message.Property _ ->
failwith "Bad message"
| Message.Error _ -> ()
in handle msg
in

View File

@ -2,6 +2,7 @@ open Core.Std
let run ezfio_filename =
Qputils.set_ezfio_filename ezfio_filename;
let qmcchem_info =
Lazy.force Qmcchem_config.qmcchem_info
in

View File

@ -2,7 +2,7 @@ open Core.Std
let run ?c ?d ~l ezfio_filename =
Ezfio.set_file ezfio_filename;
Qputils.set_ezfio_filename ezfio_filename;
let input_directory =
Lazy.force Md5.input_directory

View File

@ -164,7 +164,7 @@ let display_summary () =
let run ?a ?c ?e ?h ?t ?p ezfio_file =
Ezfio.set_file ezfio_file;
Qputils.set_ezfio_filename ezfio_file;
let f (x,func) =
match x with
| Some property -> func property

View File

@ -143,10 +143,7 @@ let ssh_run host dataserver ezfio_filename =
let run a d ?q ?s ezfio_filename =
Ezfio.set_file ezfio_filename;
let ezfio_filename =
Lazy.force Qputils.ezfio_filename
in
Qputils.set_ezfio_filename ezfio_filename;
(* Signal handler to Kill properly all the processes *)
let handler s =

View File

@ -2,7 +2,7 @@ open Core.Std
let run ezfio_filename =
Ezfio.set_file ezfio_filename ;
Qputils.set_ezfio_filename ezfio_filename;
Status.write Status.Stopping

View File

@ -9,34 +9,40 @@ let split s =
|> Str.split split_re
let set_ezfio_filename ezfio_filename =
let () =
if (not (Sys.file_exists_exn ezfio_filename)) then
failwith (ezfio_filename^" does not exist")
in
let () =
match (Sys.is_directory ezfio_filename) with
| `Yes -> Ezfio.set_file ezfio_filename ;
| _ -> failwith ("Error : "^ezfio_filename^" is not a directory")
in
let dir, result =
Filename.realpath ezfio_filename
|> Filename.split
in
Unix.chdir dir ;
Ezfio.set_file result
let ezfio_filename = lazy (
let f =
!Ezfio.ezfio_filename
in
let full_path =
begin
if f = "EZFIO_File" then
match f with
| "EZFIO_File" ->
begin
if (Array.length Sys.argv = 1) then
failwith "Error : EZFIO directory not specified on the command line\n";
let ezfio_filename = Sys.argv.(1)
in
let () =
match (Sys.is_directory ezfio_filename) with
| `Yes -> Ezfio.set_file ezfio_filename ;
| _ -> failwith ("Error : "^ezfio_filename^" not found")
in ezfio_filename
end
else
f
Sys.argv.(1)
end
| f -> f
in
let dir, result =
Filename.realpath full_path
|> Filename.split
in
Unix.chdir dir;
result
set_ezfio_filename full_path;
!Ezfio.ezfio_filename
)

View File

@ -235,13 +235,12 @@ BEGIN_PROVIDER [ double precision, E_loc ]
E_loc += E_kin_elec(i) + E_pot_elec(i)
enddo
! Avoid divergence of E_loc
if (qmc_method == t_DMC) then
double precision :: delta_e
delta_e = E_loc-E_ref
E_loc = E_ref + erf(1.d0/(time_step*delta_e*time_step*delta_e)) * delta_e
endif
! ! Avoid divergence of E_loc
! if (qmc_method == t_DMC) then
! double precision :: delta_e
! delta_e = E_loc-E_ref
! E_loc = E_ref + erf(1.d0/(time_step*delta_e*time_step*delta_e)) * delta_e
! endif
E_loc_min = min(E_loc,E_loc_min)
E_loc_max = max(E_loc,E_loc_max)

View File

@ -47,15 +47,15 @@ BEGIN_PROVIDER [ double precision, wf_extension ]
SOFT_TOUCH wf_extension_min wf_extension_max
END_PROVIDER
BEGIN_PROVIDER [ double precision, dmc_pop_weight ]
BEGIN_PROVIDER [ double precision, srmc_pop_weight ]
implicit none
BEGIN_DOC
! Weight of the DMC population
! Weight of the SRMC population
END_DOC
dmc_pop_weight = pop_weight_mult
dmc_pop_weight_min = min(dmc_pop_weight,dmc_pop_weight_min)
dmc_pop_weight_max = max(dmc_pop_weight,dmc_pop_weight_max)
SOFT_TOUCH dmc_pop_weight_min dmc_pop_weight_max
srmc_pop_weight = pop_weight_mult
srmc_pop_weight_min = min(srmc_pop_weight,srmc_pop_weight_min)
srmc_pop_weight_max = max(srmc_pop_weight,srmc_pop_weight_max)
SOFT_TOUCH srmc_pop_weight_min srmc_pop_weight_max
END_PROVIDER

View File

@ -24,6 +24,12 @@ t = """
$X_block_walk = $X_dmc_block_walk
$X_2_block_walk = $X_2_dmc_block_walk
endif
else if (qmc_method == t_SRMC) then
PROVIDE E_loc_srmc_block_walk
if (calc_$X) then
$X_block_walk = $X_srmc_block_walk
$X_2_block_walk = $X_2_srmc_block_walk
endif
endif
END_PROVIDER

View File

@ -44,13 +44,21 @@ END_SHELL
real, allocatable :: elec_coord_tmp(:,:,:)
integer :: mod_align
double precision :: psi_value_save(walk_num)
double precision :: psi_value_save_tmp(walk_num)
integer :: trapped_walk_tmp(walk_num)
double precision :: E_loc_save(walk_num_dmc_max)
double precision :: E_loc_save_tmp(walk_num_dmc_max)
double precision :: psi_value_save(walk_num_dmc_max)
double precision :: psi_value_save_tmp(walk_num_dmc_max)
double precision :: dmc_weight(walk_num_dmc_max)
integer :: trapped_walk_tmp(walk_num_dmc_max)
!DIR$ ATTRIBUTES ALIGN : $IRP_ALIGN :: E_loc_save
!DIR$ ATTRIBUTES ALIGN : $IRP_ALIGN :: E_loc_save_tmp
!DIR$ ATTRIBUTES ALIGN : $IRP_ALIGN :: dmc_weight
!DIR$ ATTRIBUTES ALIGN : $IRP_ALIGN :: psi_value_save
!DIR$ ATTRIBUTES ALIGN : $IRP_ALIGN :: psi_value_save_tmp
allocate ( elec_coord_tmp(mod_align(elec_num+1),3,walk_num) )
allocate ( elec_coord_tmp(mod_align(elec_num+1),3,walk_num_dmc_max) )
psi_value_save = 0.d0
psi_value_save_tmp = 0.d0
dmc_weight = 1.d0
! Initialization
if (vmc_algo /= t_Brownian) then
@ -71,8 +79,6 @@ t = """
$X_2_dmc_block_walk = 0.d0
!DIR$ VECTOR ALIGNED
$X_2_dmc_block_walk_kahan = 0.d0
$X_min = huge(1.)
$X_max =-huge(1.)
endif
"""
for p in properties:
@ -88,35 +94,79 @@ END_SHELL
block_weight = 0.d0
real, external :: accep_rate
double precision :: delta, thr, E0
thr = 2.d0/time_step_sq
E0 = E_ref
do while (loop)
! Every walker makes a step
do i_walk=1,walk_num
do i_walk=1,walk_num_dmc
integer :: i,j,l
do l=1,3
do i=1,elec_num+1
elec_coord(i,l) = elec_coord_full(i,l,i_walk)
elec_coord(i,l) = elec_coord_full_dmc(i,l,i_walk)
enddo
enddo
TOUCH elec_coord
double precision :: p,q
real :: delta_x
logical :: accepted
call brownian_step(p,q,accepted,delta_x)
if (accepted) then
trapped_walk(i_walk) = 0
else
trapped_walk(i_walk) += 1
endif
if ( (trapped_walk(i_walk) < trapped_walk_max).and. &
(psi_value * psi_value_save(i_walk) >= 0.d0) ) then
delta = ((E_loc+E_loc_save(i_walk))*0.5d0 - E0) * p
if ( delta > thr ) then
dmc_weight(i_walk) = dexp(-dtime_step*thr)
else if ( delta < -thr ) then
dmc_weight(i_walk) = dexp(dtime_step*thr)
else
dmc_weight(i_walk) = dexp(-dtime_step*delta)
endif
else
dmc_weight(i_walk) = 0.d0
trapped_walk(i_walk) = 0
endif
elec_coord(elec_num+1,1) += p*time_step
elec_coord(elec_num+1,2) = E_loc
elec_coord(elec_num+1,3) = dmc_weight(i_walk)
do l=1,3
do i=1,elec_num+1
elec_coord_full_dmc(i,l,i_walk) = elec_coord(i,l)
enddo
enddo
psi_value_save(i_walk) = psi_value
E_loc_save(i_walk) = E_loc
BEGIN_SHELL [ /usr/bin/python ]
from properties import *
t = """
if (calc_$X) then
! Kahan's summation algorithm to compute these sums reducing the rounding error:
! $X_dmc_block_walk += $X * pop_weight_mult
! $X_2_dmc_block_walk += $X_2 * pop_weight_mult
! $X_dmc_block_walk += $X * dmc_weight(i_walk)
! $X_2_dmc_block_walk += $X_2 * dmc_weight(i_walk)
! see http://en.wikipedia.org/wiki/Kahan_summation_algorithm
$X_dmc_block_walk_kahan($D2 3) = $X * pop_weight_mult - $X_dmc_block_walk_kahan($D2 1)
$X_dmc_block_walk_kahan($D2 3) = $X * dmc_weight(i_walk) - $X_dmc_block_walk_kahan($D2 1)
$X_dmc_block_walk_kahan($D2 2) = $X_dmc_block_walk $D1 + $X_dmc_block_walk_kahan($D2 3)
$X_dmc_block_walk_kahan($D2 1) = ($X_dmc_block_walk_kahan($D2 2) - $X_dmc_block_walk $D1 ) &
- $X_dmc_block_walk_kahan($D2 3)
$X_dmc_block_walk $D1 = $X_dmc_block_walk_kahan($D2 2)
$X_2_dmc_block_walk_kahan($D2 3) = $X_2 * pop_weight_mult - $X_2_dmc_block_walk_kahan($D2 1)
$X_2_dmc_block_walk_kahan($D2 3) = $X_2 * dmc_weight(i_walk) - $X_2_dmc_block_walk_kahan($D2 1)
$X_2_dmc_block_walk_kahan($D2 2) = $X_2_dmc_block_walk $D1 + $X_2_dmc_block_walk_kahan($D2 3)
$X_2_dmc_block_walk_kahan($D2 1) = ($X_2_dmc_block_walk_kahan($D2 2) - $X_2_dmc_block_walk $D1 ) &
- $X_2_dmc_block_walk_kahan($D2 3)
@ -135,92 +185,59 @@ for p in properties:
END_SHELL
double precision :: p,q
real :: delta_x
logical :: accepted
call brownian_step(p,q,accepted,delta_x)
if (accepted) then
trapped_walk(i_walk) = 0
else
trapped_walk(i_walk) += 1
endif
if ( (trapped_walk(i_walk) < trapped_walk_max).and. &
(psi_value * psi_value_save(i_walk) >= 0.d0) ) then
dmc_weight(i_walk) = dexp(dtime_step*(E_ref - E_loc))
else
dmc_weight(i_walk) = 0.d0
trapped_walk(i_walk) = 0
endif
elec_coord(elec_num+1,1) += p*time_step
elec_coord(elec_num+1,2) = E_loc
elec_coord(elec_num+1,3) = dmc_weight(i_walk)
do l=1,3
do i=1,elec_num+1
elec_coord_full(i,l,i_walk) = elec_coord(i,l)
enddo
enddo
psi_value_save(i_walk) = psi_value
block_weight += dmc_weight(i_walk)
enddo
! Move to the next projection step
if (dmc_projection > 0) then
dmc_projection_step = mod(dmc_projection_step,dmc_projection)+1
else
dmc_projection_step = 1
endif
! Eventually, recompute the weight of the population
if (dmc_projection_step == 1) then
pop_weight_mult = 1.d0
do k=1,dmc_projection
pop_weight_mult *= pop_weight(k)
enddo
endif
! Remove contribution of the old value of the weight at the new
! projection step
pop_weight_mult *= 1.d0/pop_weight(dmc_projection_step)
! Compute the new weight of the population
! Population control
double precision :: sum_weight
sum_weight = 0.d0
do k=1,walk_num
do k=1,walk_num_dmc
sum_weight += dmc_weight(k)
enddo
pop_weight(dmc_projection_step) = sum_weight/dble(walk_num)
E0 = E_ref - log(real(walk_num_dmc)/real(walk_num)) * 0.1d0/dtime_step
! Update the running population weight
pop_weight_mult *= pop_weight(dmc_projection_step)
! Branching
integer :: ipos(walk_num_dmc_max), walk_num_dmc_new
double precision, external :: qmc_ranf
double precision :: r
block_weight += pop_weight_mult * dble(walk_num)
! Reconfiguration
integer :: ipos(walk_num)
call reconfigure(ipos,dmc_weight)
do k=1,walk_num
do k=1,walk_num_dmc
do l=1,3
do i=1,elec_num+1
elec_coord_tmp(i,l,k) = elec_coord_full(i,l,k)
elec_coord_tmp(i,l,k) = elec_coord_full_dmc(i,l,k)
enddo
enddo
psi_value_save_tmp(k) = psi_value_save(k)
E_loc_save_tmp(k) = E_loc_save(k)
trapped_walk_tmp(k) = trapped_walk(k)
ipos(k) = k
enddo
do k=1,walk_num_dmc
r = qmc_ranf()
if (dmc_weight(k) > 1.d0) then
if ( 1.d0+r < dmc_weight(k) ) then
walk_num_dmc = walk_num_dmc+1
ipos(walk_num_dmc) = k
endif
else
if ( r > dmc_weight(k) ) then
ipos(k) = ipos(walk_num_dmc)
walk_num_dmc = walk_num_dmc-1
endif
endif
enddo
integer :: ipm
do k=1,walk_num
do k=1,walk_num_dmc
ipm = ipos(k)
do l=1,3
do i=1,elec_num+1
elec_coord_full(i,l,k) = elec_coord_tmp(i,l,ipm)
elec_coord_full_dmc(i,l,k) = elec_coord_tmp(i,l,ipm)
enddo
enddo
E_loc_save(k) = E_loc_save_tmp(ipm)
psi_value_save(k) = psi_value_save_tmp(ipm)
trapped_walk(k) = trapped_walk_tmp(ipm)
enddo
@ -237,7 +254,7 @@ END_SHELL
cpu2 = cpu1
endif
SOFT_TOUCH elec_coord_full psi_value psi_grad_psi_inv_x psi_grad_psi_inv_y psi_grad_psi_inv_z elec_coord pop_weight_mult
SOFT_TOUCH elec_coord_full_dmc psi_value psi_grad_psi_inv_x psi_grad_psi_inv_y psi_grad_psi_inv_z elec_coord
enddo
@ -259,6 +276,22 @@ END_SHELL
deallocate ( elec_coord_tmp )
do k=1,min(walk_num,walk_num_dmc)
do l=1,3
do i=1,elec_num+1
elec_coord_full(i,l,k) = elec_coord_full_dmc(i,l,k)
enddo
enddo
enddo
do k=walk_num_dmc+1,walk_num
do l=1,3
do i=1,elec_num+1
elec_coord_full(i,l,k) = elec_coord_full_dmc(i,l,mod(k,walk_num_dmc)+1)
enddo
enddo
enddo
SOFT_TOUCH elec_coord_full
END_PROVIDER
@ -271,36 +304,7 @@ BEGIN_PROVIDER [ double precision, E_ref ]
call get_simulation_E_ref(E_ref)
END_PROVIDER
BEGIN_PROVIDER [ double precision, pop_weight_mult ]
implicit none
BEGIN_DOC
! Population weight of DMC
END_DOC
pop_weight_mult = pop_weight(dmc_projection)
END_PROVIDER
BEGIN_PROVIDER [ integer, dmc_projection ]
&BEGIN_PROVIDER [ integer, dmc_projection_step ]
implicit none
BEGIN_DOC
! Number of projection steps for SRMC
END_DOC
real :: dmc_projection_time
dmc_projection_time = 1.
call get_simulation_dmc_projection_time(dmc_projection_time)
dmc_projection = int( dmc_projection_time/time_step)
dmc_projection_step = 0
END_PROVIDER
BEGIN_PROVIDER [ double precision, pop_weight, (0:dmc_projection+1) ]
implicit none
BEGIN_DOC
! Population weight of DMC
END_DOC
pop_weight = 1.d0
END_PROVIDER
BEGIN_PROVIDER [ integer, trapped_walk, (walk_num_8) ]
BEGIN_PROVIDER [ integer, trapped_walk, (walk_num_dmc_max) ]
&BEGIN_PROVIDER [ integer, trapped_walk_max ]
implicit none
BEGIN_DOC
@ -311,13 +315,36 @@ END_PROVIDER
END_PROVIDER
BEGIN_PROVIDER [ double precision, dmc_weight, (walk_num_8) ]
BEGIN_PROVIDER [ integer, walk_num_dmc ]
implicit none
BEGIN_DOC
! Weight of the walkers in the DMC algorithm: exp(-time_step*(E_loc-E_ref))
! Current number of walkers in DMC
END_DOC
!DIR$ VECTOR ALIGNED
dmc_weight = 1.d0
walk_num_dmc = walk_num
END_PROVIDER
BEGIN_PROVIDER [ integer, walk_num_dmc_max ]
implicit none
BEGIN_DOC
! Max number of walkers in DMC
END_DOC
walk_num_dmc_max = 3 * walk_num
END_PROVIDER
BEGIN_PROVIDER [ real, elec_coord_full_dmc, (elec_num+1,3,walk_num_dmc_max)]
implicit none
BEGIN_DOC
! DMC population
END_DOC
integer :: i,k,l
do k=1,walk_num
do l=1,3
do i=1,elec_num+1
elec_coord_full_dmc(i,l,k) = elec_coord_full(i,l,k)
enddo
enddo
enddo
END_PROVIDER

View File

@ -69,11 +69,11 @@ BEGIN_PROVIDER [ integer(ZMQ_PTR), zmq_to_dataserver_socket ]
endif
integer :: i
i=4
rc = f77_zmq_setsockopt(zmq_to_dataserver_socket, ZMQ_SNDTIMEO, 120000, i)
rc = f77_zmq_setsockopt(zmq_to_dataserver_socket, ZMQ_SNDTIMEO, 600000, i)
if (rc /= 0) then
call abrt(irp_here, 'Unable to set send timout in zmq_to_dataserver_socket')
endif
rc = f77_zmq_setsockopt(zmq_to_dataserver_socket, ZMQ_RCVTIMEO, 120000, i)
rc = f77_zmq_setsockopt(zmq_to_dataserver_socket, ZMQ_RCVTIMEO, 600000, i)
if (rc /= 0) then
call abrt(irp_here, 'Unable to set recv timout in zmq_to_dataserver_socket')
endif
@ -108,6 +108,7 @@ BEGIN_PROVIDER [ integer(ZMQ_PTR), zmq_socket_push ]
character*(8), external :: zmq_port
zmq_socket_push = f77_zmq_socket(zmq_context, ZMQ_PUSH)
address = trim(dataserver_address)//':'//zmq_port(2)
rc = f77_zmq_setsockopt(zmq_socket_push,ZMQ_LINGER,600000,4)
rc = f77_zmq_connect(zmq_socket_push, trim(address))
if (rc /= 0) then
call abrt(irp_here, 'Unable to connect zmq_socket_push')

View File

@ -36,7 +36,7 @@ data = [ \
("simulation_equilibration" , "logical" , "" ),
("simulation_block_time" , "integer" , "" ),
("simulation_time_step" , "real" , "" ),
("simulation_dmc_projection_time" , "real" , "" ),
("simulation_srmc_projection_time" , "real" , "" ),
("simulation_method" , "character*(32)", "" ),
("simulation_save_data" , "logical" , "" ),
("simulation_print_level" , "integer" , "" ),

View File

@ -148,7 +148,7 @@ BEGIN_PROVIDER [ integer, qmc_method ]
implicit none
include 'types.F'
BEGIN_DOC
! qmc_method : Calculation method. Can be t_VMC, t_DMC
! qmc_method : Calculation method. Can be t_VMC, t_DMC, t_SRMC
END_DOC
character*(32) :: method
method = types(t_VMC)
@ -158,8 +158,10 @@ BEGIN_PROVIDER [ integer, qmc_method ]
qmc_method = t_VMC
else if (method == types(t_DMC)) then
qmc_method = t_DMC
else if (method == types(t_SRMC)) then
qmc_method = t_SRMC
else
call abrt(irp_here, 'Method should be ( VMC | DMC )')
call abrt(irp_here, 'Method should be ( VMC | DMC | SRMC )')
endif
call cinfo(irp_here,'qmc_method',trim(method))
@ -276,12 +278,15 @@ BEGIN_PROVIDER [ integer, vmc_algo ]
else if (Sampling == types(t_Langevin)) then
vmc_algo = t_Langevin
if (qmc_method == t_DMC) then
vmc_algo = t_Brownian
stop 'Langevin incompatible with DMC'
endif
if (qmc_method == t_SRMC) then
stop 'Langevin incompatible with SRMC'
endif
else if (Sampling == types(t_MTM)) then
vmc_algo = t_MTM
else
call abrt(irp_here,'Sampling should be (Brownian|Langevin|MTM|Read)')
call abrt(irp_here,'Sampling should be (Brownian|Langevin)')
endif
call cinfo(irp_here,'Sampling',Sampling)

View File

@ -5,6 +5,7 @@
integer, parameter :: t_VMC = 7
integer, parameter :: t_DMC = 8
integer, parameter :: t_SRMC = 9
integer, parameter :: t_Simple = 11
integer, parameter :: t_None = 12
@ -24,7 +25,7 @@
' ', &
'VMC ', &
'DMC ', &
' ', &
'SRMC ', &
' ', &
'Simple ', &
'None ', &