Skip to content

Commit

Permalink
Merge pull request #1 from Duumbo/main
Browse files Browse the repository at this point in the history
(style) Fixed warnings
  • Loading branch information
Duumbo authored Nov 13, 2024
2 parents 7ef3930 + b161eaa commit cb84f1e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 37 deletions.
6 changes: 3 additions & 3 deletions src/bin/boboche2000.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::ptr::addr_of;
use std::slice::from_raw_parts as slice;
use log::info;

use impurity::{FockState, RandomStateGeneration, VarParams, SysParams, generate_bitmask, DerivativeOperator};
Expand Down Expand Up @@ -31,12 +29,14 @@ const NMCWARMUP: usize = 1000;
const CLEAN_UPDATE_FREQUENCY: usize = 8;
const TOLERENCE_SHERMAN_MORRISSON: f64 = 1e-15;
const TOLERANCE_SINGULARITY: f64 = 1e-15;
const MONTE_CARLO_CONVERGENCE_TOLERANCE: f64 = 1e-1;
const _MONTE_CARLO_CONVERGENCE_TOLERANCE: f64 = 1e-1;

#[allow(dead_code)]
fn sq(a: f64) -> f64 {
a * a
}

#[allow(dead_code)]
fn mean_energy_analytic_2sites(params: &VarParams, _sys: &SysParams) -> f64 {
let f00 = params.fij[0 + SIZE*SIZE] - params.fij[0 + 2*SIZE*SIZE];
let f01 = params.fij[1 + SIZE*SIZE] - params.fij[2 + 2*SIZE*SIZE];
Expand Down
8 changes: 4 additions & 4 deletions src/bin/dvmc_fastupdate.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use blas::{daxpy, dcopy, ddot, dnrm2, dscal, idamax};
use log::{debug, error, info};
use blas::{daxpy, dcopy, dnrm2, dscal, idamax};
use log::{debug, info};
use rand_mt::Mt64;
use indicatif::{ProgressBar, ProgressStyle};
use std::fs::File;
use std::io::Write;

use impurity::optimisation::{conjugate_gradiant, spread_eigenvalues};
use impurity::optimisation::conjugate_gradiant;
use impurity::{generate_bitmask, DerivativeOperator, FockState, RandomStateGeneration, SysParams, VarParams};
use impurity::monte_carlo::compute_mean_energy;

Expand All @@ -19,7 +19,7 @@ const NELEC: usize = SIZE;
const NMCSAMP: usize = 1_000;
const NMCWARMUP: usize = 1000;
const MCSAMPLE_INTERVAL: usize = 2;
const NTHREADS: usize = 6;
const _NTHREADS: usize = 6;
const CLEAN_UPDATE_FREQUENCY: usize = 2;
const TOLERENCE_SHERMAN_MORRISSON: f64 = 1e-12;
const TOLERENCE_SINGULARITY: f64 = 1e-12;
Expand Down
3 changes: 0 additions & 3 deletions src/density.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ where T: BitOps + std::fmt::Debug + std::fmt::Display + From<SpinState> + std::o
let spin = hopping.2;
let n_sites = new_state.n_sites;

// TMP
let proj = previous_proj.clone();

let (pfaffian_ratio, b_vec, col) = {
let fij = &params.fij;
let vij = &params.vij;
Expand Down
32 changes: 5 additions & 27 deletions src/monte_carlo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,8 @@ fn compute_hamiltonian<T: BitOps + std::fmt::Display + std::fmt::Debug>(state: F
e / (pstate.pfaff * <f64>::exp(proj))
}

fn get_sign<T: BitOps>(s1: &FockState<T>, hop: &(usize, usize, Spin)) -> usize {
let (a, b) = if hop.0 < hop.1 {
(hop.1, hop.0)
} else {
(hop.0, hop.1)
};
trace!("First mask: {:08b}, second mask: {:08b}", !(<u8>::MAX >> a), <u8>::MAX >> (b + 1));
let mask = {
!(<T>::ones() >> a) & (<T>::ones() >> (b + 1))
};
let n_ones = match hop.2 {
Spin::Up => {
(s1.spin_up & mask).count_ones()
},
Spin::Down => {
(s1.spin_down & mask).count_ones()
}
};

n_ones as usize
}

fn compute_derivative_operator<T: BitOps + std::fmt::Debug + std::fmt::Display + From<u8>>
(state: FockState<T>, pstate: &PfaffianState, der: &mut DerivativeOperator, params: &VarParams, sys: &SysParams)
(state: FockState<T>, pstate: &PfaffianState, der: &mut DerivativeOperator, sys: &SysParams)
{
compute_gutzwiller_der(state, sys.size, der);
compute_jastrow_der(state, der, sys.size);
Expand Down Expand Up @@ -151,7 +129,7 @@ where Standard: Distribution<T>
let mut _lip = <f64>::ln(<f64>::abs(<f64>::exp(proj) * pstate.pfaff)) * 2.0;
let mut n_accepted_updates: usize = 0;
let mut energy: f64 = 0.0;
let mut energy_sq: f64 = 0.0;
let mut _energy_sq: f64 = 0.0;
let mut proj_copy_persistent = proj;
let mut ratio_prod = 1.0;
let mut sample_counter: usize = 0;
Expand Down Expand Up @@ -204,7 +182,7 @@ where Standard: Distribution<T>
// We need to reset the counter that the warmup increased.
derivatives.mu = 0;
// Compute the derivative for the first element in the markov chain
compute_derivative_operator(state, &pstate, derivatives, params, sys);
compute_derivative_operator(state, &pstate, derivatives, sys);
for mc_it in 0..(sys.nmcsample * sys.mcsample_interval) {
let mut proj_copy = proj;
trace!("Before proposition: ~O_[0, {}] = {}", derivatives.mu + 1, derivatives.o_tilde[(derivatives.n * (derivatives.mu + 1)) as usize]);
Expand Down Expand Up @@ -239,7 +217,7 @@ where Standard: Distribution<T>
// Compute the derivative operator
if sample_counter >= sys.mcsample_interval {
derivatives.mu += 1;
compute_derivative_operator(state, &pstate, derivatives, params, sys);
compute_derivative_operator(state, &pstate, derivatives, sys);
}
}
if sample_counter >= sys.mcsample_interval {
Expand All @@ -248,7 +226,7 @@ where Standard: Distribution<T>
derivatives.visited[derivatives.mu as usize] += 1;
let state_energy = compute_hamiltonian(state, &pstate, proj, params, sys);
energy += state_energy;
energy_sq += state_energy*state_energy;
_energy_sq += state_energy*state_energy;
// Energy error estimation
let accumulation_level = <f32>::log2((mc_it + 1) as f32) as usize;
for i in 0..accumulation_level {
Expand Down

0 comments on commit cb84f1e

Please sign in to comment.