Skip to content

Commit

Permalink
Random Interactions: Initiial fully functional random daily interactions
Browse files Browse the repository at this point in the history
- Per day generation of random interactions via host layer function(s)
- Target number per individual generated once at start of simulation, from a normal distribution from model parameters
- Not all target amounts will lead to valid interaction combinations, leading to less actual interactions than intended
- Does not exclude self interactions yet
- Does not exclude repeat interactions on a given day (but this would increase the likelihood of exposure)
- Implemented in serial on the CPU - will not scale well, but GPU implementation non-trivial.
- Possible encountered a FLAME GPU 2 bug / limitation, tobe investigated and reported
- Not implemented binomeal sampling (yet)
- Added CMAKE configuraiton option for the maximum number
- Could improve perf by changing this implementation, to be investigated
  • Loading branch information
ptheywood committed Dec 3, 2024
1 parent 241bf7d commit d9e0577
Show file tree
Hide file tree
Showing 10 changed files with 296 additions and 38 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ option(BUILD_TESTING "Build the testing tree." OFF)
# Option to enable google test test discovery
cmake_dependent_option(ENABLE_GTEST_DISCOVER "Enable GTEST_DISCOVER for more detailed ctest output without -VV. This dramatically increases test suite runtime to CUDA context initialisation." OFF "BUILD_TESTING" OFF)

# CMAke Cache option for the maximum number of per-agent random interactions.
# If the value is changed here, CMakeCache.txt / the build dir will need deleting
# Or reconfigure with -DEXATEPP_ABM_MAX_RANDOM_DAILY_INTERACTIONS=<new>
set(EXATEPP_ABM_MAX_RANDOM_DAILY_INTERACTIONS "20" CACHE STRING "Maximum number of random daily interactions per agent")

# Include common rules from the FLAMEGPU/FLAMEGPU2 repositories CMake
include(${FLAMEGPU_ROOT}/cmake/common.cmake)

