Skip to content

docs: derive the three held tutorial examples with @set once #372 lands #386

Open

Description

@seabbs-bot

Three tutorial blocks build a second object from scratch where the prose says only one thing changes. PR #366 swept this pattern and converted every case whose target @set handles correctly today. These three were left alone because @set on their target silently produces a different object from the hand-built one (#369), and they need an edit here after the fix in #372 lands. None of them self-corrects.

The pages are correct and build as they are. What is missing is the demonstration, not correctness.

Page Block Target Why held
docs/src/tutorials/split-observations.md cases and deaths, lines 52-59 Ascertainment.latent_model Ascertainment wraps its latent prior in a PrefixLatentModel at construction, so @set with an unwrapped prior skips the wrapping and the derived stream samples different variable names
docs/src/tutorials/delays-dayofweek.md tv_observation at line 242, derived from observation at line 84 LatentDelay.delay LatentDelay stores its pmf reversed today, so @set on the delay stores an unreversed vector where the hand-built stores a reversed one. #372 changes the stored form
docs/src/tutorials/patch-models.md independent, pooled, coupled at lines 51, 70 and 104 Renewal.rt Renewal bakes a recurrent_step at construction that @set leaves stale, giving an object matching neither the original nor the hand-built one
docs/src/tutorials/time-varying-damping.md tv at line 35, derived from constant at line 22 AR.damp AR picks transform from the type of damp, tanh for a process and identity for a Distribution, so @set on the damp keeps identity where the hand-built gets tanh. Found while writing #366 and not part of the original #369 sweep, which only set same-type values

Each is a one-line derivation once the target is safe, for example deaths = @set cases.model.latent_model = Intercept(Normal(log(0.015), 0.25)) in place of the second hand-built chain, and the narrating sentence above it goes at the same time.

Do not write a helper function instead. The idiom wanted here is define once, derive the variant.

Verify each conversion by building the derived object and the hand-built one in the same session and comparing them field by field, recursively. == and isequal both fall back to === at struct level and return false for structurally identical objects that hold different Vector instances, so neither is a usable check here.

Related: #369, #372, #366.

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

Activity

  1. seabbs-bot commented on Sep 4, 2026

    @seabbs-bot
    CollaboratorAuthor

    Correction to the premise for the fourth row: #372 does not clear the AR case. The other three are unblocked by it; this one is not, so do not pick the issue up as a single unit once #372 merges.

    #372 derives p and re-derives init inside the inner constructor, but takes transform as given and never touches it. The default still lives only in the keyword constructor:

    function AR(damp, init, _p, ϵ_t, transform)
        p = _slot_order(damp)                                    # derived
        init = (p > 1 && init isa Distribution) ? fill(init, p) : init   # re-derived
        ...                                                      # transform passed through untouched
    
    function AR(; damp = ..., transform = _default_transform(damp))      # only place it is derived

    So an @set on .damp reconstructs through the inner constructor carrying the old transform, which is exactly the behaviour this row describes.

    Why it is not the same fix as the others

    p is derived-only — no caller may legitimately disagree with it, so deriving it in the inner constructor is safe. transform is defaulted from damp but deliberately overridable: transform = identity on a process is a valid choice. Once stored as a concrete function, "the user chose identity" and "it defaulted to identity" are indistinguishable, so unconditional re-derivation would silently discard a deliberate override. That is a worse bug than this one and an invisible one.

    The distinction has to survive the fix. One shape that preserves it is to keep the derivation lazy rather than eager — a sentinel stored in the field and resolved where it is used, so an @set on .damp carries the sentinel through and resolves correctly, while an explicit function is preserved because it is a different value. That runs against #369's general direction of deriving at construction, which is correct for fields nobody may override and not for this one.

    Also worth recording

    The property test on #372 passes over this field. It never sets damp to a process, and both Distribution and Vector{<:Distribution} map to identity, so the two sides agree by accident. Any test for this must cross all three PriorLike kinds, and should be seen to fail before the fix.

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

  2. seabbs-bot commented on Sep 5, 2026

    @seabbs-bot
    CollaboratorAuthor

    #390 does the three rows #372 unblocked, split, patch and delays, each verified field by field against the hand-built object.

    The AR.damp row stays open here, for the reason in the comment above: transform is defaulted from damp in the keyword constructor only, and re-deriving it unconditionally would discard a deliberate transform = identity.
    That needs a decision on how AR records whether transform was chosen or defaulted before the page can derive tv from constant.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions