Repository navigation
Description
Overview
Step 4 of the weak-lensing series (PyAutoMind/z_features/weak_shear.md): add al.AnalysisWeak so a non-linear search can fit lens mass models to a WeakDataset shear catalogue, mirroring the established model API of imaging/point, plus a workspace scripts/weak/modeling.py tutorial. This is the keystone of the weak-lensing home-straight push — series steps 5 (likelihood_function), 7 (Abell 2744 real data) and 8 (combined strong+weak via summed analyses) all depend on it.
Science scope: cluster/group-scale weak shear complementing strong lensing (Niemiec et al. 2020 hybrid-Lenstool; Oguri et al. 2012 SGAS) — not cosmic shear or galaxy-galaxy lensing.
Plan
- Add
autolens/weak/model/mirroringautolens/point/model/(the right template —FitWeakalready followsFitPoint's standalone pattern):AnalysisWeak,ResultWeak,VisualizerWeak,PlotterWeak. AnalysisWeak.log_likelihood_functionbuilds aTracerfrom the model instance and returnsFitWeak(dataset, tracer).log_likelihood.- Wire on-the-fly visualization through the existing nine weak plotters (
subplot_weak_dataset,subplot_fit_weak,subplot_fit_quick), with newweak_dataset/fit_weaksections in the packagedconfig/visualize/plots.yaml. - Export
al.AnalysisWeakinautolens/__init__.py; NumPy-only unit tests mirroringtest_autolens/point/model/. - Ship library PR first; workspace follow-up adds
scripts/weak/modeling.py(judgment-tier tutorial prose, style ofscripts/imaging/modeling.py) and mirrors the new plots.yaml keys into workspace config.
Detailed implementation plan
Affected Repositories
- PyAutoLens (primary — library)
- autolens_workspace (follow-up — workspace tutorial + config mirror)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoLens | main | clean |
| ./autolens_workspace | main | dirty (7 pre-existing regenerated dataset files + stray dataset.fits, unrelated to this task) |
Suggested branch: feature/weak-modeling
Worktree: ~/Code/PyAutoLabs-wt/weak-modeling/
Note: autolens_workspace is currently claimed by task lenstool-example. Library work proceeds first (combined workflow); the workspace follow-up uses the parallel-worktree pattern proven twice in this series (scripts/weak/ has zero file overlap with lenstool work) if the claim still stands at ship time.
Implementation Steps
autolens/weak/model/__init__.py— empty, matchingpoint/model.autolens/weak/model/analysis.py—class AnalysisWeak(AgAnalysis, AnalysisLens):Visualizer = VisualizerWeak,Result = ResultWeakclass attributes.__init__(self, dataset: WeakDataset, cosmology=None, title_prefix=None, use_jax=False, **kwargs).use_jax=Falsedefault:FitWeakis NumPy (cached_property+np.asarray, noxpthreading); JAX support is deliberate future work (needs pytree registration likeAnalysisPoint._register_fit_point_pytrees) — do NOT bolt it on here.log_likelihood_function(instance)→self.fit_from(instance).log_likelihood.fit_from(instance)→tracer_via_instance_from(instance)→FitWeak(dataset=self.dataset, tracer=tracer).save_attributes(paths)→ag.output_to_json(self.dataset, paths._files_path / "dataset.json")(round-trip works since theweak-dataset-from-jsonfix).
autolens/weak/model/result.py—ResultWeak(Result)mirroringResultPoint(13 lines): fallback uniformgridproperty +max_log_likelihood_fitviaanalysis.fit_from(self.instance).autolens/weak/model/plotter.py—PlotterWeak(Plotter)mirroringPlotterPoint:dataset_weak()→subplot_weak_datasetbehindplot_setting(section=["weak_dataset"], ...);fit_weak(fit, quick_update=False)→subplot_fit_weak/subplot_fit_quickbehindplot_setting(section=["fit_weak"], ...).autolens/weak/model/visualizer.py—VisualizerWeak(af.Visualizer)mirroringVisualizerPoint(107 lines):visualize_before_fitplots the dataset;visualizeplots the fit from the instance, forwardingquick_update.- Config: add to
autolens/config/visualize/plots.yaml(after thepoint_dataset/fit_point_datasetblock, same comment style):weak_dataset:withsubplot_dataset: truefit_weak:withsubplot_fit: true
- Exports:
autolens/__init__.py—from .weak.model.analysis import AnalysisWeak(alongside the existing weak exports at lines 128-130). - Tests (NumPy-only, no JAX per repo rules):
test_autolens/weak/test_analysis.py(+ plotter test if cheap) mirroringtest_autolens/point/model/test_analysis_point.py:log_likelihood_function(instance)==FitWeak(dataset, tracer).log_likelihoodfor aSimulatorShearYX(seed=1)dataset and Isothermal instance.- noise-free round-trip: simulator tracer fitted to its own noise-free output gives chi_squared == 0 (bit-exact, both use
shear_yx_2d_via_hessian_from). save_attributeswrites a loadabledataset.json(al.from_jsonround-trip).- Use direct module imports in tests (the
al.plot.Xpytest recursion gotcha from step 2 applies).
- Run full
python -m pytest test_autolens/before PR.
Workspace follow-up (second PR, after library merges)
autolens_workspace/scripts/weak/modeling.py— Nautilus fit of an Isothermal lens to thedataset/weak/simpledataset, prose in the style ofscripts/imaging/modeling.py(judgment-tier tutorial prose per WORKFLOW.md).- Mirror the new
weak_dataset/fit_weakplots.yaml sections intoautolens_workspace/config/visualize/plots.yaml(workspace configs override packaged defaults).
Key Files
autolens/point/model/{analysis,result,plotter,visualizer}.py— the template (233/13/97/107 lines).autolens/weak/fit.py—FitWeak, already exposeslog_likelihood.autolens/weak/plot/{weak_dataset_plots,fit_weak_plots}.py— the nine existing plot helpers +subplot_fit_quick.autolens/config/visualize/plots.yaml— visualization settings read byplot_setting.
Autonomy
--auto launch 2026-07-09, effective level supervised (header supervised, feature cap supervised): plan-to-issue (this issue), mechanical stretches proceed, ship sign-off parks as a batched question here, merge stays human. No Heart YELLOW acknowledgement was given at launch. Brain Feature Agent scored this too-large and suggested a 4-phase split; consolidated to the series' proven 2-PR shape (library, then workspace) — recorded here for post-hoc review.
Original Prompt
Click to expand starting prompt
We are now going to add weak lensing modeling.
First, we need to create the analysis.py module, so inspect @autolens_workspace/scripts/weak and
@PyAutoLens/autolens/imaging/model . We are basically going to make everything weak does from here a "mirror" of
the imaging model API (and also interferoter.)
The log_likelihod_function is in particular important, we already have the codw which creates the shear field
show in the @autolens_workspace/scripts/weak/simulator.py file and we can turn it into a fit in
@PyAutoLens/autolens/imaging/fit.py, so shouldnt be hard to work out the pattern and whats needed here.
I believe everything else (plotter.py, result.py, visualizer.py) should be relatively straight forward to work
out by simply copying the patterns and logic from the imaging module, but keep an eye out for unexpected tricky
parts.
Finally, read @autolens_workspace/scripts/imaging/modeling.py and then make an equivalent for
weak lensing.
Activity
Jammy2211 commentedon Jul 9, 2026
Ship sign-off requested (supervised checkpoint — run parked here)
What was done. Both halves of this task are implemented, validated and committed locally on
feature/weak-modelingin the task worktree — nothing has been pushed. Library:autolens/weak/model/{analysis,result,plotter,visualizer}.pymirroringpoint/model,al.AnalysisWeakexport,weak_dataset/fit_weakplots.yaml sections, 5 new NumPy-only tests (commit8a0733d47, +448 lines). Workspace:scripts/weak/modeling.pytutorial + config mirror (commit58f42a9a, +273 lines), developed on a parallel autolens_workspace worktree per the series precedent (lenstool-example's claim touches only root metadata files — zero overlap withscripts/weak/).Validation.
visualize_before_fit+visualize(full +quick_update) wrotesubplot_weak_dataset.png,subplot_fit_weak.png,fit_quick.png,galaxies.png.scripts/weak/modeling.pyran a real Nautilus fit (~7 min CPU): recoveredeinstein_radius = 1.556 (1.476–1.631)vs truth 1.6, centre at origin, ell_comps within ~1σ for 200 galaxies at σ=0.3 shape noise. The search's ownVisualizerWeakproduced the on-the-fly subplots inoutput/.../image/.Heart: YELLOW — reasons: workspace validation 5-failed report of 2026-07-08 11:25 (known stale per the morning triage; zero_contour fixes were merged but never re-validated), 58 stale parked scripts, autolens_assistant version pin behind, install verification not run, no release validation for current source, PyAutoMind open PR 9d old. No YELLOW acknowledgement was given at launch, so the run parks rather than ships (per AUTONOMY.md checkpoint 3).
The question. Approve shipping? On approval the run will: push both branches, open the PyAutoLens PR (
pending-release, body below) and the autolens_workspace PR (library-first merge gate noted in its body), append the autonomy-log row. If you want changes, comment them here and the next session resumes fromactive.md.Draft PyAutoLens PR body
Summary
Adds
al.AnalysisWeakso a non-linear search can fit lens mass models to aWeakDatasetshear catalogue — step 4 (the keystone) of the weak-lensing series (#579).autolens/weak/model/mirrorsautolens/point/model/:FitWeakalready followsFitPoint's standalone pattern, andAnalysisWeak.log_likelihood_functionbuilds aTracerfrom the instance and returnsFitWeak(dataset, tracer).log_likelihood.VisualizerWeak/PlotterWeakwire the nine existing weak quiver plotters into on-the-fly search visualization.API Changes
Added only — no existing symbol removed, renamed or changed.
al.AnalysisWeak(dataset, cosmology=, title_prefix=, use_jax=False)— new Analysis class forWeakDatasetfits.use_jaxdefaults toFalse(FitWeakis NumPy-only; JAX needs pytree registration — deliberate future work).weak_dataset/fit_weakinconfig/visualize/plots.yaml(workspaces should mirror — done in the companion workspace PR).See full details below.
Test Plan
test_autolens/suite in the task worktree: 347 passed.test_autolens/weak/test_analysis.py: analysis-vs-FitWeak likelihood equality, noise-free zero-chi-squared round trip, wrong-model likelihood ordering,save_attributesdataset.jsonround trip.autolens_workspace/scripts/weak/modeling.pyrecovers simulator truth within 1σ.Validation checklist (--auto run — plan was not pre-approved)
Full API Changes (for automation & release notes)
Added
autolens.weak.model.analysis.AnalysisWeak(exported asal.AnalysisWeak) — fits lens mass models toWeakDatasetshear catalogues;Result = ResultWeak,Visualizer = VisualizerWeak.autolens.weak.model.result.ResultWeak—Resultsubclass with fallback uniformgridandmax_log_likelihood_fit(aFitWeak).autolens.weak.model.plotter.PlotterWeak—dataset_weak()/fit_weak(quick_update=)behindplot_settingsectionsweak_dataset/["fit", "fit_weak"].autolens.weak.model.visualizer.VisualizerWeak—af.Visualizerfor search-time output (dataset subplot before fit; fit subplot + tracer/galaxies during).weak_dataset.subplot_dataset: trueandfit_weak: {}in packagedconfig/visualize/plots.yaml.Migration
🤖 Generated with Claude Code
Draft autolens_workspace PR body
Summary
Adds
scripts/weak/modeling.py— the weak-lensing model-fit tutorial completing the simulate → fit → model core workflow of the series — and mirrors the newweak_dataset/fit_weakvisualize/plots.yamlsections into the workspace config. Companion to the PyAutoLensAnalysisWeakPR (library-first merge gate: merge the library PR before this one).Scripts Changed
scripts/weak/modeling.py(new) — Nautilus Isothermal fit to the simulatedWeakDatasetviaal.AnalysisWeak; auto-simulates the dataset if missing; validated end-to-end (truth recovered within 1σ, ~7 min CPU).config/visualize/plots.yaml— addsweak_dataset/fit_weaksections mirroring the new packaged defaults.🤖 Generated with Claude Code
Jammy2211 commentedon Jul 9, 2026
Ship approved — PRs open 🚀
Thanks for the sign-off! Both branches are pushed and the PRs are open with
pending-release:al.AnalysisWeak+ weak model package (347 tests green)scripts/weak/modeling.py+ config mirror (merge after the library PR — library-first gate)Workspace impact: the API change is Added-only (
al.AnalysisWeak), so no migration is needed anywhere — the new demo script in #241 is the only downstream consumer. Heart's YELLOW reason set was acknowledged as part of this approval.Merge order: #580 first, then #241, then this issue can close. Once merged, the weak series home straight continues: step 5 (
likelihood_function.py) and step 6 (shear-profile + Kaiser-Squires visualization) unblock immediately; step 7 (Abell 2744 real data) and step 8 (combined strong+weak) build on this Analysis class.Jammy2211 commentedon Jul 9, 2026
Shipped ✅
Both PRs are merged (library-first order respected):
al.AnalysisWeak+autolens/weak/model/package (CI green on 3.12 + 3.13)scripts/weak/modeling.py+ config mirror + navigator catalogue (smoke + navigator checks green; the initial catalogue-staleness red was fixed by the prescribedregenerate_navigator.pyrun)The weak-lensing series now has its keystone: simulate → fit → model all work end to end, and steps 5 (likelihood_function), 6 (shear-profile/Kaiser-Squires visualization), 7 (Abell 2744 real data), 8 (combined strong+weak) and 9 (PYAUTO_SMALL_DATASETS smoke support) are unblocked. Continuing the home straight under --auto: step 6 next, then 5.
Closing this issue.