Giter VIP home page Giter VIP logo

lattice-qcd-rs's Introduction

Lattice QCD rs

License Build codecov

Classical lattice QCD simulation and tools.

This library provides tool to simulate a pure gauge SU(3) theory on a lattice. It aimed to provide generic tool such that many different simulation or methods can be used. You can easily choose the Monte Carlo algorithm, you can implement you own Hamiltonian etc. It provides also an easy way to do simulation in dimension between 1 and usize::MAX. So this library is not limited to d = 3 or d = 4.

Check out my other repo plaquette, a set of simulation binary I used for my research.

Features:

  • Generic dimension;
  • Configurable Monte Carlo algorithm;
  • Multi Platform;
  • Configurable Hamiltonian;
  • Serde support;
  • Native rust;
  • Some statistical tools;

Not yet implemented features:

  • More statistical tools;
  • Fermion support;
  • SU(N) support;
  • Config file;
  • C friendly API / ABI;

Usage

Add lattice_qcd_rs = { version = "0.2.1", git = "https://github.com/ABouttefeux/lattice_qcd_rs" } into your cargo.toml. The set of features are

  • serde-serialize on by default permit the use of serde on some structure
  • no-overflow-test usage interns to desable overflow test for coverage.

At the moment it is not on crates.io. Maybe I will add it. But for the moment it is still in development. Note that you may want to specify a specific commit as for now I may introduce breaking changes. I will however commit to more stability once I am ready to release version 0.2.0.

First let us see how to do a simulation on a 10x10x10x10 lattice with beta = 1. We are looking to compute 1/3 <Re(Tr(P_{ij}))> the trace of all plaquette after a certain number of steps. In our cases Beta is small so we choose 100'000 steps.

extern crate lattice_qcd_rs as lq;
extern crate rand_xoshiro;

use lq::prelude::*;

# use std::error::Error;
# fn main() -> Result<(), Box<dyn Error>> {
    let mut rng = rand_xoshiro::Xoshiro256PlusPlus::from_entropy();

    let size = 1000_f64;
    let number_of_pts = 10;
    let beta = 1_f64;

    let mut simulation =
        LatticeStateDefault::<4>::new_determinist(size, beta, number_of_pts, &mut rng)?;

    let spread_parameter = 0.1_f64;
    let mut mc = MetropolisHastingsDeltaDiagnostic::new(spread_parameter, rng)?;

    for _ in 0..100 {
        for _ in 0..1_000 {
            simulation = simulation.monte_carlo_step(&mut mc)?;
        }
        // the more we advance te more the link matrices
        // will deviate form SU(3), so we reprojet to SU(3)
        // every 1_000 steps.
        simulation.normalize_link_matrices();
    }

    let average = simulation.average_trace_plaquette().ok_or(ImplementationError::Unreachable)?.real() / 3_f64;
# Ok(())
# }

This library use rayon as a way to do some computation in parallel. However not everything can be parallelized. I advice that if you want to do multiple similar simulation (for instance you want to do for Beta = 1, 1.1, 1.2, ...) to use rayon. In order to do multiple parallel simulation.

Looking for more concrete example ? Check out my other repo plaquette. It contain the binary I use for my research.

I want to do my own thing.

I want to use my own hamiltonian

implement the trait LatticeState.

If you want to use your own state with the hybride Monte Carlo you will have to implement LatticeStateWithEField for LatticeStateEFSyncDefault<YourState>

I want to use my own Monte Carlo algorithm.

I provide two algorithm: Metropolis Hastings and hybride Monte Carlo

Look at the traits MonteCarlo, or alternatively MonteCarloDefault.

MonteCarloDefault can be easier to implement but note that the entire Hamiltonian is computed each time we do step for the previous and the new one which can be slower to compute the delta Hamiltonian.

To use a MonteCarloDefault as a MonteCarlo there is a wrapper: MCWrapper.

Why ?

This some code for my PhD thesis. Mainly I use arXiv:0707.2458, arXiv:0902.28568 and arXiv:2010.07316 as a basis.

Goal

The goal is to provide an easy to use, fast and safe library to do classical lattice simulation.

Discussion about Random Number Generators (RNGs)

This library use the trait rand::RngCore any time a random number generator. The choice of RNG is up to the user of the library. However there is a few trade offs to consider.

Let us break the different generator into categories. For more details see https://rust-random.github.io/book/guide-gen.html.

