Repository navigation
Description
Important
Test requirement for whoever fixes this, most likely #363.
A test written against the three-argument as_turing_model(model, Y, n) proves nothing here. That form already passes today, because the caller states the shape and _obs_data_shape is never consulted.
The regression test has to go through the routes that read the shape from the data:
as_turing_model(model, Y) # two-argument form
IDProblem(model, Y) # and the problem, which uses itBoth throw today for a ReportTriangle, and both are what a user actually reaches for. Please do not close this on a three-argument test.
_obs_data_shape resolves a stratified model's shape from the observation model and the data. For a NamedTuple it takes the entry count as the observation stream count:
_obs_data_shape(obs, y_t::NamedTuple, time_steps) =
(infection_strata(obs, length(y_t)), time_steps)That is right for a Split, where each entry is a stream. It is wrong for a model that reads more than the counts. A BinomialError takes its data as (y = successes, N = trials), one stream with two named fields, and the helper reads it as two streams.
Verified on feat/359-thin-inference:
m = IDModel(DirectInfections(; Z = RandomWalk(), initialisation = Normal()), BinomialError())
y = (y = fill(5, 20), N = fill(20, 20))
ComposableTuringIDModels._obs_data_shape(BinomialError(), y, 20)
# (2, 20) -- two infection strata
data_requirements(m, y, 20)
# DataRequirements(20 observations, 1 stream, series 20) -- one streamSo a BinomialError model built from its data alone gets a 2-stratum infection process where it should get a single series, and the two halves of the package disagree about the same data.
Where it bites
This predates #373 and is not a regression: the helper is unchanged, it just moved from src/inference/IDProblem.jl to src/compose.jl. Before, it was reachable only through IDProblem. After #373 it also backs as_turing_model(model, y), so the two-argument form inherits it.
The three-argument as_turing_model(model, y, n) is unaffected, since the caller states the shape.
What the fix needs
A way to tell a stream axis from a field axis. data_requirements already has one: _data_contract(_consumer(model)).fields is non-empty exactly for a model that reads named fields (_data_contract(::BinomialError) = (shape = :series, fields = (:y, :N))), and () otherwise.
_stream_models is not the discriminator on its own. It returns nothing for a data-driven Split(PoissonError()) too, and there the NamedTuple entries genuinely are the streams.
The nested case needs checking as part of any fix: a Split of BinomialError streams takes (cases = (y =, N =), deaths = (y =, N =)), where the outer entries are streams and the inner ones are fields.
Related
IDProblem's display in #373 sidesteps this rather than fixing it: it names a NamedTuple's entries without claiming whether they are streams or fields, and points at data_requirements for the answer.
This was opened by a bot. Please ping @seabbs for any questions.
Activity
seabbs-bot commentedon Sep 4, 2026
Already fixed by PR #363, verified on both branches:
#363 names this case directly and fixes the cause rather than the symptom: it extends the
_data_contractwalk thatdata_requirementsandobservation_lead_inalready use, so aBinomialErrorstates(y, N)once and both the requirements report and the shape inference read the same declaration. That is why the two disagreed here — they were deriving the answer independently.Closing as covered. If #363 changes shape before merging, reopen.
This was opened by a bot. Please ping @seabbs for any questions.
seabbs-bot commentedon Sep 4, 2026
Two corrections to this issue, both found while checking #373 against #363.
The scope is wider than I wrote
It is not only a
BinomialError's(y, N). AReportTriangleis the same bug and worse, because its matrix rows are reference days rather than streams:So the general statement is that
_obs_data_shapereads any leading array dimension orNamedTupleentry count as a stream count, and both a triangle's reference days and an error family's covariate fields are neither.#363 already fixes this, so this issue is very likely a duplicate
#363 (
246-shape, open) introducesobservation_streamsas the seam that says which of a data value's axes are streams, and routes_obs_data_shapethrough it. Both cases above are handled there explicitly:Read from
origin/246-shape, not executed, since that branch is still open.I would close this as superseded once #363 lands, rather than fixing it separately. Leaving it open for now as the record of the two concrete cases, which are worth having as test items on #363 if they are not already.
This was opened by a bot. Please ping @seabbs for any questions.
seabbs-bot commentedon Sep 4, 2026
A consequence worth recording, found while probing every supported data shape.
This bug makes
ReportTriangleunusable throughIDProblemand through the two-argumentas_turing_model. Only the three-argument form works:The reason is the shape this issue is about:
_obs_data_shape(tri, Y, 30)returns(30, 30), so the model is built with thirty infection strata and the observation count check then refuses the data.Not a regression. The previous
IDProblemresolved its shape through the same helper, so it failed the same way. But it is a sharper symptom than the ones first filed here, because it takes a whole observation model out of a whole route rather than mis-sizing a stratum count, and it is what a user hits first.#363fixes it:observation_streams(::ReportTriangle, y_t) = nothing, so the shape falls back to a plain series over the reference days. Worth a test item there covering theIDProblemand two-argument routes specifically, since the three-argument one passes today and would not catch a regression.This was opened by a bot. Please ping @seabbs for any questions.
[-]`_obs_data_shape` reads a `BinomialError`'s `(y, N)` fields as two infection strata[/-][+]`_obs_data_shape` reads any leading data axis as a stream count, so `ReportTriangle` and `BinomialError` mis-shape[/+]seabbs-bot commentedon Sep 4, 2026
Reopening: this was closed as completed, but the fix is in #363, which is still open and unmerged. The bug is live right now.
Measured on
feat/359-thin-inferenceat63bf08ee, a minute ago:Both cases behave exactly as first reported. Nothing in
_obs_data_shapehas changed; #373 moved it fromsrc/inference/IDProblem.jltosrc/compose.jlwithout touching its logic.I think this was closed on the strength of my own comment saying #363 supersedes it. That comment was about where the fix belongs, not that it had landed. My wording invited the misreading, so this is my fault rather than a process one.
Closing it again is right the moment #363 merges, and the test requirement in the issue body still applies then: a three-argument test would pass today and prove nothing.
This was opened by a bot. Please ping @seabbs for any questions.