Skip to content

laser.cohorts.vitaldynamics

vitaldynamics

Vital dynamics components for cohort-based simulation.

Provides NonDiseaseMortality, a component that applies background (non-disease) mortality to one or more compartment states each simulation tick.

ConstantPopBirths

ConstantPopBirths(model)

Constant-population birth component.

Reads the per-node death count recorded by NonDiseaseMortality at each tick and adds the same number of individuals back into the S compartment, keeping the total population constant across ticks.

Must be ordered after NonDiseaseMortality in the component list so that non_disease_mortality is populated before births are applied.

Example

ndm = NonDiseaseMortality(model, r_mortality=1/365/70) cpb = ConstantPopBirths(model) model.components = [Susceptible(model), ndm, cpb]

Initialize the ConstantPopBirths component.

Parameters:

Name Type Description Default
model Model

The parent model instance.

required

properties property

properties

Return the node properties required by this component.

Returns:

Type Description
list[PropertyType]

list[PropertyType]: [("non_disease_mortality", nticks, np.int32, 0)]

states property

states

Return the compartment states used by this component.

Returns:

Type Description
list[str]

list[str]: ["S"]

end_step

end_step(tick)

No-op end-of-step hook.

Parameters:

Name Type Description Default
tick int

Current simulation tick (0-indexed).

required

setup

setup()

No-op setup hook.

start_step

start_step(tick)

No-op start-of-step hook.

Parameters:

Name Type Description Default
tick int

Current simulation tick (0-indexed).

required

step

step(tick)

Add births equal to deaths recorded this tick into the S compartment.

Reads nodes.non_disease_mortality[tick] — the deaths accumulated by NonDiseaseMortality during the current tick — and adds that count to states.S[tick+1], replacing every death with one new susceptible.

Parameters:

Name Type Description Default
tick int

Current simulation tick (0-indexed).

required

NonDiseaseMortality

NonDiseaseMortality(model, r_mortality, states=None)

Background (non-disease) mortality component.

Applies a binomial mortality draw each tick to the specified compartment states, removing individuals and recording the deaths in nodes.non_disease_mortality.

By default acts on every state in model.states. Passing states restricts mortality to only the named compartments, creating an implicit mask over the state axis.

Example

ndm = NonDiseaseMortality(model, r_mortality=1/365/70) # ~70-year life expectancy ndm_s_only = NonDiseaseMortality(model, r_mortality=1/365/70, states=["S"])

Initialize the NonDiseaseMortality component.

Parameters:

Name Type Description Default
model Model

The parent model instance.

required
r_mortality int | float | ValuesMap | ndarray

Per-tick, per-node crude mortality rate. A scalar is broadcast to all ticks and nodes via ValuesMap.from_scalar; a ValuesMap or 2-D array of shape (nticks, nnodes) is used directly.

required
states Iterable[str] | None

Names of compartment states to apply mortality to. Accepts any iterable (list, tuple, set, generator, etc.). None applies mortality to every state in model.states.

None

properties property

properties

Return the node properties required by this component.

Returns:

Type Description
list[PropertyType]

list[PropertyType]: [("non_disease_mortality", nticks, np.int32, 0)]

states property

states

Return the compartment states created by this component.

Returns:

Type Description
list[str]

list[str]: Empty list; this component acts on existing states but does not create any new ones.

end_step

end_step(tick)

No-op end-of-step hook.

Parameters:

Name Type Description Default
tick int

Current simulation tick (0-indexed).

required

setup

setup()

Build a boolean state mask for the target compartment states.

Resolves which states to apply mortality to — all states when states was None, or the requested subset — then builds a boolean mask over the state axis using get_state_index so that step can select all target states in one vectorised operation.

start_step

start_step(tick)

No-op start-of-step hook.

Parameters:

Name Type Description Default
tick int

Current simulation tick (0-indexed).

required

step

step(tick)

Apply binomial mortality draws to all target states in one operation.

Selects all target compartments at tick+1 via the boolean state mask, draws deaths from a binomial distribution for all of them at once, subtracts the deaths back via boolean-index assignment, and accumulates per-node totals in nodes.non_disease_mortality.

Parameters:

Name Type Description Default
tick int

Current simulation tick (0-indexed).

required