Skip to content

Commit a6415bc

Browse files
Fix all tests
1 parent ae84523 commit a6415bc

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

crates/mvmc-core/src/monte_carlo/observables.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl ObservableCalculator {
165165
/// amplitude_ratio: Complex64::new(1.0, 0.0),
166166
/// };
167167
///
168-
/// calculator.add_sample(&config, &step);
168+
/// calculator.add_sample(&config, &step, 1.5);
169169
/// ```
170170
pub fn add_sample(&mut self, config: &ElectronConfiguration, _step: &MetropolisStep, local_energy: f64) {
171171
// Use provided local energy instead of calculating

crates/mvmc-core/src/vmc/engine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl VmcEngine {
138138
/// use mvmc_physics::hamiltonian::{HubbardHamiltonian, Hamiltonian};
139139
/// use mvmc_physics::lattice::ChainLattice;
140140
///
141-
/// let sr_params = SRParameters::new(1000, 100, 100, 1e-6, 1e-6, 0.1, 100, 1e-6);
141+
/// let sr_params = SRParameters::new(1000, 100, 100, 1e-6, 1e-6, 0.1, 100, 1e-6, true);
142142
/// let mc_params = MonteCarloParameters::new(100, 1, 1000, false, 1);
143143
/// let params = VmcParameters::new(
144144
/// SiteCount::new(4),

crates/mvmc-physics/src/hamiltonian/heisenberg.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl HeisenbergHamiltonian {
128128

129129
for site in 0..self.lattice.n_sites() {
130130
let spin_z = config[site].value_f64();
131-
energy -= self.magnetic_field * 0.5 * spin_z;
131+
energy -= self.magnetic_field * spin_z;
132132
}
133133

134134
energy
@@ -234,9 +234,9 @@ impl Hamiltonian for HeisenbergHamiltonian {
234234

235235
// Matrix element for Heisenberg exchange flip term
236236
// H contains J * (S^+_i S^-_j + S^-_i S^+_j) for spin-1/2
237-
// C実装では正の符号で定義されているため、負の符号を適用
238-
// Thus, <↓↑|H|↑↓> = -J
239-
Complex64::new(-self.exchange, 0.0)
237+
// For spin-1/2, the matrix element is J/2 * (S^+_i S^-_j + S^-_i S^+_j)
238+
// Thus, <↓↑|H|↑↓> = -J/2
239+
Complex64::new(-self.exchange * 0.5, 0.0)
240240
}
241241

242242
fn diagonal_element(&self, config: &[Spin]) -> f64 {

crates/mvmc-physics/src/wavefunction/slater.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -464,14 +464,14 @@ impl SlaterDeterminant {
464464

465465
// Calculate determinant for up spins
466466
let up_det = if up_sites.len() > 0 {
467-
self.calculate_determinant_for_sites(&up_sites)
467+
self.calculate_determinant_for_sites(&up_sites, 0)
468468
} else {
469469
Complex64::new(1.0, 0.0)
470470
};
471471

472472
// Calculate determinant for down spins
473473
let down_det = if down_sites.len() > 0 {
474-
self.calculate_determinant_for_sites(&down_sites)
474+
self.calculate_determinant_for_sites(&down_sites, up_sites.len())
475475
} else {
476476
Complex64::new(1.0, 0.0)
477477
};
@@ -486,7 +486,7 @@ impl SlaterDeterminant {
486486
///
487487
/// # Returns
488488
/// * `Complex64` - The determinant value
489-
fn calculate_determinant_for_sites(&self, sites: &[usize]) -> Complex64 {
489+
fn calculate_determinant_for_sites(&self, sites: &[usize], orbital_offset: usize) -> Complex64 {
490490
if sites.len() == 0 {
491491
return Complex64::new(1.0, 0.0);
492492
}
@@ -496,12 +496,15 @@ impl SlaterDeterminant {
496496
}
497497

498498
// Create submatrix for occupied sites
499-
let mut submatrix = Array2::zeros((sites.len(), sites.len()));
499+
// We need a square matrix for determinant calculation
500+
let n_electrons = sites.len();
501+
let mut submatrix = Array2::zeros((n_electrons, n_electrons));
500502
for (i, &site) in sites.iter().enumerate() {
501-
for j in 0..sites.len() {
502-
if j < self.ne {
503-
submatrix[[i, j]] = self.orbitals[[site, j]];
504-
}
503+
for j in 0..n_electrons {
504+
// For each electron in this spin sector, select the appropriate orbital
505+
// The orbital index should be the electron index within this spin sector plus the offset
506+
let orbital_index = orbital_offset + j;
507+
submatrix[[i, j]] = self.orbitals[[site, orbital_index]];
505508
}
506509
}
507510

0 commit comments

Comments
 (0)