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
|
|
|
|
|
|
|
|
2016-01-18 20:17:37 +01:00
|
|
|
let create m =
|
|
|
|
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);
|
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);
|
2016-01-18 20:17:37 +01:00
|
|
|
}
|
|
|
|
| [ prop ; c ; pid ; b ; w ; v ] ->
|
|
|
|
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);
|
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
|
|
|
|
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
|
|
|
|
| (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
|
|
|
|
let rec build accu = function
|
|
|
|
| [] -> Array.of_list accu
|
|
|
|
| w ->
|
|
|
|
let (result, tail) =
|
|
|
|
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
|
|
|
|
| prop :: c :: pid :: b :: d :: w :: l ->
|
|
|
|
let property =
|
|
|
|
Property.of_string prop
|
|
|
|
in
|
|
|
|
begin
|
|
|
|
assert (not (Property.is_scalar property));
|
|
|
|
let a =
|
|
|
|
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);
|
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
|
|
|
|
|
|
|
|
|
|
|
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)
|
2019-07-19 17:06:01 +02:00
|
|
|
| Register (h,p) -> Printf.sprintf "Register : %s %d"
|
|
|
|
(Compute_node.to_string h) p
|
|
|
|
| Unregister (h,p) -> Printf.sprintf "Unregister : %s %d"
|
|
|
|
(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
|
|
|
|
|
|
|
|