Skip to content

Add live-roster fertility with persistent parity (OP2(b)) - #613

Draft
MaxGhenis wants to merge 5 commits into
masterfrom
openpop-op2b-fertility-20261106
Draft

MaxGhenis wants to merge 5 commits into
masterfrom
openpop-op2b-fertility-20261106

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

WIP. OP2(b) of docs/design/open_population.md: live-roster fertility with persistent parity. It's stacked on #599, whose commits show in this diff until that PR lands. Four files belong to this part: live_fertility.py, test_live_fertility.py and one seal-list line in each of two files.

What it adds

open_population/live_fertility.py holds three pieces:

  • LiveRosterFertility applies maternal fertility to the live roster each year.
    • It draws one tagged uniform per woman at risk, from LIVE_FERTILITY_STREAM_TAG at her ordinal.
    • It reads her parity from the roster, counts a birth when the uniform falls strictly below her probability, and carries the count forward uncapped. The probability band caps at 3, as the sealed helper does (models/family_transitions/components/fertility.py:190).
    • It hands the year's births to an injected materializer exactly once.
    • The lookup and event schema follow the maternal kernel (engine/marital.py:349–400). Unlike that kernel, which starts parity at zero on each call (engine/marital.py:363), the step reads a woman's parity from the roster.
  • ParitySeed labels a caller-supplied parity mapping with one of two named methods and a ConventionSource. It seeds nullable integer parity and leaves anyone it omits missing, so it never asserts a childless arrival (engine/entrant_domains.py:50–55).
  • BirthDecadeRule declares how cohorts outside the fit are treated: refuse, continue_from a decade in the fit, or zero_outside_fit.

Four refusals are new and live in the module: ParitySeedMissing, BirthDecadeRuleInvalid, FertilityInputInvalid and FertilityDrawInvalid. Where §8 names the condition, the step uses IdOrStreamCollision or ExtrapolationUndeclared from errors.py.

A GPT-6.1 Sol lane wrote the module and its 111 tests on invented data. I read the module against the sealed code it cites.

No real value enters. The PR carries no seed, fit or convention choice. ParitySeed.require_frozen and LiveRosterFertility.require_frozen refuse any source short of frozen. Newborn girls stay outside the fertility risk set through OP2(a)'s marker until a later milestone admits them.

Readings to check

  • A woman with no fertility marker needs a known birth year, even when her age would put her outside the fertile range. Without the year, the step can't establish her age, and the roster's age column doesn't decide risk. Marked women and men skip the check.
  • continue_from covers only cohorts after the fit. An earlier cohort outside the fit still refuses under ExtrapolationUndeclared.
  • zero_outside_fit still draws a uniform for women in those cohorts and never gives them a birth. The kernel does the same: it draws for every eligible woman (engine/marital.py:385) and gives a cohort missing from the fit probability zero (models/family_transitions/components/fertility.py:191–193).
  • A missing marker value doesn't exclude. Only True excludes a woman, and a roster without the column admits every eligible incumbent.

Invariants

Design §7's fertility rows, each with a property-based test alongside the examples:

  1. Each live year matches one maternal-kernel invocation, row for row, in all five event columns, their dtypes, their order and the draws they use, cohorts absent from the fit included.
  2. Each mother's parity starts at her seed, rises by exactly one per birth, never falls or resets, and ends at her seed plus her births in the ledger. Counts above three keep rising while the probability uses band three.
  3. Identical seeds replay exactly. Permuted rosters, shorter prefixes, and direct and registry stream classes give identical output.
  4. Removing a woman through mortality leaves every other woman's draw unchanged, since draws key on ordinals.
  5. Under coupled draws, raising probabilities can't remove a birth.
  6. A woman outside the domain draws nothing, gives no birth and keeps her parity, and a year with no woman at risk calls the materializer once with a typed empty birth table.

Through run_gate. The birth adapter accepts the additions, count and weight accounting reconciles every year, and a run with no woman at risk matches the closed run slice by slice.

Evidence

On the host, one process, at this commit's tree:

  • tests/open_population/test_live_fertility.py and test_conventions.py: 167 passed in 34.55 s, 111 of them in test_live_fertility.py.
  • Black (-l 79) and Ruff come back clean.
  • tests/estimates/test_birth_evidence_artifact.py: 14 passed in 36.14 s, so the seal holds with live_fertility.py in both exclusion lists.

The builder's 50 mutants each ran under a 1.5 GiB cap with Hypothesis's explain phase off, after an unmutated control that passed (111 passed). All 50 fail a test, and none broke the run. The source file was restored after each, and the clone is clean at this commit.

Plan

Follow-up for the next design commit

The builder found a stale citation in sealed code. engine/entrant_domains.py:51–52 attributes zero-parity initialization to steps.py:451–506, which materializes children. The zero start is engine/marital.py:363. The sealed file stays as it is; the design can cite the right line.

🤖 Generated with Claude Code

MaxGhenis and others added 5 commits November 6, 2026 06:11
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]>
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]>
open_population/live_fertility.py applies maternal fertility to the
live roster. LiveRosterFertility draws one tagged uniform per woman at
risk, reads her parity from the roster and carries it forward uncapped,
and hands the year's births to an injected materializer once. The
probability lookup and event schema follow engine/marital.py:349-400.

ParitySeed labels a caller-supplied parity mapping with one of two named
methods and a ConventionSource, and leaves omitted people missing.
BirthDecadeRule declares how cohorts outside the fit are treated:
refuse, continue from a fit decade, or zero outside the fit. Both keep
their sources in draft until require_frozen passes. No seed, fit or
convention value enters.

A GPT-6.1 Sol lane wrote the module and its 111 tests on invented
data. Both seal lists exclude the module after errors.py.

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

vercel Bot commented Nov 29, 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 12:48pm UTC

Request Review

This branch was successfully deployed

1 active deployment
Preview — 50d02ecc 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