Skip to content

Fix HEALPix spin!=0 inverse/forward inaccuracy from Wigner-d node#387

Open
slosar wants to merge 1 commit into
astro-informatics:mainfrom
slosar:fix/healpix-spin-recursion-node
Open

Fix HEALPix spin!=0 inverse/forward inaccuracy from Wigner-d node#387
slosar wants to merge 1 commit into
astro-informatics:mainfrom
slosar:fix/healpix-spin-recursion-node

Conversation

@slosar

@slosar slosar commented Jun 14, 2026

Copy link
Copy Markdown

Note: this bug was uncovered and fixed by agentic AI tools, but it is a real non-trivial bug whose fix should be merged. We need sasfe_abs for avoit hitting nans for auto-diff. There is a test added that fails in the current main version, but passes here, so it would be good to keep it. Below is the machine generated description:

The on-the-fly Price-McEwen Wigner-d recursion renormalises each step by bigi = 1/|dl_entry| and tracks lbig = log|dl_entry|. When an intermediate recursion value dl_entry is exactly zero (a node), bigi becomes inf and lbig becomes -inf, so dl_iter = inf*0 = NaN and the running log-norm goes to -inf. These NaNs are silently dropped by the nansum that accumulates ftm/flm, discarding that mode's contribution and producing percent-level errors.

Exact-zero nodes are essentially never hit by the generic theta samples of mw/mwss/dh/gl sampling, but HEALPix rings sit at rational cos(theta) values that land exactly on nodes for spin != 0, so spin-2 HEALPix transforms carried few-percent pointwise errors (spin-0 was unaffected and existing HEALPix tests only covered spin 0).

Guard the renormalisation so that where dl_entry == 0 we use bigi = 1 and lbig = 0, leaving lrenorm unchanged and setting the normalised value to 0, which is exactly consistent with the recursion bookkeeping. Applied to all four recursion paths (numpy/jax inverse and forward).

Adds a regression test comparing the recursive HEALPix spin-1/2 inverse against the independent Turok-recursion base transform.

The on-the-fly Price-McEwen Wigner-d recursion renormalises each step by
bigi = 1/|dl_entry| and tracks lbig = log|dl_entry|. When an intermediate
recursion value dl_entry is exactly zero (a node), bigi becomes inf and
lbig becomes -inf, so dl_iter = inf*0 = NaN and the running log-norm goes
to -inf. These NaNs are silently dropped by the nansum that accumulates
ftm/flm, discarding that mode's contribution and producing percent-level
errors.

Exact-zero nodes are essentially never hit by the generic theta samples of
mw/mwss/dh/gl sampling, but HEALPix rings sit at rational cos(theta) values
that land exactly on nodes for spin != 0, so spin-2 HEALPix transforms
carried few-percent pointwise errors (spin-0 was unaffected and existing
HEALPix tests only covered spin 0).

Guard the renormalisation so that where dl_entry == 0 we use bigi = 1 and
lbig = 0, leaving lrenorm unchanged and setting the normalised value to 0,
which is exactly consistent with the recursion bookkeeping. Applied to all
four recursion paths (numpy/jax inverse and forward).

Adds a regression test comparing the recursive HEALPix spin-1/2 inverse
against the independent Turok-recursion base transform.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.11%. Comparing base (4ef1ee5) to head (cefdf46).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #387      +/-   ##
==========================================
+ Coverage   96.10%   96.11%   +0.01%     
==========================================
  Files          34       34              
  Lines        3539     3551      +12     
==========================================
+ Hits         3401     3413      +12     
  Misses        138      138              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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