Skip to content

fix: LOSSampler raises on a cosmology that mismatches the colossus name - #874

Merged
Jammy2211 merged 2 commits into
mainfrom
feature/lossampler-cosmology-mismatch
Nov 20, 2026
Merged

Jammy2211 merged 2 commits into
mainfrom
feature/lossampler-cosmology-mismatch

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Closes #873

What

After #868 (hmf → colossus), mass_function_ab_from(cosmology_astropy=...) and LOSSampler(cosmology_astropy=..., cosmology=...) ignored a cosmology that disagrees with the colossus cosmology name. The only signal was a DeprecationWarning, which Python hides from library callers. So a WMAP9 caller with the default "planck15" silently got the Planck15 halo mass function (intercept 8.116 vs 8.108, about 2% in halo counts).

The fix is a check, not a mapping. Both arguments are now compared with the colossus cosmology on H0 (rtol 1e-3), Om0 (rtol 1e-2) and curvature Ok0 (atol 1e-3). On a mismatch it raises a ValueError that names both cosmologies and the argument that fixes it. Om0 is looser because colossus counts massive neutrinos in Om0: astropy Planck15 has 0.3075 and colossus planck15 has 0.3089, a 0.45% gap. WMAP9 differs from planck15 by 2.3% in H0 and 7% in Om0.

  • LOSSampler runs the check only when it computes halo statistics with colossus. If both coefficient arrays are precomputed, it needs no colossus and runs no check. The workspace los_halos simulators work this way, so they are unaffected.
  • Matching pairs work unchanged: Planck15 with planck15, WMAP9 with WMAP9, and the default LOSSampler().
  • cosmology_astropy stays deprecated and still warns.

Decision (in the plan, issue #873): the prompt left open whether to map the astropy cosmology to colossus or to raise; the Witness accepts either. I chose to raise. Colossus fromAstropy needs sigma8 and ns, which an astropy cosmology does not carry, so a mapping would have to invent them.

Overlap with sibling PRs

#870 and #872 change substructure_util.py. This PR only changes los.py and test_los.py, so the lines do not overlap.

Tests

  • test_autolens/lens/test_los.py: 12 passed (-n 4). New tests:
    • test__mass_function_ab_from__mismatched_cosmology_astropy_raises: WMAP9 with the default raises, naming both cosmologies and the cosmology_name hint; a curved LambdaCDM raises on Ok0; WMAP9 with WMAP9 works (B = 8.108).
    • test__los_sampler__mismatched_cosmology_raises: cosmology=FlatLambdaCDM(WMAP9 values) raises, and so does cosmology_astropy=WMAP9. Precomputed coefficients still work.
    • test__los_sampler__matching_cosmology_pair_is_accepted.
  • The existing deprecation test now passes a real astropy Planck15 instead of object().

Smoke

Targeted smoke (pyauto-heart smoke --targeted): no curated script references the change, so it ran the import check autolens_workspace/scripts/guides/galaxies.py, which passed.

Review

The first independent review (leg 3) returned FINDINGS:

  1. The hint named the wrong argument for mass_function_ab_from.
  2. A non-flat cosmology passed the check on H0 and Om0 alone.

Both are fixed in ebe5a62. The re-review verdict is CLEAN; its only nit is that match="Ok0" is a loose regex, though the test is still sound because H0 and Om0 match exactly in that case.

🤖 Generated with Claude Code

Jammy2211 and others added 2 commits November 19, 2026 21:37
cosmology_astropy (deprecated) and LOSSampler(cosmology=...) were silently
ignored by the colossus halo mass function and concentration relation, so a
WMAP9 caller with the default planck15 colossus name got the Planck15 halo
statistics. Both are now checked (H0, Om0) against the colossus cosmology and
a mismatch raises a ValueError naming both.

Closes #873

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ture (Ok0)

Review findings: mass_function_ab_from's hint now names cosmology_name (not
cosmology_name_colossus), and a non-flat cosmology no longer passes the check
on H0/Om0 alone (LambdaCDM Ode0=0.5 vs planck15 raises, tested).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jammy2211
Jammy2211 merged commit 1aec850 into main Nov 20, 2026
5 checks passed
@Jammy2211
Jammy2211 deleted the feature/lossampler-cosmology-mismatch branch November 20, 2026 08:25
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.

fix: LOSSampler raises on a cosmology that mismatches the colossus name

1 participant