Skip to content

census node per lineage, not segment: closes #2540 - #2541

Open
petrelharp wants to merge 2 commits into
tskit-dev:mainfrom
petrelharp:census_fix
Open

census node per lineage, not segment: closes #2540#2541
petrelharp wants to merge 2 commits into
tskit-dev:mainfrom
petrelharp:census_fix

Conversation

@petrelharp

Copy link
Copy Markdown
Contributor

I think this was a conceptual error: all segments in a given lineage at a given time point in the simulation are in the same genome (=node=haplosome), and hence in doing a census event we should assign a single node to each lineage, not each segment.

If we agree, this needs an update to the CHANGELOG (and maybe another test? I'm not sure if we've a good way to test this).

Also note the test that triggers #2540 (but this - I think - fixes).

@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.81%. Comparing base (4d661d1) to head (461260f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2541   +/-   ##
=======================================
  Coverage   93.81%   93.81%           
=======================================
  Files          20       20           
  Lines       12216    12216           
  Branches     2250     2250           
=======================================
  Hits        11461    11461           
  Misses        574      574           
  Partials      181      181           
Flag Coverage Δ
C 84.13% <50.00%> (ø)
c-python 72.80% <0.00%> (ø)
python-tests 98.58% <ø> (ø)

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

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

@petrelharp

petrelharp commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

Verification that (after fixing it) the new test catches the bug without this fix:

$ git checkout main lib/msprime.c
$ make
$ uv run pytest tests/test_demography.py::TestCensusEvent::test_census_at_end_time
=========================================================================================== test session starts ===========================================================================================
platform linux -- Python 3.13.12, pytest-9.1.1, pluggy-1.6.0
rootdir: /home/peter/projects/tskit-dev/msprime
configfile: pyproject.toml
plugins: xdist-3.8.0, cov-7.1.0
4 workers [1 item]      
Fatal Python error: Aborted

@petrelharp

Copy link
Copy Markdown
Contributor Author

What does this affect? So I think it definitely is a bug, in that we're calling things different nodes that aren't really; but this only affects census nodes: it's not going to change anything about the subsequent simulation. So, it's a pretty minor bug. It'd only affect people who wanted to see how many distinct ancestors there were at a given time using a census event

I got curious: how big of an effect is this? Here's a jupyter notebook:
census_edges.ipynb
(run with uv run --with plotnine --with jupyterlab jupyter lab),
and in this simulation of 100 samples from rho=0.01 there's a lot of census nodes that have more than one segment (like, a third of them): here is all the edges below census nodes (of which there are 154), and the color is how many distinct segments a given parent census node has (55 have > 1):
Screenshot From 2026-08-29 08-44-09

@petrelharp

Copy link
Copy Markdown
Contributor Author

(Note: one might naively hope that adding census nodes literally does not change the output of the simulation, seed-by-seed, except for the census nodes, but this turns out not to be true; I'm not actually sure why.)

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