Forward n_timepoints and first_day_dow to ascertainment models - #891
Closed
developer-rpai wants to merge 1 commit into
Closed
developer-rpai wants to merge 1 commit into
developer-rpai wants to merge 1 commit into
Conversation
…v#890) MultiSignalModel now passes n_timepoints (shared model-axis length) and first_day_dow (axis-origin day-of-week) when sampling registered ascertainment models, so ascertainment models with temporal processes can produce full-axis, calendar-aligned trajectories. Existing scalar ascertainment implementations accept **kwargs and are unaffected. Adds AscertainmentModel.requires_calendar_anchor() (default False, mirroring the latent-process API) and includes ascertainment models in MultiSignalModel's obs_start_date entry check. Tests: time-varying day-of-week ascertainment test double verifies the forwarded axis context and calendar alignment; anchor checks fire from both sample() and validate_data(); scalar JointAscertainment output is unchanged with and without the new kwargs; requires_calendar_anchor() defaults to False for scalar implementations.
developer-rpai
requested review from
cdc-mitzimorris,
dylanhmorris and
sbidari
as code owners
September 20, 2026 05:26
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The implementation fulfills the issue requirements with appropriate validation, documentation, and regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Forwards model-axis timing context to ascertainment models, enabling calendar-aligned, time-varying ascertainment.
Changes:
- Passes
n_timepointsandfirst_day_dowduring ascertainment sampling. - Adds calendar-anchor requirements and validation.
- Adds coverage for temporal and scalar ascertainment behavior.
| File | Description |
|---|---|
pyrenew/ascertainment/base.py |
Defines and documents the calendar-anchor contract. |
pyrenew/model/multisignal_model.py |
Forwards timing context and validates required anchors. |
test/test_ascertainment.py |
Tests default anchor behavior. |
test/test_pyrenew_builder.py |
Tests forwarding, alignment, validation, and compatibility. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Collaborator
|
thank you for this PR, but this issue is not ready for implementation. see #890 (comment) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #890.
What the issue is
MultiSignalModelcomputes the shared model-axis length andfirst_day_dowand forwards both to the latent process and every observation process — but calls each registeredAscertainmentModel.sample()with no arguments. That prevents ascertainment models with temporal processes (e.g. time-varying ascertainment) from producing full-axis, calendar-aligned trajectories, even though theAscertainmentModel.sample(**kwargs)contract explicitly allows model-context arguments.Approach
MultiSignalModel.sample()now passesn_timepoints(shared axis length,n_init + n_days_post_init) andfirst_day_dowto each ascertainment model'ssample(). Existing scalar implementations (JointAscertainment,RatioLinkedAscertainment) already accept**kwargsand ignore them, so this is backward-compatible.AscertainmentModel.requires_calendar_anchor()(defaultFalse, mirroring the latent-process API). Subclasses sampling a calendar-aligned temporal process can override it to returnTrue._check_obs_start_date()now includes ascertainment models when deciding whetherobs_start_dateis required, so a missing calendar anchor fails fast at the model entry with a clear message naming the offending ascertainment model. This covers bothsample()andvalidate_data()(both call_check_obs_start_date).AscertainmentModel.sample()docstring and onMultiSignalModel'sascertainment_modelsparameter.Tests
New tests in
test/test_pyrenew_builder.py(TestTimeVaryingAscertainment, 4 tests) andtest/test_ascertainment.py(TestRequiresCalendarAnchor, 2 tests), using a time-varying ascertainment test double with a day-of-week effect that requires both kwargs andrequires_calendar_anchor() == True:n_timepointsandfirst_day_dow, and the sampled trajectory is calendar-aligned to the suppliedobs_start_date;obs_start_dateraises from bothsample()andvalidate_data()naming the ascertainment model;JointAscertainmentoutput is byte-identical with and withoutobs_start_date(new kwargs safely ignored); and the 3 new behavior tests fail against the unfixed code while the scalar test passes either way;requires_calendar_anchor()defaults toFalsefor both scalar implementations.Local results: 105 passed across
test/test_pyrenew_builder.py+test/test_ascertainment.py, 6 passed in the two weekly-ascertainment integration tests;ruff checkandruff format --checkclean. I ran these with jax 0.11.2 / numpyro 0.22.0 in a local venv — upstream CI is authoritative for the full matrix.