10
1
mirror of https://gitlab.com/scemama/qmcchem.git synced 2024-11-06 22:23:39 +01:00

Added range in qmcchem_result

This commit is contained in:
Anthony Scemama 2016-02-19 11:20:34 +01:00
parent 1a21f891e3
commit 654579b953
3 changed files with 117 additions and 57 deletions

View File

@ -826,7 +826,7 @@ let run ?(daemon=true) ezfio_filename =
with with
| _ -> () | _ -> ()
end; end;
Qmcchem_result.display_summary (); Qmcchem_result.display_summary ~range:(0.,100.);
in in
(** {3 Main function} *) (** {3 Main function} *)

View File

@ -2,9 +2,9 @@ open Core.Std
open Qptypes open Qptypes
(** Display a table that can be plotted by gnuplot *) (** Display a table that can be plotted by gnuplot *)
let display_table property = let display_table ~range property =
let p = Property.of_string property let p = Property.of_string property
|> Random_variable.of_raw_data |> Random_variable.of_raw_data ~range
in in
let conv = Random_variable.convergence p let conv = Random_variable.convergence p
and rconv = Random_variable.rev_convergence p and rconv = Random_variable.rev_convergence p
@ -21,16 +21,16 @@ let display_table property =
(** Display a convergence plot of the requested property *) (** Display a convergence plot of the requested property *)
let display_plot property = let display_plot ~range property =
print_string ("display_plot "^property^".\n") print_string ("display_plot "^property^".\n")
;; ;;
(** Display a convergence table of the error *) (** Display a convergence table of the error *)
let display_err_convergence property = let display_err_convergence ~range property =
let p = let p =
Property.of_string property Property.of_string property
|> Random_variable.of_raw_data |> Random_variable.of_raw_data ~range
in in
let rec aux n p = let rec aux n p =
match Random_variable.ave_error p with match Random_variable.ave_error p with
@ -53,10 +53,10 @@ let display_err_convergence property =
;; ;;
(** Display the centered cumulants of a property *) (** Display the centered cumulants of a property *)
let display_cumulants property = let display_cumulants ~range property =
let p = let p =
Property.of_string property Property.of_string property
|> Random_variable.of_raw_data |> Random_variable.of_raw_data ~range
in in
let cum = let cum =
Random_variable.centered_cumulants p Random_variable.centered_cumulants p
@ -74,10 +74,10 @@ let display_cumulants property =
(** Display a table for the autocovariance of the property *) (** Display a table for the autocovariance of the property *)
let display_autocovariance property = let display_autocovariance ~range property =
let p = let p =
Property.of_string property Property.of_string property
|> Random_variable.of_raw_data |> Random_variable.of_raw_data ~range
in in
Random_variable.autocovariance p Random_variable.autocovariance p
|> List.iteri ~f:(fun i x -> |> List.iteri ~f:(fun i x ->
@ -85,10 +85,10 @@ let display_autocovariance property =
;; ;;
(** Display a histogram of the property *) (** Display a histogram of the property *)
let display_histogram property = let display_histogram ~range property =
let p = let p =
Property.of_string property Property.of_string property
|> Random_variable.of_raw_data |> Random_variable.of_raw_data ~range
in in
let histo = let histo =
Random_variable.histogram p Random_variable.histogram p
@ -132,12 +132,12 @@ let display_histogram property =
(** Display a summary of all the cmoputed quantities *) (** Display a summary of all the cmoputed quantities *)
let display_summary () = let display_summary ~range =
let properties = let properties =
Lazy.force Block.properties Lazy.force Block.properties
and print_property property = and print_property property =
let p = Random_variable.of_raw_data property let p = Random_variable.of_raw_data ~range property
in in
Printf.printf "%20s : %s\n" Printf.printf "%20s : %s\n"
(Property.to_string property) (Property.to_string property)
@ -147,10 +147,10 @@ let display_summary () =
let cpu = let cpu =
Random_variable.of_raw_data Property.Cpu Random_variable.of_raw_data ~range Property.Cpu
|> Random_variable.sum |> Random_variable.sum
and wall = and wall =
Random_variable.of_raw_data Property.Wall Random_variable.of_raw_data ~range Property.Wall
|> Random_variable.max_value_per_compute_node |> Random_variable.max_value_per_compute_node
|> Random_variable.sum |> Random_variable.sum
in in
@ -162,13 +162,25 @@ let display_summary () =
;; ;;
let run ?a ?c ?e ?h ?t ?p ezfio_file = let run ?a ?c ?e ?h ?t ?p ?rmin ?rmax ezfio_file =
Qputils.set_ezfio_filename ezfio_file; Qputils.set_ezfio_filename ezfio_file;
let f (x,func) =
match x with let rmin =
| Some property -> func property match rmin with
| None -> () | None -> 0.
| Some x when (x<0) -> failwith "rmin should be >= 0"
| Some x when (x>100) -> failwith "rmin should be <= 100"
| Some x -> Float.of_int x
and rmax =
match rmax with
| None -> 100.
| Some x when (x<0) -> failwith "rmax should be >= 0"
| Some x when (x>100) -> failwith "rmax should be <= 100"
| Some x -> Float.of_int x
in
let range =
(rmin, rmax)
in in
let l = let l =
@ -181,6 +193,12 @@ let run ?a ?c ?e ?h ?t ?p ezfio_file =
] ]
in in
let f (x,func) =
match x with
| Some property -> func ~range property
| None -> ()
in
List.iter ~f l List.iter ~f l
; ;
@ -190,7 +208,7 @@ let run ?a ?c ?e ?h ?t ?p ezfio_file =
| (Some _,_) -> false | (Some _,_) -> false
) l ) l
) then ) then
display_summary () display_summary ~range
;; ;;
@ -207,6 +225,10 @@ let spec =
~doc:"property Display the histogram of the property blocks" ~doc:"property Display the histogram of the property blocks"
+> flag "p" (optional string) +> flag "p" (optional string)
~doc:"property Display a convergence plot for a property" ~doc:"property Display a convergence plot for a property"
+> flag "rmin" (optional int)
~doc:"int Lower bound of the percentage of the total weight to consider (default 0)"
+> flag "rmax" (optional int)
~doc:"int Upper bound of the percentage of the total weight to consider (default 100)"
+> flag "t" (optional string) +> flag "t" (optional string)
~doc:"property Print a table for the convergence of a property" ~doc:"property Print a table for the convergence of a property"
+> anon ("ezfio_file" %: string) +> anon ("ezfio_file" %: string)
@ -217,7 +239,7 @@ let command =
~summary: "Displays the results computed in an EZFIO directory." ~summary: "Displays the results computed in an EZFIO directory."
~readme:(fun () -> "Displays the results computed in an EZFIO directory.") ~readme:(fun () -> "Displays the results computed in an EZFIO directory.")
spec spec
(fun a c e h p t ezfio_file () -> run ?a ?c ?e ?h ?t ?p ezfio_file ) (fun a c e h p rmin rmax t ezfio_file () -> run ?a ?c ?e ?h ?t ?p ?rmin ?rmax ezfio_file )
;; ;;

