Skip to content

fix: LOSSampler mass function from colossus, drop hmf - #868

Merged
Jammy2211 merged 2 commits into
mainfrom
feature/los-sampler-colossus-mass-function
Nov 19, 2026
Merged

Jammy2211 merged 2 commits into
mainfrom
feature/los-sampler-colossus-mass-function

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Closes #867

What

LOSSampler with no precomputed coefficients raised ModuleNotFoundError: No module named 'hmf'. hmf was never a declared dependency, and hmf.fitting_functions moved in hmf 3.7. The Sheth-Tormen mass function is now computed with colossus (massFunction, model='sheth99'). The sampler already used colossus for the Ludlow+16 concentration relation.

  • mass_function_ab_from fits colossus sheth99 on the same mass grid as before. It gains a cosmology_name argument (default "planck15").
  • cosmology_astropy is still accepted in mass_function_ab_from and LOSSampler, but it is ignored and raises a DeprecationWarning. Existing calls keep working.
  • If colossus is missing, the coefficient fits raise an ImportError that names colossus and gives the install command.
  • pyproject.toml has a new los = ["colossus"] extra. It is included in optional, which CI installs, so the new tests run in CI rather than being skipped.

Workspace PR (merge after this one): see the linked autolens_workspace PR.

Evidence

Witness (no hmf installed, colossus installed; LOSSampler(z_lens=0.5, z_source=1.0, seed=1), no coefficients passed, test mode off):

hmf installed: False
slopes: -1.9054 -1.9057 -1.9061 -1.9065 -1.9070 -1.9076 -1.9082 -1.9089 -1.9097 | max |A+1.906| = 0.0037
expected halos 1e7-1e10 in 5": 1293.7 (ref 1282, ratio 1.0091)

The new unit test test__los_sampler__default_coefficients_match_sheth_tormen_reference asserts the same limits.

  • Tests: pytest -n 4 test_autolens/lens/test_los.py gives 9 passed. Three tests are new: the Witness, the clear message when colossus is missing, and the cosmology_astropy deprecation warning.
  • Targeted smoke: no curated smoke script references the change, so pyauto-heart smoke --targeted ran the import check autolens_workspace/scripts/imaging/modeling.py: PASS.
  • Review (leg 3): an independent reviewer returned CLEAN. It cross-checked the colossus units three ways: against colossus M2dndM (ratio 1.000), against a hand-built Sheth-Tormen calculation from colossus sigma(R) (ratio 0.99999997), and against the formula of the old hmf SMT model.

API change

This is a backward-compatible signature change: one keyword added, one keyword deprecated. No public name is added or removed. No other library depends on autolens.lens.los.

Follow-ups (not in this PR)

  • autolens_workspace_developer/los/simulator.py has the same silent placeholder fallback. That repo was not claimed for this task.
  • Heart's heart/config/colab_gate.yaml has an hmf entry for los.py. It is stale now that los.py no longer imports hmf.

🤖 Generated with Claude Code

Jammy2211 and others added 2 commits November 19, 2026 19:01
mass_function_ab_from imported `hmf.fitting_functions`, which moved in hmf
3.7, and hmf was never a declared dependency, so LOSSampler with no
precomputed coefficients raised ModuleNotFoundError. The Sheth-Tormen mass
function is now computed with colossus (model='sheth99'), which the sampler
already used for the Ludlow+16 concentration relation.

- colossus becomes the `los` optional extra (in `optional`, which CI installs)
- a missing colossus raises an ImportError naming it and how to install it
- `cosmology_astropy` is deprecated and ignored, with a DeprecationWarning

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 mass function from colossus, drop hmf and silent los_halos fallback

1 participant