Skip to content

Commit

Permalink
parallel iterators [wip]
Browse files Browse the repository at this point in the history
  • Loading branch information
ABouttefeux committed Nov 19, 2023
1 parent ec5e8b9 commit 02b11ca
Show file tree
Hide file tree
Showing 31 changed files with 2,747 additions and 1,358 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
- [`LatticeStateDefault::new_determinist`] now takes the rng as a generic parameter instead of an impl trait type and can be unsized
- [`LatticeStateEFSyncDefault::new_random_e_state`] now takes the rng as a generic parameter instead of an impl trait type and can be unsized
- [`LatticeStateEFSyncDefault::new_determinist`] now takes the distribution as a generic parameter instead of an impl trait type and can be unsized

- possible name collision for [`IteratorDirection`], [`IteratorLatticeLinkCanonical`] and [`IteratorLatticePoint`] for trait method [`Iterator`], [`ExactSizeIterator`], [`rayon::iter::ParallelIterator`] and [`rayon::iter::IndexedParallelIterator`].
- [`IteratorLatticePoint::new`] is not constant anymore.
- [`IteratorLatticeLinkCanonical::new`] is not constant anymore.

## non breaking
- remove the extern crate declaration in lib.rs
Expand All @@ -21,6 +23,11 @@
- [`LatticeStateEFSyncDefault::new_random_threaded`] now takes unsized distribution.
- [`LinkMatrix`::iter`] and [`LinkMatrix::iter_mut`] now also implements [`DoubleEndedIterator`]
- moved the definition of [`DirectionConversionError`] out of the proc macro into lattice.rs
- add comments on some private items
- organize internal code in private submodule with reexport
- depreciate [`random_matrix_2`]
- depreciate [`FixedPointNumber`] and [`I32U128`] which never implemented
- implemented the trait [`DoubleEndedIterator`], [`rayon::iter::ParallelIterator`], [`rayon::iter::IndexedParallelIterator`] and [`rayon::iter::plumbing::Producer`] for [`IteratorDirection`], [`IteratorLatticeLinkCanonical`] and [`IteratorLatticePoint`]

# v0.2.1

Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ crate-type = ["lib"]
[features]
serde-serialize = ["dep:serde", "nalgebra/serde-serialize"]
overflow-test = []
# experimental = []
default = ["serde-serialize", "overflow-test"]


Expand Down
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- cspell: ignore Serde xoshiro PRNG CSPRNG ranlux codecov usize -->
# ![Lattice QCD rs](logo.svg)

![](https://img.shields.io/badge/language-Rust-orange)
Expand All @@ -10,7 +11,7 @@
## 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.
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 128. So this library is not limited to d = 3 or d = 4.

Check out my other repo [plaquette](https://github.com/ABouttefeux/plaquette), a set of simulation binary I used for my research.

Expand All @@ -33,16 +34,14 @@ Check out my other repo [plaquette](https://github.com/ABouttefeux/plaquette), a

## Usage

Add `lattice_qcd_rs = { version = "0.2.1", git = "https://github.com/ABouttefeux/lattice_qcd_rs" }` into your `cargo.toml`.
The library may use feature of the latest **stable** release. I do not intend to use any nightly feature.

Add `lattice_qcd_rs = { version = "0.3.0", 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`.
- `no-overflow-test` usage interns to disable overflow test for coverage.

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.
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.

```rust,ignore
extern crate lattice_qcd_rs as lq;
Expand All @@ -69,7 +68,7 @@ use lq::prelude::*;
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)
// will deviate form SU(3), so we reproject to SU(3)
// every 1_000 steps.
simulation.normalize_link_matrices();
}
Expand All @@ -79,7 +78,7 @@ use lq::prelude::*;
# }
```

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.
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](https://github.com/ABouttefeux/plaquette). It contain the binary I use for my research.

Expand All @@ -89,14 +88,14 @@ Looking for more concrete example ? Check out my other repo [plaquette](https://

implement the trait [`LatticeState`](https://abouttefeux.github.io/lattice-qcd-rs/lattice_qcd_rs/simulation/state/trait.LatticeState.html).

If you want to use your own state with the [hybride Monte Carlo](https://abouttefeux.github.io/lattice-qcd-rs/lattice_qcd_rs/simulation/monte_carlo/hybride_monte_carlo/struct.HybridMonteCarloDiagnostic.html)
If you want to use your own state with the [Hybrid Monte Carlo](https://abouttefeux.github.io/lattice-qcd-rs/lattice_qcd_rs/simulation/monte_carlo/hybride_monte_carlo/struct.HybridMonteCarloDiagnostic.html)
you will have to implement
[`LatticeStateWithEField`](https://abouttefeux.github.io/lattice-qcd-rs/lattice_qcd_rs/simulation/state/trait.LatticeStateWithEField.html) for [`LatticeStateEFSyncDefault<YourState>`](https://abouttefeux.github.io/lattice-qcd-rs/lattice_qcd_rs/simulation/state/struct.LatticeStateEFSyncDefault.html)

#### I want to use my own Monte Carlo algorithm.

I provide two algorithm: [Metropolis Hastings](https://abouttefeux.github.io/lattice-qcd-rs/lattice_qcd_rs/simulation/monte_carlo/metropolis_hastings/struct.MetropolisHastingsDeltaDiagnostic.html)
and [hybride Monte Carlo](https://abouttefeux.github.io/lattice-qcd-rs/lattice_qcd_rs/simulation/monte_carlo/hybride_monte_carlo/struct.HybridMonteCarloDiagnostic.html)
and [Hybrid Monte Carlo](https://abouttefeux.github.io/lattice-qcd-rs/lattice_qcd_rs/simulation/monte_carlo/hybride_monte_carlo/struct.HybridMonteCarloDiagnostic.html)

Look at the traits [`MonteCarlo`](https://abouttefeux.github.io/lattice-qcd-rs/lattice_qcd_rs/simulation/monte_carlo/trait.MonteCarlo.html),
or alternatively [`MonteCarloDefault`](https://abouttefeux.github.io/lattice-qcd-rs/lattice_qcd_rs/simulation/monte_carlo/trait.MonteCarloDefault.html).
Expand Down Expand Up @@ -125,7 +124,7 @@ 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`](https://docs.rs/rand_xoshiro/0.6.0/rand_xoshiro/struct.Xoshiro256PlusPlus.html)
- **Recommended** [`rand_xoshiro::Xoshiro256PlusPlus`](https://docs.rs/rand_xoshiro/0.6.0/rand_xoshiro/struct.Xoshiro256PlusPlus.html)
Non-cryptographic. It has good performance and statistical quality, reproducible, and has useful `jump` function.
It is the recommended PRNG.
- [`rand::rngs::ThreadRng`](https://docs.rs/rand/0.8.3/rand/rngs/struct.ThreadRng.html) a CSPRNG. The data is not reproducible and it is reseeded often. It is however slow.
Expand Down
145 changes: 145 additions & 0 deletions bacon.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# This is a configuration file for the bacon tool
#
# Bacon repository: https://github.com/Canop/bacon
# Complete help on configuration: https://dystroy.org/bacon/config/
# You can also check bacon's own bacon.toml file
# as an example: https://github.com/Canop/bacon/blob/main/bacon.toml

default_job = "clippy"

[jobs.check]
command = ["cargo", "check", "--all", "--color", "always"]
need_stdout = false

[jobs.check-all]
command = ["cargo", "check", "--all", "--all-targets", "--color", "always"]
need_stdout = false

[jobs.clippy]
command = [
"cargo",
"clippy",
"--all",
"--all-targets",
"--all-features",
"--color",
"always",
"--",
# "--no-deps",
]
need_stdout = false

# This job lets you run
# - all tests: bacon test
# - a specific test: bacon test -- config::test_default_files
# - the tests of a package: bacon test -- -- -p config
[jobs.test]
command = [
"cargo",
"test",
"--all",
# "--all-targets",
"--no-fail-fast",
"--all-features",
"--color",
"always",
"--",
"--color",
"always", # see https://github.com/Canop/bacon/issues/124
]
need_stdout = true

[jobs.test-no-run]
command = [
"cargo",
"test",
"--all",
"--all-targets",
"--all-features",
"--color",
"always",
"--no-run",
"--",
"--color",
"always", # see https://github.com/Canop/bacon/issues/124
]
need_stdout = true

[jobs.doc]
command = [
"cargo",
"doc",
"--all",
"--document-private-items",
"--all-features",
"--color",
"always",
# "--no-deps",
]
need_stdout = false

# If the doc compiles, then it opens in your browser and bacon switches
# to the previous job
[jobs.doc-open]
command = [
"cargo",
"doc",
"--all",
"--all-features",
"--color",
"always",
# "--no-deps",
"--open",
]
need_stdout = false
on_success = "back" # so that we don't open the browser at each change

# You can run your application and have the result displayed in bacon,
# *if* it makes sense for this crate.
# Don't forget the `--color always` part or the errors won't be
# properly parsed.
# If your program never stops (eg a server), you may set `background`
# to false to have the cargo run output immediately displayed instead
# of waiting for program's end.
[jobs.run]
command = [
"cargo",
"run",
"--color",
"always",
# put launch parameters for your program behind a `--` separator
]
need_stdout = true
allow_warnings = true
background = true

# This parameterized job runs the example of your choice, as soon
# as the code compiles.
# Call it as
# bacon ex -- my-example
[jobs.ex]
command = ["cargo", "run", "--color", "always", "--example"]
need_stdout = true
allow_warnings = true

[jobs.fmt-check]
command = ["cargo", "fmt", "--all", "--check", "--", "--color", "always"]
need_stdout = true

[jobs.fmt]
command = ["cargo", "fmt", "--all", "--", "--color", "always"]
need_stdout = false

# You may define here keybindings that would be specific to
# a project, for example a shortcut to launch a specific job.
# Shortcuts to internal functions (scrolling, toggling, etc.)
# should go in your personal global prefs.toml file instead.
[keybindings]
# alt-m = "job:my-job"
alt-t = "job:test-no-run"
f = "job:fmt"
alt-f = "job:fmt-check"
d = "job:doc"
alt-d = "job:doc-open"
r = "rerun"
f5 = "rerun"
Loading

0 comments on commit 02b11ca

Please sign in to comment.