View File

@ -1,5 +1,5 @@
open Core.Std;; open Core.Std
open Qptypes;; open Qptypes
type t = type t =
{ property : Property.t ; { property : Property.t ;
@ -75,14 +75,52 @@ end
(** Build from raw data *) (** Build from raw data. Range values are given in percent. *)
let of_raw_data ?(locked=true) property = let of_raw_data ?(locked=true) ~range property =
let data = let data =
Block.raw_data ~locked () Block.raw_data ~locked ()
|> List.filter ~f:(fun x -> x.Block.property = property) |> List.filter ~f:(fun x -> x.Block.property = property)
in in
{ property ; data }
;; let data_in_range rmin rmax =
let total_weight =
List.fold_left data ~init:0. ~f:(fun accu x ->
(Weight.to_float x.Block.weight) +. accu
)
in
let wmin, wmax =
rmin *. total_weight *. 0.01,
rmax *. total_weight *. 0.01
in
let (_, new_data) =
List.fold_left data ~init:(0.,[]) ~f:(fun (wsum, l) x ->
if (wsum > wmax) then
(wsum,l)
else
begin
let wsum_new =
wsum +. (Weight.to_float x.Block.weight)
in
if (wsum_new > wmin) then
(wsum_new, x::l)
else
(wsum_new, l)
end
)
in
List.rev new_data
in
let result =
match range with
| (0.,100.) -> { property ; data }
| (rmin,rmax) -> { property ; data=data_in_range rmin rmax }
in
result
(** Compute average *) (** Compute average *)
@ -121,7 +159,7 @@ let average { property ; data } =
in in
Array.map num ~f:(fun x -> x *. denom_inv) Array.map num ~f:(fun x -> x *. denom_inv)
|> Average.of_float_array ~dim |> Average.of_float_array ~dim
;;
(** Compute sum (for CPU/Wall time) *) (** Compute sum (for CPU/Wall time) *)
@ -130,7 +168,7 @@ let sum { property ; data } =
let num = (Weight.to_float x.Block.weight) *. (Sample.to_float x.Block.value) let num = (Weight.to_float x.Block.weight) *. (Sample.to_float x.Block.value)
in accu +. num in accu +. num
) )
;;
(** Calculation of the average and error bar *) (** Calculation of the average and error bar *)
@ -212,7 +250,7 @@ let ave_error { property ; data } =
| (_,None) -> 0.) | (_,None) -> 0.)
|> Average.of_float_array ~dim) |> Average.of_float_array ~dim)
) )
;;
@ -226,7 +264,7 @@ let fold_blocks ~f { property ; data } =
let x = Sample.to_float block.Block.value let x = Sample.to_float block.Block.value
in f accu x in f accu x
) )
;;
(** Convergence plot *) (** Convergence plot *)
@ -278,13 +316,13 @@ let convergence { property ; data } =
~n:0. ~n:0.
~accu:[ (s /. w, 0.) ] ~accu:[ (s /. w, 0.) ]
end end
;;
let rev_convergence { property ; data } = let rev_convergence { property ; data } =
let p = { property=property ; data = List.rev data } in let p = { property=property ; data = List.rev data } in
convergence p convergence p
|> List.rev |> List.rev
;;
(** Min and max of block *) (** Min and max of block *)
@ -293,14 +331,14 @@ let min_block =
if (x < accu) then x if (x < accu) then x
else accu else accu
) )
;;
let max_block = let max_block =
fold_blocks ~f:(fun accu x -> fold_blocks ~f:(fun accu x ->
if (x > accu) then x if (x > accu) then x
else accu else accu
) )
;;
(** Create a hash table for merging *) (** Create a hash table for merging *)
@ -359,7 +397,7 @@ let create_hash ~hashable ~create_key ?(update_block_id=(fun x->x)) t =
) )
); );
table table
;;
(** Genergic merge function *) (** Genergic merge function *)
@ -375,7 +413,7 @@ let merge ~hashable ~create_key ?update_block_id t =
else 0) else 0)
|> List.map ~f:(fun (x,y) -> y) |> List.map ~f:(fun (x,y) -> y)
} }
;;
(** Merge per block id *) (** Merge per block id *)
@ -383,7 +421,7 @@ let merge_per_block_id =
merge merge
~hashable:Int.hashable ~hashable:Int.hashable
~create_key:(fun block -> Block_id.to_int block.Block.block_id) ~create_key:(fun block -> Block_id.to_int block.Block.block_id)
;;
(** Merge per compute_node *) (** Merge per compute_node *)
let merge_per_compute_node = let merge_per_compute_node =
@ -392,7 +430,7 @@ let merge_per_compute_node =
~create_key:(fun block -> ~create_key:(fun block ->
Printf.sprintf "%s" Printf.sprintf "%s"
(Compute_node.to_string block.Block.compute_node) ) (Compute_node.to_string block.Block.compute_node) )
;;
(** Merge per Compute_node and PID *) (** Merge per Compute_node and PID *)
@ -403,7 +441,7 @@ let merge_per_compute_node_and_pid =
Printf.sprintf "%s %10.10d" Printf.sprintf "%s %10.10d"
(Compute_node.to_string block.Block.compute_node) (Compute_node.to_string block.Block.compute_node)
(Pid.to_int block.Block.pid) ) (Pid.to_int block.Block.pid) )
;;
(** Merge per Compute_node and BlockId *) (** Merge per Compute_node and BlockId *)
@ -414,7 +452,7 @@ let merge_per_compute_node_and_block_id =
Printf.sprintf "%s %10.10d" Printf.sprintf "%s %10.10d"
(Compute_node.to_string block.Block.compute_node) (Compute_node.to_string block.Block.compute_node)
(Block_id.to_int block.Block.block_id) ) (Block_id.to_int block.Block.block_id) )
;;
@ -428,7 +466,7 @@ let compress =
~update_block_id:(fun block_id -> ~update_block_id:(fun block_id ->
((Block_id.to_int block_id)+1)/2 ((Block_id.to_int block_id)+1)/2
|> Block_id.of_int ) |> Block_id.of_int )
;;
@ -465,7 +503,7 @@ let max_value_per_compute_node t =
else 0) else 0)
|> List.map ~f:(fun (x,y) -> y) |> List.map ~f:(fun (x,y) -> y)
} }
;;
@ -514,7 +552,7 @@ let to_string p =
Average.to_float ave Average.to_float ave
|> Printf.sprintf "%16.10f" |> Printf.sprintf "%16.10f"
end end
;;
@ -568,13 +606,13 @@ let compress_files () =
match p with match p with
| Property.Cpu | Property.Cpu
| Property.Accep -> | Property.Accep ->
of_raw_data ~locked:false p of_raw_data ~locked:false ~range:(0.,100.) p
|> merge_per_compute_node |> merge_per_compute_node
| Property.Wall -> | Property.Wall ->
of_raw_data ~locked:false p of_raw_data ~locked:false ~range:(0.,100.) p
|> max_value_per_compute_node |> max_value_per_compute_node
| _ -> | _ ->
of_raw_data ~locked:false p of_raw_data ~locked:false ~range:(0.,100.) p
|> merge_per_compute_node_and_block_id |> merge_per_compute_node_and_block_id
in in
List.iter l.data ~f:(fun x -> List.iter l.data ~f:(fun x ->
@ -587,7 +625,7 @@ let compress_files () =
List.iter files ~f:Unix.remove ; List.iter files ~f:Unix.remove ;
Unix.rename ~src:(out_channel_dir^out_channel_name) ~dst:(dir_name^out_channel_name); Unix.rename ~src:(out_channel_dir^out_channel_name) ~dst:(dir_name^out_channel_name);
Unix.rmdir out_channel_dir Unix.rmdir out_channel_dir
;;
(** Autocovariance function (not weighted) *) (** Autocovariance function (not weighted) *)
@ -615,7 +653,7 @@ let autocovariance { property ; data } =
in in
Array.init ~f (Array.length data) Array.init ~f (Array.length data)
|> Array.to_list |> Array.to_list
;;
(** Computes the first 4 centered cumulants (zero mean) *) (** Computes the first 4 centered cumulants (zero mean) *)
@ -666,7 +704,7 @@ let centered_cumulants { property ; data } =
( cum3 /. denom, cum4 /. denom -. 3. ) ( cum3 /. denom, cum4 /. denom -. 3. )
in in
[| ave ; var ; cum3 ; cum4 |] [| ave ; var ; cum3 ; cum4 |]
;;
@ -708,5 +746,5 @@ let histogram { property ; data } =
in in
Array.mapi ~f:(fun i x -> (min +. (Float.of_int i)*.delta_x, x *. norm) ) result Array.mapi ~f:(fun i x -> (min +. (Float.of_int i)*.delta_x, x *. norm) ) result
|> Array.to_list |> Array.to_list
;;