The UFZ services GitLab and Mattermost will be unavailable on Monday, July 4 from 06:00 AM to 08:00 AM due to maintenance work.

Commit 45fda315 authored by Adam Reichold's avatar Adam Reichold
Browse files

WIP: Move the flower_contaminators into each FlowerPatch to be able to trace...

WIP: Move the flower_contaminators into each FlowerPatch to be able to trace through save/restore cycles.
parent 987f44c2
Pipeline #82372 passed with stage
in 3 minutes and 14 seconds
......@@ -6,17 +6,6 @@ version = 3
name = "access"
version = "0.1.0"
[[package]]
name = "ahash"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"
dependencies = [
"getrandom",
"once_cell",
"version_check",
]
[[package]]
name = "autocfg"
version = "1.1.0"
......@@ -59,33 +48,24 @@ dependencies = [
[[package]]
name = "getrandom"
version = "0.2.5"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77"
checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "hashbrown"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758"
dependencies = [
"ahash",
]
[[package]]
name = "kdtree"
version = "0.1.0"
[[package]]
name = "libc"
version = "0.2.119"
version = "0.2.121"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4"
checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f"
[[package]]
name = "libm"
......@@ -99,7 +79,6 @@ version = "0.1.0"
dependencies = [
"access",
"dump",
"hashbrown",
"memmap2",
"model",
]
......@@ -119,7 +98,6 @@ version = "0.1.0"
dependencies = [
"access",
"bitmap",
"hashbrown",
"kdtree",
"process",
"queue",
......@@ -140,12 +118,6 @@ dependencies = [
"libm",
]
[[package]]
name = "once_cell"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9"
[[package]]
name = "pkg-config"
version = "0.3.24"
......@@ -226,12 +198,6 @@ dependencies = [
"memmap2",
]
[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
......
......@@ -15,7 +15,6 @@ path = "src/lib.rs"
[dependencies]
access = { path = "libraries/access" }
bitmap = { path = "libraries/bitmap" }
hashbrown = "0.12"
kdtree = { path = "libraries/kdtree" }
process = { path = "libraries/process" }
queue = { path = "libraries/queue" }
......
......@@ -102,7 +102,15 @@ unsafe impl Dump for TemporalNetwork {
}
}
unsafe impl Dump for FlowerPatch {}
unsafe impl Dump for FlowerPatch {
fn save<'a>(&'a self, buf: &mut Vec<IoSlice<'a>>, pos: &mut usize) {
self.flower_contaminators.save(buf, pos);
}
unsafe fn restore(buf: &mut [u8], this: *mut Self) -> &mut [u8] {
Dump::restore(buf, addr_of_mut!((*this).flower_contaminators))
}
}
unsafe impl Dump for FlowerPatchEvent {}
......
......@@ -8,6 +8,5 @@ edition = "2018"
[dependencies]
access = { path = "../libraries/access" }
dump = { path = "../libraries/dump" }
hashbrown = "0.12"
memmap2 = "0.5"
model = { path = ".." }
use std::collections::{HashMap, HashSet};
use std::env::args_os;
use hashbrown::{HashMap, HashSet};
use measurements::{collect, flower_patches, insects};
fn main() {
......
use std::collections::{HashMap, HashSet};
use std::env::args_os;
use hashbrown::{HashMap, HashSet};
use measurements::{collect, insects};
use model::{insect::Species as InsectSpecies, observer::Observation};
......
use std::collections::HashMap;
use std::env::args_os;
use hashbrown::HashMap;
use measurements::{collect, flower_patches, insects};
use model::{flower_patch::Species as FlowerPatchSpecies, insect::Species as InsectSpecies};
......
......@@ -36,7 +36,7 @@ use crate::{
pathogen::{colony_decontamination, colony_infection_contamination, Contaminated},
space::{reduce, shortest_path, Vector},
units::Tick,
Contacts, FlowerContaminators, NextId, Rng, TaggedIndex, TemporalNetwork, Vectors,
Contacts, NextId, Rng, TaggedIndex, TemporalNetwork, Vectors,
};
\end{hiddencode}
......@@ -93,7 +93,6 @@ impl Bumblebee {
flower_patch_locations: &KDTree<FlowerPatchLocation>,
visible_flower_patch_locations: &mut Vec<&'static FlowerPatchLocation>,
visited_flowers: &mut Vec<u16>,
flower_contaminators: &mut FlowerContaminators,
flower_patch_events: &mut BinaryHeap<FlowerPatchEvent>,
tick: Tick,
flower_patches: &mut [FlowerPatch],
......@@ -168,7 +167,6 @@ impl Bumblebee {
flower_patch_locations,
visible_flower_patch_locations,
visited_flowers,
flower_contaminators,
flower_patch_events,
tick,
flower_patches,
......
......@@ -40,7 +40,7 @@ Having both a continuous representation of available resources by tracking necta
The auxiliary variable \inlinecode{contaminated\_by\_species} is used to track which insect species was responsible for last contamination of a flower in this patch and does not affect the pathogen dynamics but is used as a micro-observable as described in \autoref{micro-observables}.
\begin{code}
#[derive(Clone, Copy)]
#[derive(Clone)]
pub struct FlowerPatch {
pub species: Species,
pub nectar: Mass,
......@@ -49,6 +49,7 @@ pub struct FlowerPatch {
pub empty_flowers: Bitmap,
pub contaminated_flowers: Bitmap,
pub contaminated_by_species: MaybeUninit<InsectSpecies>,
pub flower_contaminators: Box<[Vec<(u32, Tick)>]>,
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
......@@ -110,6 +111,12 @@ For the non-depleted flower patches, the discrete representation of available ne
nectar
};
let flower_contaminators = if params.trace_temporal_network {
(0..flowers).map(|_| Default::default()).collect()
} else {
Default::default()
};
Self {
species,
nectar,
......@@ -118,6 +125,7 @@ For the non-depleted flower patches, the discrete representation of available ne
empty_flowers,
contaminated_flowers,
contaminated_by_species: MaybeUninit::uninit(),
flower_contaminators,
}
}
}
......
......@@ -45,7 +45,7 @@ use crate::{
reduce_lifetime,
space::{reduce, Vector, WithinDistanceOfLine},
units::Tick,
Contacts, FlowerContaminators, NextId, Rng, TaggedIndex, TemporalNetwork, Vectors,
Contacts, NextId, Rng, TaggedIndex, TemporalNetwork, Vectors,
};
\end{hiddencode}
......@@ -107,7 +107,6 @@ The state update \marginpar{state update} directly manages the reproductive acti
flower_patch_locations: &KDTree<FlowerPatchLocation>,
visible_flower_patch_locations: &mut Vec<&'static FlowerPatchLocation>,
visited_flowers: &mut Vec<u16>,
flower_contaminators: &mut FlowerContaminators,
flower_patch_events: &mut BinaryHeap<FlowerPatchEvent>,
clutch_locations: &KDTree<ClutchLocation>,
visible_clutch_locations: &mut Vec<&'static ClutchLocation>,
......@@ -229,7 +228,6 @@ The integration with the generic insect submodel is handled via the \inlinecode{
flower_patch_locations,
visible_flower_patch_locations,
visited_flowers,
flower_contaminators,
flower_patch_events,
tick,
flower_patches,
......
......@@ -431,7 +431,6 @@ Finally, an associative set of lists of messages used to relocate mobile entitie
grid,
flower_patch_locations: KDTree::new(flower_patch_locations.into()),
visible_flower_patch_locations: Default::default(),
flower_contaminators: Default::default(),
clutch_locations: KDTree::new(clutch_locations.into()),
visible_clutch_locations: Default::default(),
nest_locations: KDTree::new(nest_locations.into()),
......
......@@ -45,7 +45,7 @@ use crate::{
reduce_lifetime,
space::{reduce, Vector, WithinDistanceOfLine},
units::{Tick, Volume},
Contacts, FlowerContaminators, NextId, Rng, TaggedIndex, TemporalNetwork, Vectors,
Contacts, NextId, Rng, TaggedIndex, TemporalNetwork, Vectors,
};
\end{hiddencode}
......@@ -147,7 +147,6 @@ The state update function \marginpar{state update} implements the state machine
flower_patch_locations: &KDTree<FlowerPatchLocation>,
visible_flower_patch_locations: &mut Vec<&'static FlowerPatchLocation>,
visited_flowers: &mut Vec<u16>,
flower_contaminators: &mut FlowerContaminators,
flower_patch_events: &mut BinaryHeap<FlowerPatchEvent>,
tick: Tick,
flower_patches: &mut [FlowerPatch],
......@@ -284,7 +283,6 @@ As the scarcity of nectar is primarily used as a driver for the exploration of t
&mut self.pathogen_status,
*index,
flower,
flower_contaminators,
flower_patch_events,
tick,
flower_patch,
......
......@@ -24,7 +24,6 @@ pub mod units;
use std::collections::BinaryHeap;
use std::mem::transmute;
use hashbrown::HashMap;
pub use rand_chacha::ChaCha8Rng as CryptoRng;
pub use rand_pcg::Pcg64 as Rng;
......@@ -118,7 +117,7 @@ It also contains several auxiliary data structures which are used during the sim
TODO: Furthermore, the \inlinecode{visited_flowers} buffers are used to store the trajectories each insect takes along the flowers within a patch which are stored independently of the state of the insects as they are never relocated to another subworld as a relocation implies not being within a flower patch.
Finally, the \inlinecode{flower_contaminators} hash table is used to determine which individual is responsible for contaminating a flower wihtin a patch and is used to trace the temporal structure of potentially epidemiologically relevant contacts.
TODO: Finally, the \inlinecode{flower_contaminators} hash table is used to determine which individual is responsible for contaminating a flower wihtin a patch and is used to trace the temporal structure of potentially epidemiologically relevant contacts.
\begin{code}
pub struct Model {
......@@ -127,15 +126,12 @@ pub struct Model {
pub grid: Grid,
pub flower_patch_locations: KDTree<FlowerPatchLocation>,
visible_flower_patch_locations: Vec<&'static FlowerPatchLocation>,
flower_contaminators: FlowerContaminators,
pub clutch_locations: KDTree<ClutchLocation>,
visible_clutch_locations: Vec<&'static ClutchLocation>,
pub nest_locations: KDTree<NestLocation>,
visible_nest_locations: Vec<&'static NestLocation>,
relocations: MailBoxes<Relocation>,
}
pub type FlowerContaminators = HashMap<(TaggedIndex, u16), Vec<(u32, Tick)>>;
\end{code}
The subworld state itself consists of the current time step \inlinecode{tick}, the state associated with the various entities resp. their driving submodels, a PCG pseudo-random number generator (PRNG) \inlinecode{rng} \autocite{pcg_family_algorithms_random_number_generation} and the measurements of several micro-observables.
......@@ -253,7 +249,6 @@ impl Model {
&self.grid,
&self.flower_patch_locations,
&mut self.visible_flower_patch_locations,
&mut self.flower_contaminators,
&self.clutch_locations,
&mut self.visible_clutch_locations,
&self.nest_locations,
......@@ -353,7 +348,6 @@ impl World {
grid: &Grid,
flower_patch_locations: &KDTree<FlowerPatchLocation>,
visible_flower_patch_locations: &mut Vec<&'static FlowerPatchLocation>,
flower_contaminators: &mut FlowerContaminators,
clutch_locations: &KDTree<ClutchLocation>,
visible_clutch_locations: &mut Vec<&'static ClutchLocation>,
nest_locations: &KDTree<NestLocation>,
......@@ -387,7 +381,6 @@ The invocation order between the three insect families is fixed, i.e. first the
flower_patch_locations,
visible_flower_patch_locations,
&mut self.visited_flowers[0][idx],
flower_contaminators,
&mut self.flower_patch_events,
clutch_locations,
visible_clutch_locations,
......@@ -460,7 +453,6 @@ Note that the entries of the \inlinecode{visited\_flowers} arrays are never disc
flower_patch_locations,
visible_flower_patch_locations,
&mut self.visited_flowers[1][idx],
flower_contaminators,
&mut self.flower_patch_events,
nest_locations,
visible_nest_locations,
......@@ -499,7 +491,6 @@ Note that the entries of the \inlinecode{visited\_flowers} arrays are never disc
flower_patch_locations,
visible_flower_patch_locations,
&mut self.visited_flowers[2][idx],
flower_contaminators,
&mut self.flower_patch_events,
self.tick,
&mut self.flower_patches,
......
......@@ -62,7 +62,7 @@ use crate::{
insect::Species as InsectSpecies,
params::{Bumblebee as BumblebeeParams, Insect as InsectParams, Params},
units::Tick,
FlowerContaminators, Rng, TaggedIndex, TemporalNetwork, Vectors,
Rng, TaggedIndex, TemporalNetwork, Vectors,
};
\end{hiddencode}
......@@ -104,7 +104,6 @@ pub fn infection_contamination(
status: &mut Status,
index: TaggedIndex,
flower: u16,
flower_contaminators: &mut FlowerContaminators,
flower_patch_events: &mut BinaryHeap<FlowerPatchEvent>,
tick: Tick,
flower_patch: &mut FlowerPatch,
......@@ -121,7 +120,7 @@ The \inlinecode{flower_contaminators} hash table is used to track which individu
\begin{code}
if params.trace_temporal_network {
let flower_contaminators = flower_contaminators.entry((index, flower)).or_default();
let flower_contaminators = &mut flower_patch.flower_contaminators[flower as usize];
flower_contaminators.retain(|(contaminator, decontaminates_at)| {
if *decontaminates_at > tick {
......
......@@ -44,7 +44,7 @@ use crate::{
reduce_lifetime,
space::{reduce, shortest_path, Vector, WithinDistanceOfLine},
units::Tick,
Contacts, FlowerContaminators, NextId, Rng, TaggedIndex, TemporalNetwork, Vectors,
Contacts, NextId, Rng, TaggedIndex, TemporalNetwork, Vectors,
};
\end{hiddencode}
......@@ -101,7 +101,6 @@ impl SolitaryBee {
flower_patch_locations: &KDTree<FlowerPatchLocation>,
visible_flower_patch_locations: &mut Vec<&'static FlowerPatchLocation>,
visited_flowers: &mut Vec<u16>,
flower_contaminators: &mut FlowerContaminators,
flower_patch_events: &mut BinaryHeap<FlowerPatchEvent>,
nest_locations: &KDTree<NestLocation>,
visible_nest_locations: &mut Vec<&'static NestLocation>,
......@@ -235,7 +234,6 @@ impl SolitaryBee {
flower_patch_locations,
visible_flower_patch_locations,
visited_flowers,
flower_contaminators,
flower_patch_events,
tick,
flower_patches,
......
Markdown is supported
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