Skip to content

Add the demographic phase's shared conventions - #599

Draft
MaxGhenis wants to merge 7 commits into
masterfrom
openpop-demographic-shared-20261106
Draft

MaxGhenis wants to merge 7 commits into
masterfrom
openpop-demographic-shared-20261106

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

WIP. This is the first commit of the open-population lane's demographic phase, under d1925. OP2(a), OP2(b), OP3 and OP4 start side by side from this branch, on new files, and this PR lands before any of them.

What changes

OP0.1's six records stay in draft, and its coordinator questions say no provisional choice freezes itself. So each part takes a convention as a required input with no default. open_population/conventions.py gives those parts one place to meet:

  • ConventionSource names an input's record and status (invented, proposed or frozen), and require_frozen refuses by a named condition.
  • ComponentControls holds annual controls in thousands by named component, with a direction and a universe. OP3's reader emits them, and OP4's law consumes them.
  • ExitTimingConvention holds the one share OP3's bridge and OP4's law read: how much of a year's exit risk an entrant faces in its entry year.
  • Constants name the roster columns and stream tags more than one part writes or reads. FOREIGN_BORN_COLUMN names the nativity column OP4's law reads, which build_entrant_schedule already writes on entrants.

errors.py gains four refusals from design §8: CONTROL_SOURCE_UNAVAILABLE, UNIVERSE_BRIDGE_UNRESOLVED, TIMING_BRIDGE_UNRESOLVED and EXTRAPOLATION_UNDECLARED. No projection reads the new module yet.

The reducer's seal now covers the package. conventions.py joins both exclusion lists, as design §2.10 asks. Reading those lists turned up a gap: test_post_review_exclusions_are_unreachable_from_birth_evidence never named open_population, so nothing on master asserted that the reducer can't reach the package the tuple leaves out of its identity. So this PR makes two more changes in tests/estimates/test_birth_evidence_artifact.py:

  • The reachability test builds the module set from the package itself, as it does for graph, so a part's new module gets the check unasked.
  • test_every_open_population_module_is_an_exact_exclusion fails by name when a module in the package misses the tuple.

The tuple keeps exact files. A package prefix would have saved each part a line, but tests/track_u2/test_u2_isolation.py:252–255 requires "Exact files, never directories". Parts instead insert after separate lines in OP1's block, so they merge without touching each other. git merge-file on copies of both files merged all six with no conflict.

Invariants

  1. Only a frozen source passes require_frozen.
  2. A control table holds finite, non-negative amounts under integer years and named components, construction copies it, and total rounds the exact sum once.
  3. for_year returns every component the table names or refuses, so a known zero differs from a missing row.
  4. Controls refuse another universe by name.
  5. entry_year_probability lies in [0, annual], even if a platform's expm1 rounds high. It returns each end exactly, rises with the annual figure and the share (to one unit of rounding), and reads the annual figure as a constant hazard. The share reads as a plain float.
  6. Shared stream tags differ from each other and from the two existing tags, and the sealed registry and OP1's direct class draw the same numbers under them.
  7. FOREIGN_BORN_COLUMN names the column build_entrant_schedule writes.
  8. No module in open_population is reachable from the reducer, and each one is an exact entry in the tuple.

tests/open_population/test_conventions.py holds 1 to 7, with Hypothesis properties for 2, 3 and 5 and a differential for 6, on invented values only. tests/estimates/test_birth_evidence_artifact.py holds 8.

Evidence

