Skip to content

feat: PointDataset.redshift + cluster-scale simulator #464

Closed

Description

@Jammy2211

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 redshift to PointDataset with CSV round-trip + validation.
  • Write autolens_workspace/scripts/cluster/simulator.py using the group/simulator.py multi-galaxy pattern and the point_source/simulator.py CSV pattern, plus NFWMCRLudlowSph host halo and dPIEMassSph galaxy 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 consumes PointDataset.redshift into af.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)

  1. autolens/point/dataset.py:
    • Add redshift: Optional[float] = None parameter to PointDataset.__init__.
    • Add _REDSHIFT_HEADERS = ["redshift"].
    • In output_to_csv, include the redshift column if any dataset has a non-None redshift.
    • In list_from_csv, parse the redshift column when present; validate that all rows in a name group share the same redshift value.
  2. 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)

  1. autolens_workspace/scripts/cluster/simulator.py:
    • Grid + adaptive over-sampling centered on all 5 lens galaxy centres.
    • 5 main_lens_galaxies using SersicSph light + dPIEMassSph mass.
    • 1 host DM halo as a standalone al.Galaxy with NFWMCRLudlowSph(mass_at_200=10**14.5, redshift_object=z_lens, redshift_source=z_source), no light profile.
    • 2 source_galaxies at the same redshift, each with SersicCore light + al.ps.Point.
    • PointSolver → positions per source → PointDataset per source → combine via output_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

  1. admin_jammy/prompt/cluster/1_visualization.md: deep research on cluster visualization requirements + spec for autolens_workspace_test/scripts/cluster/visualization.py.
  2. admin_jammy/prompt/cluster/2_csv_model_redshift.md: design the model-construction helper that consumes PointDataset.redshift and wires it into af.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

  1. Jammy2211 commented on Apr 20, 2026

    @Jammy2211
    CollaboratorAuthor

    Library PR Created — 2026-04-20

    PR

    Status

    Workspace changes needed. Next: /start_workspace

    API Changes

    • PointDataset.__init__ gains optional redshift: Optional[float] = None kwarg; new .redshift attribute on the instance.
    • CSV I/O (output_to_csv, list_from_csv, to_csv, from_csv) round-trips a redshift column, emitted when any dataset supplies one.
    • Per-source validation: a name group in a loaded CSV must share a single redshift across all rows; mixed or partially-populated values raise ValueError.
    • No migration required — additive-only, existing callers and CSVs unaffected.

    Workspace Impact Discovery

    autolens_workspace/scripts/cluster/ already contains simulator.py, modeling.py, start_here.py. modeling.py and start_here.py are listed in PyAutoBuild/autobuild/config/no_run.yaml ("not maintained, test mode breaks it"). simulator.py is not in no_run.yaml. Workspace follow-up will revise the existing simulator.py to match the refined plan (NFWMCRLudlowSph host halo, 5 main lens galaxies, 2 sources at same redshift, combined CSV with redshift column, dPIEMassSph).

  2. Jammy2211 commented on Apr 20, 2026

    @Jammy2211
    CollaboratorAuthor

    Smoke Test Results — 2026-04-20

    Branch: feature/cluster-simulator — additive PointDataset.redshift optional parameter.

    Summary

    Workspace Passed Failed Skipped Missing Total
    autofit_workspace 5 0 1 0 6
    autogalaxy_workspace 4 2 0 0 6
    autolens_workspace 6 1 0 0 7
    autolens_workspace_test 11 1 0 0 12
    euclid_strong_lens_modeling_pipeline 6 0 0 0 6
    TOTAL 32 4 1 0 37

    Result: 32/36 PASS. All 4 failures are pre-existing missing-dataset FileNotFoundErrors — none caused by the PointDataset.redshift change.

    Failures (pre-existing, reproduce on main)
    1. autogalaxy_workspace/scripts/imaging/start_here.py — dataset/imaging/extra_galaxies/mask_extra_galaxies.fits not in repo.
    2. autogalaxy_workspace/scripts/interferometer/start_here.py — dataset/interferometer/ directory does not exist.
    3. autolens_workspace/scripts/interferometer/modeling.py — dataset/interferometer/ directory does not exist.
    4. autolens_workspace_test/scripts/database/scrape/general.py — dataset/imaging/no_lens_light/data.fits not in repo.
  3. Jammy2211 commented on Apr 20, 2026

    @Jammy2211
    CollaboratorAuthor

    Smoke Test Results — 2026-04-20

    Workspace Passed Failed Total
    autofit_workspace 6 0 6
    autogalaxy_workspace 4 2 6
    autolens_workspace 6 1 7
    autolens_workspace_test 11 1 12
    euclid_strong_lens_modeling_pipeline 6 0 6

    All failures are pre-existing (reproduce on main, unrelated to this PR):

    Failures (all pre-existing)

    autogalaxy_workspace/scripts/imaging/start_here.py

    FileNotFoundError: [Errno 2] No such file or directory: 'dataset/imaging/extra_galaxies/mask_extra_galaxies.fits'
    

    autogalaxy_workspace/scripts/interferometer/start_here.py

    subprocess.CalledProcessError: Command ['python', 'scripts/interferometer/simulator.py'] returned non-zero exit status 1.
    (missing dataset/interferometer/)
    

    autolens_workspace/scripts/interferometer/modeling.py

    subprocess.CalledProcessError: Command ['python', 'scripts/interferometer/simulator.py'] returned non-zero exit status 1.
    (missing dataset/interferometer/)
    

    autolens_workspace_test/scripts/database/scrape/general.py

    FileNotFoundError: [Errno 2] No such file or directory: 'dataset/imaging/no_lens_light/data.fits'
    

    Cluster simulator explicit run: exit code 0, dataset/cluster/simple/point_datasets.csv produced with redshift column ✓

    Workspace PR: PyAutoLabs/autolens_workspace#77

  4. Jammy2211 commented on Apr 20, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped — 2026-04-20

    PRs

    Upstream PR

    #465

    Summary

    Added optional redshift field to PointDataset with CSV round-trip and per-source validation (library). Rewrote autolens_workspace/scripts/cluster/simulator.py as a 5-member small cluster with a standalone NFWMCRLudlowSph dark matter host halo and 2 point sources at z=1.0 producing 3 multiple images each, writing a combined point_datasets.csv as the canonical hand-editable cluster input. Removed cluster/simulator from no_run.yaml so it runs in the release build.

    Session Notes

    • Parameter tuning gotcha: original plan specified mass_at_200 = 10^14.5 but the resulting NFW + dPIE combination was too weak to multi-image the chosen source positions — only a single image per source came out of the PointSolver. Bumped to mass_at_200 = 10^15.3 and scaled dPIEMassSph.b0 by 2x to get 3 images per source. Documented the choice in the simulator docstring.
    • Scope parking: modeling.py and start_here.py in scripts/cluster/ are still listed in no_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 in autolens_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 pipes PointDataset.redshift (from the CSV) into af.Model(al.Galaxy, redshift=...) so the CSV becomes the single source of truth for source redshifts during modeling. Without this, the CSV's new redshift column is non-load-bearing on the modeling side.
    • Stray path/to/model/json/model.json was created in the workspace by a smoke-test script with an unset output-path. Pre-existing in main too — worth a separate cleanup pass later.
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