Skip to content

Evaluate coalescence rates at the terminal augmented time - #2547

Merged
jeromekelleher merged 2 commits into
tskit-dev:mainfrom
ArtificialZeng:codex/terminal-coalescence-hazard
Oct 27, 2026
Merged

jeromekelleher merged 2 commits into
tskit-dev:mainfrom
ArtificialZeng:codex/terminal-coalescence-hazard

Conversation

@ArtificialZeng

@ArtificialZeng ArtificialZeng commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

A size change at the final augmented trajectory time can leave coalescence_rate_trajectory reporting the preceding epoch's hazard. For one population changing from1000 to10000 at time100, query [0,100] returns r(100)=0.0005 instead of the documented 1/(2*10000)=0.00005; appending101 makes the value at100 correct. Both default doubled-grid validation and validation-off reproduce this without warnings. Survival at100 remains exp(-0.05).

The proposed change evaluates current population sizes and the existing point-movement block at every augmented grid point, and propagates only when another time follows. It also protects the final duplicate-zero case from an added event application. This addresses terminal instantaneous movements under the same ordering already used at interior points. All epoch breaks are appended internally, so the affected point is the last augmented point, which may differ from the last requested point.

Validation on pinned main 45cfa59d828757352f7ab1a55c19b55102d40d22, CPython3.13/macOS arm64:

  • Thirty new neutral regressions: baseline20failed/10passed; candidate30passed. Sixteen relevant existing trajectory cases pass in both. The new cases cover terminal size jumps/clamping, prefix consistency, partial/complete and ordered positive-time lineage movements, singleton/zero-time queries and zero-survival behavior.
  • A separate68-case analytic verifier: baseline42cases mismatch; candidate68pass. Scalar and isolated-population mixture formulas provide the oracle. An independent reviewing context reproduced these and checked an additional exact sequential-movement example.
  • A separately packaged current-source native rebuild reproduced the same paired outcomes. Python and actual native-extension imports are asserted against their selected tree; neutral test collection prevents accidentally substituting candidate code into the baseline.
  • Existing five-term matrix-exponential truncation explains a1.39e-11 mixture-survival discrepancy. Its analytic remainder bound2.08e-11 is retained; the common verifier uses survival atol5e-11 and tight rate checks. The10×scalar rate discrepancy does not depend on that tolerance. The full upstream/CUnit/platform matrix was not run locally.

V2 changes only a new test's bitwise equality to an explicit relative1e-12 comparison; the runtime repair is unchanged. The original frozen evidence remains retained. This remains computational checking rather than external human peer review. The patch retains the existing finite-precision underflow and piecewise-constant growth-propagation conventions. Empty queries naturally change from an internal UnboundLocalError to empty arrays; that was not an established supported-input contract. Earlier duplicate-zero/time-zero behavior is preserved. No ancestry simulation, coalescence-time distribution, mean-TMRCA or affected-publication impact is established by this diagnostic error.

This is an AI-assisted scientific-software contribution. Maintainer review of the intended endpoint contract and repair scope would be appreciated.

Formatting follow-up: commit5642717 applies the requested Ruff line wrap; pinned Ruff0.15.1 checks pass locally and the test AST is unchanged. All13 checks on this exact PR head now pass, including the Tests, Docs and Lint workflows. The synchronized AI-Biology-Lab PR33 head94b4e1f also passes all9 checks and rebuilt native paired evidence. This does not replace specialist review of rate/event semantics.

@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.82%. Comparing base (45cfa59) to head (5642717).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2547      +/-   ##
==========================================
- Coverage   93.82%   93.82%   -0.01%     
==========================================
  Files          20       20              
  Lines       12228    12224       -4     
  Branches     2254     2254              
==========================================
- Hits        11473    11469       -4     
  Misses        574      574              
  Partials      181      181              
Flag Coverage Δ
C 84.14% <ø> (ø)
c-python 72.74% <ø> (ø)
python-tests 98.58% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Python API 98.61% <100.00%> (-0.01%) ⬇️
Python C interface 92.88% <ø> (ø)
C library 91.05% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jeromekelleher

Copy link
Copy Markdown
Member

The changes LGTM, but I'm not an expert on this code. @apragsdale - I think you were involved in writing this, would you mind taking a look please?

@ArtificialZeng - lint is failing FYI

@ArtificialZeng

Copy link
Copy Markdown
Contributor Author

Thank you for checking this and for asking the relevant author to review it. I have applied the requested Ruff line wrap in commit 5642717. Pinned Ruff 0.15.1 formatting and lint checks now pass locally; the test AST and scientific implementation are unchanged.

The synchronized reproduction packet in AI-Biology-Lab PR #33 has also been updated. Its reused native baseline/candidate replay still matches the original 30 regression, 68 analytic-oracle, and 16 existing-case outcomes, with no skips.

The new upstream-head Tests, Docs and Lint runs currently require maintainer approval, so I am not claiming they have passed. I appreciate the further review of the rate/event semantics.

@apragsdale

Copy link
Copy Markdown
Contributor

It looks fine to me as well.

@jeromekelleher
jeromekelleher added this pull request to the merge queue Oct 27, 2026
Merged via the queue into tskit-dev:main with commit 7954a72 Oct 27, 2026
13 checks passed
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.

3 participants