All on the host, in one process, with a one-minute load under 130.

  • At the head, e6e96cd4. It merges master 331ae7de (987c42cc, tree equal to git merge-tree's, no conflict) and recounts the tier files: unit 26,654 → 26,733 and artifact 7,141 → 7,142, total 36,203. The PR's two test modules, collected by name under each marker, add 79 unit tests and 1 artifact test. At 987c42cc they gave 93 passed in 7.71 s, and against master the PR still changes its five files plus the two tier files.
  • At 60c2ba2a. It answers review shared-r2's minor and nit, in tests/open_population/test_conventions.py only. A grid test checks 2,478 invented (annual, share) pairs against the 200-digit oracle at eight units of rounding; the host's worst is two. A second test checks shared-r2's two pairs against 1 - sqrt(1 - p). The module gave 79 passed in 4.97 s. Ten numeric mutants each die, among them shared-r2's two survivors: p * share for risks below 1e-8, and p for risks above 1 - 1e-12.
  • At fe903613. It adds three regressions near zero to tests/open_population/test_conventions.py, and changes nothing else. That module gave 56 passed in 8.07 s. Review shared-r1's three surviving mutants each die now: log(1 - p) for log1p(-p), shares below 1e-10 read as zero, and results zeroed for annual risks below 1e-15.
  • At eb5b6851. The tests/open_population modules other than the stream scan gave 306 passed and 1 xfailed in 34.23 s, and the seal module gave 14 passed in 7.43 s. Black and Ruff pass on the PR's Python files.
  • Seal mutants, at 68df7397. All five died: three that make the package reachable and two that drop a module from the tuple.
  • Conventions mutants, at 68df7397. 31 of 34 died. The head adds a test for each of the three survivors, and each now dies:
    • math.fsum becoming sum. Python 3.14's built-in sum compensates, so 2 million random tables never told the two apart. Just past a tie, the exact sum rounds up where a compensated total stops.
    • The share staying uncoerced.
    • The bound at the annual probability going. A search of 80 million invented pairs never saw that bound fire on this platform's expm1. The test patches np.expm1 to round one unit high, and the bound holds.

The commit after 68df7397 changes tests/open_population/test_conventions.py only.

Plan

  • Module, refusals, tests and exclusion lists.
  • Seal coverage for the package.
  • Host run and mutants, with results here.
  • Sol review, shared-r1, at eb5b6851: REVISE, one major finding. No test pinned the exit share's accuracy near zero. fe903613 answers it.
  • Sol delta review, shared-r2, at fe903613: APPROVE, with one minor finding and one nit, both on test coverage. 60c2ba2a answers them.
  • Sol delta review, shared-r3, at 60c2ba2a (running).
  • Merge master 331ae7de and recount the tier files, at e6e96cd4.
  • Green CI at the head, then the merge request.

🤖 Generated with Claude Code

OP2, OP3 and OP4 start side by side from this commit. They meet at one
module: required inputs that name their source and status, the annual
controls OP3's reader emits and OP4's law consumes, the exit-timing
convention OP3's bridge and OP4's law share, and the roster columns and
stream tags more than one part writes or reads. It also adds the four
named refusals those parts raise (design §8).

No projection reads this module yet, and it joins the reducer's exclusion
list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vercel

vercel Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
social-security-model Ready Ready Preview Nov 29, 2026 1:30pm UTC

Request Review

OP4's exit law reads a row's nativity, and build_entrant_schedule already
writes foreign_born on entrants, so conventions.py names that column.

The reachability test never named open_population, so nothing asserted that
the reducer can't reach the package the exclusion list leaves out of its
identity. The test now builds the module set from the package itself, as it
does for graph, so a part's new module gets the check unasked. A second test
fails by name when a module in the package misses the list. The list keeps
exact files, as tests/track_u2/test_u2_isolation.py requires.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The conventions mutants left three survivors at 68df739, and each named a
property no example reached:
- `math.fsum` against `sum`: 3.14's built-in `sum` compensates, so no random
  table told them apart. Just past a tie the exact sum rounds up where a
  compensated total stops.
- the share's coercion to a plain float.
- the bound at the annual probability, which no search reached on this
  platform's `expm1`. A patched `expm1` that rounds one unit high shows the
  bound holding.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review shared-r1 found that no test pinned entry_year_probability near
zero: three mutants (log(1 - p) for log1p(-p), shares below 1e-10 read as
zero, and results zeroed for annual risks below 1e-15) passed all 51 tests.

Three regressions now pin it:

- half of an annual risk of 2**-100 is exactly 2**-101;
- a share of 2**-100 of an annual risk of 0.36 stays within one unit in
  the last place of a 200-digit Decimal oracle;
- a certain exit stays certain at shares of 2**-1074, 2**-100, 0.25 and
  1 - 2**-53.

All 56 conventions tests pass, and each of the three mutants now fails.
The implementation is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
MaxGhenis and others added 3 commits November 29, 2026 08:22
Review shared-r2 approved fe90361 with one minor finding and one nit.

The minor: two more shortcuts in entry_year_probability passed all 56
tests. One returned p * share for p below 1e-8; the other returned p
for p above 1 - 1e-12. Two tests now pin them.

- test_entry_year_probability_tracks_the_formula_across_a_grid checks
  2,478 invented pairs against the 200-digit oracle at eight units of
  rounding: 118 annual risks (2**-1 to 2**-60, 1 - 2**-1 to
  1 - 2**-53, and seven ordinary values) for each of 21 shares
  (2**-100 to one-half, 1 - 2**-2 to 1 - 2**-53, and four ordinary
  values). The host's worst over the grid is two units; eight leaves
  room for another platform's log1p and expm1.
- test_half_share_matches_the_square_root checks shared-r2's pairs,
  (2**-30, 0.5) and (1 - 2**-53, 0.5), against 1 - sqrt(1 - p), a
  second oracle that takes no logarithm.

On the host, the module gives 79 passed. Ten numeric mutants each fail
it: shared-r1's three, shared-r2's two, and five more (shares near one
treated as one, 1 - exp in place of -expm1, the power form, a
first-order hazard for small shares, and a float32 hazard). The
square-root test alone kills shared-r2's two.

The nit: the tiny-risk test's docstring now says its result rounds
exactly to half.

The implementation is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Master changed three of this PR's files since 02897ed: the exclusion
lists in scripts/first_estimates_birth_evidence.py and
tests/estimates/test_birth_evidence_artifact.py, and the two tier files.
Git merged them with no conflict.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Master's files read unit 26,654, artifact 7,141 and total 36,123. This
PR's two test modules, collected by name under each marker at
987c42c, add 79 unit tests (tests/open_population/test_conventions.py,
new) and 1 artifact test
(test_every_open_population_module_is_an_exact_exclusion in
tests/estimates/test_birth_evidence_artifact.py, which has 13 tests on
master and 14 here). The counts become unit 26,733, artifact 7,142 and
total 36,203. Both modules pass on the host at 987c42c: 93 passed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch was successfully deployed

1 active deployment
Preview — e6e96cd4 Deployed Nov 29, 2026 by vercel[bot]
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