Skip to content

feat(delivery): the no-collapse invariant — draws.py (ADR-013 §6) - #98

Merged
Polichinel merged 1 commit into
developmentfrom
feat/draws-no-collapse-invariant
Jul 15, 2026
Merged

Polichinel merged 1 commit into
developmentfrom
feat/draws-no-collapse-invariant

Conversation

@Polichinel

Copy link
Copy Markdown
Collaborator

The first build leg of the adopted wire contract (ADR-013 §6) — the policy boundary views-models#149 asked to have named and owned: views-postprocessing owns it, and this is it.

delivery/draws.py — assert_draws_uncollapsed(values, sample_count, *, s_min, label) raises DrawsCollapseError unless:

  1. payload is 2-D (N, S);
  2. payload S == header-declared sample_count;
  3. sample_count >= s_min (config-declared; 2 for the walking skeleton);
  4. globally ≥1 row with >1 distinct draw value — per-row zero variance explicitly legal (PGM zero-inflation), only all-rows-degenerate fails.

House invariant style: representation-free (pandas-free, auto-covered by the design-contract test), declare-don't-guess (nothing inferred from the payload), fail loud with expected-vs-found. NaN rows count as varied by design (documented + pinned — NaN is the null gates' job). Wiring into the live path lands with the #91 sink-adapter leg per the contract.

10 tests incl. the zero-inflation non-rule, the skeleton floor, header/payload mismatch naming both values. ruff clean; 142 passed, 43 xfailed.

Refs: ADR-013 §6, views-models#149 (adoption comment), #45.

The policy boundary named by views-models#149 and adopted in ADR-013: a sampled
forecast must still be draws when it ships. assert_draws_uncollapsed raises
DrawsCollapseError unless (1) the payload is 2-D (N,S); (2) payload S equals the
header-declared sample_count; (3) sample_count >= the config-declared s_min
(2 for the walking skeleton); (4) globally at least one row carries >1 distinct
draw value — per-row zero variance is explicitly legal (zero-conflict cells
dominate PGM), only an all-rows-degenerate payload fails (a collapsed forecast
wearing a sampled header).

House invariant style: representation-free (no pandas — design-contract test
auto-covers it), declare-don't-guess (sample_count/s_min are declared by the
caller from header/config, never inferred), fail loud naming expected vs found.
NaN rows count as varied by design (documented + pinned): NaN payloads are the
null gates' job. Wiring into the delivery path lands with the sink-adapter leg
(#91) per the contract; this story is the invariant + tests.

10 tests incl. the PGM zero-inflation non-rule and the skeleton floor (S=2).
ruff clean; 142 passed, 43 xfailed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Polichinel
Polichinel merged commit 9a872bb into development Jul 15, 2026
4 checks passed
@Polichinel
Polichinel deleted the feat/draws-no-collapse-invariant branch July 15, 2026 09:49
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.

1 participant