Expand Down
12 changes: 7 additions & 5 deletions data/inputs/sample.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
rng_seed,param_id,duration,n_total,n_seed_infection,population_0_9,population_10_19,population_20_29,population_30_39,population_40_49,population_50_59,population_60_69,population_70_79,population_80,household_size_1,household_size_2,household_size_3,household_size_4,household_size_5,household_size_6,p_interaction_susceptible_to_exposed,mean_time_to_infected,sd_time_to_infected,mean_time_to_recovered,sd_time_to_recovered,mean_time_to_susceptible,sd_time_to_susceptible,relative_susceptibility_0_9,relative_susceptibility_10_19,relative_susceptibility_20_29,relative_susceptibility_30_39,relative_susceptibility_40_49,relative_susceptibility_50_59,relative_susceptibility_60_69,relative_susceptibility_70_79,relative_susceptibility_80,child_network_adults,elderly_network_adults,relative_transmission_household,relative_transmission_occupation,relative_transmission_random,daily_fraction_work
12,0,365,1024,8,4,4,4,4,4,4,3,2,1,442,492,208,165,51,27,0.05,3.5,1.0,7.0,1.0,28,5.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.2,0.2,2.0,1.0,1.0,0.02
12,1,365,4096,8,331,370,374,371,361,415,377,270,142,442,492,208,165,51,27,0.10,3.5,2.0,7.0,2.0,28,10.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.2,0.2,2.0,0.5,0.5,0.001
12,2,365,16384,8,331,370,374,371,361,415,377,270,142,442,492,208,165,51,27,0.10,3.5,1.0,7.0,1.0,28,5.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.2,0.2,2.0,0.3,0.3,0.001
12,3,1,54,8,331,370,374,371,361,415,377,270,142,0,0,0,0,0,1,0.10,3.5,1.0,7.0,1.0,28,5.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.2,0.2,2.0,0.3,0.3,0.001
rng_seed,param_id,duration,n_total,n_seed_infection,population_0_9,population_10_19,population_20_29,population_30_39,population_40_49,population_50_59,population_60_69,population_70_79,population_80,household_size_1,household_size_2,household_size_3,household_size_4,household_size_5,household_size_6,p_interaction_susceptible_to_exposed,mean_time_to_infected,sd_time_to_infected,mean_time_to_recovered,sd_time_to_recovered,mean_time_to_susceptible,sd_time_to_susceptible,relative_susceptibility_0_9,relative_susceptibility_10_19,relative_susceptibility_20_29,relative_susceptibility_30_39,relative_susceptibility_40_49,relative_susceptibility_50_59,relative_susceptibility_60_69,relative_susceptibility_70_79,relative_susceptibility_80,child_network_adults,elderly_network_adults,relative_transmission_household,relative_transmission_occupation,relative_transmission_random,daily_fraction_work,mean_random_interactions_0_19,sd_random_interactions_0_19,mean_random_interactions_20_69,sd_random_interactions_20_69,mean_random_interactions_70plus,sd_random_interactions_70plus
12,0,60,32,4,331,370,374,371,361,415,377,270,142,442,492,208,165,51,27,0.10,3.5,2.0,7.0,2.0,28,10.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.2,0.2,2.0,0.5,0.5,0.001,2,2,100,4,3,3
12,1,365,32,4,331,370,374,371,361,415,377,270,142,442,492,208,165,51,27,0.10,3.5,2.0,7.0,2.0,28,10.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.2,0.2,2.0,0.5,0.5,0.001,2,2,4,4,3,3
12,2,365,1024,8,331,370,374,371,361,415,377,270,142,442,492,208,165,51,27,0.10,3.5,2.0,7.0,2.0,28,10.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.2,0.2,2.0,0.5,0.5,0.001,2,2,4,4,3,3
12,3,365,4096,8,331,370,374,371,361,415,377,270,142,442,492,208,165,51,27,0.10,3.5,2.0,7.0,2.0,28,10.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.2,0.2,2.0,0.5,0.5,0.001,2,2,4,4,3,3
12,4,365,4096,8,331,370,374,371,361,415,377,270,142,442,492,208,165,51,27,0.10,3.5,2.0,7.0,2.0,28,10.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.2,0.2,2.0,0.5,0.5,0.001,2,2,4,4,3,3
12,5,365,65536,8,331,370,374,371,361,415,377,270,142,442,492,208,165,51,27,0.10,3.5,2.0,7.0,2.0,28,10.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.2,0.2,2.0,0.5,0.5,0.001,2,2,4,4,3,3
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ cmake --build . --target exatepp_abm -j 8
| `CMAKE_CUDA_ARCHITECTURES` | `"50;60;70;80;90"` | ` Specify which CUDA [Compute Capability](https://developer.nvidia.com/cuda-gpus) Architectures to build for |
| `CMAKE_BUILD_TYPE` | `Release` | CMake build configuration, setting optimisation levels etc. Choose from [`Release`, `RelWithDebInfo`, `MinSizeRel`, `Debug`] |
| `BUILD_TESTING` | `OFF` | Enable / disable the test suite |
| `EXATEPP_ABM_MAX_RANDOM_DAILY_INTERACTIONS` | `20` | The maximum number of per agent random daily interactions for the build. If this is exceeded due to model parameters an error will be reported, and you must reconfigure and rebuild with a higher value. |
| `FLAMEGPU_VISUALISATION` | `OFF` | If FLAME GPU's 3D interactive visualisation should be enabled. Requires OpenGL and local execution. |
| `FLAMEGPU_SEATBELTS` | `ON` | Enable / Disable additional runtime checks which harm performance but increase usability |
| `FLAMEGPU_SHARE_USAGE_STATISTICS` | `ON` | Enable / Disable FLAME GPU 2 telemetry which helps evidence use/impact of FLAME GPU 2. See the [FLAME GPU 2 user guide for more information](https://docs.flamegpu.com/guide/telemetry/) |
Expand Down
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ target_compile_definitions(${LIBRARY_NAME} PUBLIC "$<$<CONFIG:RelWithDebInfo>:CM
target_compile_definitions(${LIBRARY_NAME} PUBLIC "$<$<CONFIG:MinSizeRel>:CMAKE_BUILD_TYPE=\"MinSizeRel\">")
target_compile_definitions(${LIBRARY_NAME} PUBLIC "$<$<CONFIG:Debug>:CMAKE_BUILD_TYPE=\"Debug\">")

# Set the upper limit of the per agent max random interaction count
if(EXATEPP_ABM_MAX_RANDOM_DAILY_INTERACTIONS GREATER 0)
target_compile_definitions(${LIBRARY_NAME} PUBLIC "EXATEPP_ABM_MAX_RANDOM_DAILY_INTERACTIONS=${EXATEPP_ABM_MAX_RANDOM_DAILY_INTERACTIONS}")
endif()


# Add src directory to include path, publicly so that the target library inherits this dependency (for now).
target_include_directories("${LIBRARY_NAME}" PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")

Expand Down
22 changes: 15 additions & 7 deletions src/exateppabm/exatepp_abm.cu
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ int entrypoint(int argc, char* argv[]) {
// Add disease progression
exateppabm::disease::SEIR::appendLayers(model);

// Generate the population of agents
// prior to the simulation creation so any mutation of the model environment is applied. this is not ideal and will need adjusting for ensembles.
// @todo - this should probably be an in init function for ease of moving to a ensembles, but then cannot pass parameters in.
const std::uint64_t pop_seed = config->rng_seed; // @todo - split seeds
auto personPopulation = exateppabm::population::generate(model, *config, cli_params->verbosity > 0);
if (personPopulation == nullptr) {
throw std::runtime_error("@todo - bad population generation function.");
}

// Construct the Simulation instance from the model.
flamegpu::CUDASimulation simulation(model);

Expand All @@ -111,6 +120,11 @@ int entrypoint(int argc, char* argv[]) {

// Setup simulation configuration options

// If verbosity is high enough (-vvv or more) then enable flamegpu's verbose output
if (cli_params->verbosity > 2) {
simulation.SimulationConfig().verbosity = flamegpu::Verbosity::Verbose;
}

simulation.SimulationConfig().steps = config->duration; // @todo - change this to be controlled by an exit condition?

// Seed the FLAME GPU 2 RNG seed. This is independent from RNG on the host, but we only have one RNG engine available in FLAME GPU 2 currently.
Expand All @@ -119,13 +133,7 @@ int entrypoint(int argc, char* argv[]) {
// Set the GPU index
simulation.CUDAConfig().device_id = cli_params->device;

// Generate the population of agents.
// @todo - this should probably be an in init function for ease of moving to a ensembles, but then cannot pass parameters in.
const std::uint64_t pop_seed = config->rng_seed; // @todo - split seeds
auto personPopulation = exateppabm::population::generate(model, *config, cli_params->verbosity > 0);
if (personPopulation == nullptr) {
throw std::runtime_error("@todo - bad population generation function.");
}
// add the population to this simulation instance
simulation.setPopulationData(*personPopulation);

perfFile.timers.preSimulate.stop();
Expand Down
24 changes: 24 additions & 0 deletions src/exateppabm/input.cu
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,24 @@ std::shared_ptr<exateppabm::input::config> read(const std::filesystem::path p, c
if (!valueFromCSVLine(line, c->daily_fraction_work)) {
throw std::runtime_error("bad value for daily_fraction_work during csv parsing @todo\n");
}
if (!valueFromCSVLine(line, c->mean_random_interactions_0_19)) {
throw std::runtime_error("bad value for mean_random_interactions_0_19 during csv parsing @todo\n");
}
if (!valueFromCSVLine(line, c->sd_random_interactions_0_19)) {
throw std::runtime_error("bad value for sd_random_interactions_0_19 during csv parsing @todo\n");
}
if (!valueFromCSVLine(line, c->mean_random_interactions_20_69)) {
throw std::runtime_error("bad value for mean_random_interactions_20_69 during csv parsing @todo\n");
}
if (!valueFromCSVLine(line, c->sd_random_interactions_20_69)) {
throw std::runtime_error("bad value for sd_random_interactions_20_69 during csv parsing @todo\n");
}
if (!valueFromCSVLine(line, c->mean_random_interactions_70plus)) {
throw std::runtime_error("bad value for mean_random_interactions_70plus during csv parsing @todo\n");
}
if (!valueFromCSVLine(line, c->sd_random_interactions_70plus)) {
throw std::runtime_error("bad value for sd_random_interactions_70plus during csv parsing @todo\n");
}

} else {
throw std::runtime_error("failed to read the paramameter value line @todo nicer error message");
Expand Down Expand Up @@ -275,6 +293,12 @@ void print(exateppabm::input::config config) {
fmt::print(" relative_transmission_occupation = {}\n", config.relative_transmission_occupation);
fmt::print(" relative_transmission_random = {}\n", config.relative_transmission_occupation);
fmt::print(" daily_fraction_work = {}\n", config.daily_fraction_work);
fmt::print(" mean_random_interactions_0_19 = {}\n", config.mean_random_interactions_0_19);
fmt::print(" sd_random_interactions_0_19 = {}\n", config.sd_random_interactions_0_19);
fmt::print(" mean_random_interactions_20_69 = {}\n", config.mean_random_interactions_20_69);
fmt::print(" sd_random_interactions_20_69 = {}\n", config.sd_random_interactions_20_69);
fmt::print(" mean_random_interactions_70plus = {}\n", config.mean_random_interactions_70plus);
fmt::print(" sd_random_interactions_70plus = {}\n", config.sd_random_interactions_70plus);
fmt::print("}}\n");
}

Expand Down
33 changes: 32 additions & 1 deletion src/exateppabm/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,40 @@ struct config {
/**
* Fraction of people in work network interacted with per day (by rng sampling)
*
* @todo - this probably needs using differntly with more realistic networks
* @todo - this probably needs using differently with more realistic networks
*/
float daily_fraction_work = 0.5f;

/**
* Mean number of random interactions for 0-19 year olds
* Arbitrary default value
*/
double mean_random_interactions_0_19 = 2u;
/**
* Standard deviation for the number of random interactions per day for 0-19 year olds
* Default value is arbitrary
*/
double sd_random_interactions_0_19 = 2u;
/**
* Mean number of random interactions for 20-69 year olds
* Arbitrary default value
*/
double mean_random_interactions_20_69 = 4u;
/**
* Standard deviation for the number of random interactions per day for 20-69 year olds
* Default value is arbitrary
*/
double sd_random_interactions_20_69 = 4u;
/**
* Mean number of random interactions for 70+ year olds
* Arbitrary default value
*/
double mean_random_interactions_70plus = 2u;
/**
* Standard deviation for the number of random interactions per day for 70+ year olds
* Default value is arbitrary
*/
double sd_random_interactions_70plus = 2u;
};

/**
Expand Down
Loading

0 comments on commit d9e0577

Please sign in to comment.