Some of the possible choice :

  • Recomanded rand_xoshiro::Xoshiro256PlusPlus Non-cryptographic. It has good performance and statistical quality, reproducible, and has useful jump function. It is the recommended PRNG.
  • rand::rngs::ThreadRng a CSPRNG. The data is not reproducible and it is reseeded often. It is however slow.
  • rand::rngs::StdRng cryptographic secure, can be seeded. It is determinist but not reproducible between platform. It is however slow.
  • rand_jitter::JitterRng True RNG but very slow.

Also ranlux is a good choice. But there is no native rust implementation of it that I know of (except mine but it is very slow).

Other Examples

use lattice_qcd_rs::{
    error::ImplementationError,
    ComplexField,
    simulation::monte_carlo::MetropolisHastingsDeltaDiagnostic,
    simulation::state::{LatticeState, LatticeStateDefault},
};

# use std::error::Error;
# fn main() -> Result<(), Box<dyn Error>> {
let mut rng = rand::thread_rng();

let size = 1_000_f64;
let number_of_pts = 4;
let beta = 2_f64;
let mut simulation =
    LatticeStateDefault::<4>::new_determinist(size, beta, number_of_pts, &mut rng)?;

let spread_parameter = 1E-5_f64;
let mut mc = MetropolisHastingsDeltaDiagnostic::new(spread_parameter, rng)
    .ok_or(ImplementationError::OptionWithUnexpectedNone)?;

let number_of_sims = 100;
for _ in 0..number_of_sims / 10 {
    for _ in 0..10 {
        simulation = simulation.monte_carlo_step(&mut mc)?;
    }
    simulation.normalize_link_matrices(); // we renormalize all matrices back to SU(3);
}
let average = simulation.average_trace_plaquette()
    .ok_or(ImplementationError::OptionWithUnexpectedNone)?
    .real();
# Ok(())
# }

Alternatively other Monte Carlo algorithm can be used like,

use lattice_qcd_rs::{
    error::ImplementationError,
    simulation::monte_carlo::{McWrapper, MetropolisHastingsDiagnostic},
    simulation::state::{LatticeState, LatticeStateDefault},
};

# use std::error::Error;
# fn main() -> Result<(), Box<dyn Error>> {
let mut rng = rand::thread_rng();

let size = 1_000_f64;
let number_of_pts = 4;
let beta = 2_f64;
let mut simulation =
    LatticeStateDefault::<3>::new_determinist(size, beta, number_of_pts, &mut rng)?;

let number_of_rand = 20;
let spread_parameter = 1E-5_f64;
let mut mc = McWrapper::new(
    MetropolisHastingsDiagnostic::new(number_of_rand, spread_parameter)
        .ok_or(ImplementationError::OptionWithUnexpectedNone)?,
    rng,
);

simulation = simulation.monte_carlo_step(&mut mc)?;
simulation.normalize_link_matrices();
# Ok(())
# }

or

use lattice_qcd_rs::{
    integrator::SymplecticEulerRayon,
    simulation::monte_carlo::HybridMonteCarloDiagnostic,
    simulation::state::{LatticeState, LatticeStateDefault},
};

# use std::error::Error;
# fn main() -> Result<(), Box<dyn Error>> {
let mut rng = rand::thread_rng();

let size = 1_000_f64;
let number_of_pts = 4;
let beta = 2_f64;
let mut simulation =
    LatticeStateDefault::<3>::new_determinist(size, beta, number_of_pts, &mut rng)?;

let delta_t = 1E-3_f64;
let number_of_step = 10;
let mut mc =
    HybridMonteCarloDiagnostic::new(delta_t, number_of_step, SymplecticEulerRayon::new(), rng);

simulation = simulation.monte_carlo_step(&mut mc)?;
simulation.normalize_link_matrices();
# Ok(())
# }

lattice-qcd-rs's People

Contributors

abouttefeux avatar dependabot-preview[bot] avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

lattice-qcd-rs's Issues

