diff --git a/.gitignore b/.gitignore index c68d905e..0d054205 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,4 @@ dist/ *.parquet *.profraw lcov.txt - +.DS_Store diff --git a/src/cosmic/mod.rs b/src/cosmic/mod.rs index 7b1be543..d9864c65 100644 --- a/src/cosmic/mod.rs +++ b/src/cosmic/mod.rs @@ -28,6 +28,7 @@ use hifitime::SECONDS_PER_DAY; use std::fmt; use std::fs::File; use std::io::Read; +#[cfg(not(target_arch = "wasm32"))] use std::time::Instant; /// A trait allowing for something to have an epoch @@ -180,10 +181,12 @@ impl Xb { return Err(NyxError::LoadingError("XB buffer is empty".to_string())); } + #[cfg(not(target_arch = "wasm32"))] let decode_start = Instant::now(); match Self::decode(input_xb_buf) { Ok(xb) => { + #[cfg(not(target_arch = "wasm32"))] debug!("Loaded XB in {} ms.", decode_start.elapsed().as_millis()); Ok(xb) } diff --git a/src/mc/montecarlo.rs b/src/mc/montecarlo.rs index bea825c6..debf0428 100644 --- a/src/mc/montecarlo.rs +++ b/src/mc/montecarlo.rs @@ -25,7 +25,9 @@ use crate::mc::DispersedState; use crate::md::trajectory::Interpolatable; use crate::md::EventEvaluator; use crate::propagators::{ErrorCtrl, Propagator}; -use crate::time::{Duration, Epoch, Unit}; +#[cfg(not(target_arch = "wasm32"))] +use crate::time::Unit; +use crate::time::{Duration, Epoch}; use crate::State; use indicatif::{ParallelProgressIterator, ProgressBar, ProgressStyle}; use rand_distr::Distribution; @@ -34,6 +36,7 @@ use rayon::prelude::*; use std::f64; use std::fmt; use std::sync::mpsc::channel; +#[cfg(not(target_arch = "wasm32"))] use std::time::Instant as StdInstant; /// A Monte Carlo framework, automatically running on all threads via a thread pool. This framework is targeted toward analysis of time-continuous variables. @@ -126,6 +129,7 @@ where let (tx, rx) = channel(); // Generate all states (must be done separately because the rng is not thread safe) + #[cfg(not(target_arch = "wasm32"))] let start = StdInstant::now(); init_states.par_iter().progress_with(pb).for_each_with( (prop, tx), @@ -147,12 +151,15 @@ where }, ); - let clock_time = StdInstant::now() - start; - println!( - "Propagated {} states in {}", - num_runs, - clock_time.as_secs_f64() * Unit::Second - ); + #[cfg(not(target_arch = "wasm32"))] + { + let clock_time = StdInstant::now() - start; + println!( + "Propagated {} states in {}", + num_runs, + clock_time.as_secs_f64() * Unit::Second + ); + } // Collect all of the results and sort them by run index let mut runs = rx @@ -214,6 +221,7 @@ where let (tx, rx) = channel(); // And propagate on the thread pool + #[cfg(not(target_arch = "wasm32"))] let start = StdInstant::now(); init_states.par_iter().progress_with(pb).for_each_with( (prop, tx), @@ -236,12 +244,15 @@ where }, ); - let clock_time = StdInstant::now() - start; - println!( - "Propagated {} states in {}", - num_runs, - clock_time.as_secs_f64() * Unit::Second - ); + #[cfg(not(target_arch = "wasm32"))] + { + let clock_time = StdInstant::now() - start; + println!( + "Propagated {} states in {}", + num_runs, + clock_time.as_secs_f64() * Unit::Second + ); + } // Collect all of the results and sort them by run index let mut runs = rx.iter().collect::>>>(); diff --git a/src/md/opti/raphson_finite_diff.rs b/src/md/opti/raphson_finite_diff.rs index 0e684344..083ae9eb 100644 --- a/src/md/opti/raphson_finite_diff.rs +++ b/src/md/opti/raphson_finite_diff.rs @@ -29,6 +29,7 @@ use crate::propagators::error_ctrl::ErrorCtrl; use crate::pseudo_inverse; use hifitime::TimeUnits; use rayon::prelude::*; +#[cfg(not(target_arch = "wasm32"))] use std::time::Instant; impl<'a, E: ErrorCtrl, const V: usize, const O: usize> Optimizer<'a, E, V, O> { @@ -195,6 +196,7 @@ impl<'a, E: ErrorCtrl, const V: usize, const O: usize> Optimizer<'a, E, V, O> { let width = f64::from(max_obj_val).log10() as usize + 2 + max_obj_tol; + #[cfg(not(target_arch = "wasm32"))] let start_instant = Instant::now(); for it in 0..=self.iterations { @@ -457,7 +459,10 @@ impl<'a, E: ErrorCtrl, const V: usize, const O: usize> Optimizer<'a, E, V, O> { } if converged { + #[cfg(not(target_arch = "wasm32"))] let conv_dur = Instant::now() - start_instant; + #[cfg(target_arch = "wasm32")] + let conv_dur = Duration::ZERO.into(); let mut corrected_state = xi_start; let mut state_correction = Vector6::::zeros(); diff --git a/src/md/opti/raphson_hyperdual.rs b/src/md/opti/raphson_hyperdual.rs index ca613747..bc2153a0 100644 --- a/src/md/opti/raphson_hyperdual.rs +++ b/src/md/opti/raphson_hyperdual.rs @@ -25,6 +25,7 @@ pub use crate::md::{Variable, Vary}; use crate::propagators::error_ctrl::ErrorCtrl; use crate::pseudo_inverse; use crate::utils::are_eigenvalues_stable; +#[cfg(not(target_arch = "wasm32"))] use std::time::Instant; impl<'a, E: ErrorCtrl, const V: usize, const O: usize> Optimizer<'a, E, V, O> { @@ -118,6 +119,7 @@ impl<'a, E: ErrorCtrl, const V: usize, const O: usize> Optimizer<'a, E, V, O> { let width = f64::from(max_obj_val).log10() as usize + 2 + max_obj_tol; + #[cfg(not(target_arch = "wasm32"))] let start_instant = Instant::now(); for it in 0..=self.iterations { @@ -216,7 +218,10 @@ impl<'a, E: ErrorCtrl, const V: usize, const O: usize> Optimizer<'a, E, V, O> { } if converged { + #[cfg(not(target_arch = "wasm32"))] let conv_dur = Instant::now() - start_instant; + #[cfg(target_arch = "wasm32")] + let conv_dur = Duration::ZERO.into(); let mut state = xi_start; // Convert the total correction from VNC back to integration frame in case that's needed. for (i, var) in self.variables.iter().enumerate() { diff --git a/src/md/trajectory/orbit_traj.rs b/src/md/trajectory/orbit_traj.rs index 1a45aff8..b18d135d 100644 --- a/src/md/trajectory/orbit_traj.rs +++ b/src/md/trajectory/orbit_traj.rs @@ -32,6 +32,7 @@ use std::io::{BufRead, BufReader, BufWriter, Write}; use std::path::{Path, PathBuf}; use std::str::FromStr; use std::sync::Arc; +#[cfg(not(target_arch = "wasm32"))] use std::time::Instant; impl Traj { @@ -44,6 +45,8 @@ impl Traj { "No trajectory to convert".to_string(), ))); } + + #[cfg(not(target_arch = "wasm32"))] let start_instant = Instant::now(); let mut traj = Self::new(); for state in &self.states { @@ -51,12 +54,21 @@ impl Traj { } traj.finalize(); + #[cfg(not(target_arch = "wasm32"))] info!( "Converted trajectory from {} to {} in {} ms: {traj}", self.first().frame, new_frame, (Instant::now() - start_instant).as_millis() ); + + #[cfg(target_arch = "wasm32")] + info!( + "Converted trajectory from {} to {}: {traj}", + self.first().frame, + new_frame, + ); + Ok(traj) } diff --git a/src/md/trajectory/sc_traj.rs b/src/md/trajectory/sc_traj.rs index 354e3d4e..2bbf1911 100644 --- a/src/md/trajectory/sc_traj.rs +++ b/src/md/trajectory/sc_traj.rs @@ -27,6 +27,7 @@ use std::collections::HashMap; use std::error::Error; use std::path::{Path, PathBuf}; use std::sync::Arc; +#[cfg(not(target_arch = "wasm32"))] use std::time::Instant; impl Traj { @@ -38,6 +39,8 @@ impl Traj { "No trajectory to convert".to_string(), ))); } + + #[cfg(not(target_arch = "wasm32"))] let start_instant = Instant::now(); let mut traj = Self::new(); for state in &self.states { @@ -46,12 +49,21 @@ impl Traj { } traj.finalize(); + #[cfg(not(target_arch = "wasm32"))] info!( "Converted trajectory from {} to {} in {} ms: {traj}", self.first().orbit.frame, new_frame, (Instant::now() - start_instant).as_millis() ); + + #[cfg(target_arch = "wasm32")] + info!( + "Converted trajectory from {} to {}: {traj}", + self.first().orbit.frame, + new_frame, + ); + Ok(traj) } diff --git a/src/propagators/instance.rs b/src/propagators/instance.rs index 6f22f292..99b324f6 100644 --- a/src/propagators/instance.rs +++ b/src/propagators/instance.rs @@ -30,6 +30,7 @@ use rayon::iter::ParallelBridge; use rayon::prelude::ParallelIterator; use std::f64; use std::sync::mpsc::{channel, Sender}; +#[cfg(not(target_arch = "wasm32"))] use std::time::Instant; /// A Propagator allows propagating a set of dynamics forward or backward in time. @@ -78,8 +79,11 @@ where return Ok(self.state); } let stop_time = self.state.epoch() + duration; + + #[cfg(not(target_arch = "wasm32"))] let tick = Instant::now(); let log_progress = duration.abs() >= 2 * Unit::Minute; + if log_progress { // Prevent the print spam for orbit determination cases info!("Propagating for {} until {}", duration, stop_time); @@ -98,9 +102,12 @@ where { if stop_time == epoch { // No propagation necessary - if log_progress { - let tock: Duration = tick.elapsed().into(); - info!("Done in {}", tock); + #[cfg(not(target_arch = "wasm32"))] + { + if log_progress { + let tock: Duration = tick.elapsed().into(); + info!("Done in {}", tock); + } } return Ok(self.state); } @@ -120,13 +127,19 @@ where // Restore the step size for subsequent calls self.set_step(prev_step_size, prev_step_kind); + if backprop { self.step_size = -self.step_size; // Restore to a positive step size } - if log_progress { - let tock: Duration = tick.elapsed().into(); - info!("Done in {}", tock); + + #[cfg(not(target_arch = "wasm32"))] + { + if log_progress { + let tock: Duration = tick.elapsed().into(); + info!("Done in {}", tock); + } } + return Ok(self.state); } else { self.single_step()?;