Skip to content

Name parameters generically, not after their component - #283

Merged
seabbs merged 18 commits into
mainfrom
chore/generic-parameter-names
Aug 28, 2026
Merged

seabbs merged 18 commits into
mainfrom
chore/generic-parameter-names

Conversation

@seabbs-bot

@seabbs-bot seabbs-bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Collaborator

#274, which this was branched on, merged on 2026-08-20, so the diff shown
here is now this PR's own change and nothing else. Reviewable standalone.

What

Parameter names no longer spell their component's name into the parameter. A
component knows nothing about what it will be composed with, so it names a
quantity for what the quantity is; where two components then want the same
name, the composition that puts them together applies the prefix. That is the
rule #274 documents, and this makes the components follow it.

component old new
AR ar_init init
AR damp_AR damp
RandomWalk rw_init init
Hierarchy hierarchy_mean mean
ARStep (struct field) damp_AR damp
DiffLatentModel latent_init init
DiffLatentModel (inner process) damp, init, θ, std diff.damp, diff.init, diff.θ, diff.std

Breaking, and quietly so on the read side: fix and condition ignore a
name the model does not have, so a stale fix(model, (damp_AR = 0.5,)) keeps
running and pins nothing. NEWS.md carries the full mapping. Every test,
docstring and doc page that read an old name is updated — three tutorials'
pp_keys blocks, the condition_model docstring example, and the test items
that match on the names.

DiffLatentModel is the one that needed a prefix, not a longer name

An earlier version of this PR left DiffLatentModel's latent_init alone,
on the grounds that renaming it to init collides with the init of the
inner process it wraps prefix-off. That was the right diagnosis and the wrong
remedy: it kept a component-prefixed name to dodge a collision, which is the
thing this PR exists to stop doing.

The rule the rest of the PR follows applies here too — prefix at the point of
conflict. DiffLatentModel composes two latent processes, so it namespaces
the one it differences:

init          the differencing integration constants
diff.init     the inner process's own init
diff.damp     …and its other parameters
diff.θ
diff.std

arima inherits this, so an ARIMA chain reads init, diff.init,
diff.damp and diff.θ. Both docstrings gained a runnable block printing
keys(VarInfo(...)) so the names are on the page rather than asserted in
prose.

This widens the breaking surface: pinning an inner parameter now needs the
nested form, fix(mdl, (diff = (damp = 0.1,),)). Spelling the dotted path as
a single symbol matches nothing, and fix ignores a name the model does not
have, so such a call silently pins nothing. NEWS.md says so explicitly.

Does anything now collide?

No. Two processes that share init only meet under a composition that already
prefixes. Measured over 13 compositions, alone and under a renewal, plus
Hierarchy and Stratify; every one passes check_model before and after:

Combine(AR, RandomWalk)   Combine.1.init, Combine.1.damp, …, Combine.2.init, …
Concat(AR, RandomWalk)    Concat.1.init, …, Concat.2.init, …
Stratify(AR, AR)          init, damp, std, ϵ_t, across.init, across.damp, …
Hierarchy(across = AR)    mean, group_effects.init, group_effects.damp, …
Prefix(AR)                p.init, p.damp, p.std, p.ϵ_t

Left alone, with reasons

  • arima's ar_init / diff_init keyword arguments. They name two
    different init slots in one constructor signature, so they disambiguate
    rather than describe a component. Not chain names.
  • init_incidence, cluster_factor, import_rates, std, θ, ϵ_t.
    These name the quantity, not the component. init_incidence in
    particular must not become init: it sits at the same level as a
    prefix-off latent's init under a renewal.
  • I₀ / initial_infs in SIRParams / SEIRParams. Descriptive, not
    component-prefixed. They are inconsistent with each other, which is worth
    a separate look, not this sweep.

Tests

latent components name their parameters generically asserts the new names
and that CombineLatentModels still separates two processes that share
init. A second item pins the diff namespace: that DiffLatentModel's own
init and the inner process's diff.init are distinct variables, that the
composition passes check_model, and that arima produces the documented
set.