api checklist

  • Naming (crate aligns with Rust naming conventions)
    • Casing conforms to RFC 430 ([C-CASE])
    • Ad-hoc conversions follow as_, to_, into_ conventions ([C-CONV])
    • Getter names follow Rust convention ([C-GETTER])
    • Methods on collections that produce iterators follow iter, iter_mut, into_iter ([C-ITER])
    • Iterator type names match the methods that produce them ([C-ITER-TY])
    • Feature names are free of placeholder words ([C-FEATURE])
    • Names use a consistent word order ([C-WORD-ORDER])
  • Interoperability (crate interacts nicely with other library functionality)
    • Types eagerly implement common traits ([C-COMMON-TRAITS])
      • Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug,
        Display, Default
    • Conversions use the standard traits From, AsRef, AsMut ([C-CONV-TRAITS])
    • Collections implement FromIterator and Extend ([C-COLLECT])
    • Data structures implement Serde's Serialize, Deserialize ([C-SERDE])
    • Types are Send and Sync where possible ([C-SEND-SYNC])
    • Error types are meaningful and well-behaved ([C-GOOD-ERR])
    • Binary number types provide Hex, Octal, Binary formatting ([C-NUM-FMT])
    • Generic reader/writer functions take R: Read and W: Write by value ([C-RW-VALUE])
  • Macros (crate presents well-behaved macros)
    • Input syntax is evocative of the output ([C-EVOCATIVE])
    • Macros compose well with attributes ([C-MACRO-ATTR])
    • Item macros work anywhere that items are allowed ([C-ANYWHERE])
    • Item macros support visibility specifiers ([C-MACRO-VIS])
    • Type fragments are flexible ([C-MACRO-TY])
  • Documentation (crate is abundantly documented)
    • Crate level docs are thorough and include examples ([C-CRATE-DOC])
    • All items have a rustdoc example ([C-EXAMPLE])
    • Examples use ?, not try!, not unwrap ([C-QUESTION-MARK])
    • Function docs include error, panic, and safety considerations ([C-FAILURE])
    • Prose contains hyperlinks to relevant things ([C-LINK])
    • Cargo.toml includes all common metadata ([C-METADATA])
      • authors, description, license, homepage, documentation, repository,
        readme, keywords, categories
    • Crate sets html_root_url attribute "https://docs.rs/CRATE/X.Y.Z" ([C-HTML-ROOT])
    • Release notes document all significant changes ([C-RELNOTES])
    • Rustdoc does not show unhelpful implementation details ([C-HIDDEN])
  • Predictability (crate enables legible code that acts how it looks)
    • Smart pointers do not add inherent methods ([C-SMART-PTR])
    • Conversions live on the most specific type involved ([C-CONV-SPECIFIC])
    • Functions with a clear receiver are methods ([C-METHOD])
    • Functions do not take out-parameters ([C-NO-OUT])
    • Operator overloads are unsurprising ([C-OVERLOAD])
    • Only smart pointers implement Deref and DerefMut ([C-DEREF])
    • Constructors are static, inherent methods ([C-CTOR])
  • Flexibility (crate supports diverse real-world use cases)
    • Functions expose intermediate results to avoid duplicate work ([C-INTERMEDIATE])
    • Caller decides where to copy and place data ([C-CALLER-CONTROL])
    • Functions minimize assumptions about parameters by using generics ([C-GENERIC])
    • Traits are object-safe if they may be useful as a trait object ([C-OBJECT]) -> impl LatticeState for Box ?
  • Type safety (crate leverages the type system effectively)
    • Newtypes provide static distinctions ([C-NEWTYPE])
    • Arguments convey meaning through types, not bool or Option ([C-CUSTOM-TYPE])
    • Types for a set of flags are bitflags, not enums ([C-BITFLAG])
    • Builders enable construction of complex values ([C-BUILDER])
  • Dependability (crate is unlikely to do the wrong thing)
    • Functions validate their arguments ([C-VALIDATE])
    • Destructors never fail ([C-DTOR-FAIL])
    • Destructors that may block have alternatives ([C-DTOR-BLOCK])
  • Debuggability (crate is conducive to easy debugging)
    • All public types implement Debug ([C-DEBUG])
    • Debug representation is never empty ([C-DEBUG-NONEMPTY])
  • Future proofing (crate is free to improve without breaking users' code)
    • Sealed traits protect against downstream implementations ([C-SEALED])
    • Structs have private fields ([C-STRUCT-PRIVATE])
    • Newtypes encapsulate implementation details ([C-NEWTYPE-HIDE])
    • Data structures do not duplicate derived trait bounds ([C-STRUCT-BOUNDS])
  • Necessities (to whom they matter, they really matter)
    • โŒ Public dependencies of a stable crate are stable ([C-STABLE])
    • Crate and its dependencies have a permissive license ([C-PERMISSIVE])

Dependabot can't resolve your Rust dependency files

Dependabot can't resolve your Rust dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

This project is part of a Rust workspace but is not the workspace root.Please update your settings so Dependabot points at the workspace root instead of /average_of_plaquette.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Dependabot can't resolve your Rust dependency files

Dependabot can't resolve your Rust dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

This project is part of a Rust workspace but is not the workspace root.Please update your settings so Dependabot points at the workspace root instead of /simulation-bin.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.