Skip to content

Commit ac13db9

Browse files
committed
Disable timing by default, enable when needed
1 parent 694782f commit ac13db9

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

crates/argmin/src/core/executor.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ where
7070
checkpoint: None,
7171
timeout: None,
7272
ctrlc: true,
73-
timer: true,
73+
timer: false,
7474
}
7575
}
7676

@@ -313,6 +313,7 @@ where
313313
mode: ObserverMode,
314314
) -> Self {
315315
self.observers.push(observer, mode);
316+
self.timer = true;
316317
self
317318
}
318319

@@ -383,9 +384,9 @@ where
383384
self
384385
}
385386

386-
/// Enables or disables timing of individual iterations (default: enabled).
387+
/// Enables or disables timing of individual iterations (default: false).
387388
///
388-
/// Setting this to false will silently be ignored in case a timeout is set.
389+
/// In case a timeout is set, this will automatically be set to true.
389390
///
390391
/// # Example
391392
///
@@ -766,7 +767,7 @@ mod tests {
766767
let problem = TestProblem::new();
767768
let timeout = std::time::Duration::from_secs(2);
768769

769-
let executor = Executor::new(problem, solver);
770+
let executor = Executor::new(problem, solver).timer(true);
770771
assert!(executor.timer);
771772
assert!(executor.timeout.is_none());
772773

crates/argmin/src/core/state/iterstate.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ pub struct IterState<P, G, J, H, R, F> {
8282
pub max_iters: u64,
8383
/// Evaluation counts
8484
pub counts: HashMap<String, u64>,
85+
/// Update evaluation counts?
86+
pub counting_enabled: bool,
8587
/// Time required so far
8688
pub time: Option<instant::Duration>,
8789
/// Status of optimization execution
@@ -1040,6 +1042,7 @@ where
10401042
last_best_iter: 0,
10411043
max_iters: std::u64::MAX,
10421044
counts: HashMap::new(),
1045+
counting_enabled: false,
10431046
time: Some(instant::Duration::new(0, 0)),
10441047
termination_status: TerminationStatus::NotTerminated,
10451048
}
@@ -1339,7 +1342,7 @@ where
13391342
/// ```
13401343
/// # use std::collections::HashMap;
13411344
/// # use argmin::core::{Problem, IterState, State, ArgminFloat};
1342-
/// # let mut state: IterState<Vec<f64>, (), (), (), (), f64> = IterState::new();
1345+
/// # let mut state: IterState<Vec<f64>, (), (), (), (), f64> = IterState::new().counting(true);
13431346
/// # assert_eq!(state.counts, HashMap::new());
13441347
/// # state.counts.insert("test2".to_string(), 10u64);
13451348
/// #
@@ -1356,9 +1359,11 @@ where
13561359
/// # assert_eq!(state.counts, hm);
13571360
/// ```
13581361
fn func_counts<O>(&mut self, problem: &Problem<O>) {
1359-
for (k, &v) in problem.counts.iter() {
1360-
let count = self.counts.entry(k.to_string()).or_insert(0);
1361-
*count = v
1362+
if self.counting_enabled {
1363+
for (k, &v) in problem.counts.iter() {
1364+
let count = self.counts.entry(k.to_string()).or_insert(0);
1365+
*count = v
1366+
}
13621367
}
13631368
}
13641369

0 commit comments

Comments
 (0)