Repository navigation
Description
Besides the individual engine, core has several ways to simulate without people. The daily-count path (src/models/count_simulation.jl, 755 lines) is the general one: simulate takes it through the count_rule trait whenever nothing about an individual feeds back on transmission, and its counts have the same distribution as simulating each person. simulate_by_generation (src/models/generation_counts.jl, 1,045 lines, and src/models/generation_campaign.jl, 341) is not counts of the individual model. It has no timing step, natural history, per-case interventions, observation or line list. Its gamma multiplier shared by a generation and its 1 − exp depletion applied once per generation make it a chain-binomial (TSIR-type) approximation, of the same kind as the mean-field and linear-noise ones. generation_campaign.jl decides inside the engine loop what a campaign's budget and dosing rule do, against rule 3 of the design checklist in CLAUDE.md. The per-generation multiplier has also spread into the individual path (src/offspring_route.jl), where it links cases infected on different days only because they share a generation label. The mean-field, linear-noise and hybrid approximations and their mixing and vaccination versions (population_dynamics.jl, hybrid.jl, mixing_population_dynamics.jl, mixing_vaccination.jl, 2,073 lines) were built to filter large outbreaks and are no longer needed. Nothing outside them uses them, outbreak_state_space included.
Keep the daily-count path as the one route to counts. Remove simulate_by_generation, GenerationCounts, generation_campaign.jl and the ByGeneration resolution, with the resolution parameter on BranchingProcess if nothing else uses it. Move the mean-field, linear-noise and hybrid approximations, with their docs and tests, into a satellite package under lib/. Before the generation path goes, the daily-count path needs two things for a particle filter on counts to stay possible. The first is an immune population: count_rule returns nothing for a BranchingProcess with one, and the run falls back to individuals. The second is a light state to continue and copy. CountSimulationState keeps every cohort's history (inflow, cohort_infectiousness, cohort_members, generation_counts), while continuing needs only the cohorts still inside the generation time's support and the susceptibles. A bootstrap filter copies one state per particle per observation:
using EpiBranch, Distributions, BenchmarkTools, Random
model = BranchingProcess(Poisson(4.5), DiscreteNonParametric([14], [1.0]);
population = Population(30_000))
# max_generations is needed for simulate to take the count route
state = simulate(model; n_initial = 50, max_time = 42.0, max_generations = 10_000,
rng = Xoshiro(1))
typeof(state).name.name
# CountSimulationState
@benchmark copy($state)
# median 312 μs, 390.26 KiB, 5048 allocations
@benchmark simulate($model, copy($state); max_time = 56.0, rng = Xoshiro(2))
# median 415 μs, 539.30 KiB, 6706 allocations
late = simulate(model; n_initial = 50, max_time = 20 * 14.0, max_generations = 10_000,
rng = Xoshiro(1))
@benchmark simulate($model, copy($late); max_time = 21 * 14.0, rng = Xoshiro(2))
# median 1.34 ms, 1.87 MiB, 22267 allocations
# one step of the generation path, for comparison
gmodel = BranchingProcess(Poisson(4.5); population = Population(30_000))
g = simulate_by_generation(gmodel; n_initial = 50, max_generations = 3, rng = Xoshiro(1))
@benchmark simulate($gmodel, $g; max_generations = 4)
# median 0.09 μs, 0 bytes, 0 allocations
Activity
sbfnk-bot commentedon Nov 27, 2026
Relayed for @sbfnk:
Also remove the
multiplierkeyword and field fromBranchingProcessand its multi-type constructors (multi_type_offspring.jl,contact_matrices.jl), along with_Multipliedinoffspring_route.jl, the public seamsscale_meanandsum_offspring, their rows in the extending reference, and the multiplier checks incount_rule,offspring_law_unchangedandobserved_cases. Its only purpose was to keep the individual path consistent with the generation path. On the individual path it links cases only through their generation label, which means nothing in calendar time once the generation time is continuous. It turns off the count path, the closed-form likelihoods and observed cases. Per-case dispersion (the offspring law),RenewalOffspringor a calendar for time variation, and offspring specifications for chain-to-chain variation cover what it would be used for.On main at 9690136,
sum_offspringis used only ingeneration_counts.jl, not by the count path, andscale_meanonly by the multiplier: ingeneration_counts.jl,offspring_route.jland the two_check_scalablehelpers inbranching_process.jlandmulti_type_offspring.jl, which go with it.