Skip to content

Commit

Permalink
Merge pull request #18 from reinismu/print-progress
Browse files Browse the repository at this point in the history
Print progress for layers compute
  • Loading branch information
krukah authored Oct 15, 2024
2 parents c528117 + 75eb507 commit 8231a0d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
38 changes: 37 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ log = "0.4.22"
env_logger = "0.11.5"
rayon = "1.10.0"
byteorder = "1.5.0"
itertools = "0.13.0"
indicatif = "0.17.8"

[dev-dependencies]
criterion = { version = "0.3", features = ["html_reports"] }
Expand Down
18 changes: 15 additions & 3 deletions src/clustering/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use crate::clustering::abstraction::Abstraction;
use crate::clustering::histogram::Histogram;
use crate::clustering::metric::Metric;
use crate::clustering::xor::Pair;
use indicatif::ProgressBar;
use indicatif::ProgressStyle;
use rand::distributions::Distribution;
use rand::distributions::WeightedIndex;
use rand::rngs::StdRng;
Expand Down Expand Up @@ -77,7 +79,7 @@ impl Layer {
/// simply go to the previous street
fn inner_street(&self) -> Street {
log::info!(
"advancing street from {} to {}",
"advancing street from {} -> {}",
self.street,
self.street.prev()
);
Expand All @@ -91,7 +93,7 @@ impl Layer {
/// the distnace isn't symmetric in the first place only because our heuristic algo is not fully accurate
fn inner_metric(&self) -> Metric {
log::info!(
"computing metric from {} to {}",
"computing metric from {} -> {}",
self.street,
self.street.prev()
);
Expand Down Expand Up @@ -119,17 +121,27 @@ impl Layer {
/// 4. collect `Abstraction`s into a `Histogram`, for each `Observation`
fn inner_points(&self) -> ObservationSpace {
log::info!(
"computing projections from {} to {}",
"computing projections from {} -> {}",
self.street,
self.street.prev()
);
// pretty progress bar
let n = self.street.prev().n_isomorphisms() as u64;
let tick = std::time::Duration::from_secs(5);
let style = "[{elapsed}] {spinner:.green} {wide_bar:.green} ETA {eta}";
let style = ProgressStyle::with_template(style).unwrap();
let progress = ProgressBar::new(n);
progress.set_style(style);
progress.enable_steady_tick(tick);
//
ObservationSpace(
Observation::exhaust(self.street.prev())
.filter(|o| Isomorphism::is_canonical(o))
.map(|o| Isomorphism::from(o)) // isomorphism translation
.collect::<Vec<Isomorphism>>() // isomorphism translation
.into_par_iter()
.map(|inner| (inner, self.lookup.projection(&inner)))
.inspect(|_| progress.inc(1))
.collect::<BTreeMap<Isomorphism, Histogram>>(),
)
}
Expand Down

0 comments on commit 8231a0d

Please sign in to comment.