Commit e960f691 authored by Benoit Barbot's avatar Benoit Barbot
Browse files

improve readme

parents d79e326f 8ae0efaf
Pipeline #2282 passed with stages
in 2 minutes
version=0.15.0
version=0.19.0
......@@ -72,33 +72,43 @@ struct
type out = unit
type monitor_state = {
mutable total_time : float;
mutable total_length : int;
mutable apericube : int;
}
type t =
Format.formatter
* (weight, bound) ZoneGraph.t
* style
* (int * int * float) ref
* monitor_state
* (string ->
(float Sampling.transChoice * string Sampling.transChoice) list)
let new_traj (_, _, _, mon_state, _) = mon_state := (0, 0, 0.0)
let new_traj (_, _, _, mon_state, _) =
mon_state.total_time <- 0.0;
mon_state.total_length <- 0;
mon_state.apericube <- 0
let init outfile rg ost parse_action =
let mon_state = ref (0, 0, 0.0) in
let mon_state = { total_time = 0.0; total_length = 0; apericube = 0 } in
((outfile, rg, ost, mon_state, parse_action) : t)
let end_traj (outfile, _, (ost, _), mon_state, _) store_traj =
( if store_traj then
let aper, size, duration = !mon_state in
Format.fprintf outfile "%i\t%i\t%g" aper size duration );
if store_traj then
Format.fprintf outfile "%i\t%i\t%g" mon_state.apericube
mon_state.total_length mon_state.total_time;
if ost <> Void || store_traj then fprintf outfile "@."
let end_sampling _ = ()
module StringMap = Map.Make (String)
let up_state ((outfile, rgpoly, (ost, is_interactive), _, parse_action) : t)
?smp (st : State.t) i (u1, u2) =
( match ost with
let up_state
((outfile, rgpoly, (ost, is_interactive), monitor_state, parse_action) :
t) ?smp (st : State.t) i (u1, u2) =
(match ost with
| TimewordState -> fprintf outfile "(%a)@." print_state st
| StateList -> fprintf outfile "%a@." print_state st
| StateListFull -> fprintf outfile "%a\t%i@." print_state st 1
......@@ -166,15 +176,15 @@ struct
| _ when u1 = 1.0 -> Some (snd @@ List.nth accl (n - 1))
| _ when skip > 0.0 ->
Some
( snd
(snd
@@ List.find
(fun ((x, y), _) -> x <= skip && skip < y)
accl )
accl)
| _ ->
Some
( snd
(snd
@@ List.nth accl
(min (int_of_float (u1 *. float n)) (n - 1)) ))
(min (int_of_float (u1 *. float n)) (n - 1))))
|> (fun m ->
StringMap.fold
(fun _ v acc ->
......@@ -184,10 +194,14 @@ struct
let target =
rgpoly.statelist.((List.hd tr.ZoneGraph.miniedge).target)
in
let ct = monitor_state.total_time in
fprintf f
"%s{\"label\":\"%s\",\"min_time\": %g, \"max_time\":%g, \"time\":%g, \"target\":\"%s\"}"
"%s{\"label\":\"%s\",\"current_time\": %g, \"min_time\": \
%g, \"max_time\":%g, \"time\":%g, \"relative_time\":%g, \
\"target\":\"%s\"}"
(if i > 0 then "," else "")
tr.ZoneGraph.action low up time target.name))
tr.ZoneGraph.action ct (low +. ct) (up +. ct) (time +. ct)
time target.name))
rgpoly.ZoneGraph.statelist.(get_loc st).ZoneGraph.transition
| Debug ->
fprintf outfile "@[<h 0>%a@. @[<v 2>@[<v 0>%a@]@]@]@."
......@@ -213,7 +227,7 @@ struct
tr.ZoneGraph.action low up W.print weight w target.name
else fprintf f "[%s]-[%g;%g]@," tr.ZoneGraph.action low up))
rgpoly.ZoneGraph.statelist.(get_loc st).ZoneGraph.transition
| Void | Word | Timestamp | Timeword | TimeAndLabels -> () );
| Void | Word | Timestamp | Timeword | TimeAndLabels -> ());
if is_interactive then
let rec aux () =
......@@ -246,9 +260,9 @@ struct
let up_trans (outfile, _, (ost, _), mon_state, _) time tr i =
let t2 = int_of_float time in
(mon_state :=
let ap, size, tt = !mon_state in
((2 * ap) + t2, size + 1, tt +. time));
mon_state.total_time <- mon_state.total_time +. time;
mon_state.total_length <- mon_state.total_length + 1;
mon_state.apericube <- (2 * mon_state.apericube) + t2;
match ost with
| Debug when Array.length tr.ZoneGraph.weight > 0 ->
let weight, cdf, _ = tr.ZoneGraph.weight.(i) in
......@@ -264,8 +278,7 @@ struct
| StateListDelay ->
fprintf outfile "\t%i@.@." (int_of_char tr.ZoneGraph.action.[0])
| TimeAndLabels ->
fprintf outfile "%f\t%i@."
((fun (_, _, a) -> a) !mon_state)
fprintf outfile "%f\t%i@." mon_state.total_time
(int_of_char tr.ZoneGraph.action.[0])
| StateList | Void | CoSim -> ()
end
......
......@@ -22,7 +22,7 @@
(modules wordgen)
(instrumentation (backend bisect_ppx))
(libraries wordgen_lib unix arguments)
(modes native))
(modes native byte))
......
......@@ -35,18 +35,18 @@ let newton_raphson_iterate ?(factor = 1e-9) ?(max_iter = 20) ?bound f guess_p =
delta := copysign (0.9 *. abs_float !result) !delta
else delta := shift;
delta1 := 3.0 *. !delta;
delta2 := 3.0 *. !delta );
delta2 := 3.0 *. !delta);
(*Format.printf "test2@.";*)
guess := !result;
result := !result -. !delta;
if !result <= !min then (
delta := 0.5 *. (!guess -. !min);
result := !guess -. !delta;
if !result = !min || !result = !max then raise Exit )
if !result = !min || !result = !max then raise Exit)
else if !result >= !max then (
delta := 0.5 *. (!guess -. !max);
result := !guess -. !delta;
if !result = !min || !result = !max then raise Exit );
if !result = !min || !result = !max then raise Exit);
if !delta > 0.0 then max := !guess else min := !guess;
if abs_float (!result *. factor) >= abs_float !delta then raise Exit
done;
......@@ -97,7 +97,7 @@ let rec bisect_increasing ?(factor = 1e-10) ?(strict = true) ?(relax = 0.0) ?low
(*Format.printf "right\n";*)
bisect_increasing ~relax ~strict ~factor ~low:(m, fx, a)
(m -. (relax *. width), bmax +. (relax *. width))
f_to_evaluate )
f_to_evaluate)
else
let fx, _, _ = f_to_evaluate bmax in
if classify_float fx = FP_nan || fx > 0.0 || fx < yfmin then
......
......@@ -216,7 +216,7 @@ struct
(fun k v b ->
if b && v > F.zero then Format.fprintf f "+";
Format.fprintf f "%s%a"
( match (F.is_exact, v, is_not_const k) with
(match (F.is_exact, v, is_not_const k) with
| false, v1, true when v1 = F.of_float 1.0 -> ""
| false, v1, true when v1 = F.of_float (-1.0) -> "-"
| false, v1, _ when v1 = F.of_float 0.5 -> "½"
......@@ -226,7 +226,7 @@ struct
| false, v1, _ when v1 = F.of_float (-0.75) -> "-¾"
| false, v1, _ when v1 = F.of_float (-0.25) -> "-¼"
| _, x, _ when F.is_integer x -> string_of_int (F.to_int x)
| _ -> F.to_string v )
| _ -> F.to_string v)
print_monome k;
true)
a false
......@@ -422,7 +422,7 @@ struct
if a <> 0 then (
let k2 = Array.copy k in
k2.(x) <- a - 1;
add_mon k2 (F.mul v (F.of_int a)) it )
add_mon k2 (F.mul v (F.of_int a)) it)
else it)
p Poly.empty
......@@ -613,7 +613,8 @@ struct
else
let upval = cc up in
if upval <> lowval then dicho low up true lowval
else dicho up (2.0 *. up) false upval
else if up < 1. /. factor then dicho up (2.0 *. up) false upval
else up
in
dicho start 1.0 false (cc start)
......
......@@ -12,16 +12,16 @@ let only_parse = ref false
let computation ta outfile =
if !only_parse then npoly := -1;
let module Bound =
( val if !npoly < 0 then
(module ZoneGraphInput.GeneralBound : ZoneGraphInput.BoundType)
else (module ZoneGraphInput.LinearBound) )
(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 ta in
Js_of_ocaml.Worker.post_message ParseOK;
let module Param =
( val Compute.gen_param rg.ZoneGraph.var_string !rational_impl !frequency
!expected_duration !boltzmann_param !expected_size !verbose !npoly )
(val Compute.gen_param rg.ZoneGraph.var_string !rational_impl !frequency
!expected_duration !boltzmann_param !expected_size !verbose !npoly)
in
if not !only_parse then (
let module Weight = Compute.Instantiate (Fl.Num) (Bound) (Param) () in
......@@ -31,12 +31,19 @@ let computation ta outfile =
Weight.compute_params ?seed:!random_seed !template rgpoly
in
if !print_rg then printf "%a@." (ZoneGraph.print Bound.print) rgpoly;
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;
Format.fprintf form "@.";
Format.printf "%a@." (ZoneGraph.print Bound.print) rgpoly;
Js_of_ocaml.Worker.post_message
(Graph (String.escaped (Buffer.contents buff))));
Weight.sample smp ~outfile ?seed:!Arguments.random_seed ?boltz
~out_style:(!out_style, false) ~max_iter:!max_iteration
~sampler:(Low_disc_sampler.get_sampler !sampler)
~store_traj:!store_traj rgpoly !template !nbtraj )
~store_traj:!store_traj rgpoly !template !nbtraj)
let main cmd ta out_formatter =
reset spec_short;
......@@ -49,6 +56,7 @@ let main cmd ta out_formatter =
(("--only-parse", Arg.Clear only_parse, "") :: spec_caml_arg)
(fun _ -> ())
usage_str;
post_parse ();
computation ta out_formatter
let _ =
......@@ -58,27 +66,27 @@ let _ =
print_endline "Stop"
| Task x ->*)
( is_stopped := false;
print_endline "New Job";
let buff_std = Buffer.create 10 in
Format.set_formatter_output_functions (Buffer.add_substring buff_std)
(fun () ->
let m = Buffer.contents buff_std in
Buffer.clear buff_std;
Js_of_ocaml.Worker.post_message (StdOut m));
let buff_out = Buffer.create 100 in
let out_formatter =
Format.make_formatter (Buffer.add_substring buff_out) (fun () ->
let m = Buffer.contents buff_out in
Buffer.clear buff_out;
Js_of_ocaml.Worker.post_message (Data m))
in
(*computation out_formatter x;*)
try
main cmd ta out_formatter;
Js_of_ocaml.Worker.post_message Finish
with
| Interrupted -> ()
| x ->
Js_of_ocaml.Worker.post_message
(Error (String.escaped (Printexc.to_string x))) ))
(is_stopped := false;
print_endline "New Job";
let buff_std = Buffer.create 10 in
Format.set_formatter_output_functions (Buffer.add_substring buff_std)
(fun () ->
let m = Buffer.contents buff_std in
Buffer.clear buff_std;
Js_of_ocaml.Worker.post_message (StdOut m));
let buff_out = Buffer.create 100 in
let out_formatter =
Format.make_formatter (Buffer.add_substring buff_out) (fun () ->
let m = Buffer.contents buff_out in
Buffer.clear buff_out;
Js_of_ocaml.Worker.post_message (Data m))
in
(*computation out_formatter x;*)
try
main cmd ta out_formatter;
Js_of_ocaml.Worker.post_message Finish
with
| Interrupted -> ()
| x ->
Js_of_ocaml.Worker.post_message
(Error (String.escaped (Printexc.to_string x)))))
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