mirror of
https://gitlab.com/scemama/qmcchem.git
synced 2025-01-02 17:45:39 +01:00
Removing core
This commit is contained in:
parent
16acf1fe89
commit
4c870cb62b
@ -73,6 +73,21 @@ end = struct
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
let hashtbl_to_alist table =
|
||||||
|
Hashtbl.fold (fun k v a -> (k,v) :: a) table []
|
||||||
|
|
||||||
|
let hashtbl_change table key f =
|
||||||
|
let elt =
|
||||||
|
try
|
||||||
|
Some (Hashtbl.find table key)
|
||||||
|
with
|
||||||
|
| Not_found -> None
|
||||||
|
in
|
||||||
|
let new_elt = f elt in
|
||||||
|
match new_elt with
|
||||||
|
| None -> Hashtbl.remove table key
|
||||||
|
| Some value -> Hashtbl.replace table key value
|
||||||
|
|
||||||
|
|
||||||
(** Build from raw data. Range values are given in percent. *)
|
(** Build from raw data. Range values are given in percent. *)
|
||||||
let of_raw_data ?(locked=true) ~range property =
|
let of_raw_data ?(locked=true) ~range property =
|
||||||
@ -260,7 +275,7 @@ let fold_blocks ~f { property ; data } =
|
|||||||
let block = List.hd data in
|
let block = List.hd data in
|
||||||
Sample.to_float block.Block.value
|
Sample.to_float block.Block.value
|
||||||
with
|
with
|
||||||
| Failure "hd" -> 0.
|
| Failure _ -> 0.
|
||||||
in
|
in
|
||||||
List.fold_left (fun accu block ->
|
List.fold_left (fun accu block ->
|
||||||
let x = Sample.to_float block.Block.value
|
let x = Sample.to_float block.Block.value
|
||||||
@ -347,13 +362,13 @@ let max_block =
|
|||||||
let create_hash ~create_key ?(update_block_id=(fun x->x))
|
let create_hash ~create_key ?(update_block_id=(fun x->x))
|
||||||
?(update_value=(fun wc vc wb vb sw -> (wc *. vc +. wb *. vb) /. sw) )
|
?(update_value=(fun wc vc wb vb sw -> (wc *. vc +. wb *. vb) /. sw) )
|
||||||
?(update_weight=(fun wc wb -> wc +. wb) ) t =
|
?(update_weight=(fun wc wb -> wc +. wb) ) t =
|
||||||
let table = String.Table.create ()
|
let table = Hashtbl.create 63
|
||||||
in
|
in
|
||||||
List.iter t.data ~f:(fun block ->
|
List.iter (fun block ->
|
||||||
let key = create_key block
|
let key = create_key block
|
||||||
in
|
in
|
||||||
let open Block in
|
let open Block in
|
||||||
Hashtbl.change table key (function
|
hashtbl_change table key (function
|
||||||
| Some current ->
|
| Some current ->
|
||||||
let wc, wb =
|
let wc, wb =
|
||||||
Weight.to_float current.weight,
|
Weight.to_float current.weight,
|
||||||
@ -384,7 +399,7 @@ let create_hash ~create_key ?(update_block_id=(fun x->x))
|
|||||||
{ property = current.property ;
|
{ property = current.property ;
|
||||||
weight = Weight.of_float sw ;
|
weight = Weight.of_float sw ;
|
||||||
value =
|
value =
|
||||||
Array.init dim ~f:(fun i -> update_value wc vc.(i) wb vb.(i) sw)
|
Array.init dim (fun i -> update_value wc vc.(i) wb vb.(i) sw)
|
||||||
|> Sample.of_float_array ~dim ;
|
|> Sample.of_float_array ~dim ;
|
||||||
block_id = update_block_id block.block_id;
|
block_id = update_block_id block.block_id;
|
||||||
pid = block.pid ;
|
pid = block.pid ;
|
||||||
@ -399,7 +414,7 @@ let create_hash ~create_key ?(update_block_id=(fun x->x))
|
|||||||
compute_node = block.compute_node;
|
compute_node = block.compute_node;
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
) t.data ;
|
||||||
table
|
table
|
||||||
|
|
||||||
|
|
||||||
@ -409,12 +424,12 @@ let merge ~create_key ?update_block_id ?update_value ?update_weight t =
|
|||||||
let table = create_hash ~create_key ?update_block_id ?update_value ?update_weight t
|
let table = create_hash ~create_key ?update_block_id ?update_value ?update_weight t
|
||||||
in
|
in
|
||||||
{ property = t.property ;
|
{ property = t.property ;
|
||||||
data = Hashtbl.to_alist table
|
data = hashtbl_to_alist table
|
||||||
|> List.sort ~cmp:(fun x y ->
|
|> List.sort (fun x y ->
|
||||||
if (x>y) then 1
|
if (x>y) then 1
|
||||||
else if (x<y) then -1
|
else if (x<y) then -1
|
||||||
else 0)
|
else 0)
|
||||||
|> List.map ~f:(fun (x,y) -> y)
|
|> List.map (fun (x,y) -> y)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -440,7 +455,7 @@ let merge_per_compute_node_and_pid =
|
|||||||
~create_key:(fun block ->
|
~create_key:(fun block ->
|
||||||
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) )
|
(block.Block.pid) )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -453,9 +468,9 @@ let merge_per_compute_node_and_block_id =
|
|||||||
(Block_id.to_int block.Block.block_id) )
|
(Block_id.to_int block.Block.block_id) )
|
||||||
|
|
||||||
let error_x_over_y = function
|
let error_x_over_y = function
|
||||||
| [] -> (Average.of_float 0., None)
|
| [] -> (Average.of_float 0., None)
|
||||||
| (x,_)::[] -> (Average.of_float x, None)
|
| (x,_)::[] -> (Average.of_float x , None)
|
||||||
| (x,w)::tail ->
|
| (x,w)::tail ->
|
||||||
begin
|
begin
|
||||||
let avcu0 = ref 0.
|
let avcu0 = ref 0.
|
||||||
and ansum = ref w
|
and ansum = ref w
|
||||||
@ -466,17 +481,17 @@ let error_x_over_y = function
|
|||||||
in
|
in
|
||||||
let avcu = ref !avbl
|
let avcu = ref !avbl
|
||||||
in
|
in
|
||||||
List.iter tail ~f:(fun (x,w) ->
|
List.iter (fun (x,w) ->
|
||||||
avcu0 := !avsum /. !ansum;
|
avcu0 := !avsum /. !ansum;
|
||||||
ansum := !ansum +. w;
|
ansum := !ansum +. w;
|
||||||
avsum := !avsum +. x;
|
avsum := !avsum +. x;
|
||||||
avbl := x /. w ;
|
avbl := x /. w ;
|
||||||
if (!ansum <> 0.) then
|
if (!ansum <> 0.) then
|
||||||
avcu := !avsum /. !ansum
|
avcu := !avsum /. !ansum
|
||||||
else ();
|
else ();
|
||||||
avsq := !avsq +. (1. -. w /. !ansum) *. (!avbl -. !avcu0) *. (!avbl -. !avcu0) *. w;
|
avsq := !avsq +. (1. -. w /. !ansum) *. (!avbl -. !avcu0) *. (!avbl -. !avcu0) *. w;
|
||||||
n := !n +. 1.
|
n := !n +. 1.
|
||||||
);
|
) tail ;
|
||||||
let arg =
|
let arg =
|
||||||
abs_float (!avsq /.(!ansum *. (!n -. 1.)))
|
abs_float (!avsq /.(!ansum *. (!n -. 1.)))
|
||||||
in
|
in
|
||||||
@ -490,7 +505,7 @@ let error_x_over_y = function
|
|||||||
(** Create float, variable operators *)
|
(** Create float, variable operators *)
|
||||||
let one_variable_operator ~update_value p f =
|
let one_variable_operator ~update_value p f =
|
||||||
{ p with
|
{ p with
|
||||||
data = List.map ~f:(fun b -> { b with
|
data = List.map (fun b -> { b with
|
||||||
Block.value = Sample.of_float (update_value (Sample.to_float b.Block.value) ) }
|
Block.value = Sample.of_float (update_value (Sample.to_float b.Block.value) ) }
|
||||||
) p.data }
|
) p.data }
|
||||||
|
|
||||||
@ -515,7 +530,7 @@ let two_variable_operator ~update_value p1 p2 =
|
|||||||
Printf.sprintf "%s %10.10d %10.10d"
|
Printf.sprintf "%s %10.10d %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)
|
||||||
(Pid.to_int block.Block.pid) )
|
(block.Block.pid) )
|
||||||
~update_weight:(fun wc wb -> wc )
|
~update_weight:(fun wc wb -> wc )
|
||||||
{ property = p1.property ;
|
{ property = p1.property ;
|
||||||
data = List.concat [ p1.data ; p2.data ] }
|
data = List.concat [ p1.data ; p2.data ] }
|
||||||
@ -555,13 +570,13 @@ let max_value_per_compute_node t =
|
|||||||
let create_key block =
|
let create_key block =
|
||||||
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)
|
(block.Block.pid)
|
||||||
in
|
in
|
||||||
List.iter t.data ~f:(fun block ->
|
List.iter (fun block ->
|
||||||
let key = create_key block
|
let key = create_key block
|
||||||
in
|
in
|
||||||
let open Block in
|
let open Block in
|
||||||
Hashtbl.change table key (function
|
hashtbl_change table key (function
|
||||||
| Some current ->
|
| Some current ->
|
||||||
let vc = Sample.to_float current.value
|
let vc = Sample.to_float current.value
|
||||||
and vb = Sample.to_float block.value
|
and vb = Sample.to_float block.value
|
||||||
@ -572,14 +587,14 @@ let max_value_per_compute_node t =
|
|||||||
Some block
|
Some block
|
||||||
| None -> Some block
|
| None -> Some block
|
||||||
)
|
)
|
||||||
);
|
) t.data ;
|
||||||
{ property = t.property ;
|
{ property = t.property ;
|
||||||
data = Hashtbl.to_alist table
|
data = hashtbl_to_alist table
|
||||||
|> List.sort ~cmp:(fun x y ->
|
|> List.sort (fun x y ->
|
||||||
if (x>y) then 1
|
if (x>y) then 1
|
||||||
else if (x<y) then -1
|
else if (x<y) then -1
|
||||||
else 0)
|
else 0)
|
||||||
|> List.map ~f:(fun (x,y) -> y)
|
|> List.map (fun (x,y) -> y)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -653,12 +668,12 @@ let compress_files () =
|
|||||||
in
|
in
|
||||||
let files =
|
let files =
|
||||||
Sys.ls_dir dir_name
|
Sys.ls_dir dir_name
|
||||||
|> List.filter ~f:(fun x ->
|
|> List.filter (fun x ->
|
||||||
match String.substr_index ~pattern:"locked" x with
|
match String.substr_index ~pattern:"locked" x with
|
||||||
| Some x -> false
|
| Some x -> false
|
||||||
| None -> true
|
| None -> true
|
||||||
)
|
)
|
||||||
|> List.map ~f:(fun x -> dir_name^x)
|
|> List.map (fun x -> dir_name^x)
|
||||||
in
|
in
|
||||||
|
|
||||||
let out_channel_dir =
|
let out_channel_dir =
|
||||||
@ -670,7 +685,7 @@ let compress_files () =
|
|||||||
Lazy.force Qmcchem_config.hostname
|
Lazy.force Qmcchem_config.hostname
|
||||||
and suffix =
|
and suffix =
|
||||||
Unix.getpid ()
|
Unix.getpid ()
|
||||||
|> Pid.to_string
|
|> string_of_int
|
||||||
in
|
in
|
||||||
String.concat [ hostname ; "." ; suffix ]
|
String.concat [ hostname ; "." ; suffix ]
|
||||||
in
|
in
|
||||||
@ -679,7 +694,7 @@ let compress_files () =
|
|||||||
Out_channel.create (out_channel_dir ^ out_channel_name)
|
Out_channel.create (out_channel_dir ^ out_channel_name)
|
||||||
in
|
in
|
||||||
|
|
||||||
List.iter properties ~f:(fun p ->
|
List.iter (fun p ->
|
||||||
let l =
|
let l =
|
||||||
match p with
|
match p with
|
||||||
| Property.Cpu
|
| Property.Cpu
|
||||||
@ -693,14 +708,14 @@ let compress_files () =
|
|||||||
of_raw_data ~locked:false ~range:(0.,100.) 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 (fun x ->
|
||||||
Out_channel.output_string block_channel (Block.to_string x);
|
Out_channel.output_string block_channel (Block.to_string x);
|
||||||
Out_channel.output_char block_channel '\n';
|
Out_channel.output_char block_channel '\n';
|
||||||
);
|
) l.data
|
||||||
);
|
) properties ;
|
||||||
Out_channel.close block_channel;
|
Out_channel.close block_channel;
|
||||||
|
|
||||||
List.iter files ~f:Unix.remove ;
|
List.iter Unix.remove files ;
|
||||||
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
|
||||||
|
|
||||||
@ -716,20 +731,20 @@ let autocovariance { property ; data } =
|
|||||||
with { property ; data } -> Array.of_list data
|
with { property ; data } -> Array.of_list data
|
||||||
in
|
in
|
||||||
let x_t =
|
let x_t =
|
||||||
Array.map ~f:(fun x -> (Sample.to_float x.Block.value) -. ave) data
|
Array.map (fun x -> (Sample.to_float x.Block.value) -. ave) data
|
||||||
in
|
in
|
||||||
let f i =
|
let f i =
|
||||||
let denom =
|
let denom =
|
||||||
if (i > 1) then (float_of_int i) else 1.
|
if (i > 1) then (float_of_int i) else 1.
|
||||||
in
|
in
|
||||||
let r =
|
let r =
|
||||||
Array.sub ~pos:0 ~len:i x_t
|
Array.sub 0 i x_t
|
||||||
|> Array.fold_left ~init:0. ~f:(fun accu x ->
|
|> Array.fold_left (fun accu x ->
|
||||||
accu +. x *. x_t.(i))
|
accu +. x *. x_t.(i)) 0.
|
||||||
in
|
in
|
||||||
r /. denom
|
r /. denom
|
||||||
in
|
in
|
||||||
Array.init ~f (Array.length data)
|
Array.init (Array.length data) f
|
||||||
|> Array.to_list
|
|> Array.to_list
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user