2015-12-19 02:35:13 +01:00
|
|
|
open Qptypes
|
|
|
|
|
|
|
|
type t =
|
2019-07-19 17:06:01 +02:00
|
|
|
| Property of Block.t
|
|
|
|
| Walkers of Compute_node.t * int * (float array) array
|
|
|
|
| Register of Compute_node.t * int
|
|
|
|
| Unregister of Compute_node.t * int
|
|
|
|
| Test
|
|
|
|
| GetWalkers of Strictly_positive_int.t
|
|
|
|
| Ezfio of string
|
|
|
|
| Error of string
|
2015-12-19 02:35:13 +01:00
|
|
|
|
|
|
|
|
2022-01-12 19:05:15 +01:00
|
|
|
let of_string_list m =
|
2016-01-18 20:17:37 +01:00
|
|
|
try
|
|
|
|
match m with
|
|
|
|
| [ "cpu" ; c ; pid ; b ; "1" ; v ] ->
|
2015-12-19 02:35:13 +01:00
|
|
|
let open Block in
|
2016-01-18 20:17:37 +01:00
|
|
|
Property
|
|
|
|
{ property = Property.Cpu;
|
2019-07-19 17:06:01 +02:00
|
|
|
value = Sample.of_float (float_of_string v) ;
|
2016-01-18 20:17:37 +01:00
|
|
|
weight = Weight.of_float 1.;
|
|
|
|
compute_node = Compute_node.of_string c;
|
2019-07-19 17:06:01 +02:00
|
|
|
pid = int_of_string pid;
|
|
|
|
block_id = Block_id.of_int (int_of_string b);
|
2022-01-06 17:43:31 +01:00
|
|
|
}
|
2016-01-18 20:17:37 +01:00
|
|
|
| [ "accep" ; c ; pid ; b ; "1" ; v ] ->
|
|
|
|
let open Block in
|
|
|
|
Property
|
|
|
|
{ property = Property.Accep;
|
2019-07-19 17:06:01 +02:00
|
|
|
value = Sample.of_float (float_of_string v) ;
|
2016-01-18 20:17:37 +01:00
|
|
|
weight = Weight.of_float 1.;
|
|
|
|
compute_node = Compute_node.of_string c;
|
2019-07-19 17:06:01 +02:00
|
|
|
pid = int_of_string pid;
|
|
|
|
block_id = Block_id.of_int (int_of_string b);
|
2022-01-06 17:43:31 +01:00
|
|
|
}
|
|
|
|
| [ prop ; c ; pid ; b ; w ; v ] ->
|
2016-01-18 20:17:37 +01:00
|
|
|
let open Block in
|
|
|
|
Property
|
|
|
|
{ property = Property.of_string prop;
|
2019-07-19 17:06:01 +02:00
|
|
|
value = Sample.of_float (float_of_string v);
|
|
|
|
weight = Weight.of_float (float_of_string w);
|
2016-01-18 20:17:37 +01:00
|
|
|
compute_node = Compute_node.of_string c;
|
2019-07-19 17:06:01 +02:00
|
|
|
pid = int_of_string pid;
|
|
|
|
block_id = Block_id.of_int (int_of_string b);
|
2022-01-06 17:43:31 +01:00
|
|
|
}
|
2016-01-18 20:17:37 +01:00
|
|
|
| "elec_coord" :: c :: pid :: _ :: n ::walkers ->
|
2015-12-19 02:35:13 +01:00
|
|
|
begin
|
2016-04-05 00:48:37 +02:00
|
|
|
let elec_num =
|
2016-01-18 20:17:37 +01:00
|
|
|
Lazy.force Qputils.elec_num
|
2022-01-06 17:43:31 +01:00
|
|
|
and n =
|
2019-07-19 17:06:01 +02:00
|
|
|
int_of_string n
|
2016-01-18 20:17:37 +01:00
|
|
|
in
|
|
|
|
assert (n = List.length walkers);
|
|
|
|
let rec build_walker accu = function
|
2022-01-06 17:43:31 +01:00
|
|
|
| (0,tail) ->
|
|
|
|
let result =
|
|
|
|
List.rev accu
|
2020-04-15 14:40:33 +02:00
|
|
|
|> List.rev_map float_of_string
|
|
|
|
|> List.rev
|
2016-01-18 20:17:37 +01:00
|
|
|
|> Array.of_list
|
|
|
|
in
|
|
|
|
(result, tail)
|
|
|
|
| (n,head::tail) ->
|
|
|
|
build_walker (head::accu) (n-1, tail)
|
|
|
|
| _ -> failwith "Bad walkers"
|
|
|
|
in
|
2022-01-06 17:43:31 +01:00
|
|
|
let rec build accu = function
|
2016-01-18 20:17:37 +01:00
|
|
|
| [] -> Array.of_list accu
|
2022-01-06 17:43:31 +01:00
|
|
|
| w ->
|
|
|
|
let (result, tail) =
|
2016-01-18 20:17:37 +01:00
|
|
|
build_walker [] (3*elec_num+3, w)
|
|
|
|
in
|
|
|
|
build (result::accu) tail
|
|
|
|
in
|
2019-07-19 17:06:01 +02:00
|
|
|
Walkers (Compute_node.of_string c, int_of_string pid, build [] walkers)
|
2015-12-19 02:35:13 +01:00
|
|
|
end
|
2019-07-19 17:06:01 +02:00
|
|
|
| [ "get_walkers" ; n ] -> GetWalkers (n |> int_of_string |> Strictly_positive_int.of_int)
|
|
|
|
| [ "register" ; c ; pid ] -> Register (Compute_node.of_string c, int_of_string pid)
|
|
|
|
| [ "unregister" ; c ; pid ] -> Unregister (Compute_node.of_string c, int_of_string pid)
|
2016-01-18 20:17:37 +01:00
|
|
|
| [ "Test" ] -> Test
|
|
|
|
| [ "Ezfio" ; ezfio_msg ] -> Ezfio ezfio_msg
|
2022-01-12 19:05:15 +01:00
|
|
|
| prop :: c :: pid :: b :: d :: w :: "bin" :: block :: [] ->
|
|
|
|
(* Block in binary format *)
|
|
|
|
let property =
|
|
|
|
Property.of_string prop
|
|
|
|
in
|
|
|
|
begin
|
|
|
|
assert (not (Property.is_scalar property));
|
|
|
|
match Block.of_bytes ~idx:8 (Bytes.unsafe_of_string block) with
|
|
|
|
| Some block -> Property block
|
|
|
|
| None -> failwith "Invalid block"
|
|
|
|
end
|
2022-01-06 17:43:31 +01:00
|
|
|
| prop :: c :: pid :: b :: d :: w :: l ->
|
2022-01-12 19:05:15 +01:00
|
|
|
(* Bock in text format *)
|
2016-01-18 20:17:37 +01:00
|
|
|
let property =
|
|
|
|
Property.of_string prop
|
|
|
|
in
|
|
|
|
begin
|
|
|
|
assert (not (Property.is_scalar property));
|
2022-01-06 17:43:31 +01:00
|
|
|
let a =
|
2016-01-18 20:17:37 +01:00
|
|
|
Array.of_list l
|
2019-07-19 17:06:01 +02:00
|
|
|
|> Array.map float_of_string
|
2016-01-18 20:17:37 +01:00
|
|
|
and dim =
|
2019-07-19 17:06:01 +02:00
|
|
|
int_of_string d
|
2016-01-18 20:17:37 +01:00
|
|
|
in
|
|
|
|
assert (Array.length a = dim);
|
|
|
|
let open Block in
|
|
|
|
Property
|
|
|
|
{ property = property ;
|
|
|
|
value = Sample.of_float_array ~dim a;
|
2019-07-19 17:06:01 +02:00
|
|
|
weight = Weight.of_float (float_of_string w);
|
2016-01-18 20:17:37 +01:00
|
|
|
compute_node = Compute_node.of_string c;
|
2019-07-19 17:06:01 +02:00
|
|
|
pid = int_of_string pid;
|
|
|
|
block_id = Block_id.of_int (int_of_string b);
|
2022-01-06 17:43:31 +01:00
|
|
|
}
|
2016-01-18 20:17:37 +01:00
|
|
|
end
|
2019-07-19 17:06:01 +02:00
|
|
|
| l -> Error (String.concat ":" l)
|
2016-01-18 20:17:37 +01:00
|
|
|
with
|
|
|
|
| Assert_failure (l,_,_) -> Error l
|
|
|
|
| _ -> Error "Unknown error"
|
2015-12-19 02:35:13 +01:00
|
|
|
|
|
|
|
|
2022-01-12 19:05:15 +01:00
|
|
|
|
2015-12-19 02:35:13 +01:00
|
|
|
let to_string = function
|
|
|
|
| Property b -> "Property : "^(Block.to_string b)
|
2019-07-19 17:06:01 +02:00
|
|
|
| Walkers (h,p,w) -> Printf.sprintf "Walkers : %s %d : %d walkers"
|
|
|
|
(Compute_node.to_string h) p (Array.length w)
|
2015-12-19 02:35:13 +01:00
|
|
|
| GetWalkers n -> Printf.sprintf "GetWalkers %d" (Strictly_positive_int.to_int n)
|
2022-01-06 17:43:31 +01:00
|
|
|
| Register (h,p) -> Printf.sprintf "Register : %s %d"
|
2019-07-19 17:06:01 +02:00
|
|
|
(Compute_node.to_string h) p
|
2022-01-06 17:43:31 +01:00
|
|
|
| Unregister (h,p) -> Printf.sprintf "Unregister : %s %d"
|
2019-07-19 17:06:01 +02:00
|
|
|
(Compute_node.to_string h) p
|
2015-12-19 02:35:13 +01:00
|
|
|
| Test -> "Test"
|
|
|
|
| Ezfio msg -> "Ezfio "^msg
|
2016-01-18 20:17:37 +01:00
|
|
|
| Error msg -> "Error "^msg
|
2015-12-19 02:35:13 +01:00
|
|
|
|
|
|
|
|
2022-01-12 19:05:15 +01:00
|
|
|
let create m =
|
|
|
|
of_string_list m
|
|
|
|
|