Skip to content

Add initial immunity fraction parameter#148

Draft
debog wants to merge 9 commits intodevelopmentfrom
dg/initial_immune
Draft

Add initial immunity fraction parameter#148
debog wants to merge 9 commits intodevelopmentfrom
dg/initial_immune

Conversation

@debog
Copy link
Copy Markdown
Collaborator

@debog debog commented Feb 20, 2026

Add configurable initial immunity fraction for disease initialization: Implements a new parameter disease.initial_immunity_fraction that allows users to specify the fraction of agents (0.0 to 1.0) that are initially immune at simulation start. This feature supports both Census and UrbanPop initialization types and can be configured per disease in multi-disease simulations.

Implementation: Added initial_immunity_fraction parameter to DiseaseParm structure with default value 0.0. Modified setAgentData function to accept disease parameters and random engine. Updated agent initialization to randomly assign immune status based on specified fraction. Immune duration is sampled from gamma distribution using immune_length_alpha and immune_length_beta parameters. Updated both Census and UrbanPop initialization code paths.

Code structure refactoring: Created AgentEnums.H to hold shared enum definitions and helper functions, eliminating circular dependency between AgentDefinitions.H and DiseaseParm.H. This removes the need for forward declarations and resolves all compilation warnings.

Usage: For single disease:

disease.initial_immunity_fraction = 0.1

For multiple diseases:

disease_<name1>.initial_immunity_fraction = 0.2
disease_<name2>.initial_immunity_fraction = 0.15

Default value is 0.0, ensuring existing simulations are unaffected unless parameter is explicitly set.

debog and others added 9 commits February 19, 2026 16:10
Implement configurable initial immunity fraction for agent-based disease modeling.
Agents can be initialized as immune based on a user-specified fraction (0.0-1.0)
per disease, with immune duration sampled from gamma distribution.

Changes:
- Add initial_immunity_fraction parameter to DiseaseParm structure
- Update setAgentData to randomly assign immune status at initialization
- Modify Census and UrbanPop initialization to support initial immunity
- Update documentation in inputs.defaults and RST files
- Support disease-specific parameters for multiple disease simulations

Default value is 0.0 (no initial immunity) to maintain backward compatibility.
Create AgentEnums.H to hold shared enum definitions and helper functions used by both AgentDefinitions.H and DiseaseParm.H. This eliminates circular dependency and removes need for forward declarations.

Changes:
- Create src/AgentEnums.H with AgeGroups, SchoolType, IntIdx, IntIdxDisease, RealIdxDisease, Status, DiseaseStats enums and i0(), r0() helper functions
- Update src/AgentDefinitions.H to include AgentEnums.H and remove duplicate definitions
- Update src/DiseaseParm.H to include AgentEnums.H instead of AgentDefinitions.H
- Include DiseaseParm.H in AgentDefinitions.H after basic definitions to provide complete type for setAgentData function

Build completes without warnings or errors.
Modify initial immunity implementation to place agents at random points within their immunity period rather than all starting at the beginning.

Changes:
- Sample full immune duration from gamma distribution
- Set remaining immunity to uniform random value between 0 and full duration
- Update both Census and UrbanPop initialization code paths
- Update documentation in inputs.defaults and RST files to reflect new behavior

This provides more realistic initial conditions for simulations with pre-existing immunity.
Short-circuit the immunity check so amrex::Random(engine) is not called when initial_immunity_fraction is 0.0. Previously, the random draw was consumed unconditionally for every agent, advancing the RNG state and causing results to diverge from baseline even with default parameters.
Replace host pointer arrays with Gpu::AsyncArray to prevent illegal
memory access on device. Fixes CUDA error 700 on Nvidia GPUs.

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant