Commit 93f69231 authored by Benoit Barbot's avatar Benoit Barbot
Browse files

progress

parent 9aa9561a
Pipeline #1696 passed with stages
in 32 seconds
......@@ -55,7 +55,7 @@ let build_cmd_elem (opt,x,help) =
if !(S.content) = S.def then ""
else Printf.sprintf " %s %s" opt (S.to_string !(S.content))
let reset (_,x,_) = match x with
let reset_elem (_,x,_) = match x with
Bool a -> a:= false
| Set_int a -> a:= None
| Set_float a -> a:= None
......@@ -67,6 +67,8 @@ let reset (_,x,_) = match x with
let module S = (val s:SYM) in
S.content := S.def
let reset l = List.iter reset_elem l
let build_cmd l =
let str = List.fold_left (fun acc elem -> acc ^ (build_cmd_elem elem)) "wordgen" l in
str
......
......@@ -15,12 +15,12 @@ let build_interface_elem up (opt,x,help) =
| Int (f,df) -> [text_input ~_type:"number" ~on_change:(fun x ->
(match int_of_string_opt x with
None -> f := df
| Some v -> f:= v);up ()) (string_of_int df)]
| Some v -> f:= v);up ()) (string_of_int !f)]
| Float (f,df) -> [text_input ~_type:"text" ~on_change:(fun x ->
(match float_of_string_opt x with
None -> f := df
| Some v -> f :=v);up ()) (string_of_float df)]
| String (a,ds) -> [text_input ~_type:"text" ~on_change:(fun x -> a:= x;up ()) ds]
| Some v -> f :=v);up ()) (string_of_float !f)]
| String (a,ds) -> [text_input ~_type:"text" ~on_change:(fun x -> a:= x;up ()) !a]
| Symbol s ->
let module S = (val s : SYM) in
[select S.list ~def:(S.to_string !S.content) ~on_change:(fun x -> S.content := S.of_string x;up ())]
......@@ -30,9 +30,9 @@ let build_interface_elem up (opt,x,help) =
let build_cmd l =
(Arguments.build_cmd l)^" automata.prism"
let autocompute = ref true
let build_interface ?(class_="") ?(stop=(fun () -> ())) up l =
let cmd,cmdup = kbd' (build_cmd l) in
let autocompute = ref true in
let up2 () =
cmdup (build_cmd l);
if !autocompute then up true else up false in
......@@ -64,11 +64,12 @@ let _ = run @@ fun () ->
| Some q -> file_content := urldecode q);
(match List.assoc_opt "cmd" args with
None -> ()
| Some cmd -> ("wordgen " ^cmd)
|> urldecode
|> String.split_on_char ' '
|> Array.of_list
|> (fun a -> Arg.parse_argv a Arguments.spec_caml_arg (fun _ -> ()) Arguments.usage_str)
| Some cmd ->
cmd
|> urldecode
|> String.split_on_char ' '
|> Array.of_list
|> (fun a -> Arg.parse_argv a Arguments.spec_caml_arg (fun _ -> ()) Arguments.usage_str)
);
......@@ -128,22 +129,11 @@ let _ = run @@ fun () ->
container_up [];
Buffer.clear buffstd;
Buffer.clear buffdata;
worker##postMessage(Worker_sync.Task {
Worker_sync.ta = !file_content;
rational_impl = !rational_impl;
frequency = !frequency;
expected_duration = !expected_duration;
verbose = !verbose;
npoly = !npoly;
print_rg = !print_rg;
sampling_meth = !sampling_meth;
sampler = !sampler;
out_style = !out_style;
max_iteration = !max_iteration;
store_traj = !store_traj;
nbtraj = !nbtraj;
only_parse = not b;
}) in
let cmd =
Arguments.spec_short @ ["--autocompute",Arguments.Bool autocompute,""]
|> build_cmd
|> String.escaped in
worker##postMessage( (cmd, !file_content) ) in
let txin = text_area ~class_:"input_file col-sm-6" ~on_change:(fun x->
file_content:=x;
......@@ -157,7 +147,7 @@ let _ = run @@ fun () ->
a ~href:"https://git.lacl.fr/barbot/wordgen" [text "the source repository page"];
text ". Be aware the tool Wordgen is a native commandline tool, this website if limited in speed and functionalities.";
];
build_interface ~class_:"" ~stop:(fun () -> worker##postMessage (Worker_sync.Stop)) launch_compt Arguments.spec_short;];
build_interface ~class_:"" (*~stop:(fun () -> worker##postMessage (Worker_sync.Stop))*) launch_compt Arguments.spec_short;];
div ~class_:"" [div ~class_:"output" [ txin; container]];
dirlink;
br ();
......
open Worker_sync
open Arguments
let is_stopped =ref true
exception Interrupted
let computation outfile task =
let module Bound = (val if task.npoly<0 then (module ZoneGraphInput.GeneralBound:ZoneGraphInput.BoundType )
let only_parse = ref false
let computation ta outfile =
let module Bound = (val if !npoly<0 then (module ZoneGraphInput.GeneralBound:ZoneGraphInput.BoundType )
else (module ZoneGraphInput.LinearBound )) in
let module ZGI = ZoneGraphInput.Make (Bound) in
let rg = ZGI.input_from_string task.ta in
let rg = ZGI.input_from_string ta in
Js_of_ocaml.Worker.post_message ParseOK;
if not task.only_parse then (
let module R = (val if task.rational_impl then (module Fl.Num :Fl.FSIG) else (module Fl.Float:Fl.FSIG)) in
if not !only_parse then (
let module R = (val if !rational_impl then (module Fl.Num :Fl.FSIG) else (module Fl.Float:Fl.FSIG)) in
let module P = Polynome.Make (R) (struct let var_string= rg.ZoneGraph.var_string end) in
let module Weight = (
val if task.frequency = None && task.expected_duration = None then (module P:Semantic.WeightStructure)
else (module ExpPoly.Make(P)(struct
let smp = if P.F.is_exact then None else task.frequency
let tvar = P.var_of_int 0
let svar= P.var_of_int (P.nb_var-1)
end))) in
val if !frequency = None && !expected_duration = None then (module P:Semantic.WeightStructure)
else (module ExpPoly.Make(P)(struct
let smp = if P.F.is_exact then None else !frequency
let tvar = P.var_of_int 0
let svar= P.var_of_int (P.nb_var-1)
end))) in
let module FunIt = Semantic.Make (Bound) (Weight) in
let weights,rgpoly =
if task.npoly > 0 then (
if task.verbose>0 then (
if !npoly > 0 then (
if !verbose>0 then (
Format.printf "Computing Distribution[%s; %s] -> %i: ["
(if Weight.F.is_exact then "exact rational" else "floating point")
Weight.desc
task.npoly;
!npoly;
flush stdout;
Format.print_flush ()
);
let w,rgp = FunIt.iterate_functionnal ~update:(fun () ->
if !is_stopped then raise Interrupted;
Format.printf "|"; Format.print_flush ())
rg task.npoly in
if task.verbose>0 then Format.printf "] [%.2fs]@." (Common.check_time ());
w,rgp
) else
if !is_stopped then raise Interrupted;
Format.printf "|"; Format.print_flush ())
rg !npoly in
if !verbose>0 then Format.printf "] [%.2fs]@." (Common.check_time ());
w,rgp )
else
FunIt.iterate_functionnal rg 0
in
if task.print_rg then (
if !print_rg then (
let buff = Buffer.create 100 in
let form = Format.formatter_of_buffer buff in
ZoneGraph.print_dot rgpoly Bound.print form;
......@@ -53,10 +56,10 @@ let computation outfile task =
(* Compute s from expected_duration *)
let smp = match task.expected_duration with
None -> task.frequency
let smp = match !expected_duration with
None -> !frequency
| Some target ->
if task.verbose>0 then (
if !verbose>0 then (
Format.printf "Computing laplace parameter s for E[T]=%g " target; flush stdout;
Format.print_flush ();
);
......@@ -66,7 +69,7 @@ let computation outfile task =
Format.printf "Target outside range, aborting@.";
exit 1
| Ok ( x, (low,mid,up), nt) ->
if task.verbose>0 then (
if !verbose>0 then (
Format.printf "range:[%g; %g; %g]" low mid up;
Format.printf " -> s=%g;E[T]=%g [%.2fs]@." x nt (Common.check_time ());
);
......@@ -75,31 +78,45 @@ let computation outfile task =
let module M = MainLoop.Make (FunIt) (struct let smp = smp end) in
let template_word = match task.sampling_meth with
Exact -> Array.make task.npoly (Semantic.Fixed,Semantic.Fixed)
let template_word = match !sampling_meth with
Exact -> Array.make !npoly (Semantic.Fixed,Semantic.Fixed)
| Receding x -> Array.make x (Semantic.Fixed,Semantic.Fixed)
| Driven l -> Array.of_list l in
let lengthword = Array.length template_word in
Low_disc_sampler.init lengthword;
M.sample ~outfile
~out_style: task.out_style
~max_iter: task.max_iteration
~verbose: task.verbose
~sampler: (Low_disc_sampler.get_sampler task.sampler)
~store_traj: task.store_traj
~out_style: !out_style
~max_iter: !max_iteration
~verbose: !verbose
~sampler: (Low_disc_sampler.get_sampler !sampler)
~store_traj: !store_traj
rgpoly
template_word
task.nbtraj
!nbtraj
)
let main cmd ta out_formatter =
reset spec_short;
only_parse := true;
Arg.current:=0;
let argv =
cmd
|> Scanf.unescaped
|> String.split_on_char ' '
|> Array.of_list in
Arg.parse_argv argv (("--autocompute",Arg.Clear only_parse,"")::spec_caml_arg) (fun _ -> ()) usage_str;
post_parse ();
computation ta out_formatter
let _ =
Js_of_ocaml.Worker.set_onmessage (function
| Stop ->
Js_of_ocaml.Worker.set_onmessage (function (cmd,ta) ->
(* | Stop ->
is_stopped := true;
print_endline "Stop"
| Task x ->
| Task x ->*)
is_stopped := false;
print_endline ("New Job");
let buff_std = Buffer.create 10 in
......@@ -115,7 +132,8 @@ let _ =
Buffer.clear buff_out;
Js_of_ocaml.Worker.post_message (Data m)) in
try
computation out_formatter x;
(*computation out_formatter x;*)
main cmd ta out_formatter;
Js_of_ocaml.Worker.post_message (Finish)
with
Interrupted -> ()
......
type task = {
ta : string;
rational_impl : bool;
frequency : float option;
expected_duration : float option;
verbose : int;
npoly : int;
print_rg : bool;
sampling_meth : Arguments.samplingMeth;
out_style : OutFormat.output_style;
sampler : Low_disc_sampler.t;
max_iteration : int;
store_traj :bool;
nbtraj : int;
only_parse : bool;
}
(*
type order = Task of task | Stop
*)
type result_type =
| StdOut of string
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment