Repository navigation
Description
Overview
LOSSampler with no precomputed coefficients raises ModuleNotFoundError in the declared environment: mass_function_ab_from imports hmf (undeclared) and hmf.fitting_functions (moved in hmf 3.7). The workspace los_halos simulators catch the ImportError and silently fall back to placeholder coefficients that under-count halos by up to 20% at z = 0.9. This fix computes the Sheth-Tormen mass function from colossus (already used for the concentration relation), declares colossus as an optional dependency, and removes the silent fallback from the workspace.
Plan
- Rewrite
mass_function_ab_fromto fit colossusmassFunction(model='sheth99'), dropping hmf entirely. - Give both coefficient functions one clear
ImportErrornaming colossus and how to install it. - Keep the old
cosmology_astropyargument accepted but ignored, with aDeprecationWarning, so existing calls do not break. - Declare a
los = ["colossus"]extra in PyAutoLens and add it tooptional(which CI installs). - Add unit tests: the Witness (slope and expected count) and the clear-message path when colossus is missing.
- Workspace: drop the
try/except ImportErrorplaceholder block fromsimulator.pyandsimulator_jax.py; letLOSSamplercompute the coefficients, so a missing colossus stops with the library's message. - Tier line:
effective level: supervised; merge mode: auto-merge on green if the Witness passes after a merge slot
Detailed implementation plan
Affected Repositories
- PyAutoLens (primary)
- autolens_workspace
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| lens/PyAutoLens | main (== origin/main a79a6b2) | clean |
| lens/autolens_workspace | main (origin/main 4674ae89) | workspace_index.json only |
Suggested branch: feature/los-sampler-colossus-mass-function
Worktree root: ~/Code/PyAutoLabs-wt/lossampler_hmf_import_fails_and_los_halos/
Work classification: Both (library first)
Implementation Steps
autolens/lens/los.py- New private
_import_colossus()that raisesImportError("... requires the optional dependency colossus: pip install colossus (or autolens[los]) ...")from the original error. mass_function_ab_from(redshift, cosmology_astropy=None, m_min_log10=5.9, m_max_log10=10.1, dlog10m=0.1, cosmology_name="planck15"): evaluatemassFunction(m*h, z, mdef="fof", model="sheth99", q_out="dndlnM"), convert to dn/dm in Mpc^-3 Msun^-1 (dndlnM * h^3 / m), least-squares fitlog10(dn/dm) = A log10(m) + Bon the same mass grid as before.cosmology_astropynot None →DeprecationWarning, ignored.mass_concentration_ab_fromuses_import_colossus().LOSSampler: passcosmology_name_colossusto the mass-function fit;cosmology_astropydeprecated (warn if given); docstrings updated.
- New private
pyproject.toml:los = ["colossus"];optionalgains"autolens[los]".test_autolens/lens/test_los.py:importorskip("colossus")Witness test (per-plane slope within 0.02 of -1.906; summednumber_of_halos_fromwithin 5% of 1282 for z_lens 0.5, z_source 1.0, 1e7–1e10, 5"), plus a missing-colossus test (sys.modules["colossus"] = Nonevia monkeypatch) asserting the message.- Workspace
scripts/imaging/features/advanced/los_halos/simulator.pyandsimulator_jax.py: remove the try/except block and the hmf/astropy text; do not pass coefficients; text explains colossus is required (Sheth-Tormen + Ludlow16). Notebooks are regenerated at release, not edited.
Measured prototype (colossus sheth99, Planck15): A = -1.9054 (z=0.1) to -1.9097 (z=0.9); expected total 1293.7 halos vs 1281.7 with the hmf SMT fit (+0.9%). Fit takes ~0.01 s for 9 planes.
Key Files
autolens/lens/los.py,pyproject.toml,test_autolens/lens/test_los.pyautolens_workspace/scripts/imaging/features/advanced/los_halos/simulator.py,simulator_jax.py
Original Prompt
Click to expand starting prompt
LOSSampler hmf import fails and los_halos falls back silently
Type: bug
Target: PyAutoLens
Repos:
- PyAutoLens
- autolens_workspace
Difficulty: medium
Autonomy: supervised
Priority: medium
Status: formalised
Consequence: glance
Witness: In an environment with the declared dependencies only,LOSSampler(z_lens=0.5, z_source=1.0)with no precomputed coefficients samples a population whose per-plane mass-function slope is within 0.02 of -1.906 and whose expected halo count for 1e7 to 1e10 solar masses in a 5 arcsecond cone is within 5% of 1282; and the workspacelos_halossimulators either use those real coefficients or stop with a clear message, never a silent placeholder.
Review-minutes: 3
Unattended: ready
Lane: any
Finding
Three linked problems, measured on PyAutoLens main a79a6b2, 2026-11-19.
@PyAutoLens/autolens/lens/los.pymass_function_ab_fromdoesimport hmf.fitting_functions.
With hmf 3.7.2 this raisesModuleNotFoundError; the module now lives at
hmf.mass_function.fitting_functions.hmfis not a declared dependency of any library, and is not installed in the science
environment.LOSSamplerwith no precomputed coefficients therefore raises.@autolens_workspace/scripts/imaging/features/advanced/los_halos/simulator.pyand
simulator_jax.pywrap the coefficient calculation inexcept ImportErrorand fall back to
[-1.9, 8.0]for the mass function and[-3.0, 40.0]for the concentration relation. Because
problem 1 is anImportError, this fallback runs even when hmf is installed.
The placeholders are not close. Real fitted coefficients run from A = -1.905, B = 8.053 at z = 0.1 to
A = -1.910, B = 8.171 at z = 0.9. The fallback ignores redshift evolution and under-counts halos by
up to 20 to 23% at z = 0.9. The concentration fallback is off by up to 17%, 32% and 56% at
z = 0.1, 0.5 and 0.9.
Why it matters
Every run of the workspace line-of-sight examples in the current environment simulates a halo
population that is not the Sheth-Tormen plus Ludlow16 population the text describes, with no
message saying so.
Ask
Preferred: drop hmf and compute the mass function from colossus
(colossus.lss.mass_function.massFunction, model='sheth99'), which the sampler already uses for
the concentration relation. Measured agreement of the existing power-law fit with colossus
sheth99: integrated number 0.98 to 1.00, integrated mass 0.992. Then declare colossus as an
optional dependency of PyAutoLens for the line-of-sight feature.
Minimal alternative: fix the import path and declare hmf as an optional dependency.
In both cases, change the workspace simulators so a missing dependency stops with a clear message
or prints a loud warning; do not keep a silent placeholder. Library fix first, workspace second.
Provenance
[from: research dm-sightlines-cdm] Checks 3 and 4 of the verification run. Scripts and logs:
Science/scratch/dm_sightlines_research_2026-11-19/evidence/verify/check3_massfunction.py,
check3_import.log, check4_concentration.py.
Activity
Jammy2211 commentedon Nov 19, 2026
Shipped
Merged in #868 and PyAutoLabs/autolens_workspace#681 (2026-11-19, /prm, merged unchanged).
LOSSamplernow fits the Sheth-Tormen mass function from colossus (newautolens[los]extra); a missing colossus raises a named ImportError and thelos_halossimulators no longer fall back silently. Witness PASS with no hmf (slopes within 0.0037 of -1.906, expected count +0.9% vs the old hmf fit). Independent adversary (Fable 5.2): CLEAN. Human ruling: fine for los_halos to stop in Colab. Follow-ups already filed: Heart colab gate rationale, non-Planck cosmology ignored.Not yet released (pending-release). Record: PyAutoMind complete/2026/11/lossampler-hmf-import-fails-and-los-halos.md