Skip to content

Commit

Permalink
change imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ABouttefeux committed Feb 25, 2024
1 parent 9749cd2 commit a6cecfe
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 79 deletions.
5 changes: 2 additions & 3 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, f64, vec::Vec};
use std::{collections::HashMap, f64};

use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput};
use lattice_qcd_rs::{
Expand All @@ -8,8 +8,7 @@ use lattice_qcd_rs::{
HybridMonteCarloDiagnostic, LatticeState, LatticeStateDefault, LatticeStateEFSyncDefault,
MetropolisHastingsSweep, SimulationStateSynchronous,
},
su3::su3_exp_i,
su3::su3_exp_r,
su3::{su3_exp_i, su3_exp_r},
Complex, Real,
};
use rand::rngs::ThreadRng;
Expand Down
21 changes: 11 additions & 10 deletions src/field.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
//! Represent the fields on the lattice.

use std::fmt::{self, Display};
use std::iter::{FromIterator, FusedIterator};
use std::{
ops::{Add, AddAssign, Div, DivAssign, Index, IndexMut, Mul, MulAssign, Neg, Sub, SubAssign},
vec::Vec,
use std::iter::FusedIterator;
use std::ops::{
Add, AddAssign, Div, DivAssign, Index, IndexMut, Mul, MulAssign, Neg, Sub, SubAssign,
};

use nalgebra::{ComplexField, Matrix3, SVector};
use rand_distr::Distribution;
use rayon::iter::FromParallelIterator;
use rayon::prelude::*;
#[cfg(feature = "serde-serialize")]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -1656,14 +1654,17 @@ mod test {
use std::error::Error;

use approx::*;
use rand::rngs::StdRng;
use rand::SeedableRng;
use nalgebra::SVector;
use rand::{rngs::StdRng, SeedableRng};
use rand_distr::Uniform;

use super::super::{lattice::*, Complex};
use super::*;
use super::{EField, LinkMatrix, Su3Adjoint};
use crate::error::{ImplementationError, LatticeInitializationError};
use crate::su3::su3_exp_r;
use crate::lattice::{
Direction, LatticeCyclic, LatticeElementToIndex, LatticeLink, LatticeLinkCanonical,
LatticePoint,
};
use crate::{su3::su3_exp_r, thread::ThreadError, CMatrix3, Complex, ComplexField};

const EPSILON: f64 = 0.000_000_001_f64;
const SEED_RNG: u64 = 0x45_78_93_f4_4a_b0_67_f0;
Expand Down
21 changes: 9 additions & 12 deletions src/integrator/symplectic_euler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,22 @@
use std::{
error,
fmt::{self, Display},
vec::Vec,
};

use nalgebra::SVector;
#[cfg(feature = "serde-serialize")]
use serde::{Deserialize, Serialize};

use super::{
super::{
field::{EField, LinkMatrix, Su3Adjoint},
lattice::LatticeCyclic,
simulation::{
LatticeState, LatticeStateWithEField, LatticeStateWithEFieldNew, SimulationStateLeap,
SimulationStateSynchronous,
},
thread::{run_pool_parallel_vec, ThreadError},
CMatrix3, Real,
use super::{integrate_efield, integrate_link, SymplecticIntegrator};
use crate::{
field::{EField, LinkMatrix, Su3Adjoint},
lattice::LatticeCyclic,
simulation::{
LatticeState, LatticeStateWithEField, LatticeStateWithEFieldNew, SimulationStateLeap,
SimulationStateSynchronous,
},
integrate_efield, integrate_link, SymplecticIntegrator,
thread::{run_pool_parallel_vec, ThreadError},
CMatrix3, Real,
};

/// Error for [`SymplecticEuler`].
Expand Down
25 changes: 10 additions & 15 deletions src/integrator/symplectic_euler_rayon.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
//! Basic symplectic Euler integrator using [`Rayon`](https://docs.rs/rayon/1.5.1/rayon/).

use std::{
fmt::{self, Display},
vec::Vec,
};
use std::fmt::{self, Display};

use nalgebra::SVector;
#[cfg(feature = "serde-serialize")]
use serde::{Deserialize, Serialize};

use super::{
super::{
field::{EField, LinkMatrix, Su3Adjoint},
lattice::LatticeCyclic,
simulation::{
LatticeState, LatticeStateWithEField, LatticeStateWithEFieldNew, SimulationStateLeap,
SimulationStateSynchronous,
},
thread::run_pool_parallel_rayon,
Real,
use super::{integrate_efield, integrate_link, CMatrix3, SymplecticIntegrator};
use crate::{
field::{EField, LinkMatrix, Su3Adjoint},
lattice::LatticeCyclic,
simulation::{
LatticeState, LatticeStateWithEField, LatticeStateWithEFieldNew, SimulationStateLeap,
SimulationStateSynchronous,
},
integrate_efield, integrate_link, CMatrix3, SymplecticIntegrator,
thread::run_pool_parallel_rayon,
Real,
};

/// Basic symplectic Euler integrator using Rayon.
Expand Down
1 change: 0 additions & 1 deletion src/lattice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ mod iterator;
mod lattice_cyclic;

use std::cmp::Ordering;
use std::convert::TryInto;
use std::error::Error;
use std::fmt::{self, Display};
use std::iter::FusedIterator;
Expand Down
1 change: 0 additions & 1 deletion src/simulation/monte_carlo/hybrid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
//! ```

use std::marker::PhantomData;
use std::vec::Vec;
use std::{
error::Error,
fmt::{self, Debug, Display},
Expand Down
22 changes: 9 additions & 13 deletions src/simulation/monte_carlo/metropolis_hastings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,16 @@ use rand_distr::{Bernoulli, Distribution, Uniform};
#[cfg(feature = "serde-serialize")]
use serde::{Deserialize, Serialize};

use super::{
super::{
super::{
error::Never,
field::LinkMatrix,
lattice::{
Direction, LatticeCyclic, LatticeElementToIndex, LatticeLink, LatticeLinkCanonical,
LatticePoint,
},
su3, Complex, Real,
},
state::{LatticeState, LatticeStateDefault, LatticeStateNew},
use super::{delta_s_old_new_cmp, MonteCarlo, MonteCarloDefault};
use crate::{
error::Never,
field::LinkMatrix,
lattice::{
Direction, LatticeCyclic, LatticeElementToIndex, LatticeLink, LatticeLinkCanonical,
LatticePoint,
},
delta_s_old_new_cmp, MonteCarlo, MonteCarloDefault,
simulation::state::{LatticeState, LatticeStateDefault, LatticeStateNew},
su3, Complex, Real,
};

/// Metropolis Hastings algorithm. Very slow, use [`MetropolisHastingsDeltaDiagnostic`]
Expand Down
18 changes: 7 additions & 11 deletions src/simulation/monte_carlo/metropolis_hastings_sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@ use rand_distr::{Bernoulli, Distribution};
#[cfg(feature = "serde-serialize")]
use serde::{Deserialize, Serialize};

use super::{
super::{
super::{
error::Never,
field::LinkMatrix,
lattice::{LatticeCyclic, LatticeElementToIndex, LatticeLink, LatticeLinkCanonical},
su3, Complex, Real,
},
state::{LatticeState, LatticeStateDefault},
},
delta_s_old_new_cmp, MonteCarlo,
use super::{delta_s_old_new_cmp, MonteCarlo};
use crate::{
error::Never,
field::LinkMatrix,
lattice::{LatticeCyclic, LatticeElementToIndex, LatticeLink, LatticeLinkCanonical},
simulation::state::{LatticeState, LatticeStateDefault},
su3, Complex, Real,
};

/// Metropolis Hastings method by doing a pass on all points
Expand Down
6 changes: 2 additions & 4 deletions src/simulation/monte_carlo/overrelaxation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,21 +235,19 @@ impl<const D: usize> MonteCarlo<LatticeStateDefault<D>, D> for OverrelaxationSwe

#[cfg(test)]
mod test {
use std::error::{self, Error};
use std::error::Error;

use rand::rngs::StdRng;
use rand::SeedableRng;

use super::super::super::state::{LatticeState, LatticeStateDefault};
use super::super::MonteCarlo;
use super::*;

const SEED_RNG: u64 = 0x45_78_93_f4_4a_b0_67_f0;

fn test_same_energy<MC>(mc: &mut MC, rng: &mut impl rand::Rng) -> Result<(), Box<dyn Error>>
where
MC: MonteCarlo<LatticeStateDefault<3>, 3>,
MC::Error: error::Error + 'static,
MC::Error: Error + 'static,
{
let state = LatticeStateDefault::<3>::new_determinist(1_f64, 1_f64, 4, rng)?;
let h = state.hamiltonian_links();
Expand Down
3 changes: 0 additions & 3 deletions src/simulation/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use std::fmt::{self, Display};
use crossbeam::thread;
use nalgebra::{ComplexField, SVector};
use rand_distr::Distribution;
use rayon::iter::ParallelBridge;
use rayon::prelude::*;
#[cfg(feature = "serde-serialize")]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -1562,9 +1561,7 @@ where

#[cfg(test)]
mod test {

use super::*;
use crate::error::StateInitializationError;

#[test]
fn leap_frog_simulation() -> Result<(), StateInitializationError> {
Expand Down
5 changes: 3 additions & 2 deletions src/su2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,10 @@ pub fn random_matrix_2<R: Rng + ?Sized>(rng: &mut R) -> CMatrix2 {
#[cfg(test)]
mod test {
use rand::{rngs::StdRng, SeedableRng};
use rand_distr::Distribution;
use rand_distr::{Distribution, Uniform};

use super::*;
use super::{is_matrix_su2, project_to_su2, project_to_su2_unorm, random_su2, PAULI_MATRICES};
use crate::{CMatrix2, Complex, ComplexField};

const EPSILON: f64 = 0.000_000_001_f64;
const SEED_RNG: u64 = 0x45_78_93_f4_4a_b0_67_f0;
Expand Down
1 change: 0 additions & 1 deletion src/su3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,6 @@ mod test {
use rand::{rngs::StdRng, SeedableRng};

use super::*;
use crate::{assert_eq_matrix, I};

const EPSILON: f64 = 0.000_000_001_f64;
const SEED_RNG: u64 = 0x45_78_93_f4_4a_b0_67_f0;
Expand Down
4 changes: 1 addition & 3 deletions src/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ use std::{
error::Error,
fmt::{self, Display, Formatter},
hash::Hash,
iter::Iterator,
panic::{catch_unwind, AssertUnwindSafe},
sync::{mpsc, Arc, Mutex},
vec::Vec,
};

use crossbeam::thread::{self, ScopedJoinHandle};
Expand Down Expand Up @@ -724,7 +722,7 @@ where
mod test {
use std::error::Error;

use super::*;
use super::{insert_in_vec, ThreadAnyError, ThreadError};
use crate::error::ImplementationError;

#[test]
Expand Down

0 comments on commit a6cecfe

Please sign in to comment.