Repository navigation
Description
Overview
Add cluster-scale strong lens simulation support to autolens. This requires a library change to PointDataset (optional redshift field on the CSV/API) and a new workspace simulator script that demonstrates a small cluster: 5 main lens galaxies, 2 multiply imaged sources at the same redshift, and a host dark matter halo modeled as NFWMCRLudlowSph with mass_at_200 = 10^14.5. The simulator uses the dPIEMassSph (Pseudo-Isothermal Elliptical) profile for the main lens galaxies and outputs a single combined CSV for both point datasets. Two follow-up prompts are written for cluster visualization and for the CSV-to-model redshift linkage.
Plan
- Add optional
redshifttoPointDatasetwith CSV round-trip + validation. - Write
autolens_workspace/scripts/cluster/simulator.pyusing thegroup/simulator.pymulti-galaxy pattern and thepoint_source/simulator.pyCSV pattern, plusNFWMCRLudlowSphhost halo anddPIEMassSphgalaxy mass profiles. - Document the manual-CSV-editing workflow in the simulator docstrings.
- Write
admin_jammy/prompt/cluster/1_visualization.md(deep research on cluster plotting +autolens_workspace_test/scripts/cluster/visualization.py). - Write
admin_jammy/prompt/cluster/2_csv_model_redshift.md(design model-construction helper that consumesPointDataset.redshiftintoaf.Model(al.Galaxy, redshift=...)).
Detailed implementation plan
Affected Repositories
- Jammy2211/PyAutoLens (primary — library change, ships first)
- Jammy2211/autolens_workspace (new simulator script)
Work Classification
Both — library change ships first, then workspace.
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoLens | main | clean |
| ./autolens_workspace | main | clean |
Suggested branch: feature/cluster-simulator
Worktree root: ~/Code/PyAutoLabs-wt/cluster-simulator/ (created later by /start_library)
Implementation Steps — Library (PyAutoLens)
autolens/point/dataset.py:- Add
redshift: Optional[float] = Noneparameter toPointDataset.__init__. - Add
_REDSHIFT_HEADERS = ["redshift"]. - In
output_to_csv, include theredshiftcolumn if any dataset has a non-None redshift. - In
list_from_csv, parse theredshiftcolumn when present; validate that all rows in a name group share the same redshift value.
- Add
test_autolens/point/test_dataset.py:- Round-trip test: dataset with redshift → CSV → datasets, redshift preserved.
- Mixed-presence test: some datasets with redshift, some without — column emitted when any are set, blank cells tolerated.
- Consistency test: rows in a group with differing redshift values raise.
Implementation Steps — Workspace (autolens_workspace)
autolens_workspace/scripts/cluster/simulator.py:- Grid + adaptive over-sampling centered on all 5 lens galaxy centres.
- 5
main_lens_galaxiesusingSersicSphlight +dPIEMassSphmass. - 1 host DM halo as a standalone
al.GalaxywithNFWMCRLudlowSph(mass_at_200=10**14.5, redshift_object=z_lens, redshift_source=z_source), no light profile. - 2
source_galaxiesat the same redshift, each withSersicCorelight +al.ps.Point. PointSolver→ positions per source →PointDatasetper source → combine viaoutput_to_csv. Source redshift stored on the dataset.- Output tracer JSON, per-category centre JSONs (main lenses, host halo anchor, sources), and combined PNGs (noting visualization limitations for cluster scale).
- Docstring section explaining how to hand-edit the combined CSV.
Implementation Steps — Follow-up prompts
admin_jammy/prompt/cluster/1_visualization.md: deep research on cluster visualization requirements + spec forautolens_workspace_test/scripts/cluster/visualization.py.admin_jammy/prompt/cluster/2_csv_model_redshift.md: design the model-construction helper that consumesPointDataset.redshiftand wires it intoaf.Model(al.Galaxy, redshift=..., point_0=...)so the CSV is authoritative.
Key Files
PyAutoLens/autolens/point/dataset.py— add redshift to API/CSV.PyAutoLens/test_autolens/point/test_dataset.py— round-trip + validation tests.autolens_workspace/scripts/cluster/simulator.py— new.admin_jammy/prompt/cluster/1_visualization.md— new.admin_jammy/prompt/cluster/2_csv_model_redshift.md— new.
Original Prompt
Click to expand starting prompt
I am going to add cluster stong lens analysis to autolens, whcih autolens can already do but needs a series of 5 or so claude prompts to get us to a point where it good and mature.
First, we need to be able to simulate strong lens cluster lensing data. The good news is, the ability to generate the required point source images from the source code is already possible. We basically just take the file @autolens_workspace/scripts/point_source/simulator.py and make it have many more lens galaxies, reading through @autolens_workspace/scripts/groups/simulator.py to see how the API For multiple lens gaalxies begins to add up as well as how we output images of the cluster we simulator (but modeling will use point sources).
For now, can you assume the system has 5 main lens galaxies, 2 multiply imaged source galaxies, a host dark matter halo which is not tied to any indivdiual lens gaalxy but included in the model "on top", with a mass of 1e14.5. This is not many galaxies for a cluster, but we will build everything for a small cluster and then rework the example to full complexity.
Use the .csv interface of the PointDataset when you write simulator.py and document it explaining how a user can manually adjust the .csv tables to set up their data, which is more practical than python code or other options.
In cluster strong lensing, its common to use PIEP, so use the mass prpfile in dual_pseudo_isothermal_mass.py and try to work out what good physical values for the system are.
The simulator script will output visualization, but they will not be optimal for a cluster which is has different requirements for good viewing than the galaxy scale lenses visualization has been designed for. So output the visuals but we will then improve on them in the next claude prompt. In fact, make a follow up prompt cluster/1_visualizaiton.md, that does some deep research to think abou the requiremnets of cluster visualization for us to work through (for example, images are much larger in size, need individual multiple images plotted on in different colors, Maybe needs functionality to plot the individual images on a subplot from the PointDataset list). Also have this prompt make an autolens_workspace_test/scipts/cluster/visualization.py file.
Activity
Jammy2211 commentedon Apr 20, 2026
Library PR Created — 2026-04-20
PR
Status
Workspace changes needed. Next: /start_workspace
API Changes
PointDataset.__init__gains optionalredshift: Optional[float] = Nonekwarg; new.redshiftattribute on the instance.output_to_csv,list_from_csv,to_csv,from_csv) round-trips aredshiftcolumn, emitted when any dataset supplies one.namegroup in a loaded CSV must share a single redshift across all rows; mixed or partially-populated values raiseValueError.Workspace Impact Discovery
autolens_workspace/scripts/cluster/already containssimulator.py,modeling.py,start_here.py.modeling.pyandstart_here.pyare listed inPyAutoBuild/autobuild/config/no_run.yaml("not maintained, test mode breaks it").simulator.pyis not in no_run.yaml. Workspace follow-up will revise the existingsimulator.pyto match the refined plan (NFWMCRLudlowSphhost halo, 5 main lens galaxies, 2 sources at same redshift, combined CSV with redshift column,dPIEMassSph).Jammy2211 commentedon Apr 20, 2026
Smoke Test Results — 2026-04-20
Branch:
feature/cluster-simulator— additivePointDataset.redshiftoptional parameter.Summary
Result: 32/36 PASS. All 4 failures are pre-existing missing-dataset
FileNotFoundErrors — none caused by thePointDataset.redshiftchange.Failures (pre-existing, reproduce on main)
autogalaxy_workspace/scripts/imaging/start_here.py—dataset/imaging/extra_galaxies/mask_extra_galaxies.fitsnot in repo.autogalaxy_workspace/scripts/interferometer/start_here.py—dataset/interferometer/directory does not exist.autolens_workspace/scripts/interferometer/modeling.py—dataset/interferometer/directory does not exist.autolens_workspace_test/scripts/database/scrape/general.py—dataset/imaging/no_lens_light/data.fitsnot in repo.Jammy2211 commentedon Apr 20, 2026
Smoke Test Results — 2026-04-20
All failures are pre-existing (reproduce on
main, unrelated to this PR):Failures (all pre-existing)
autogalaxy_workspace/scripts/imaging/start_here.py
autogalaxy_workspace/scripts/interferometer/start_here.py
autolens_workspace/scripts/interferometer/modeling.py
autolens_workspace_test/scripts/database/scrape/general.py
Cluster simulator explicit run: exit code 0,
dataset/cluster/simple/point_datasets.csvproduced withredshiftcolumn ✓Workspace PR: PyAutoLabs/autolens_workspace#77
Jammy2211 commentedon Apr 20, 2026
Shipped — 2026-04-20
PRs
Upstream PR
#465
Summary
Added optional
redshiftfield toPointDatasetwith CSV round-trip and per-source validation (library). Rewroteautolens_workspace/scripts/cluster/simulator.pyas a 5-member small cluster with a standaloneNFWMCRLudlowSphdark matter host halo and 2 point sources at z=1.0 producing 3 multiple images each, writing a combinedpoint_datasets.csvas the canonical hand-editable cluster input. Removedcluster/simulatorfromno_run.yamlso it runs in the release build.Session Notes
mass_at_200 = 10^14.5but the resulting NFW + dPIE combination was too weak to multi-image the chosen source positions — only a single image per source came out of thePointSolver. Bumped tomass_at_200 = 10^15.3and scaleddPIEMassSph.b0by 2x to get 3 images per source. Documented the choice in the simulator docstring.modeling.pyandstart_here.pyinscripts/cluster/are still listed inno_run.yaml("not maintained, test mode breaks it") and were deliberately left untouched. Their rewrite is blocked on the two follow-up prompts:admin_jammy/prompt/cluster/1_visualization.md— deep research on cluster-scale visualization + prototype script inautolens_workspace_test/scripts/cluster/visualization.py. Default galaxy-scale plotters are suboptimal at 100"x100" field size; prototype surfaces what library-side plotter changes are needed.admin_jammy/prompt/cluster/2_csv_model_redshift.md— design a helper that pipesPointDataset.redshift(from the CSV) intoaf.Model(al.Galaxy, redshift=...)so the CSV becomes the single source of truth for source redshifts during modeling. Without this, the CSV's newredshiftcolumn is non-load-bearing on the modeling side.path/to/model/json/model.jsonwas created in the workspace by a smoke-test script with an unset output-path. Pre-existing inmaintoo — worth a separate cleanup pass later.fix: effective_einstein_radius falls back to NumPy when jax_zero_cont…