Repository navigation
Run on the redesigned ComposableRecurrences and cut glue - #453
Conversation
Pin ComposableRecurrences at ba05903, the head of its redesign branch. CTIDM needed no source change to run on it. Describe a custom renewal step as a pure ComposableRecurrences step rather than a forward! method for the Step role. Declare the tutorial ring coupling linear so its gradient takes the dense coupling rule instead of plain AD of the whole operator. Compute expected_Rt's denominator with a Convolution instead of a hand-written loop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iyq8PXsdfyhWyzdjES
The pre-scan seam put every modifier behind a prefixed submodel, even a Depletion or Transform that samples nothing. That level cost about 115 µs of a Mooncake reverse gradient against 4 µs for the renewal without modifiers. A modifier that draws nothing is now resolved by a plain function, and a run of them ends the recursion. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iyq8PXsdfyhWyzdjES
Try this Pull Request!Option 1: Julia Package ManagerOpen Julia and type: import Pkg
Pkg.activate(temp=true)
Pkg.add(url="https://github.com/EpiAware/ComposableTuringIDModels.jl", rev="claude/cr-redesign-port")
using ComposableTuringIDModelsOption 2: Local CheckoutIf you have the repo locally: git checkout claude/cr-redesign-port
julia --project=. -e "using Pkg; Pkg.instantiate()" |
|
Generated by Claude Code |
|
Two more failures that are not caused by this PR. Each fails with the same error on the base branch
Generated by Claude Code |
Add tests for modifiers that draw nothing, the empty tuple, a mixed tuple keeping positional prefixes on draws, and expected_Rt against the explicit generation-interval sum. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iyq8PXsdfyhWyzdjES
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
So the error comes from neither the CR repin nor the changes here. Generated by Claude Code |
|
📖 Documentation preview is ready! View the docs for this PR at: https://EpiAware.github.io/ComposableTuringIDModels.jl/previews/PR453/ This preview will be updated automatically when you push new commits. |
Summary
Runs CTIDM on the redesigned ComposableRecurrences (CR) and cuts the glue around it.
CR is pinned at
ba059035c6b820fa73bce60b96a735c5cce9181c, the head ofclaude/amazing-shannon-6nrow8(CR PR #907) that was tested.CTIDM needed no source change to run on the redesign.
It defines no CR pieces of its own in
src/(noforward!,pullback!or hand pullback), so the move to pure steps did not touch it.I found no CR regressions.
Changes:
Project.toml,test/Project.tomlanddocs/Project.tomlpoint atba05903.src/infection_models/renewal/modifiers.jl): a new step-level behaviour is now described as a pureComposableRecurrences.step(m, θ, v, s)with an optionalinit. It no longer saysforward!for theSteprole, and it says no pullback is needed.docs/src/tutorials/patch-models.md): theRingcoupling declaresCR.islinear(::Ring) = true. Its gradient then takes the dense-coupling rule rather than plain AD of the whole operator, and CR no longer logs the "plain AD" note.Couplings keep
forward!for thePressurerole in the redesign, so the method itself is unchanged.expected_RtusesConvolutioninstead of a hand-written loop._resolve_modifiers): a modifier that draws nothing (SusceptibleDepletion, or a CRDepletion,Redistribute,AllocateorTransformpassed directly) is now resolved by a plain function instead of a prefixed submodel. That submodel level was the main cost of a Mooncake reverse gradient for any renewal with a modifier (timings below).Test results (local, Julia 1.12.7, Linux, 4 cores)
Main suite (
julia --project=test test/runtests.jl, includes QA, JET and formatting):The 4 broken results are in the managed QA testset and are pre-existing:
quality_onlyat the old pin (142ae78) gives 302 passed, 4 broken, the same as this branch.AD suite (
julia --project=test/ad test/ad/runtests.jl <tag>, one backend per process), this branch:The broken entries are the listed ODE scenario.
The Enzyme reverse error is
Renewal+Split cascade posterior(IllegalTypeAnalysisExceptionin DynamicPPL's submodeltilde_assume!!).It is pre-existing: it reproduces identically at the old CR pin with the original CTIDM, and on new CR with the original CTIDM.
CI on
composable-recurrences(run 46495803209) already fails both Enzyme jobs on the Split scenarios.Before the seam change, ForwardDiff (1008/1008) and ReverseDiff tape (987 pass, 1 broken) gave the same counts.
Not run: the docs build (DocumenterVitepress with CairoMakie).
I checked the edited
Ringsnippet against CR directly: with and withoutislinearthe outputs agree.Timings
All are the minimum of 200 calls to a prepared
DifferentiationInterface.gradientof the AD-fixture log densities, in µs.Gradients agree to 1e-4 between each pair.
Old CR (
142ae78) vs new CR (ba05903), CTIDM unchanged, Mooncake reverse:The other backends were within noise (ratios 0.87 to 1.27 on runs of 0.2 to 10 µs, with other jobs running), and no gradient changed.
Modifier seam, Renewal + Poisson, n = 8 (
seam.jl, new CR):SusceptibleDepletionCR.Depletionpassed directlyCR.Transform(+, 0.1)passed directlyImportedCasesSusceptibleDepletion+ImportedCasesAD-fixture scenarios, original CTIDM vs this branch on new CR:
ImportedCasesstill costs about 115 µs under Mooncake.The CR operator with a drawn scalar
Transform(+, ι)takes 0.6 µs under Mooncake, so the cost is in DynamicPPL's prefixed submodel path rather than CR.That is a follow-up for CTIDM, not part of this PR.
expected_Rtis not on any gradient path. Its primal on a 200-day series with a 5-day interval went from 5.7 µs to 0.42 µs, with identical output.Audit: what CTIDM already takes from CR, what changed, what stays
Already CR calls, no change: AR / random walk (
Recurrencevia_extend), MA (Convolution),ExpGrowthRatecumulative sum (Recurrencevia_cumulate),LatentDelay(Convolution,TimeVarying),Aggregate(CR.window_sums), seeding (CR.exponential_history), susceptible depletion (Depletion(N, Floor())), imports (Transform(+, ι)), strata mixing (coupling,PerStratum,Pairwise).Replaced:
expected_Rtdenominator loop →Convolution.Tried and reverted:
R_to_r(two Newton steps) →CR.growth_rate. The split NUTS test failed: during the initial step-size searchR₁reachesInf, andgrowth_ratethrowsArgumentError("growth_rate did not converge in 50 steps for R = Inf"). CTIDM'sR_to_rreturnsNaN, and the sampler rejects the proposal. Kept CTIDM'sR_to_r. Reproducer below.Left, and why:
src/utils/recurrences.jl(_cumulate,_extend): two one-line wrappers that name the CR calls shared by four models. Inlining them repeats the keyword set four times.DiffLatentModel:cumsumapplieddtimes to[init; diff].Base.cumsumis shorter than aRecurrencewith a binomial kernel and has no history to set up.neg_MGF,r_to_R: closed-form sums, not recurrences.ReportTriangle,CombineInfections,Splitloops: they loop over tilde statements or strata, not a recurrence.Places where CR's API made CTIDM code awkward
For CR's API stabilisation (CR issue #916):
AbstractRenewalModifier:CR.ismodifier(::Type)) or abstract type would letRenewalaccept any CR modifier.growth_ratethrows on extreme values.R = Infor1e300gives "did not converge" andR = 0gives "R must be positive"; onlyNaNpasses. Inside a sampler a throw aborts the run, where aNaNwould reject the proposal. This blocks replacing CTIDM'sR_to_r.growth_ratealso takes oneRand oneg, so a per-stratum seed loops:[R_to_r(Rt₀[g], view(w, g, :)) for g in eachindex(Rt₀)].Recurrencekernel is lag 1 first and aConvolutionkernel is lag 0 first, so a renewal denominator from a generation interval needs a padded zero:strata × 1matrix:Generated by Claude Code