pub trait MonteCarloDefault<State, const D: usize> where
    State: LatticeState<D>, 
{ type Error; fn potential_next_element<Rng>(
        &mut self,
        state: &State,
        rng: &mut Rng
    ) -> Result<State, Self::Error>
        Rng: Rng + ?Sized
; fn probability_of_replacement(old_state: &State, new_state: &State) -> Real { ... } fn next_element_default<Rng>(
        &mut self,
        state: State,
        rng: &mut Rng
    ) -> Result<State, Self::Error>
        Rng: Rng + ?Sized
, { ... } }
Expand description

Some times it is easier to just implement a potential next element, the rest is done automatically using an McWrapper.

To get an MonteCarlo use the wrapper McWrapper.


use lattice_qcd_rs::error::ImplementationError;
use lattice_qcd_rs::simulation::{
    LatticeState, LatticeStateDefault, McWrapper, MetropolisHastingsDiagnostic, MonteCarlo,
use rand::SeedableRng;

let rng = rand::rngs::StdRng::seed_from_u64(0); // change with your seed
let mh = MetropolisHastingsDiagnostic::new(1, 0.1_f64)
let mut wrapper = McWrapper::new(mh, rng);

// Realistically you want more steps than 10

let mut state = LatticeStateDefault::<3>::new_cold(1_f64, 6_f64, 4)?;
for _ in 0..100 {
    state = state.monte_carlo_step(&mut wrapper)?;
        "probability of acceptance during last step {}, does it accepted the change ? {}",
    // or state.monte_carlo_step(&mut wrapper)?;
    // operation to track the progress or the evolution
// operation at the end of the simulation
let (_, rng) = wrapper.deconstruct(); // get the rng back
                                      // continue with further operation using the same rng ...

Associated Types

Error returned while getting the next element.

Required methods

Generate a radom element from the previous element (like a Markov chain).


Gives an error if a potential next element cannot be generated.

Provided methods

probability of the next element to replace the current one.

by default it is Exp(-H_old) / Exp(-H_new).

Get the next element in the chain either the old state or a new one replacing it.


Gives an error if a potential next element cannot be generated.