Test run

Full unit suite on this branch, excluding the :ad-tagged items:

Package | Pass 1632 | Error 1 | Broken 5 | 18m43s

That run predates the DiffLatentModel commits; CI covers the current head.
The one error is Renewal composes modifiers onto a RenewalStep, pre-existing
on main and unrelated; filed as #284.

Status

Ready. The three review comments from seabbs-review-bot are all answered and
resolved: two accepted and fixed in a00e8bc, one declined with reasoning.

CI. One red check, ad / Enzyme forward, and it is CANCELLED rather than
failed — the 60-minute job cap that backend hits across the repo. All 26 other
checks pass.

No overlap with anything else open. This is the only open PR touching
src/latent_models/. The four open observation PRs (#272, #302, #309, #319) do
not touch a file this one does.

One known unrelated error, Renewal composes modifiers onto a RenewalStep,
pre-existing on main and filed as #284.

This was opened by a bot. Please ping @seabbs for any questions.

Adds a failing regression for #268: a Gaussian-process `R_t` and a
`NormalError` observation both sample a bare `σ` into one flattened
namespace, so the second assignment overwrites the first, `check_model`
fails and `sample` refuses to run.

Also sweeps every latent process against every error family, since this
class of clash is invisible until the two are composed.
`HilbertSpaceGP` and `ExactGP` sampled a bare `σ` for the marginal
standard deviation and a bare `ℓ` for the length scale. A latent process
composes into its host prefix-off (the package standard), so the GP's `σ`
landed in the same flattened namespace as an observation error model's own
`σ` and one silently overwrote the other: `check_model` failed and
`sample` refused to run on a Gaussian-process `R_t` with a `NormalError`.

The hyperparameters are now sampled as `gp_ℓ` and `gp_σ`. They stay flat,
so a chain is still read by a predictable name (`chain[:gp_σ]`), and the
error models keep their own `σ`. The weights (`β`, `z`) are unchanged.

Fixes #268
Says what the sampled names are and why they are GP-owned, so a reader
knows what to read out of a chain.
Components name their parameters for what they are, so two of them can want
the same name and the fix is a prefix applied where the conflict happens.
The conformance sweep now asserts both halves of that: the bare Gaussian
process against `NormalError` FAILS `check_model` on `σ`, and the same
pairing wrapped in a `PrefixLatentModel` passes, for every latent process in
the sweep.

The GP test items go back to reading `ℓ` and `σ`, which is what the
hyperparameters are called once the rename is reverted.

Red against the current `gp_ℓ` / `gp_σ` names.
Reverts the rename to `gp_ℓ` / `gp_σ`. The Gaussian processes sample `ℓ` and
`σ` again, which is what the package wants: a component names its parameters
for what they are, and a prefix is applied where a conflict actually occurs
rather than spelled into every name.

The defect left is that the collision does not point at its fix. A reader who
composes a Gaussian process with `NormalError` gets "Assigning to the variable
σ led to a previous value being overwritten" and nothing that names
`PrefixLatentModel`. So both GP docstrings now say which names they sample,
that they reach the top level of a composed model unprefixed, and how to
prefix them, with a runnable example of the working composition.

`PrefixLatentModel` and `PrefixObservationModel` appeared nowhere in
`docs/src`. The composable-design page now has a section on parameter names
that motivates them with this collision and shows both halves: the bare model
failing `check_model` and the prefixed one passing.

Fixes #268
The parameter-names section listed `damp` and `init` as examples, which are
still `damp_AR` and `ar_init` on this branch. Use names the package actually
samples.
@seabbs-bot
seabbs-bot requested a review from seabbs as a code owner August 18, 2026 12:45

@seabbs-review-bot seabbs-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR renames component-specific parameter names (ar_init, damp_AR, rw_init, hierarchy_mean) to generic ones (init, damp, mean) and documents the resulting namespace-collision risk with PrefixLatentModel/PrefixObservationModel. The rename itself is consistent and well tested (no stale old names remain, DiffLatentModel's deliberate exception is tested), but the accompanying documentation carries two issue-number references that breach the project's explicit no-development-history standard, and the same explanatory paragraph about the σ collision is duplicated verbatim across two docstrings and design.md.

Automated first pass by seabbs-review-bot (Claude sonnet), triggered by: first pass. Not a human review. @seabbs can comment @seabbs-review-bot to re-run it, or add the no-review label to opt this PR out. Ping @seabbs with any questions.

Comment thread NEWS.md Resolved
@seabbs

seabbs commented Aug 18, 2026

Copy link
Copy Markdown
Member

This implies it makes ssense for diff_init and latent_init to both exist despite them being about the same parameter. This needs updating I think towards diff init or maybe a bare in in the difflatent model (forcing use of prefix when i.e AR is used inside it whcih maybe is common enough we want to avoid.

@codecov

codecov Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
ad-enzyme-reverse 66.37% <100.00%> (+0.48%) ⬆️
ad-forwarddiff 66.92% <100.00%> (+0.47%) ⬆️
ad-mooncake-forward 66.92% <100.00%> (+0.47%) ⬆️
ad-mooncake-reverse 66.92% <100.00%> (ø)
ad-reversediff 67.07% <100.00%> (+0.46%) ⬆️
ad-reversediff-compiled 67.07% <100.00%> (ø)
unit 93.58% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/latent_models/combinations/arima.jl 100.00% <ø> (ø)
src/latent_models/manipulators/Hierarchy.jl 100.00% <100.00%> (ø)
src/latent_models/models/AR.jl 100.00% <100.00%> (ø)
src/latent_models/models/RandomWalk.jl 100.00% <100.00%> (ø)
src/latent_models/modifiers/DiffLatentModel.jl 100.00% <100.00%> (ø)
src/steps/ARStep.jl 100.00% <100.00%> (ø)
src/utils/turing-methods.jl 75.00% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

Copy link
Copy Markdown
Contributor

Try this Pull Request!

Option 1: Julia Package Manager

Open Julia and type:

import Pkg
Pkg.activate(temp=true)
Pkg.add(url="https://github.com/EpiAware/ComposableTuringIDModels.jl", rev="chore/generic-parameter-names")
using ComposableTuringIDModels

Option 2: Local Checkout

If you have the repo locally:

git checkout chore/generic-parameter-names
julia --project=. -e "using Pkg; Pkg.instantiate()"

@github-actions

Copy link
Copy Markdown
Contributor

📖 Documentation preview is ready!

View the docs for this PR at: https://EpiAware.github.io/ComposableTuringIDModels.jl/previews/PR283/

This preview will be updated automatically when you push new commits.

@github-actions

github-actions Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark comparison vs base

Minimum time per call. Buckets are PR time as a % of base, so lower is faster (🟢 faster, ⚪ within 5%, 🔴 slower). Counts of benchmarks per bucket:

Group 🟢 <50% 🟢 50–75% 🟢 75–95% ⚪ 95–105% 🔴 105–125% 🔴 125–150% 🔴 >150%
Evaluation · · · 6 3 · ·
ForwardDiff · · · 2 · · ·
ReverseDiff (tape) · · · 1 · · 1
Mooncake reverse · · 1 1 · · ·
Enzyme reverse · · · 1 · · ·
Evaluation — 9 benchmarks (by time change)
Benchmark base PR time memory
Model evaluation / RandomWalk latent / forward 420.0 ns 481.0 ns 🔴 1.15× ⚪ 1.0×
Model evaluation / RandomWalk latent / rand 451.0 ns 490.0 ns 🔴 1.09× ⚪ 1.0×
Sampling / NUTS (DirectInfections+Poisson, 50 draws) 89.99 ms 97.21 ms 🔴 1.08× ⚪ 1.0×
Model evaluation / DirectInfections+Poisson / rand 661.0 ns 681.0 ns ⚪ 1.03× ⚪ 1.0×
Model evaluation / AR latent / rand 631.0 ns 621.0 ns ⚪ 0.98× ⚪ 1.0×
Model evaluation / DirectInfections+Poisson / forward 1.12 μs 1.13 μs ⚪ 1.01× ⚪ 1.0×
Model evaluation / Renewal+NegativeBinomial / forward 4.69 μs 4.73 μs ⚪ 1.01× ⚪ 1.0×
Model evaluation / AR latent / forward 530.0 ns 531.0 ns ⚪ 1.0× ⚪ 1.0×
Model evaluation / Renewal+NegativeBinomial / rand 2.23 μs 2.23 μs ⚪ 1.0× ⚪ 1.0×
AD gradients — 7 benchmarks (by time change)
Benchmark base PR time memory
AD gradients / AR latent logjoint / ReverseDiff (tape) 45.84 μs 115.75 μs 🔴 2.53× ⚪ 1.0×
AD gradients / AR latent logjoint / Mooncake reverse 6.58 μs 6.16 μs 🟢 0.94× ⚪ 1.0×
AD gradients / DirectInfections+Poisson posterior / ForwardDiff 14.28 μs 14.01 μs ⚪ 0.98× ⚪ 1.0×
AD gradients / DirectInfections+Poisson posterior / ReverseDiff (tape) 105.68 μs 104.16 μs ⚪ 0.99× ⚪ 1.0×
AD gradients / DirectInfections+Poisson posterior / Mooncake reverse 9.62 μs 9.5 μs ⚪ 0.99× ⚪ 1.0×
AD gradients / AR latent logjoint / ForwardDiff 8.35 μs 8.41 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / DirectInfections+Poisson posterior / Enzyme reverse 3.47 μs 3.47 μs ⚪ 1.0× ⚪ 1.0×

Standard 8: a comment, a docstring or a docs page says what is true now and
carries no issue numbers. Both sentences read the same without them.
A parameter is named for what it is, not for the component that draws it:
`init`, not `ar_init`; `damp`, not `damp_AR`; `mean`, not `hierarchy_mean`.
Where two components then share a name, the composition that puts them
together prefixes them, which `CombineLatentModels` already does.

Also pins the one name that stays component-flavoured: `DiffLatentModel`
wraps a single inner model prefix-off, so `latent_init` cannot become `init`
without colliding with the inner process's own.

Red against the current names.
…nent

`ar_init`, `damp_AR`, `rw_init` and `hierarchy_mean` each spelled their
component's name into a parameter. A component knows nothing about what it
will be composed with, so the name it gives a quantity should say what the
quantity is; where two components then want the same name, the composition
that puts them together applies the prefix.

  - `AR`: `ar_init` → `init`, `damp_AR` → `damp`
  - `RandomWalk`: `rw_init` → `init`
  - `Hierarchy`: `hierarchy_mean` → `mean`
  - `ARStep`'s field `damp_AR` → `damp`, for the same reason

Nothing new collides. Two processes that now share `init` only meet under
`CombineLatentModels` / `ConcatLatentModels` / `Stratify`'s across slot /
`PrefixLatentModel`, all of which prefix already: measured over 13
compositions bare and under a renewal, every one still passes `check_model`.

`DiffLatentModel`'s `latent_init` is deliberately left alone. It wraps a
single inner model prefix-off, so `init` there lands on the inner process's
own: measured, `DiffLatentModel(model = AR())` and `(model = RandomWalk())`
both fail `check_model` under that rename, and the ARIMA composition the docs
ship is exactly that shape. `arima`'s `ar_init` / `diff_init` keyword
arguments also stay: they name two different init slots in one constructor.

**Breaking** for anything reading these names from a chain or pinning one
with `fix`.
NEWS.md carries the full old-to-new mapping and the names left alone with
their reasons, and the composable-design page's example names match what the
components now sample.
DiffLatentModel composes two children but prefixes only one, so its own
init prior cannot take the generic name. Assert the inner process is
namespaced under `diff` and the outer init is plain `init`, across AR,
RandomWalk, HierarchicalNormal, arima and a Renewal composition.
DiffLatentModel composes two latent processes and prefixed only one, so
its own init prior had to carry the component name to stay clear of the
inner process's `init`. Prefix the inner process under `diff` instead
and give the outer prior the generic `init`.

An ARIMA chain now reads `init`, `diff.init`, `diff.damp`, `diff.θ`,
which also says which series the parameters describe: the differenced
one, not the level.

BREAKING: `latent_init` is now `init`, and an inner parameter moves
under `diff`. Pin one through the nested form,
`fix(mdl, (diff = (damp = 0.1,),))`; a stale name is a silent no-op.
Add `DiffLatentModel` to the 0.2.0 parameter-name mapping and to the
list of components that already prefix their children.
@seabbs-bot
seabbs-bot force-pushed the chore/generic-parameter-names branch from da3cbbb to d814e57 Compare August 19, 2026 12:32
The delays tutorial's latent process is a `DiffLatentModel` wrapping an
ARMA(2,1), so namespacing the differenced process moved its parameters to
`diff.damp`, `diff.θ` and `diff.std`. The pair-plot keys and the prose
around them still named the bare forms, and `chain[pp_keys]` throws a
`KeyError` on a name the chain does not have, which failed the docs build.

Measured on the tutorial's own model, the parameters are `init`,
`diff.init`, `diff.damp`, `diff.θ`, `diff.std`, `diff.ϵ_t`,
`init_incidence`, `delay.θ`, `DayofWeek.std`, `DayofWeek.ϵ_t` and
`cluster_factor`.

The nested name is written `@varname(diff.damp)`, matching how the design
page reads a prefixed parameter; `@varname(var"diff.damp")` is a different
name and does not match.
@seabbs-bot

Copy link
Copy Markdown
Collaborator Author

The failing check was Documenter, and it was a real break in this PR

ad / Enzyme forward also shows red. That one is the 60-minute job timeout
of #291, not a failure: the log ends ##[error]The operation was canceled.
with a terminated julia orphan and no test summary, at 1h0m37s wall clock.
Nothing to do there.

The Documenter red was ours. Fixed in c87524a.

What broke

failed to run `@example` block in docs/src/tutorials/delays-dayofweek.md:188-197
  exception = KeyError: key damp not found

That tutorial's latent process is an ARIMA(2,1,1), which is
DiffLatentModel(; model = arma21, ...). Two commits interacted:

  • 6b67e27 renamed damp_AR to damp in the pair-plot keys, correct for a
    bare AR.
  • 5149dd7 then namespaced the process DiffLatentModel differences under
    diff, which moved that same parameter to diff.damp.

The tutorial was not revisited after the second commit, so pp_keys asked
for damp, θ and std when the chain holds diff.damp, diff.θ and
diff.std. chain[pp_keys] throws on a name the chain does not have, so
this failed loudly rather than silently, which is the good case.

The parameter set, measured

Built the tutorial's own model and read keys(VarInfo(...)):

init             diff.init      diff.damp      diff.θ
diff.std         diff.ϵ_t       init_incidence delay.θ
DayofWeek.std    DayofWeek.ϵ_t  cluster_factor

So pp_keys becomes diff.damp, diff.θ, diff.std, cluster_factor,
and the prose naming those three is updated to match. Every other backticked
parameter name on the page already matches this set.

One thing worth knowing about the syntax

The nested name has to be written @varname(diff.damp). That is a VarName
with symbol :diff and a .damp optic, which is what the model actually
creates, and it matches how design.md reads a prefixed parameter
(chain[@varname(gp.σ)]).

@varname(var"diff.damp") is a different name: a flat symbol that happens
to contain a dot. Indexing with it fails:

chain[@varname(diff.damp)]        -> OK, (20, 1)
chain[@varname(var"diff.damp")]   -> KeyError: key diff.damp not found

Flagging it because the tests use the flat Symbol("diff.damp") form against
varnames, which is fine there but is not the form that indexes a chain.

Verification

I did not rebuild the full docs, which takes over 90 minutes. I built the
tutorial's exact model in the docs environment, sampled it, and ran the
corrected selection and the plot call end to end:

subset OK: [Parameter(diff.damp), Parameter(diff.θ),
            Parameter(diff.std), Parameter(cluster_factor)]
pairplot OK Figure

Chain keys do not depend on the sampler, so the prior draw exercises the same
lookup the tutorial's NUTS chain does. pre-commit passes on the file.
delays-dayofweek.md is the only page using DiffLatentModel with pair-plot
keys; renewal-negbin.md and realtime-nowcast.md use an undiffed process,
so their bare damp/std are correct, and Documenter reported no error for
them.

This was opened by a bot. Please ping @seabbs for any questions.

Release notes live on the GitHub release, built on TagBot's merged-PR list,
so a changelog file in the repo is not kept. The substance of these entries
belongs in the pull request title and body, which is what the release notes
are assembled from.
@seabbs-bot

Copy link
Copy Markdown
Collaborator Author

Your diff_init / latent_init point is now implemented

You wrote that having diff_init and latent_init both exist for what is the
same parameter made no sense, and steered towards either diff.init or a bare
init in DiffLatentModel.

That is what the branch now does, in 5149dd7. DiffLatentModel prefixes the
inner process under diff and keeps the bare init for its own
integration constants:

init ~ as_turing_submodel(model.init, d; prefix = true)
diff ~ as_turing_submodel(model.model, n - d; prefix = true)

So an ARIMA chain reads init, diff.init, diff.damp, diff.θ,
diff.std, diff.ϵ_t. latent_init is gone, and so is diff_init as a
sampled name.

This takes the second of your two options, and it is deliberate for the reason
you gave. Prefixing the inner process rather than the outer prior means the
common case you were worried about — an AR inside a DiffLatentModel — needs
no PrefixLatentModel from the user. The namespace also says which series each
parameter describes: diff.damp is the damping of the differenced series, not
of the level.

Pinned in test/unit/latent_models/latent.jl:100-145, for both the bare
DiffLatentModel and arima.

Two consequences worth knowing:

  • It is breaking twice over. latent_init is now init, and inner parameters
    move under diff. A stale name in fix is a silent no-op, so the nested
    form is needed: fix(mdl, (diff = (damp = 0.1,),)).
  • delays-dayofweek.md used an ARIMA(2,1,1) and asked the chain for bare
    damp, θ, std. That broke the Documenter build and is fixed in c87524a,
    reading @varname(diff.damp) and so on.

One thing I have left alone, for your call

arima's constructor keywords are still ar_init and diff_init:

arima(; ar_init = [Normal()], diff_init = [Normal()], damp = ..., θ = ...)

These are not parameter names — the sampled names are init and diff.init —
but they are the same component-named shape this PR is removing elsewhere. The
flat keyword list of a combination builder has two init priors to place and
no namespace to separate them with, so the alternatives are a nested
arima(; diff = (init = ...,), init = ...) or leaving it as is. I have left it
as is rather than guess, since it changes the builder's signature rather than
any chain.

This was opened by a bot. Please ping @seabbs for any questions.

…er-names

# Conflicts:
#	docs/src/design.md
#	src/latent_models/models/ExactGP.jl
#	src/latent_models/models/HilbertSpaceGP.jl
#	test/unit/compose.jl
#	test/unit/latent_models/gaussian_process.jl
The testitem imported RenewalStep, ConstantRenewalStep and
SusceptibleDepletion but used Renewal and RandomWalk, so it only ran
under a blanket import from runtests.jl and errored whenever it was run
in isolation.
@seabbs
seabbs merged commit 92b4c41 into main Aug 28, 2026
26 of 27 checks passed
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.

2 participants