1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
use crate::proxy::TheoryConstraint;
use std::{fmt, time::Duration};
#[cfg(feature = "profiling")]
mod timer {
use std::time::{Duration, Instant};
#[derive(Clone, Copy)]
pub(crate) struct Span(Instant);
#[inline(always)]
pub(crate) fn start() -> Span {
Span(Instant::now())
}
#[inline(always)]
pub(crate) fn record(dst: &mut Duration, span: Span) {
*dst += span.0.elapsed();
}
}
#[cfg(not(feature = "profiling"))]
mod timer {
use std::time::Duration;
#[derive(Clone, Copy)]
pub(crate) struct Span;
#[inline(always)]
pub(crate) fn start() -> Span {
Span
}
#[inline(always)]
pub(crate) fn record(_dst: &mut Duration, _span: Span) {}
}
pub(crate) use timer::Span;
#[derive(Clone, Copy)]
pub(crate) enum TheoryKind {
Lra,
Dl,
Enum,
Other,
}
impl TheoryKind {
#[inline]
pub(crate) fn of(c: &TheoryConstraint) -> Self {
match c {
TheoryConstraint::LraLb(..) | TheoryConstraint::LraUb(..) => Self::Lra,
TheoryConstraint::DlLeq(..) => Self::Dl,
TheoryConstraint::EnumEq(..) => Self::Enum,
_ => Self::Other,
}
}
}
/// Breakdown of cumulative wall-clock time spent across solver phases.
///
/// Populated only when the `profiling` feature is enabled; otherwise
/// [`SmtStats::timing`] is `None`.
#[derive(Debug, Clone, Copy, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TimingStats {
/// Total wall-clock time spent inside [`crate::SeMiTONE::propagate`]
/// (including calls made internally by [`crate::SeMiTONE::probe_implied`]).
pub prop_total: Duration,
/// Time spent in SAT Boolean Constraint Propagation (`SatSolver::propagate`),
/// including SAT-level 1-UIP conflict analysis on propositional conflicts.
pub sat_prop: Duration,
/// Time spent asserting individual LRA lower/upper bounds during trail notification.
pub lra_bound: Duration,
/// Time spent asserting Difference Logic edges and mirroring them to LRA when needed.
pub dl: Duration,
/// Time spent asserting equality and disequality constraints in the finite-domain enum theory.
pub enum_theory: Duration,
/// Time spent in the LRA Simplex feasibility check (`LraTheory::check`).
pub lra_check: Duration,
/// Time spent in SAT 1-UIP conflict analysis triggered by theory-level conflict lemmas.
pub analyze: Duration,
/// Time spent inserting and simplifying clauses via [`crate::SeMiTONE::add_clause`]
/// and [`crate::SeMiTONE::add_learnt_clause`] (including LBD-based database reductions).
pub add_clause: Duration,
/// Time spent backtracking SAT and all theory states in [`crate::SeMiTONE::cancel_until`].
pub cancel: Duration,
}
impl TimingStats {
/// Time spent inside `SeMiTONE::propagate` outside SAT/theory/analysis sub-timers.
pub fn prop_other(&self) -> Duration {
let inner = self.sat_prop + self.lra_bound + self.dl + self.enum_theory + self.lra_check + self.analyze;
self.prop_total.saturating_sub(inner)
}
}
/// Structured runtime statistics snapshot for [`crate::SeMiTONE`].
///
/// Counters reflect either the current solver state (e.g. `num_vars`, `num_clauses`,
/// tableau dimensions) or cumulative totals since solver creation (e.g. conflicts,
/// reductions, pivots). Phase timings are recorded in [`Self::timing`] when the
/// `profiling` feature is enabled.
#[derive(Debug, Clone, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SmtStats {
/// Cumulative number of calls to [`crate::SeMiTONE::propagate`]
/// (including propagation rounds executed inside [`crate::SeMiTONE::probe_implied`]).
pub prop_calls: usize,
/// Current number of allocated SAT Boolean variables, including both
/// user-created variables and internal theory/Tseitin proxy variables.
pub num_vars: usize,
/// Current total number of multi-literal clauses stored in the SAT database
/// (permanent problem clauses plus currently retained learnt clauses).
/// Unit clauses are absorbed directly into the assignment trail and are not counted here.
pub num_clauses: usize,
/// Current number of learnt clauses retained in the SAT database (a subset of [`Self::num_clauses`]).
pub num_learnts: usize,
/// Cumulative number of LBD-based learnt-clause database reductions performed so far.
pub db_reductions: usize,
/// Cumulative number of learnt clauses removed by database reductions.
pub clauses_deleted: usize,
/// Cumulative number of propositional conflicts detected during SAT unit propagation.
pub sat_conflicts: usize,
/// Cumulative number of immediate bound conflicts (e.g., `lb > ub`) detected
/// while notifying the LRA theory of individual bound literals.
pub lra_bound_conflicts: usize,
/// Cumulative number of linear infeasibility conflicts detected by the
/// LRA Simplex feasibility check.
pub lra_check_conflicts: usize,
/// Cumulative number of negative-cycle conflicts detected by the Difference Logic theory.
pub dl_conflicts: usize,
/// Cumulative number of domain-wipeout conflicts detected by the finite-domain enum theory.
pub enum_conflicts: usize,
/// Cumulative number of multi-literal learnt clauses added via [`crate::SeMiTONE::add_learnt_clause`].
/// Serves as the denominator for [`Self::avg_learnt_len`] and [`Self::avg_learnt_lbd`].
pub learnt_added: usize,
/// Cumulative sum of literal counts across all learnt clauses counted in [`Self::learnt_added`].
pub learnt_lits_sum: usize,
/// Cumulative sum of initial Literal Block Distance (LBD) scores across all
/// learnt clauses counted in [`Self::learnt_added`].
pub learnt_lbd_sum: usize,
/// Cumulative number of Simplex pivots executed by the LRA theory during
/// feasibility checks and optimization.
pub lra_pivots: usize,
/// Current number of active basic rows in the LRA Simplex tableau.
pub lra_rows: usize,
/// Current total number of non-zero coefficients across all active LRA tableau rows.
pub lra_nnz: usize,
/// Current maximum number of non-zero terms in any single active LRA tableau row.
pub lra_max_row: usize,
/// Optional wall-clock phase timings; `Some(_)` when built with the `profiling` feature,
/// `None` otherwise.
pub timing: Option<TimingStats>,
}
impl SmtStats {
/// Returns the average number of literals per learnt clause, or `0.0` if no learnt clauses have been added yet.
pub fn avg_learnt_len(&self) -> f64 {
if self.learnt_added == 0 { 0.0 } else { self.learnt_lits_sum as f64 / self.learnt_added as f64 }
}
/// Returns the average initial LBD score per learnt clause, or `0.0` if no learnt clauses have been added yet.
pub fn avg_learnt_lbd(&self) -> f64 {
if self.learnt_added == 0 { 0.0 } else { self.learnt_lbd_sum as f64 / self.learnt_added as f64 }
}
}
impl fmt::Display for SmtStats {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"calls={} vars={} cl={}(lrn={}, red={}, del={}) sat_c={} lra_b_c={} lra_chk_c={} dl_c={} enum_c={} avg_len={:.1} avg_lbd={:.1} | pivots={} rows={} nnz={} max_row={}",
self.prop_calls,
self.num_vars,
self.num_clauses,
self.num_learnts,
self.db_reductions,
self.clauses_deleted,
self.sat_conflicts,
self.lra_bound_conflicts,
self.lra_check_conflicts,
self.dl_conflicts,
self.enum_conflicts,
self.avg_learnt_len(),
self.avg_learnt_lbd(),
self.lra_pivots,
self.lra_rows,
self.lra_nnz,
self.lra_max_row,
)?;
if let Some(t) = &self.timing {
write!(f, " | prop_tot={:.2?} sat={:.2?} lra_b={:.2?} dl={:.2?} enum={:.2?} lra_chk={:.2?} analyze={:.2?} other={:.2?} add_cl={:.2?} cancel={:.2?}", t.prop_total, t.sat_prop, t.lra_bound, t.dl, t.enum_theory, t.lra_check, t.analyze, t.prop_other(), t.add_clause, t.cancel,)?;
}
Ok(())
}
}
#[derive(Default)]
pub(crate) struct SmtProf {
prop_calls: usize,
sat_conflicts: usize,
lra_bound_conflicts: usize,
lra_check_conflicts: usize,
dl_conflicts: usize,
enum_conflicts: usize,
timing: TimingStats,
}
impl SmtProf {
#[inline(always)]
pub(crate) fn start() -> Span {
timer::start()
}
#[inline(always)]
pub(crate) fn on_prop_call(&mut self) {
self.prop_calls += 1;
}
#[inline(always)]
pub(crate) fn stop_sat_prop(&mut self, t: Span) {
timer::record(&mut self.timing.sat_prop, t);
}
#[inline(always)]
pub(crate) fn on_sat_conflict(&mut self) {
self.sat_conflicts += 1;
}
#[inline(always)]
pub(crate) fn stop_notify(&mut self, t: Span, kind: TheoryKind) {
match kind {
TheoryKind::Lra => timer::record(&mut self.timing.lra_bound, t),
TheoryKind::Dl => timer::record(&mut self.timing.dl, t),
TheoryKind::Enum => timer::record(&mut self.timing.enum_theory, t),
TheoryKind::Other => {}
}
}
#[inline(always)]
pub(crate) fn on_notify_conflict(&mut self, kind: TheoryKind) {
match kind {
TheoryKind::Lra => self.lra_bound_conflicts += 1,
TheoryKind::Dl => self.dl_conflicts += 1,
TheoryKind::Enum => self.enum_conflicts += 1,
TheoryKind::Other => {}
}
}
#[inline(always)]
pub(crate) fn stop_lra_check(&mut self, t: Span) {
timer::record(&mut self.timing.lra_check, t);
}
#[inline(always)]
pub(crate) fn on_lra_check_conflict(&mut self) {
self.lra_check_conflicts += 1;
}
#[inline(always)]
pub(crate) fn stop_analyze(&mut self, t: Span) {
timer::record(&mut self.timing.analyze, t);
}
#[inline(always)]
pub(crate) fn stop_cancel(&mut self, t: Span) {
timer::record(&mut self.timing.cancel, t);
}
#[inline(always)]
pub(crate) fn stop_prop_total(&mut self, t: Span) {
timer::record(&mut self.timing.prop_total, t);
}
#[inline(always)]
pub(crate) fn stop_add_clause(&mut self, t: Span) {
timer::record(&mut self.timing.add_clause, t);
}
pub(crate) fn snapshot(&self, num_vars: usize, (num_clauses, num_learnts, db_reductions, clauses_deleted, learnt_added, learnt_lits_sum, learnt_lbd_sum): (usize, usize, usize, usize, usize, usize, usize), lra_pivots: usize, (lra_rows, lra_nnz, lra_max_row): (usize, usize, usize)) -> SmtStats {
#[cfg(feature = "profiling")]
let timing = Some(self.timing);
#[cfg(not(feature = "profiling"))]
let timing = None;
SmtStats {
prop_calls: self.prop_calls,
num_vars,
num_clauses,
num_learnts,
db_reductions,
clauses_deleted,
sat_conflicts: self.sat_conflicts,
lra_bound_conflicts: self.lra_bound_conflicts,
lra_check_conflicts: self.lra_check_conflicts,
dl_conflicts: self.dl_conflicts,
enum_conflicts: self.enum_conflicts,
learnt_added,
learnt_lits_sum,
learnt_lbd_sum,
lra_pivots,
lra_rows,
lra_nnz,
lra_max_row,
timing,
}
}
}