10
1
mirror of https://gitlab.com/scemama/qmcchem.git synced 2024-11-12 00:53:38 +01:00
qmcchem/ocaml/Qmcchem_result.ml

274 lines
7.4 KiB
OCaml
Raw Normal View History

2015-12-19 02:35:13 +01:00
open Qptypes
(** Display a table that can be plotted by gnuplot *)
2016-02-19 11:20:34 +01:00
let display_table ~range property =
2018-03-14 17:02:52 +01:00
let p =
Property.of_string property
|> Random_variable.of_raw_data ~range
2015-12-19 02:35:13 +01:00
in
let conv = Random_variable.convergence p
and rconv = Random_variable.rev_convergence p
and data = p.Random_variable.data
in
let results =
2020-04-15 14:40:33 +02:00
List.rev_map2 (fun (val1, err1) (val2,err2) -> (val1, err1, val2, err2)) conv rconv
|> List.rev
2015-12-19 02:35:13 +01:00
in
2019-07-19 17:06:01 +02:00
List.iter2 (fun (val1, err1, val2, err2) block ->
2015-12-19 02:35:13 +01:00
Printf.printf "%10.6f %10.6f %10.6f %10.6f %10.6f\n"
val1 err1 val2 err2 (Sample.to_float block.Block.value)
2019-07-19 17:06:01 +02:00
) results data
2015-12-19 02:35:13 +01:00
(** Display a convergence plot of the requested property *)
2016-02-19 11:20:34 +01:00
let display_plot ~range property =
2015-12-19 02:35:13 +01:00
print_string ("display_plot "^property^".\n")
(** Display a convergence table of the error *)
2016-02-19 11:20:34 +01:00
let display_err_convergence ~range property =
2015-12-19 02:35:13 +01:00
let p =
Property.of_string property
2016-02-19 11:20:34 +01:00
|> Random_variable.of_raw_data ~range
2015-12-19 02:35:13 +01:00
in
let rec aux n p =
match Random_variable.ave_error p with
| (ave, Some error) ->
let (ave, error) =
Random_variable.Average.to_float ave,
Random_variable.Error.to_float error
in
Printf.printf "%10d %16.10f %16.10f\n" n ave error ;
begin
if ((3*n) < (List.length p.Random_variable.data)) then
let new_p =
Random_variable.compress p
in
aux (n+n) new_p
end
| (ave, None) -> ()
in
aux 1 p
2019-07-19 17:06:01 +02:00
2015-12-19 02:35:13 +01:00
(** Display the centered cumulants of a property *)
2016-02-19 11:20:34 +01:00
let display_cumulants ~range property =
2015-12-19 02:35:13 +01:00
let p =
Property.of_string property
2016-02-19 11:20:34 +01:00
|> Random_variable.of_raw_data ~range
2015-12-19 02:35:13 +01:00
in
let cum =
Random_variable.centered_cumulants p
in
Printf.printf "Average = %16.10f\n" cum.(0);
Printf.printf "Variance = %16.10f\n" cum.(1);
Printf.printf "Centered k3 = %16.10f\n" cum.(2);
Printf.printf "Centered k4 = %16.10f\n" cum.(3);
2017-10-10 09:39:58 +02:00
Printf.printf "\n%!";
2015-12-19 02:35:13 +01:00
let n = 1. /. 12. *. cum.(2) *. cum.(2) +.
1. /. 48. *. cum.(3) *. cum.(3)
in
Printf.printf "Non-gaussianity = %16.10f\n" n
2019-07-19 17:06:01 +02:00
2015-12-19 02:35:13 +01:00
(** Display a table for the autocovariance of the property *)
2016-02-19 11:20:34 +01:00
let display_autocovariance ~range property =
2015-12-19 02:35:13 +01:00
let p =
Property.of_string property
2016-02-19 11:20:34 +01:00
|> Random_variable.of_raw_data ~range
2015-12-19 02:35:13 +01:00
in
Random_variable.autocovariance p
2019-07-19 17:06:01 +02:00
|> List.iteri (fun i x ->
2015-12-19 02:35:13 +01:00
Printf.printf "%10d %16.10f\n" i x)
2019-07-19 17:06:01 +02:00
2015-12-19 02:35:13 +01:00
(** Display a histogram of the property *)
2016-02-19 11:20:34 +01:00
let display_histogram ~range property =
2015-12-19 02:35:13 +01:00
let p =
Property.of_string property
2016-02-19 11:20:34 +01:00
|> Random_variable.of_raw_data ~range
2015-12-19 02:35:13 +01:00
in
let histo =
Random_variable.histogram p
in
let g =
Random_variable.GaussianDist.create
~mu:(Random_variable.average p)
~sigma2:((Random_variable.centered_cumulants p).(1)
|> Random_variable.Variance.of_float)
in
let g =
Random_variable.GaussianDist.eval ~g
in
2019-07-19 17:06:01 +02:00
List.iter ( fun (x,y) ->
Printf.printf "%16.10f %16.10f %16.10f\n" x y (g ~x)) histo
2015-12-19 02:35:13 +01:00
(*
and sigma2 =
(Random_variable.centered_cumulants p).(1)
and pi =
acos(-1.)
in
let one_over_2sigma2 =
1. /. ( 2. *. sigma2 )
and mu =
Random_variable.average p
and norm =
1. /. (sqrt(sigma2 *. 2.*.pi))
in
2020-04-15 14:40:33 +02:00
List.rev_map histo ~f:(fun (x,y) ->
2015-12-19 02:35:13 +01:00
let g =
norm *. exp(-.((x-.mu)*.(x-.mu)*.one_over_2sigma2))
in
(x,y,g)
)
2020-04-15 14:40:33 +02:00
|> List.rev
|> List.iter ~f:(fun (x,y,g) ->
Printf.printf "%16.10f %16.10f %16.10f\n" x y g)
2015-12-19 02:35:13 +01:00
*)
2019-07-19 17:06:01 +02:00
2015-12-19 02:35:13 +01:00
(** Display a summary of all the cmoputed quantities *)
2016-02-19 11:20:34 +01:00
let display_summary ~range =
2015-12-19 02:35:13 +01:00
let properties =
Lazy.force Block.properties
and print_property property =
2016-02-19 11:20:34 +01:00
let p = Random_variable.of_raw_data ~range property
2015-12-19 02:35:13 +01:00
in
Printf.printf "%20s : %s\n"
(Property.to_string property)
(Random_variable.to_string p)
in
2019-07-19 17:06:01 +02:00
List.iter print_property properties ;
2015-12-19 02:35:13 +01:00
let cpu =
2016-02-19 11:20:34 +01:00
Random_variable.of_raw_data ~range Property.Cpu
2015-12-19 02:35:13 +01:00
|> Random_variable.sum
and wall =
2016-02-19 11:20:34 +01:00
Random_variable.of_raw_data ~range Property.Wall
2015-12-19 02:35:13 +01:00
|> Random_variable.max_value_per_compute_node
|> Random_variable.sum
in
let speedup =
cpu /. wall
in
2019-07-19 17:06:01 +02:00
Printf.printf "%20s : %10.2f x\n" "Speedup" speedup
2015-12-19 02:35:13 +01:00
2016-02-19 11:20:34 +01:00
let run ?a ?c ?e ?h ?t ?p ?rmin ?rmax ezfio_file =
2015-12-19 02:35:13 +01:00
Qputils.set_ezfio_filename ezfio_file;
2016-02-19 11:20:34 +01:00
let rmin =
match rmin with
| None -> 0.
2019-07-19 17:06:01 +02:00
| Some x when (float_of_string x < 0.) -> failwith "rmin should be >= 0"
| Some x when (float_of_string x > 100.) -> failwith "rmin should be <= 100"
| Some x -> float_of_string x
2016-02-19 11:20:34 +01:00
and rmax =
match rmax with
| None -> 100.
2019-07-19 17:06:01 +02:00
| Some x when (float_of_string x < 0.) -> failwith "rmax should be >= 0"
| Some x when (float_of_string x > 100.) -> failwith "rmax should be <= 100"
| Some x -> float_of_string x
2016-02-19 11:20:34 +01:00
in
let range =
(rmin, rmax)
2015-12-19 02:35:13 +01:00
in
let l =
[ (a, display_autocovariance) ;
(c, display_cumulants) ;
(e, display_err_convergence) ;
(h, display_histogram) ;
(p, display_plot) ;
(t, display_table) ;
]
in
2019-07-19 17:06:01 +02:00
List.iter (fun (x,func) ->
match x with
| Some property -> func ~range property
| None -> ()
) l;
2015-12-19 02:35:13 +01:00
2019-07-19 17:06:01 +02:00
if (List.fold_left (fun accu x ->
2015-12-19 02:35:13 +01:00
match x with
| (None, _) -> accu && true
| (Some _,_) -> false
2019-07-19 17:06:01 +02:00
) true l
2015-12-19 02:35:13 +01:00
) then
2016-02-19 11:20:34 +01:00
display_summary ~range
2019-07-19 17:06:01 +02:00
2019-07-22 12:19:12 +02:00
let command () =
2019-07-19 17:06:01 +02:00
let open Command_line in
begin
set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command");
set_description_doc "Displays the results computed in an EZFIO directory.";
[ { short='a' ; long="autocovariance" ; opt=Optional ;
doc="Display the autcovariance function of the property";
arg=With_arg "<string>" ; };
{ short='c' ; long="centered-cumulants" ; opt=Optional ;
doc="Print the centered cumulants of a property" ;
arg=With_arg "<string>"; };
{ short='e' ; long="error" ; opt=Optional ;
doc="Display the convergence of the error of the property by merging blocks";
arg=With_arg "<string>"; };
2019-07-23 17:27:02 +02:00
{ short='i' ; long="histogram" ; opt=Optional ;
2019-07-19 17:06:01 +02:00
doc="Display the histogram of the property blocks" ;
arg=With_arg "<string>"; };
{ short='p' ; long="plot" ; opt=Optional ;
doc="Display a convergence plot for a property";
arg=With_arg "<string>"; };
{ short='m' ; long="rmin" ; opt=Optional ;
doc="Lower bound of the percentage of the total weight to consider (default 0)" ;
arg=With_arg "<int>"; };
{ short='n' ; long="rmax" ; opt=Optional ;
doc="Upper bound of the percentage of the total weight to consider (default 100)" ;
arg=With_arg "<int>"; };
{ short='t' ; long="table" ; opt=Optional ;
doc="Print a table for the convergence of a property" ;
arg=With_arg "<string>"; };
anonymous "EZFIO_DIR" Mandatory "EZFIO directory";
]
|> set_specs ;
end;
let a = Command_line.get "autocovariance" in
let c = Command_line.get "centered-cumulants" in
let e = Command_line.get "error" in
let h = Command_line.get "histogram" in
let t = Command_line.get "table" in
let p = Command_line.get "plot" in
2020-06-01 23:51:37 +02:00
let rmin = Command_line.get "rmin" in
let rmax = Command_line.get "rmax" in
2019-07-19 17:06:01 +02:00
let ezfio_file =
match Command_line.anon_args () with
| ezfio_file :: [] -> ezfio_file
| _ -> (Command_line.help () ; failwith "Inconsistent command line")
in
run ?a ?c ?e ?h ?t ?p ?rmin ?rmax ezfio_file
2015-12-19 02:35:13 +01:00