Skip to content

moments_ld: default use_genotypes=True to match moments#126

Merged
andrewkern merged 2 commits into
mainfrom
feature/moments-ld-use-genotypes-default
Jun 25, 2026
Merged

moments_ld: default use_genotypes=True to match moments#126
andrewkern merged 2 commits into
mainfrom
feature/moments-ld-use-genotypes-default

Conversation

@andrewkern

Copy link
Copy Markdown
Member

Fixes #125.

Problem

pg_gpu.moments_ld.compute_ld_statistics bills itself as a drop-in replacement for moments.LD.Parsing.compute_ld_statistics, but the two had opposite defaults for the single most behavior-defining argument:

  • pg_gpu: use_genotypes=False
  • moments: use_genotypes=True

A user following our own docstring advice ("switch by changing only the import") silently changed which estimator was computed -- phased 4-way haplotype counts vs. unphased 9-way genotype counts. The two estimators agree in expectation but give different values on finite data, so the result is a large, unexplained mismatch that looks like a pg_gpu bug. This already cost a downstream user real debugging time.

On a real phased window, leaving each library on its own default produced up to ~119% disagreement (worst in the Dz family); aligning the flag brought them to floating-point agreement (max relative diff 3.3e-11).

Change

  • Flip pg_gpu's default to use_genotypes=True so a bare import swap reproduces moments out of the box.
  • Make the function docstring and the moments-integration tutorial state loudly that this flag selects the estimator, defaults to True to match moments, and must be set identically on both sides of any comparison.
  • The moments parity tests compare pg_gpu against moments' haplotype path, so pin their pg_gpu calls to use_genotypes=False. This keeps the haplotype-path parity valid and independent of the moments version (the moments 1.5.0 genotype path has a separate, unrelated pi2 sign bug fixed upstream in v1.5.3).

Compatibility note

This changes the default behavior for any existing pg_gpu-native caller of the integration layer that relied on the implicit haplotype path. That is the intended, correct-but-breaking part of the fix: the default now matches the function it claims to replace.

Verification

  • pixi run ruff check pg_gpu/ tests/ examples/ -> all checks passed.
  • CUDA_VISIBLE_DEVICES=1 pixi run -e moments pytest tests/test_moments_ld.py -> 25 passed.

pg_gpu.moments_ld.compute_ld_statistics advertises itself as a drop-in
replacement for moments.LD.Parsing.compute_ld_statistics but defaulted
use_genotypes=False while moments defaults True. A bare import swap thus
silently switched estimators (phased 4-way haplotype counts vs unphased
9-way genotype counts), which agree in expectation but differ on finite
data -- producing large, confusing discrepancies that look like a bug.

Flip the default to True so it matches moments out of the box, and make
the docstring and the moments-integration tutorial state loudly that the
flag selects the estimator and must be set identically on both sides of
any comparison.

The moments parity tests compare pg_gpu against moments' haplotype path,
so pin their pg_gpu calls to use_genotypes=False to keep that comparison
valid and independent of the moments version.
The lint job set `pixi-version: latest` in setup-pixi. A pixi release
published after the last green main run panics during `pixi install`
while solving the unrelated `moments` environment's pypi source build
on Python 3.14 ("could not initialize build dispatch correctly"),
failing the job before ruff ever runs.

Pin to v0.66.0, which resolves all environments cleanly (verified
locally, including `pixi run -e moments`). This unfloats the lint job
from broken upstream pixi releases.
@andrewkern andrewkern merged commit 820c7da into main Jun 25, 2026
1 check passed
@andrewkern andrewkern deleted the feature/moments-ld-use-genotypes-default branch June 25, 2026 21:45
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.

moments_ld.compute_ld_statistics defaults use_genotypes=False, opposite of moments (silent estimator mismatch)

1 participant