Skip to content

1406 Count subpopulations in a single pass over all persons - #1595

Draft
xsaschako wants to merge 1 commit into
mainfrom
1406-speed-up-get-subpopulation
Draft

xsaschako wants to merge 1 commit into
mainfrom
1406-speed-up-get-subpopulation

Conversation

@xsaschako

Copy link
Copy Markdown
Member

Changes and Information

Please briefly list the changes (main added features, changed items, or corrected bugs) made:

  • get_subpopulation_combined and get_subpopulation_combined_per_location_type now iterate over all persons once, instead of calling get_subpopulation (which iterates over all persons) for every location.
  • The logger in the graph_abm example counts persons per location and infection state in a single pass instead of calling get_subpopulation for every location and infection state.
  • The documentation of get_subpopulation notes that it iterates over all persons and should not be called in loops.

If need be, add additional information and what the reviewer should look out for in particular:

  • The slow path that mattered most, LogInfectionState, is fixed in 1210 abm paper logger #1507. This PR covers the remaining callers. get_subpopulation itself keeps its signature and behavior.
  • Persons currently located in another model (graph ABM) are still not counted, as before. TestModel.getSubpopulationCombined now covers this case.
  • I checked the new graph_abm logger against the old get_subpopulation counts over a full run of the example: all 386,880 per location counts matched.
  • Local test run without OpenMP only. Benchmarks were not run, since they do not compile on Apple clang.

Closes #1406

Merge Request - Guideline Checklist

Please check our git workflow. Use the draft feature if the Pull Request is not yet ready to review.

Checks by code author

  • Every addressed issue is linked (use the "Closes #ISSUE" keyword below).
  • New code adheres to coding guidelines.
  • No large data files have been added (files should in sum not exceed 100 KB, avoid PDFs, Word docs, etc.).
  • Tests are added for new functionality and a local test run was successful (with and without OpenMP).
  • Appropriate documentation within the code (Doxygen) for new functionality has been added in the code.
  • Appropriate external documentation (ReadTheDocs) for new functionality has been added to the online documentation and checked in the preview.
  • Proper attention to licenses, especially no new third-party software with conflicting license has been added.
  • (For ABM development) Checked benchmark results and ran and posted a local test above from before and after development to ensure performance is monitored.

Checks by code reviewer(s)

  • Corresponding issue(s) is/are linked and addressed.
  • Code is clean of development artifacts (no deactivated or commented code lines, no debugging printouts, etc.).
  • Appropriate unit tests have been added, CI passes, code coverage and performance is acceptable (did not decrease).
  • No large data files added in the whole history of commits(files should in sum not exceed 100 KB, avoid PDFs, Word docs, etc.).
  • On merge, add 2-5 lines with the changes (main added features, changed items, or corrected bugs) to the merge-commit-message. This can be taken from the briefly-list-the-changes above (best case) or the separate commit messages (worst case).

- get_subpopulation_combined and get_subpopulation_combined_per_location_type
  iterate over all persons once instead of calling get_subpopulation, which
  iterates over all persons, for every location.
- The logger in the graph ABM example counts persons per location and infection
  state in a single pass.
- Document that get_subpopulation iterates over all persons and should not be
  called in loops.
@xsaschako xsaschako added loc::backend This issue concerns the C++ backend implementation. model::abm This issue concerns any kind of agent-based model. class::improvement Cleanup that doesn't affect functionality class::performance Performance related issues labels Oct 8, 2026
@xsaschako
xsaschako marked this pull request as draft October 8, 2026 16:32
@codecov

codecov Bot commented Oct 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.47%. Comparing base (0888d6c) to head (991308f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1595      +/-   ##
==========================================
+ Coverage   97.44%   97.47%   +0.02%     
==========================================
  Files         190      190              
  Lines       16035    16033       -2     
==========================================
+ Hits        15626    15628       +2     
+ Misses        409      405       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

class::improvement Cleanup that doesn't affect functionality class::performance Performance related issues loc::backend This issue concerns the C++ backend implementation. model::abm This issue concerns any kind of agent-based model.

Projects

Development

Successfully merging this pull request may close these issues.

Get_subpopulation is slow

1 participant