Commit ddb4f5f9 authored by Adam Reichold's avatar Adam Reichold
Browse files

Update the random number generation scheme to use a PCG-DXSM-based generator.

parent 1b665533
Pipeline #53029 passed with stage
in 11 minutes and 30 seconds
......@@ -18,9 +18,9 @@ version = "0.1.0"
[[package]]
name = "cc"
version = "1.0.71"
version = "1.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd"
checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"
[[package]]
name = "cfg-if"
......@@ -62,9 +62,9 @@ version = "0.1.0"
[[package]]
name = "libc"
version = "0.2.106"
version = "0.2.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a60553f9a9e039a333b4e9b20573b9e9b9c0bb3a11e201ccc48ef4283456d673"
checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"
[[package]]
name = "libm"
......@@ -101,7 +101,6 @@ dependencies = [
"process",
"queue",
"rand",
"rand_chacha",
"rand_distr",
"rand_pcg",
"raster",
......@@ -143,9 +142,8 @@ version = "0.1.0"
[[package]]
name = "rand"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8"
version = "0.8.5"
source = "git+https://github.com/adamreichold/rand.git?branch=numpy-compat#b63a533cbc8500568a42dc4e6e0ab26042a2ae03"
dependencies = [
"libc",
"rand_chacha",
......@@ -155,8 +153,7 @@ dependencies = [
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
source = "git+https://github.com/adamreichold/rand.git?branch=numpy-compat#b63a533cbc8500568a42dc4e6e0ab26042a2ae03"
dependencies = [
"ppv-lite86",
"rand_core",
......@@ -164,9 +161,8 @@ dependencies = [
[[package]]
name = "rand_core"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
version = "0.6.4"
source = "git+https://github.com/adamreichold/rand.git?branch=numpy-compat#b63a533cbc8500568a42dc4e6e0ab26042a2ae03"
dependencies = [
"getrandom",
]
......@@ -174,8 +170,7 @@ dependencies = [
[[package]]
name = "rand_distr"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "964d548f8e7d12e102ef183a0de7e98180c9f8729f555897a857b96e48122d2f"
source = "git+https://github.com/adamreichold/rand.git?branch=numpy-compat#b63a533cbc8500568a42dc4e6e0ab26042a2ae03"
dependencies = [
"num-traits",
"rand",
......@@ -184,8 +179,7 @@ dependencies = [
[[package]]
name = "rand_pcg"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59cad018caf63deb318e5a4586d99a24424a364f40f1e5778c29aca23f4fc73e"
source = "git+https://github.com/adamreichold/rand.git?branch=numpy-compat#b63a533cbc8500568a42dc4e6e0ab26042a2ae03"
dependencies = [
"rand_core",
]
......
......@@ -18,8 +18,7 @@ bitmap = { path = "libraries/bitmap" }
kdtree = { path = "libraries/kdtree" }
process = { path = "libraries/process" }
queue = { path = "libraries/queue" }
rand = { version = "0.8", default-features = false, features = ["std"] }
rand_distr = "0.4"
rand_pcg = "0.3"
rand_chacha = "0.3"
rand = { git = "https://github.com/adamreichold/rand.git", branch = "numpy-compat", default-features = false, features = ["std", "nightly"] }
rand_distr = { git = "https://github.com/adamreichold/rand.git", branch = "numpy-compat" }
rand_pcg = { git = "https://github.com/adamreichold/rand.git", branch = "numpy-compat" }
raster = { path = "libraries/raster" }
......@@ -15,6 +15,6 @@ ENV RUSTUP_HOME=/usr/local/rustup \
RUN curl --output rustup-init --location https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init && \
chmod +x rustup-init && \
./rustup-init -y --no-modify-path --profile minimal --default-toolchain nightly-2021-11-01 --component clippy rustfmt --target x86_64-pc-windows-gnu && \
./rustup-init -y --no-modify-path --profile minimal --default-toolchain nightly-2021-11-21 --component clippy rustfmt --target x86_64-pc-windows-gnu && \
rm rustup-init && \
cargo install cargo-sweep
......@@ -88,9 +88,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.106"
version = "0.2.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a60553f9a9e039a333b4e9b20573b9e9b9c0bb3a11e201ccc48ef4283456d673"
checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"
[[package]]
name = "memoffset"
......
......@@ -9,6 +9,6 @@ ENV RUSTUP_HOME=/usr/local/rustup \
RUN curl --output rustup-init --location https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init && \
chmod +x rustup-init && \
./rustup-init -y --no-modify-path --profile minimal --default-toolchain nightly-2021-11-01 && \
./rustup-init -y --no-modify-path --profile minimal --default-toolchain nightly-2021-11-21 && \
rm rustup-init && \
cargo install cargo-sweep
......@@ -12,4 +12,4 @@ mpi = ["process/mpi"]
dump = { path = "../libraries/dump" }
model = { path = ".." }
process = { path = "../libraries/process" }
rand_distr = "0.4"
rand_distr = { git = "https://github.com/adamreichold/rand.git", branch = "numpy-compat" }
\subsection{Flower patch}
\label{flower-patch-submodel}
Flower patches \marginpar{rationale} are the source of nectar and pollen for the insects which need nectar to sustain their flight and the protein-rich pollen to fuel their reproductive activities. Only the availability of nectar is modelled explicitly as flowers seem to actively regulate the amount of available nectar. Presumbly this mechanism evolved to force pollinators to visit multiple plants whereas pollen is produced in large quantities to ensure a high probability of pollination for every visitation. \autocite{collection_of_pollen_by_bees} \autocite{food_for_pollinators}
Flower patches \marginpar{rationale} are the source of nectar and pollen for the insects which need nectar to sustain their flight and the protein-rich pollen to fuel their reproductive activities. Only the availability of nectar is modelled explicitly as flowers seem to actively regulate the amount of available nectar. Presumbly this mechanism evolved as it forces pollinators to visit multiple plants whereas pollen is produced in large quantities to ensure a high probability of pollination for every visitation. \autocite{collection_of_pollen_by_bees} \autocite{food_for_pollinators}
Considering the typical oral-fecal infection routes of bee pathogens, the individual flowers are the preferred unit of epidemiological contacts. But resource collection rates for seldomly studied species of wild pollinators are available only on the aggregate level of at least a single foraging bout. Additionally, the computational cost associated with tracking the relevant state variables for each flower as a separate entity has proven untenable. Therefore, the available floral resources are tracked on the aggregate flower patch level and this bulk flow of nutrients is used to drive the exploration of the landscape by the insects.
......
......@@ -21,20 +21,17 @@ use crate::{
solitary_bee::{Nest, NestLocation, SolitaryBee},
space::{mirror, Vector},
units::Length,
CryptoRng, Model, Rng, TaggedIndex, World,
Model, Rng, TaggedIndex, World,
};
\end{hiddencode}
The model is initialised independently by each process to avoid having to communicate its results from a chosen process to the other processes. To ensure a consistent initial model state all processes start with the same random seed and perform the same operations on the PRNG state even though entities that are located at other processes are discarded.
The seeding is performed in a two step process using a cryptographically secure pseudo-random number generator (CSPRNG) based on the ChaCha stream cipher \autocite{chacha_variant_salsa20} as the parent generator to seed the PRNG used for initialisation and for parallel simulation of the subworlds. This ensures that artificial correlations between the PRNG instances due to their internal structure are highly unlikely due to the avalance criterion fulfilled by the CSPRNG. \autocite{parallel_random_numbers}
\begin{code}
impl Model {
#[cold]
pub fn new(params: Params, rank: u8, size: u8) -> Self {
let mut parent_rng = CryptoRng::seed_from_u64(params.init.seed);
let mut rng = Rng::from_rng(&mut parent_rng).unwrap();
let mut rng = Rng::seed_from_u64(params.init.seed);
\end{code}
\phantomsection
......@@ -331,12 +328,13 @@ The observers are mobile entities which are initially positioned along a transec
});
\end{code}
Each subworld is provided with a PRNG seeded from a cryptographically-secure RNG to avoid artificial correlations between the streams of pseudo-random numbers.
Each subworld is provided with a PRNG seeded using the same state derived from the PRNG used for initialisation but the stream parameter given by the process rank thereby selecting independent streams for each subworld. \autocite{pcg_family_algorithms_random_number_generation}
\begin{code}
for _ in 0..rank {
rng = Rng::from_rng(&mut parent_rng).unwrap();
}
rng = Rng::new(
rng.gen::<u128>(),
rng.gen::<u128>().wrapping_add(rank as u128),
);
\end{code}
Finally, an associative set of lists of messages used to relocate mobile entities between subworlds as explained in \autoref{process-overview} is allocated for each neighbouring process as determined by the spatial subdivision described in \autoref{grid}.
......
......@@ -24,8 +24,7 @@ pub mod units;
use std::collections::BinaryHeap;
use std::mem::transmute;
pub use rand_chacha::ChaCha8Rng as CryptoRng;
pub use rand_pcg::Pcg64 as Rng;
pub use rand_pcg::Pcg64Dxsm as Rng;
use kdtree::KDTree;
use process::{MailBoxes, Message, Process};
......
......@@ -263,15 +263,15 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "libc"
version = "0.2.106"
version = "0.2.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a60553f9a9e039a333b4e9b20573b9e9b9c0bb3a11e201ccc48ef4283456d673"
checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"
[[package]]
name = "libloading"
version = "0.7.1"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0cf036d15402bea3c5d4de17b3fce76b3e4a56ebc1f577be0e7a72f7c607cf0"
checksum = "afe203d669ec979b7128619bae5a63b7b42e9203c1b29146079ee05e2f604b52"
dependencies = [
"cfg-if",
"winapi",
......@@ -339,7 +339,6 @@ dependencies = [
"process",
"queue",
"rand",
"rand_chacha",
"rand_distr",
"rand_pcg",
"raster",
......@@ -436,9 +435,8 @@ dependencies = [
[[package]]
name = "rand"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8"
version = "0.8.5"
source = "git+https://github.com/adamreichold/rand.git?branch=numpy-compat#b63a533cbc8500568a42dc4e6e0ab26042a2ae03"
dependencies = [
"libc",
"rand_chacha",
......@@ -448,8 +446,7 @@ dependencies = [
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
source = "git+https://github.com/adamreichold/rand.git?branch=numpy-compat#b63a533cbc8500568a42dc4e6e0ab26042a2ae03"
dependencies = [
"ppv-lite86",
"rand_core",
......@@ -457,9 +454,8 @@ dependencies = [
[[package]]
name = "rand_core"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
version = "0.6.4"
source = "git+https://github.com/adamreichold/rand.git?branch=numpy-compat#b63a533cbc8500568a42dc4e6e0ab26042a2ae03"
dependencies = [
"getrandom",
]
......@@ -467,8 +463,7 @@ dependencies = [
[[package]]
name = "rand_distr"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "964d548f8e7d12e102ef183a0de7e98180c9f8729f555897a857b96e48122d2f"
source = "git+https://github.com/adamreichold/rand.git?branch=numpy-compat#b63a533cbc8500568a42dc4e6e0ab26042a2ae03"
dependencies = [
"num-traits",
"rand",
......@@ -477,8 +472,7 @@ dependencies = [
[[package]]
name = "rand_pcg"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59cad018caf63deb318e5a4586d99a24424a364f40f1e5778c29aca23f4fc73e"
source = "git+https://github.com/adamreichold/rand.git?branch=numpy-compat#b63a533cbc8500568a42dc4e6e0ab26042a2ae03"
dependencies = [
"rand_core",
]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment