Skip to content

Export and document the recurrence constructor; treat the modifier seam as provisional #173

Open

Description

@seabbs-bot

The composed recurrence step and its modifier contract already exist and behave correctly, but they are not reachable from outside the package. Neither the composed step type nor the modifier abstract type is exported, and every public recurrence constructor builds a plain core step, so the composable path can be reached only by positional construction with an internal type. This issue proposes exporting and documenting the composed step, adding a modifiers keyword to the public constructor (with an empty tuple recovering the plain recurrence exactly), and framing the modifier seam as a provisional extension point rather than a settled contract.

Rationale

The clear part is that the composed recurrence step and its modifier contract exist and are correct but neither the composed step type nor the modifier abstract type is exported, and every public constructor builds a plain core step, so the composable path is reachable only by positional construction with an internal type. Exporting and documenting the recurrence constructor is wanted regardless.

The hesitancy is about the modifier approach itself: whether a modifier seam is the right way to vary a recurrence's mechanism is not settled, so this should expose the existing capability without cementing that design as the way. Frame the modifier seam as a provisional extension point rather than a settled contract, and note the open question of whether mechanism variation belongs in a modifier seam at all, so downstream code does not harden against it before the design is confirmed.

Value / effort

Value high · Effort low · Verdict nearly (design-first on the modifier seam: expose the existing capability, but keep the seam provisional rather than a committed contract).

Illustrative example

Note: this example is schematic; the real type names have been substituted with domain-neutral placeholders.

using ComposableTuringIDModels, Distributions

# The public recurrence constructor always builds a plain core step:
rec = Recurrence([0.2, 0.3, 0.5]; rt = RandomWalk(),
    initialisation_prior = Normal())
# rec.recurrent_step isa ComposableTuringIDModels.ConstantRecurrenceStep  # plain core

# The composed recurrence path already exists and is correct, but the composed
# step type and the modifier abstract type are NOT exported. Today it is
# reachable only by positional construction with internal, module-qualified
# types — awkward and brittle for downstream code:
core = ComposableTuringIDModels.ConstantRecurrenceStep(reverse([0.2, 0.3, 0.5]))
mods = (some_modifier,)  # each <: ComposableTuringIDModels.AbstractRecurrenceModifier
composed = ComposableTuringIDModels.ComposedRecurrenceStep(core, mods)
rec_composed = Recurrence([0.2, 0.3, 0.5], exp, RandomWalk(), Normal(), composed)

# --- Desired ---

# Export `ComposedRecurrenceStep` and `AbstractRecurrenceModifier`, and add a
# `modifiers` keyword to the public constructor. An empty tuple must recover the
# plain recurrence exactly:
rec = Recurrence([0.2, 0.3, 0.5]; rt = RandomWalk(),
    initialisation_prior = Normal(), modifiers = ())          # identical to plain

# A non-empty tuple threads the proposed contribution through each modifier,
# every modifier carrying its own substate across the scan:
rec = Recurrence([0.2, 0.3, 0.5]; rt = RandomWalk(),
    initialisation_prior = Normal(), modifiers = (some_modifier,))

# Document `AbstractRecurrenceModifier` (its `modifier_init_state` /
# `apply_modifier` contract) as a PROVISIONAL extension point: expose it so the
# composable path is dispatchable from outside, but flag that whether mechanism
# variation belongs in a modifier seam at all is still an open design question,
# so downstream code should not harden against it yet.

Part of #165.

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

Activity

  1. seabbs-bot commented on Aug 4, 2026

    @seabbs-bot
    CollaboratorAuthor

    Partly resolved — leaving open.

    Done: the composed step and its modifiers are now public and documented,
    reachable without any internal, module-qualified construction.
    RenewalStep, SusceptibleDepletion and ImportedCases are all exported
    (src/ComposableTuringIDModels.jl), and the public Renewal constructor
    takes modifiers directly as positional arguments (an empty modifier list
    recovers the plain renewal exactly):

    Renewal(gen_int, SusceptibleDepletion(1000.0), ImportedCases(Normal(0.0, 1.0));
        rt = RandomWalk())

    (see docs/src/design.md, "Composing accumulation steps"). The modifier
    contract (modifier_init_state / apply_modifier) is documented on
    AbstractRenewalModifier in src/steps/RenewalStep.jl.

    Not done: AbstractRenewalModifier itself is not in the top-level
    export list, so writing a new modifier from outside the package still
    needs the qualified ComposableTuringIDModels.AbstractRenewalModifier to
    subtype against — the "provisional extension point" isn't fully public
    yet.

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

  2. seabbs commented on Aug 5, 2026

    @seabbs
    Member

    is it public not exported that seems the right level no?

  3. seabbs commented on Aug 5, 2026

    @seabbs
    Member

    maybe true modifier_init_state and apply_modifier as well maybe? f

  4. seabbs-bot commented on Aug 18, 2026

    @seabbs-bot
    CollaboratorAuthor

    Verified the composed-step/modifier ask is already fully resolved (via #245,
    before this PR): RenewalStep, SusceptibleDepletion and ImportedCases
    are exported; AbstractRenewalModifier, modifier_init_state and
    apply_modifier are already public (not exported — matching your call in
    the thread above); and the public Renewal constructor already takes
    modifiers directly (Renewal(gen_int, modifiers...; rt = ...), an empty
    tuple recovering the plain renewal exactly). No code change needed there.

    Separately, PR #282 makes the related prior-slot widening seam
    (at/path_prior/prior_order/assert_prior_length, previously
    _at/_path_prior/_prior_order/_assert_prior_length) public too,
    since it was raised alongside this issue and #184.

    Leaving this open per instruction rather than closing outright, but as far
    as I can verify every concrete ask in this issue's body and comments is now
    met.

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

  5. seabbs-bot commented on Aug 20, 2026

    @seabbs-bot
    CollaboratorAuthor

    Re-checked against main at 1a3e485 (after #282 merged). Three of the four asks are met, one is not, so this stays open on a much narrower point.

    Met.

    • RenewalStep is exported (src/ComposableTuringIDModels.jl:98), and AbstractRenewalModifier, modifier_init_state and apply_modifier are public (:138-140). Confirmed with Base.isexported / Base.ispublic.
    • Renewal(gen_int, modifiers::AbstractRenewalModifier...; ...) exists (src/infection_models/Renewal.jl:170), so no positional construction with an internal type is needed.
    • No modifiers recovers the plain recurrence exactly. Under a fixed seed, rand on IDModel(Renewal(; generation_time = g, rt = RandomWalk(), initialisation = Normal()), PoissonError()) and on the same model built through the varargs constructor with no modifiers give identical draws. The step type differs (ConstantRenewalStep against RenewalStep{ConstantRenewalStep, Tuple{}}) but the sampled model does not.
    • The AbstractRenewalModifier docstring (src/steps/RenewalStep.jl) documents modifier_init_state, apply_modifier and the as_turing_model resolution seam, including the positional modifier_<i> prefixing.

    Most of this landed in #245 rather than #282; #282 confirmed it and added the prior-slot helpers.

    Not met. The provisional framing. Nothing in src/ or docs/src/ says the modifier seam is a provisional extension point, or notes the open question of whether mechanism variation belongs in a modifier seam at all. Grepping for "provisional", "not settled", "open design question" and "do not harden" over both trees returns no matches. A downstream reader of the docstring today sees a settled contract, which is the thing this issue asked to avoid.

    Left open for that. It is a sentence or two on the AbstractRenewalModifier docstring, and it is coupled to #176.

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

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