Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
285 changes: 277 additions & 8 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ members = [
"necsim/plugins/metacommunity",
"necsim/plugins/statistics",
"necsim/plugins/species",
"necsim/plugins/tskit",

"necsim/partitioning/core",
"necsim/partitioning/monolithic",
Expand All @@ -39,6 +40,7 @@ default-members = [
"necsim/plugins/metacommunity",
"necsim/plugins/statistics",
"necsim/plugins/species",
"necsim/plugins/tskit",
]

[profile.release]
Expand Down
14 changes: 14 additions & 0 deletions necsim/core/src/lineage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ use crate::{
#[repr(transparent)]
pub struct GlobalLineageReference(NonZeroOneU64);

impl GlobalLineageReference {
#[doc(hidden)]
#[must_use]
pub unsafe fn into_inner(self) -> NonZeroOneU64 {
self.0
}

#[doc(hidden)]
#[must_use]
pub unsafe fn from_inner(inner: NonZeroOneU64) -> Self {
Self(inner)
}
}

impl fmt::Display for GlobalLineageReference {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.0.get() - 2)
Expand Down
1 change: 1 addition & 0 deletions necsim/impls/no-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ serde = { version = "1.0", default-features = false, features = ["alloc", "deriv
log = "0.4"
displaydoc = { version = "0.2", default-features = false, features = [] }
final = { git = "https://github.com/MomoLangenstein/final", rev = "a2dbfd6" }
fnv = { version = "1.0", default-features = false, features = [] }

[target.'cfg(target_os = "cuda")'.dependencies]
rust-cuda = { git = "https://github.com/MomoLangenstein/rust-cuda", branch = "main", features = ["derive"], optional = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use core::{
hash::Hash,
num::{NonZeroU128, NonZeroUsize},
};
use fnv::FnvBuildHasher;

use hashbrown::HashMap;

Expand All @@ -26,7 +27,7 @@ struct RejectionSamplingGroup<E: Eq + Hash> {
pub struct DynamicAliasMethodIndexedSampler<E: Eq + Hash + Clone> {
exponents: Vec<i16>,
groups: Vec<RejectionSamplingGroup<E>>,
lookup: HashMap<E, EventLocation>,
lookup: HashMap<E, EventLocation, FnvBuildHasher>,
min_exponent: i16,
total_weight: u128,
}
Expand All @@ -47,7 +48,7 @@ impl<E: Eq + Hash> RejectionSamplingGroup<E> {

unsafe fn sample_pop_inplace<M: MathsCore, G: RngCore<M>>(
&mut self,
lookup: &mut HashMap<E, EventLocation>,
lookup: &mut HashMap<E, EventLocation, FnvBuildHasher>,
rng: &mut G,
) -> (Option<&mut Self>, E) {
if let [event] = &self.events[..] {
Expand Down Expand Up @@ -86,7 +87,7 @@ impl<E: Eq + Hash> RejectionSamplingGroup<E> {
#[cfg(test)]
fn sample_pop<M: MathsCore, G: RngCore<M>>(
mut self,
lookup: &mut HashMap<E, EventLocation>,
lookup: &mut HashMap<E, EventLocation, FnvBuildHasher>,
rng: &mut G,
) -> (Option<Self>, E) {
match unsafe { self.sample_pop_inplace(lookup, rng) } {
Expand All @@ -98,7 +99,7 @@ impl<E: Eq + Hash> RejectionSamplingGroup<E> {
unsafe fn remove_inplace(
&mut self,
index: usize,
lookup: &mut HashMap<E, EventLocation>,
lookup: &mut HashMap<E, EventLocation, FnvBuildHasher>,
) -> Option<&mut Self> {
self.events.swap_remove(index);
let weight = self.weights.swap_remove(index);
Expand All @@ -119,7 +120,11 @@ impl<E: Eq + Hash> RejectionSamplingGroup<E> {
}

#[cfg(test)]
fn remove(mut self, index: usize, lookup: &mut HashMap<E, EventLocation>) -> Option<Self> {
fn remove(
mut self,
index: usize,
lookup: &mut HashMap<E, EventLocation, FnvBuildHasher>,
) -> Option<Self> {
if unsafe { self.remove_inplace(index, lookup) }.is_some() {
Some(self)
} else {
Expand Down Expand Up @@ -158,7 +163,7 @@ impl<E: Eq + Hash + Clone> DynamicAliasMethodIndexedSampler<E> {
Self {
exponents: Vec::new(),
groups: Vec::new(),
lookup: HashMap::new(),
lookup: HashMap::default(),
min_exponent: 0_i16,
total_weight: 0_u128,
}
Expand All @@ -172,7 +177,7 @@ impl<E: Eq + Hash + Clone> DynamicAliasMethodIndexedSampler<E> {
Self {
exponents: Vec::with_capacity(capacity_log2_approx),
groups: Vec::with_capacity(capacity_log2_approx),
lookup: HashMap::with_capacity(capacity),
lookup: HashMap::with_capacity_and_hasher(capacity, FnvBuildHasher::default()),
min_exponent: 0_i16,
total_weight: 0_u128,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ fn singular_event_group() {
assert_eq!(&group.weights, &[1_u64]);
assert_eq!(group.total_weight, 1_u128);

assert!(group.remove(0, &mut HashMap::new()).is_none());
assert!(group.remove(0, &mut HashMap::default()).is_none());
}

#[test]
#[allow(clippy::too_many_lines)]
fn add_remove_event_group() {
let mut group = RejectionSamplingGroup::new(0_u8, 1_u64);

let mut lookup = HashMap::new();
let mut lookup = HashMap::default();
lookup.insert(
0_u8,
EventLocation {
Expand Down Expand Up @@ -137,7 +137,7 @@ fn add_remove_event_group() {
);

assert_eq!(
group.sample_pop(&mut HashMap::new(), &mut DummyRng::new(vec![0.0, 0.0])),
group.sample_pop(&mut HashMap::default(), &mut DummyRng::new(vec![0.0, 0.0])),
(None, 2_u8)
);
}
Expand All @@ -151,7 +151,7 @@ fn sample_single_group() {
decompose_weight(PositiveF64::new(6.0 / 12.0).unwrap()).mantissa,
);

let mut lookup = HashMap::new();
let mut lookup = HashMap::default();

for i in 1..6 {
assert_eq!(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use core::{marker::PhantomData, ops::Index};

use fnv::FnvBuildHasher;
use hashbrown::hash_map::HashMap;
use slab::Slab;

Expand All @@ -20,7 +21,7 @@ mod store;
#[derive(Debug)]
pub struct AlmostInfiniteLineageStore<M: MathsCore> {
lineages_store: Slab<Lineage>,
location_to_lineage_reference: HashMap<Location, InMemoryLineageReference>,
location_to_lineage_reference: HashMap<Location, InMemoryLineageReference, FnvBuildHasher>,
_marker: PhantomData<M>,
}

Expand All @@ -46,7 +47,8 @@ impl<M: MathsCore> AlmostInfiniteLineageStore<M> {
let lineages_amount_hint = origin_sampler.full_upper_bound_size_hint() as usize;

let mut lineages_store = Slab::with_capacity(lineages_amount_hint);
let mut location_to_lineage_references = HashMap::with_capacity(lineages_amount_hint);
let mut location_to_lineage_references =
HashMap::with_capacity_and_hasher(lineages_amount_hint, FnvBuildHasher::default());

for lineage in origin_sampler {
location_to_lineage_references.insert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use core::{marker::PhantomData, ops::Index};

use alloc::vec::Vec;

use fnv::FnvBuildHasher;
use hashbrown::hash_map::HashMap;
use slab::Slab;

Expand All @@ -21,7 +22,7 @@ pub struct GillespieLineageStore<M: MathsCore, H: Habitat<M>> {
lineages_store: Slab<Lineage>,
location_to_lineage_references: Array2D<Vec<InMemoryLineageReference>>,
indexed_location_to_lineage_reference:
HashMap<IndexedLocation, (GlobalLineageReference, usize)>,
HashMap<IndexedLocation, (GlobalLineageReference, usize), FnvBuildHasher>,
_marker: PhantomData<(M, H)>,
}

Expand Down Expand Up @@ -55,7 +56,7 @@ impl<'h, M: MathsCore, H: 'h + Habitat<M>> GillespieLineageStore<M, H> {
);

let mut indexed_location_to_lineage_reference =
HashMap::with_capacity(lineages_amount_hint);
HashMap::with_capacity_and_hasher(lineages_amount_hint, FnvBuildHasher::default());

let x_from = landscape_extent.x();
let y_from = landscape_extent.y();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use core::{marker::PhantomData, ops::Index};

use fnv::FnvBuildHasher;
use hashbrown::hash_map::HashMap;
use slab::Slab;

Expand All @@ -17,7 +18,8 @@ mod store;
#[derive(Debug)]
pub struct ClassicalLineageStore<M: MathsCore, H: Habitat<M>> {
lineages_store: Slab<Lineage>,
indexed_location_to_lineage_reference: HashMap<IndexedLocation, InMemoryLineageReference>,
indexed_location_to_lineage_reference:
HashMap<IndexedLocation, InMemoryLineageReference, FnvBuildHasher>,
_marker: PhantomData<(M, H)>,
}

Expand All @@ -43,7 +45,7 @@ impl<'h, M: MathsCore, H: 'h + Habitat<M>> ClassicalLineageStore<M, H> {
let mut lineages_store = Slab::with_capacity(lineages_amount_hint);

let mut indexed_location_to_lineage_reference =
HashMap::with_capacity(lineages_amount_hint);
HashMap::with_capacity_and_hasher(lineages_amount_hint, FnvBuildHasher::default());

for lineage in origin_sampler {
let indexed_location = lineage.indexed_location.clone();
Expand Down
1 change: 1 addition & 0 deletions necsim/plugins/metacommunity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ necsim-plugins-core = { path = "../core", features = ["export"] }
serde = { version = "1.0", features = ["derive"] }
log = { version = "0.4" }
rand = "0.8"
fnv = "1.0"
4 changes: 3 additions & 1 deletion necsim/plugins/metacommunity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extern crate log;

use std::{collections::HashSet, fmt, num::NonZeroU64};

use fnv::FnvBuildHasher;
use rand::{rngs::StdRng, Rng, SeedableRng};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -102,7 +103,8 @@ impl Reporter for MetacommunityMigrationReporter {

let mut rng = StdRng::seed_from_u64(self.seed);

let mut unique_migration_targets = HashSet::new();
let mut unique_migration_targets =
HashSet::with_capacity_and_hasher(self.migrations, FnvBuildHasher::default());

for _ in 0..self.migrations {
unique_migration_targets.insert(rng.gen_range(0..metacommunity_size.get()));
Expand Down
1 change: 1 addition & 0 deletions necsim/plugins/species/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ necsim-plugins-core = { path = "../core", features = ["export"] }
serde = { version = "1.0", features = ["derive"] }
log = { version = "0.4" }
rusqlite = "0.26"
fnv = "1.0"
9 changes: 5 additions & 4 deletions necsim/plugins/species/src/species/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{collections::HashMap, convert::TryFrom, fmt, path::PathBuf};

use fnv::FnvBuildHasher;
use rusqlite::Connection;
use serde::{Deserialize, Serialize};

Expand All @@ -26,9 +27,9 @@ pub struct SpeciesLocationsReporter {
// Original (present-time) locations of all lineages
origins: Vec<(GlobalLineageReference, IndexedLocation)>,
// Child -> Parent lineage mapping
parents: HashMap<GlobalLineageReference, GlobalLineageReference>,
parents: HashMap<GlobalLineageReference, GlobalLineageReference, FnvBuildHasher>,
// Species originator -> Species identities mapping
species: HashMap<GlobalLineageReference, SpeciesIdentity>,
species: HashMap<GlobalLineageReference, SpeciesIdentity, FnvBuildHasher>,

output: PathBuf,
table: String,
Expand Down Expand Up @@ -79,8 +80,8 @@ impl TryFrom<SpeciesLocationsReporterArgs> for SpeciesLocationsReporter {
last_dispersal_event: None,

origins: Vec::new(),
parents: HashMap::new(),
species: HashMap::new(),
parents: HashMap::default(),
species: HashMap::default(),

output: args.output,
table: args.table,
Expand Down
31 changes: 31 additions & 0 deletions necsim/plugins/tskit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
name = "necsim-plugins-tskit"
version = "0.1.0"
authors = ["Momo Langenstein <momo.langenstein17@imperial.ac.uk>"]
license = "MIT OR Apache-2.0"
edition = "2018"

[lib]
crate-type = ["cdylib"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
necsim-core = { path = "../../core" }
necsim-core-bond = { path = "../../core/bond" }
necsim-plugins-core = { path = "../core", features = ["export"] }

serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tskit = { version = "0.5", features = ["provenance"] }
uname = "0.1"
findshlibs = "0.10"
fnv = "1.0"

rustc_version = "0.4"
semver = { version = "1.0", features = ["serde"] }
git-version = "0.3"

[build-dependencies]
rustc_version = "0.4"
semver = "1.0"
Loading