Global state totals¶
sum_state() sums every element of every declared state buffer, including
scalar compartments and stages generated by chain. Aliases, parameters,
synthetic operator constants, and extra keys supplied to a structured evaluator
are not additional states. The result is an unweighted sum; continuous-axis
quadrature remains an explicit modeling choice through the integration helpers.
Optional state representations and physical measures describe extensive counts/mass and intensive densities without changing this helper. A density's physical integral requires its declared measure; an unweighted density sum generally has a different meaning.
The helper works in expressions, aliases, transition rates, and exported reaction propensities on qualified CPU backends. Flat and structured evaluation use native array reductions, so JAX tracing and Torch parameter gradients retain the same calculation. Totals are cached within an evaluation and refreshed on the next call with its new state.
A global total across groups is a coupling dependency. The compiler rejects a
factorize_axes declaration that would turn such a model into independent
blocks. When the intended equations are local, write an explicitly local total,
for example N[group] = sum_over(S[group,age:a] + I[group,age:a], age=a).
Changing a global denominator to a local denominator changes the equations.
For a staged chain named I, declaring state: [S, R] lets the helper generate
I1, I2, and so on. Declaring I as well creates an additional, separate
compartment, and its value contributes to sum_state() even if its derivative
is zero. The chain prefix alone is not a compartment declaration.
Reaction export preserves numerical propensity evaluation. A population-normalized
rate need not have a polynomial mass-action description or a certified elasticity
bound. Follow the chosen engine's metadata requirements and the documented
reactants: auto restrictions independently of whether export succeeds.