Skip to content

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

Closed

Description

@Jammy2211

Overview

After #868 (hmf → colossus), LOSSampler and mass_function_ab_from accept cosmology_astropy but ignore it, emitting only a DeprecationWarning that Python hides from non-__main__ callers. A caller passing e.g. WMAP9 with the default cosmology_name_colossus="planck15" silently gets the Planck15 mass function (~2% in halo counts). LOSSampler(cosmology=...) is likewise never checked against the colossus cosmology name.

Plan

  • Add a helper that compares a supplied cosmology (astropy or autogalaxy LensingCosmology) with the colossus cosmology by H0 and Om0, and raises a ValueError naming both when they disagree.
  • mass_function_ab_from(cosmology_astropy=...) runs the check (the argument is still deprecated, but no longer silently ignored).
  • LOSSampler runs the same check on cosmology and cosmology_astropy against cosmology_name_colossus, at sampling time and only when colossus is actually used (precomputed coefficients still need no colossus).
  • Matching pairs (e.g. Planck15 / planck15, WMAP9 / WMAP9) work unchanged.
  • Witness tests (skip without colossus).
  • effective level: supervised; merge mode: auto-merge on green if the Witness passes after a merge slot
Detailed plan

Work Classification: Library (PyAutoLens only)
Branch: feature/lossampler-cosmology-mismatch
Worktree root: ~/Code/PyAutoLabs-wt/lossampler-cosmology-mismatch/

  1. autolens/lens/los.py: new _check_cosmology_matches_colossus(cosmology, col_cosmo, cosmology_name, argument); H0 read via getattr(H0, "value", H0) (astropy Quantity); tolerances rel 1e-3 on H0, 1e-2 on Om0 (colossus Om0 includes massive neutrinos: Planck15 astropy 0.3075 vs colossus 0.3089, 0.45%). WMAP9 vs planck15 differs 2.3% in H0 and 7% in Om0.
  2. mass_function_ab_from: after setting the colossus cosmology, check cosmology_astropy if given. Deprecation warning text updated ("checked, not used").
  3. LOSSampler._sample_population: when either coefficient array is None, set the colossus cosmology and check self.cosmology and self.cosmology_astropy.
  4. Tests in test_autolens/lens/test_los.py: WMAP9+planck15 raises naming both (function + sampler, via cosmology_astropy and via cosmology=FlatLambdaCDM(H0=69.32, Om0=0.2865)); matching pairs pass; existing deprecation test passes a real Planck15.

Activity

  1. Jammy2211 commented on Nov 20, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped

    Merged 2026-11-20 via the human's /prm (shift 2026-11-19-pm2): #874

    mass_function_ab_from(cosmology_astropy=...) and LOSSampler(cosmology=..., cosmology_astropy=...) now raise a ValueError naming both cosmologies when the supplied astropy cosmology disagrees with the colossus name (H0 rtol 1e-3, Om0 rtol 1e-2, Ok0 atol 1e-3). Matching pairs and precomputed coefficients are unchanged.

    Witness: on main, WMAP9 + default planck15 silently returned the Planck15 fit (B = 8.116); now it raises, with a hint to pass cosmology_name='WMAP9'. test_los.py 12 passed; targeted smoke import check PASS; independent Opus 5.5 review FINDINGS(2) fixed, then CLEAN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions