Commit 32b9e98a authored by Benoit Barbot's avatar Benoit Barbot
Browse files

refactor

parent c4b70ee2
Pipeline #2134 passed with stages
in 2 minutes and 35 seconds
......@@ -211,7 +211,7 @@ let spec_full =
"Export debug information on the splitting in tex format" );
]
let post_parse var_string =
let post_parse () =
( match (!receding, !template_string) with
| None, None -> sampling_meth := Exact
| Some r, None -> sampling_meth := Receding r
......@@ -225,41 +225,13 @@ let post_parse var_string =
| Driven l, Some t ->
expected_duration := Some (t *. float !npoly /. float (List.length l))
| _ -> () );
(template :=
let open Wordgen_lib.Sampling in
match !sampling_meth with
| Exact when !npoly >= 0 -> Array.make !npoly (Fixed, Fixed)
| Exact (*receding 3*) -> Array.make 3 (Fixed, Fixed)
| Receding x -> Array.make x (Fixed, Fixed)
| Driven l -> Array.of_list l);
( module struct
open Wordgen_lib.Compute
let exact_rationnal = !rational_impl
let var_string = var_string
let s_param =
match (!frequency, !expected_duration) with
| None, None -> No
| Some f, None -> Fixed f
| None, Some f -> ToCompute f
| _ -> failwith "Set frequency or expected duration not both"
let z_param =
match (!boltzmann_param, !expected_size) with
| None, None -> No
| Some f, None -> Fixed f
| None, Some f -> ToCompute f
| _ -> failwith "Set boltzmann parameter or expected size not both"
let is_timed =
Array.exists (function _, true -> true | _ -> false) var_string
let verbose = !verbose
let npoly = !npoly
end : Wordgen_lib.Compute.PARAM )
template :=
let open Wordgen_lib.Sampling in
match !sampling_meth with
| Exact when !npoly >= 0 -> Array.make !npoly (Fixed, Fixed)
| Exact (*receding 3*) -> Array.make 3 (Fixed, Fixed)
| Receding x -> Array.make x (Fixed, Fixed)
| Driven l -> Array.of_list l
let spec_caml_arg = List.map to_caml_arg spec_full
......
......@@ -16,6 +16,35 @@ module type PARAM = sig
val s_param : param_type
end
let gen_param var_string rational_impl frequency expected_duration
boltzmann_param expected_size verbose npoly =
( module struct
let exact_rationnal = rational_impl
let var_string = var_string
let s_param =
match (frequency, expected_duration) with
| None, None -> No
| Some f, None -> Fixed f
| None, Some f -> ToCompute f
| _ -> failwith "Set frequency or expected duration not both"
let z_param =
match (boltzmann_param, expected_size) with
| None, None -> No
| Some f, None -> Fixed f
| None, Some f -> ToCompute f
| _ -> failwith "Set boltzmann parameter or expected size not both"
let is_timed =
Array.exists (function _, true -> true | _ -> false) var_string
let verbose = verbose
let npoly = npoly
end : PARAM )
module type COMPUTE = sig
include Semantic.S
......@@ -163,3 +192,90 @@ module Instantiate
in
M.sample ~verbose:Param.verbose
end
open Format
(* Main *)
let main print_rg infile frequency npoly expected_duration boltzmann_param
expected_size rational_impl verbose splitting_debug export_zone_graph
outfilename out_style seed is_interactive max_iteration sampler store_traj
template nbtraj =
(* check if precomputation exists *)
let precomp_exists =
if print_rg then None
else
ZoneGraphInput.precomputation_exists
~debug:(fun b ->
if verbose > 0 then
if b then
printf "Precomputation file found ! [%.2f]@."
(Common.check_time ())
else
printf
"Precomputation file found but file have change discard !@.")
infile frequency npoly
(frequency = None && expected_duration <> None)
rational_impl
in
(* Use splitted or general bound, general only for isotropic sampling *)
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
(*Building the zone graph
None means that a precomputation file exists
*)
let rgopt =
if precomp_exists = None then
Some
(ZGI.input_zone_graph ~verbose ~print_rg ~splitting_debug
?export_zone_graph infile)
else None
in
let module Param =
( val gen_param
( match (rgopt, precomp_exists) with
| Some a, _ -> a.ZoneGraph.var_string
| _, Some b -> b.ZoneGraph.var_string
| None, None -> assert false )
rational_impl frequency expected_duration boltzmann_param
expected_size verbose npoly )
in
let module Weight = Instantiate (Flq.Q) (Bound) (Param) () in
let rgpoly =
match (precomp_exists, rgopt) with
| Some content, _ ->
if verbose > 0 then
printf "Reading Distribution%s -> %i@." Weight.desc npoly;
content
| _, Some rg -> Weight.compute_weight print_rg infile rg
| None, None -> assert false
in
(*Save computation*)
ZoneGraphInput.save_precomputation infile rgpoly frequency npoly
(frequency = None && expected_duration <> None)
rational_impl;
let boltz, smp = Weight.compute_params ?seed rgpoly in
(* tidying up memory after the distribution computation*)
Gc.compact ();
if print_rg then printf "%a@." (ZoneGraph.print Bound.print) rgpoly;
let outfile =
match outfilename with
| Some st -> formatter_of_out_channel @@ open_out st
| None -> Format.std_formatter
in
Weight.sample smp ~outfile ?seed ?boltz
~out_style:(out_style, is_interactive)
~max_iter:max_iteration
~sampler:(Low_disc_sampler.get_sampler sampler)
~store_traj rgpoly template nbtraj
......@@ -20,10 +20,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*)
open Format
open Arguments
open Common
open Wordgen_lib
open Arguments
(* Parsing Arguments *)
let _ = Format.set_margin 190
......@@ -43,95 +42,22 @@ let _ =
if !narg < 1 then (
Arg.usage spec_caml_arg usage_str;
exit 1 );
if !verbose > 1 then
( if !verbose > 1 then
let cmd = build_cmd spec_full in
print_endline ("parameters : " ^ cmd)
print_endline ("parameters : " ^ cmd) );
post_parse ()
(* Main *)
let _ =
(* check if precomputation exists *)
let precomp_exists =
if !print_rg then None
else
ZoneGraphInput.precomputation_exists
~debug:(fun b ->
if !verbose > 0 then
if b then
printf "Precomputation file found ! [%.2f]@." (check_time ())
else
printf
"Precomputation file found but file have change discard !@.")
!infile !frequency !npoly
(!frequency = None && !expected_duration <> None)
!rational_impl
in
(* Use splitted or general bound, general only for isotropic sampling *)
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
(*Building the zone graph
None means that a precomputation file exists
*)
let rgopt =
if precomp_exists = None then
Some
(ZGI.input_zone_graph ~verbose:!verbose ~print_rg:!print_rg
~splitting_debug:!splitting_debug
?export_zone_graph:!export_zone_graph !infile)
else None
in
let module Param =
( val post_parse
( match (rgopt, precomp_exists) with
| Some a, _ -> a.ZoneGraph.var_string
| _, Some b -> b.ZoneGraph.var_string
| None, None -> assert false ) )
in
let module Weight = Compute.Instantiate (Flq.Q) (Bound) (Param) () in
let rgpoly =
match (precomp_exists, rgopt) with
| Some content, _ ->
if !verbose > 0 then
printf "Reading Distribution%s -> %i@." Weight.desc !npoly;
content
| _, Some rg -> Weight.compute_weight !print_rg !infile rg
| None, None -> assert false
in
(*Save computation*)
ZoneGraphInput.save_precomputation !infile rgpoly !frequency !npoly
(!frequency = None && !expected_duration <> None)
!rational_impl;
let boltz, smp = Weight.compute_params ?seed:!random_seed rgpoly in
(* tidying up memory after the distribution computation*)
Gc.compact ();
if !print_rg then printf "%a@." (ZoneGraph.print Bound.print) rgpoly;
let outfile =
match !outfilename with
| Some st -> formatter_of_out_channel @@ open_out st
| None -> Format.std_formatter
in
Weight.sample smp ~outfile ?seed:!Arguments.random_seed ?boltz
~out_style:(!out_style, !is_interactive)
~max_iter:!max_iteration
~sampler:(Low_disc_sampler.get_sampler !sampler)
~store_traj:!store_traj rgpoly !template !nbtraj
Compute.main !print_rg !infile !frequency !npoly !expected_duration
!boltzmann_param !expected_size !rational_impl !verbose !splitting_debug
!export_zone_graph !outfilename !out_style !random_seed !is_interactive
!max_iteration !sampler !store_traj !template !nbtraj
(* start gnuplot on the computed data*)
let _ =
let data = !outfilename |>>| "gnuplotout.dat" in
let gnucmd =
match !Arguments.gnuplot_cmd with
match !gnuplot_cmd with
| Some x -> Some x
| None -> OutFormat.plot_of_style !out_style !store_traj !nbtraj data
in
......@@ -152,6 +78,7 @@ let _ =
fprintf gnuplot "set pointsize 0.1\n";
fprintf gnuplot "%s" gnucmd;
ignore @@ Unix.close_process_out gnuplot
| None, Some _, _ -> eprintf "No output file specified, cannot use gnuplot\n"
| _, Some _, None -> eprintf "Nothing to plot, cannot use gnuplot\n"
| None, Some _, _ ->
Format.eprintf "No output file specified, cannot use gnuplot\n"
| _, Some _, None -> Format.eprintf "Nothing to plot, cannot use gnuplot\n"
| _, None, _ -> ()
......@@ -18,8 +18,11 @@ let computation ta outfile =
in
let module ZGI = ZoneGraphInput.Make (Bound) in
let rg = ZGI.input_from_string ta in
let module Param = (val post_parse rg.ZoneGraph.var_string) 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 )
in
if not !only_parse then (
let module Weight = Compute.Instantiate (Fl.Num) (Bound) (Param) () in
let rgpoly = Weight.compute_weight !print_rg !infile rg in
......
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