feat(lra): expose some stats

This commit is contained in:
Simon Cruanes 2021-02-16 19:18:45 -05:00
parent e2d3afb4df
commit aa20605567
2 changed files with 19 additions and 6 deletions

View file

@ -74,7 +74,7 @@ module type S = sig
type state type state
val create : A.S.T.Term.state -> state val create : ?stat:Stat.t -> A.S.T.Term.state -> state
val theory : A.S.theory val theory : A.S.theory
end end
@ -133,7 +133,7 @@ module Make(A : ARG) : S with module A = A = struct
simplex: SimpSolver.t; simplex: SimpSolver.t;
} }
let create tst : state = let create ?stat tst : state =
{ tst; { tst;
simps=T.Tbl.create 128; simps=T.Tbl.create 128;
gensym=A.Gensym.create tst; gensym=A.Gensym.create tst;
@ -141,7 +141,7 @@ module Make(A : ARG) : S with module A = A = struct
needs_th_combination=T.Tbl.create 8; needs_th_combination=T.Tbl.create 8;
encoded_le=Comb_map.empty; encoded_le=Comb_map.empty;
local_eqs = Backtrack_stack.create(); local_eqs = Backtrack_stack.create();
simplex=SimpSolver.create (); simplex=SimpSolver.create ?stat ();
} }
let push_level self = let push_level self =
@ -477,7 +477,8 @@ module Make(A : ARG) : S with module A = A = struct
let create_and_setup si = let create_and_setup si =
Log.debug 2 "(th-lra.setup)"; Log.debug 2 "(th-lra.setup)";
let st = create (SI.tst si) in let stat = SI.stats si in
let st = create ~stat (SI.tst si) in
(* TODO SI.add_simplifier si (simplify st); *) (* TODO SI.add_simplifier si (simplify st); *)
SI.add_preprocess si (preproc_lra st); SI.add_preprocess si (preproc_lra st);
SI.on_final_check si (final_check_ st); SI.on_final_check si (final_check_ st);

View file

@ -71,7 +71,7 @@ module type S = sig
type t type t
val create : unit -> t val create : ?stat:Stat.t -> unit -> t
(** Create a new simplex. *) (** Create a new simplex. *)
val push_level : t -> unit val push_level : t -> unit
@ -372,6 +372,9 @@ module Make(Var: VAR)
vars: var_state Vec.t; (* index -> var with this index *) vars: var_state Vec.t; (* index -> var with this index *)
mutable var_tbl: var_state V_map.t; (* var -> its state *) mutable var_tbl: var_state V_map.t; (* var -> its state *)
bound_stack: (var_state * [`Upper|`Lower] * bound option) Backtrack_stack.t; bound_stack: (var_state * [`Upper|`Lower] * bound option) Backtrack_stack.t;
stat_check: int Stat.counter;
stat_unsat: int Stat.counter;
stat_define: int Stat.counter;
} }
let push_level self : unit = let push_level self : unit =
@ -438,6 +441,7 @@ module Make(Var: VAR)
(* define [x] as a basic variable *) (* define [x] as a basic variable *)
let define (self:t) (x:V.t) (le:_ list) : unit = let define (self:t) (x:V.t) (le:_ list) : unit =
assert (not (has_var_ self x)); assert (not (has_var_ self x));
Stat.incr self.stat_define;
(* Log.debugf 50 (fun k->k "define-in: %a" pp self); *) (* Log.debugf 50 (fun k->k "define-in: %a" pp self); *)
let le = List.map (fun (q,v) -> q, find_var_ self v) le in let le = List.map (fun (q,v) -> q, find_var_ self v) le in
@ -685,6 +689,7 @@ module Make(Var: VAR)
| _, Some upper when Erat.(new_bnd.b_val > upper.b_val) -> | _, Some upper when Erat.(new_bnd.b_val > upper.b_val) ->
(* [b_val <= x <= upper], but [b_val > upper] *) (* [b_val <= x <= upper], but [b_val > upper] *)
let cert = Unsat_cert.bounds vs ~lower:new_bnd ~upper in let cert = Unsat_cert.bounds vs ~lower:new_bnd ~upper in
Stat.incr self.stat_unsat;
raise (E_unsat cert) raise (E_unsat cert)
| Some lower, _ when Erat.(lower.b_val >= new_bnd.b_val) -> | Some lower, _ when Erat.(lower.b_val >= new_bnd.b_val) ->
() (* subsumed by existing constraint, do nothing *) () (* subsumed by existing constraint, do nothing *)
@ -704,6 +709,7 @@ module Make(Var: VAR)
| Some lower, _ when Erat.(new_bnd.b_val < lower.b_val) -> | Some lower, _ when Erat.(new_bnd.b_val < lower.b_val) ->
(* [lower <= x <= b_val], but [b_val < lower] *) (* [lower <= x <= b_val], but [b_val < lower] *)
let cert = Unsat_cert.bounds vs ~lower ~upper:new_bnd in let cert = Unsat_cert.bounds vs ~lower ~upper:new_bnd in
Stat.incr self.stat_unsat;
raise (E_unsat cert) raise (E_unsat cert)
| _, Some upper when Erat.(upper.b_val <= new_bnd.b_val) -> | _, Some upper when Erat.(upper.b_val <= new_bnd.b_val) ->
() (* subsumed *) () (* subsumed *)
@ -810,6 +816,7 @@ module Make(Var: VAR)
let check_exn (self:t) : unit = let check_exn (self:t) : unit =
let exception Stop in let exception Stop in
Log.debugf 20 (fun k->k "(@[simplex2.check@ %a@])" pp_stats self); Log.debugf 20 (fun k->k "(@[simplex2.check@ %a@])" pp_stats self);
Stat.incr self.stat_check;
let m = self.matrix in let m = self.matrix in
try try
@ -837,6 +844,7 @@ module Make(Var: VAR)
| Some x -> x | Some x -> x
| None -> | None ->
let cert = cert_of_row_ self x_i bnd ~is_lower:true in let cert = cert_of_row_ self x_i bnd ~is_lower:true in
Stat.incr self.stat_unsat;
raise (E_unsat cert) raise (E_unsat cert)
in in
assert (Var_state.is_n_basic x_j); assert (Var_state.is_n_basic x_j);
@ -859,6 +867,7 @@ module Make(Var: VAR)
| Some x -> x | Some x -> x
| None -> | None ->
let cert = cert_of_row_ self x_i bnd ~is_lower:false in let cert = cert_of_row_ self x_i bnd ~is_lower:false in
Stat.incr self.stat_unsat;
raise (E_unsat cert) raise (E_unsat cert)
in in
assert (Var_state.is_n_basic x_j); assert (Var_state.is_n_basic x_j);
@ -874,12 +883,15 @@ module Make(Var: VAR)
Log.debugf 50 (fun k->k "(@[simplex2.check.done@])"); Log.debugf 50 (fun k->k "(@[simplex2.check.done@])");
() ()
let create () : t = let create ?(stat=Stat.global) () : t =
let self = { let self = {
matrix=Matrix.create(); matrix=Matrix.create();
vars=Vec.create(); vars=Vec.create();
var_tbl=V_map.empty; var_tbl=V_map.empty;
bound_stack=Backtrack_stack.create(); bound_stack=Backtrack_stack.create();
stat_check=Stat.mk_int stat "simplex.check";
stat_unsat=Stat.mk_int stat "simplex.unsat";
stat_define=Stat.mk_int stat "simplex.define";
} in } in
self self