Skip to content

Commit

Permalink
Disable timing by default, enable when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
pacak committed Mar 26, 2024
1 parent 35e00e2 commit 3ba43d9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
8 changes: 4 additions & 4 deletions crates/argmin/src/core/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ where
checkpoint: None,
timeout: None,
ctrlc: true,
timer: true,
timer: false,
}
}

Expand Down Expand Up @@ -383,9 +383,9 @@ where
self
}

/// Enables or disables timing of individual iterations (default: enabled).
/// Enables or disables timing of individual iterations (default: false).
///
/// Setting this to false will silently be ignored in case a timeout is set.
/// In case a timeout is set, this will automatically be set to true.
///
/// # Example
///
Expand Down Expand Up @@ -766,7 +766,7 @@ mod tests {
let problem = TestProblem::new();
let timeout = std::time::Duration::from_secs(2);

let executor = Executor::new(problem, solver);
let executor = Executor::new(problem, solver).timer(true);
assert!(executor.timer);
assert!(executor.timeout.is_none());

Expand Down
13 changes: 9 additions & 4 deletions crates/argmin/src/core/state/iterstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ pub struct IterState<P, G, J, H, R, F> {
pub max_iters: u64,
/// Evaluation counts
pub counts: HashMap<String, u64>,
/// Update evaluation counts?
pub counting_enabled: bool,
/// Time required so far
pub time: Option<instant::Duration>,
/// Status of optimization execution
Expand Down Expand Up @@ -1040,6 +1042,7 @@ where
last_best_iter: 0,
max_iters: std::u64::MAX,
counts: HashMap::new(),
counting_enabled: false,
time: Some(instant::Duration::new(0, 0)),
termination_status: TerminationStatus::NotTerminated,
}
Expand Down Expand Up @@ -1339,7 +1342,7 @@ where
/// ```
/// # use std::collections::HashMap;
/// # use argmin::core::{Problem, IterState, State, ArgminFloat};
/// # let mut state: IterState<Vec<f64>, (), (), (), (), f64> = IterState::new();
/// # let mut state: IterState<Vec<f64>, (), (), (), (), f64> = IterState::new().counting(true);
/// # assert_eq!(state.counts, HashMap::new());
/// # state.counts.insert("test2".to_string(), 10u64);
/// #
Expand All @@ -1356,9 +1359,11 @@ where
/// # assert_eq!(state.counts, hm);
/// ```
fn func_counts<O>(&mut self, problem: &Problem<O>) {
for (k, &v) in problem.counts.iter() {
let count = self.counts.entry(k.to_string()).or_insert(0);
*count = v
if self.counting_enabled {
for (k, &v) in problem.counts.iter() {
let count = self.counts.entry(k.to_string()).or_insert(0);
*count = v
}
}
}

Expand Down

0 comments on commit 3ba43d9

Please sign in to comment.