Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network-based interactions #24

Merged
merged 29 commits into from
Dec 11, 2024
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7438736
Bugfix: Set the phase duration for initially infected individuals so …
ptheywood Nov 15, 2024
9e451c1
Add initial household networks generation and interaction
ptheywood Nov 15, 2024
c8c60d0
WIP: initial home/network split, reference model doesn't behave as ex…
ptheywood Nov 19, 2024
6b30f6c
Implement per individual file and demo plotting script
ptheywood Nov 19, 2024
972e96e
Switch to GCC 8 compatible inclusive_scan
ptheywood Nov 25, 2024
0fb31a3
fixup: port another std::inclusive_scan
ptheywood Nov 25, 2024
e18b55d
Implement GCC 8 compatible std::recduce(first, last, init)
ptheywood Nov 25, 2024
75076d3
Tests: tests for GCC 8 compatible reduce
ptheywood Nov 25, 2024
86a0606
Refactor GCC 8 compatible inclusive_scan methods to be more like C++1…
ptheywood Nov 25, 2024
93292af
fixup lint
ptheywood Nov 25, 2024
1681a72
Visualisation: Group agents by household, reduce impact on non-vis bu…
ptheywood Nov 25, 2024
4186658
Performance: Switch to bucket messaging to improve performance
ptheywood Nov 26, 2024
adf5434
Tests: expand util testing
ptheywood Nov 26, 2024
a53e4df
Add missing struct members to cli::print
ptheywood Nov 26, 2024
b13e6e8
wip: refactoring
ptheywood Nov 26, 2024
631c472
Refactor: Move per-agent visualisation variable initialisation to vis…
ptheywood Nov 27, 2024
6e644d3
Refactor: Change how household/populations are generated and add tests
ptheywood Nov 27, 2024
46973be
Fixup: fixup vis build after refactor
ptheywood Nov 29, 2024
6262e2d
Readme: remove rogue backtick
ptheywood Nov 29, 2024
d63a1e3
Readme: Markdown fix
ptheywood Nov 29, 2024
3f6f592
Wip: random network
ptheywood Nov 29, 2024
16c7aea
Fix initial id-based pair-wise random interactions
ptheywood Dec 2, 2024
241bf7d
Tests: Fix std::TestPopulation.generateHouseholdStructures for older gcc
ptheywood Dec 2, 2024
d9e0577
Random Interactions: Initiial fully functional random daily interactions
ptheywood Dec 3, 2024
35e2368
sample data file fixup - accidentally commeted error triggering entry
ptheywood Dec 4, 2024
7a15473
Random interaction workaround based on flamegpu version
ptheywood Dec 5, 2024
bfee518
Fixup: Remove debuguing exit statement realted to flamegpu bug
ptheywood Dec 10, 2024
53b1fdb
Small world network implementation. WIP commit prior to FLAMEGPU_INIT…
ptheywood Dec 10, 2024
622fe82
Refactoring, small world networks & workarounds
ptheywood Dec 11, 2024
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
Prev Previous commit
Next Next commit
Implement GCC 8 compatible std::recduce(first, last, init)
ptheywood committed Nov 29, 2024
commit e18b55d9148ce1ede37708c0016bb4b056ff4ddf
6 changes: 3 additions & 3 deletions src/exateppabm/population.cu
Original file line number Diff line number Diff line change
@@ -38,14 +38,14 @@ std::vector<T> generateHouseholdSizes(const exateppabm::input::config config, co
// Initialise vector with each config household size
std::vector<std::uint64_t> countPerSize = {{config.household_size_1, config.household_size_2, config.household_size_3, config.household_size_4, config.household_size_5, config.household_size_6}};
// get the sum, to find relative proportions
std::uint64_t sumConfigHouseholdSizes = std::reduce(countPerSize.begin(), countPerSize.end());
std::uint64_t sumConfigHouseholdSizes = exateppabm::util::reduce(countPerSize.begin(), countPerSize.end(), 0ull);
// Get the number of people in each household band for the reference size
// Find the number of people that the reference household sizes can account for
std::vector<std::uint64_t> peoplePerHouseSize = countPerSize;
for (std::size_t idx = 0; idx < peoplePerHouseSize.size(); idx++) {
peoplePerHouseSize[idx] = (idx + 1) * peoplePerHouseSize[idx];
}
std::uint64_t sumConfigPeoplePerHouseSize = std::reduce(peoplePerHouseSize.begin(), peoplePerHouseSize.end());
std::uint64_t sumConfigPeoplePerHouseSize = exateppabm::util::reduce(peoplePerHouseSize.begin(), peoplePerHouseSize.end(), 0ull);
double configMeanPeoplePerHouseSize = sumConfigPeoplePerHouseSize / static_cast<double>(sumConfigHouseholdSizes);

if (verbose) {
@@ -106,7 +106,7 @@ std::vector<T> generateHouseholdSizes(const exateppabm::input::config config, co
}
fmt::print("}}\n");
// Sum the number of people per household
std::uint64_t sumPeoplePerHouse = std::reduce(peoplePerHouse.begin(), peoplePerHouse.end(), 0ull);
std::uint64_t sumPeoplePerHouse = exateppabm::util::reduce(peoplePerHouse.begin(), peoplePerHouse.end(), 0ull);
// Check the mean still agrees.
double generatedMeanPeoplePerHouseSize = sumPeoplePerHouse / static_cast<double>(peoplePerHouse.size());
fmt::print("generated mean household size {}\n", generatedMeanPeoplePerHouseSize);
33 changes: 33 additions & 0 deletions src/exateppabm/util.h
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
#include <cstdint>
#include <string>
#include <numeric>
#include <algorithm>

namespace exateppabm {
namespace util {
@@ -92,5 +93,37 @@ void inplace_inclusive_scan(T& container) {
#endif // defined(EXATEPP_ABM_USE_STD_INCLUSIVE_SCAN) && EXATEPP_ABM_USE_STD_INCLUSIVE_SCAN
}

/**
* reduce elements of a container, i.e. std::reduce, for libstdc++ which does not support c++17 (i.e. GCC 8)
*
* equivalent to std::reduce(first, last, init);
*
* @param first - input iterator for the first element
* @param last - input iterator for the last element
* @param init - initial value to reduce into (and inferred type)
* @return reduction (sum) if values between in [first, last)
*/
template <typename InputIt, typename T>
T naive_reduce(InputIt first, InputIt last, T init) {
for (; first != last; ++first) {
init += *first;
}
return init;
}

/**
* reduce elements of a container, using std::reduce if possible, else a naive implementation.
*
* equivalent to std::reduce(first, last, init);
*/
template <typename InputIt, typename T>
T reduce(InputIt first, InputIt last, T init) {
#if defined(EXATEPP_ABM_USE_STD_INCLUSIVE_SCAN) && EXATEPP_ABM_USE_STD_INCLUSIVE_SCAN
return std::reduce(first, last, init);
#else
return naive_reduce(first, last, init);
#endif // defined(EXATEPP_ABM_USE_STD_INCLUSIVE_SCAN) && EXATEPP_ABM_USE_STD_INCLUSIVE_SCAN
}

} // namespace util
} // namespace exateppabm