diff --git a/.gitignore b/.gitignore index 5923432..8ed7f40 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,26 @@ __jax_cache__/ # Local virtualenvs .venv/ venv/ + +# Auto-simulated input datasets — regenerated by profiler scripts, not committed. +# The pre-existing datasets (e.g. imaging/hst, interferometer/sma, point_source/simple/*.json) +# remain tracked and are NOT covered by these rules. +dataset/cluster/ +dataset/group/ +dataset/multi/ +dataset/imaging/simple/ +dataset/interferometer/simple/ +dataset/point_source/simple/data.fits +dataset/point_source/simple/noise_map.fits +dataset/point_source/simple/psf.fits +dataset/point_source/simple/point_dataset_positions_only.csv + +# Datacube simulator outputs — regenerated each run +dataset/datacube/sim_*/ + +# Profiling result artifacts — written by scripts under likelihood/, simulators/, searches/. +# Each run produces fresh versioned JSON+PNG; Phase 4's dashboard will explicitly select +# which artifacts to commit. Until then, results stay local. +results/likelihood/ +results/simulators/ +results/searches/ diff --git a/dataset/imaging/hst/data.fits b/dataset/imaging/hst/data.fits new file mode 100644 index 0000000..f0f9c28 Binary files /dev/null and b/dataset/imaging/hst/data.fits differ diff --git a/dataset/imaging/hst/noise_map.fits b/dataset/imaging/hst/noise_map.fits new file mode 100644 index 0000000..fee51bf Binary files /dev/null and b/dataset/imaging/hst/noise_map.fits differ diff --git a/dataset/imaging/hst/psf.fits b/dataset/imaging/hst/psf.fits new file mode 100644 index 0000000..1f7babf Binary files /dev/null and b/dataset/imaging/hst/psf.fits differ diff --git a/dataset/imaging/hst/tracer.json b/dataset/imaging/hst/tracer.json new file mode 100644 index 0000000..60f4998 --- /dev/null +++ b/dataset/imaging/hst/tracer.json @@ -0,0 +1,110 @@ +{ + "type": "instance", + "class_path": "autolens.lens.tracer.Tracer", + "arguments": { + "galaxies": { + "type": "list", + "values": [ + { + "type": "instance", + "class_path": "autogalaxy.galaxy.galaxy.Galaxy", + "arguments": { + "redshift": 0.5, + "label": null, + "bulge": { + "type": "instance", + "class_path": "autogalaxy.profiles.light.standard.sersic.Sersic", + "arguments": { + "intensity": 2.0, + "ell_comps": { + "type": "tuple", + "values": [ + 0.05263157894736841, + 3.2227547345982974e-18 + ] + }, + "centre": { + "type": "tuple", + "values": [ + 0.0, + 0.0 + ] + }, + "sersic_index": 3.0, + "effective_radius": 0.6 + } + }, + "mass": { + "type": "instance", + "class_path": "autogalaxy.profiles.mass.total.isothermal.Isothermal", + "arguments": { + "ell_comps": { + "type": "tuple", + "values": [ + 0.05263157894736841, + 3.2227547345982974e-18 + ] + }, + "centre": { + "type": "tuple", + "values": [ + 0.0, + 0.0 + ] + }, + "einstein_radius": 1.6 + } + }, + "shear": { + "type": "instance", + "class_path": "autogalaxy.profiles.mass.sheets.external_shear.ExternalShear", + "arguments": { + "gamma_2": 0.05, + "gamma_1": 0.05 + } + } + } + }, + { + "type": "instance", + "class_path": "autogalaxy.galaxy.galaxy.Galaxy", + "arguments": { + "redshift": 1.0, + "label": null, + "bulge": { + "type": "instance", + "class_path": "autogalaxy.profiles.light.standard.sersic_core.SersicCore", + "arguments": { + "intensity": 4.0, + "gamma": 0.25, + "ell_comps": { + "type": "tuple", + "values": [ + 0.0962250448649376, + -0.05555555555555551 + ] + }, + "centre": { + "type": "tuple", + "values": [ + 0.0, + 0.0 + ] + }, + "sersic_index": 1.0, + "effective_radius": 0.1, + "alpha": 3.0, + "radius_break": 0.025 + } + } + } + } + ] + }, + "cosmology": { + "type": "instance", + "class_path": "autogalaxy.cosmology.model.Planck15", + "arguments": {} + } + } +} \ No newline at end of file diff --git a/dataset/imaging/source_complex/data.fits b/dataset/imaging/source_complex/data.fits new file mode 100644 index 0000000..9ae1b79 Binary files /dev/null and b/dataset/imaging/source_complex/data.fits differ diff --git a/dataset/imaging/source_complex/noise_map.fits b/dataset/imaging/source_complex/noise_map.fits new file mode 100644 index 0000000..0761473 Binary files /dev/null and b/dataset/imaging/source_complex/noise_map.fits differ diff --git a/dataset/imaging/source_complex/psf.fits b/dataset/imaging/source_complex/psf.fits new file mode 100644 index 0000000..b181b8c Binary files /dev/null and b/dataset/imaging/source_complex/psf.fits differ diff --git a/dataset/interferometer/sma/data.fits b/dataset/interferometer/sma/data.fits new file mode 100644 index 0000000..d49ad21 Binary files /dev/null and b/dataset/interferometer/sma/data.fits differ diff --git a/dataset/interferometer/sma/noise_map.fits b/dataset/interferometer/sma/noise_map.fits new file mode 100644 index 0000000..f421a36 Binary files /dev/null and b/dataset/interferometer/sma/noise_map.fits differ diff --git a/dataset/interferometer/sma/positions.json b/dataset/interferometer/sma/positions.json new file mode 100644 index 0000000..690a98e --- /dev/null +++ b/dataset/interferometer/sma/positions.json @@ -0,0 +1,20 @@ +{ + "type": "instance", + "class_path": "autoarray.structures.grids.irregular_2d.Grid2DIrregular", + "arguments": { + "values": { + "type": "ndarray", + "array": [ + [ + -1.35078125, + -0.505632540438727 + ], + [ + 0.77734375, + 1.6648436277960226 + ] + ], + "dtype": "float64" + } + } +} \ No newline at end of file diff --git a/dataset/interferometer/sma/tracer.json b/dataset/interferometer/sma/tracer.json new file mode 100644 index 0000000..51169ab --- /dev/null +++ b/dataset/interferometer/sma/tracer.json @@ -0,0 +1,111 @@ +{ + "type": "instance", + "class_path": "autolens.lens.tracer.Tracer", + "arguments": { + "cosmology": { + "type": "instance", + "class_path": "autogalaxy.cosmology.model.Planck15", + "arguments": {} + }, + "galaxies": { + "type": "list", + "values": [ + { + "type": "instance", + "class_path": "autogalaxy.galaxy.galaxy.Galaxy", + "arguments": { + "label": null, + "redshift": 0.5, + "mass": { + "type": "instance", + "class_path": "autogalaxy.profiles.mass.total.isothermal.Isothermal", + "arguments": { +<<<<<<< Updated upstream + "einstein_radius": 1.6, + "centre": { +======= + "ell_comps": { +>>>>>>> Stashed changes + "type": "tuple", + "values": [ + 0.05263157894736841, + 3.2227547345982974e-18 + ] + }, +<<<<<<< Updated upstream + "ell_comps": { +======= + "centre": { +>>>>>>> Stashed changes + "type": "tuple", + "values": [ + 0.0, + 0.0 + ] + }, + "einstein_radius": 1.6 + } + }, + "shear": { + "type": "instance", + "class_path": "autogalaxy.profiles.mass.sheets.external_shear.ExternalShear", + "arguments": { + "gamma_1": 0.05, + "gamma_2": 0.05 + } + } + } + }, + { + "type": "instance", + "class_path": "autogalaxy.galaxy.galaxy.Galaxy", + "arguments": { + "label": null, + "redshift": 1.0, + "bulge": { + "type": "instance", + "class_path": "autogalaxy.profiles.light.standard.sersic_core.SersicCore", + "arguments": { + "alpha": 3.0, +<<<<<<< Updated upstream + "gamma": 0.25, + "effective_radius": 1.0, + "centre": { +======= + "intensity": 0.3, + "gamma": 0.25, + "radius_break": 0.025, + "ell_comps": { +>>>>>>> Stashed changes + "type": "tuple", + "values": [ + 0.1, + 0.1 + ] + }, +<<<<<<< Updated upstream + "intensity": 0.3, + "radius_break": 0.025, + "ell_comps": { +======= + "centre": { +>>>>>>> Stashed changes + "type": "tuple", + "values": [ + 0.0962250448649376, + -0.05555555555555551 + ] + }, +<<<<<<< Updated upstream +======= + "effective_radius": 1.0, +>>>>>>> Stashed changes + "sersic_index": 2.5 + } + } + } + } + ] + } + } +} \ No newline at end of file diff --git a/dataset/interferometer/sma/uv_wavelengths.fits b/dataset/interferometer/sma/uv_wavelengths.fits new file mode 100644 index 0000000..02737ba Binary files /dev/null and b/dataset/interferometer/sma/uv_wavelengths.fits differ diff --git a/dataset/point_source/simple/point_dataset_positions_only.json b/dataset/point_source/simple/point_dataset_positions_only.json new file mode 100644 index 0000000..8e02886 --- /dev/null +++ b/dataset/point_source/simple/point_dataset_positions_only.json @@ -0,0 +1,56 @@ +{ + "type": "instance", + "class_path": "autolens.point.dataset.PointDataset", + "arguments": { + "positions_noise_map": { + "type": "instance", + "class_path": "autoarray.structures.arrays.irregular.ArrayIrregular", + "arguments": { + "values": { + "type": "ndarray", + "array": [ + 0.05, + 0.05, + 0.05, + 0.05 + ], + "dtype": "float64" + } + } + }, + "fluxes": null, + "time_delays_noise_map": null, + "time_delays": null, + "positions": { + "type": "instance", + "class_path": "autoarray.structures.grids.irregular_2d.Grid2DIrregular", + "arguments": { + "values": { + "type": "ndarray", + "array": [ + [ + -1.0285552366239088, + -1.092385071774359 + ], + [ + 0.3509304746580634, + 1.6278794213275605 + ], + [ + 1.5748094742113987, + 0.4342241069464528 + ], + [ + 1.2452712382900812, + 1.2238422712179249 + ] + ], + "dtype": "float64" + } + } + }, + "name": "point_0", + "fluxes_noise_map": null, + "redshift": null + } +} \ No newline at end of file diff --git a/dataset/point_source/simple/tracer.json b/dataset/point_source/simple/tracer.json new file mode 100644 index 0000000..0124d90 --- /dev/null +++ b/dataset/point_source/simple/tracer.json @@ -0,0 +1,78 @@ +{ + "type": "instance", + "class_path": "autolens.lens.tracer.Tracer", + "arguments": { + "galaxies": { + "type": "list", + "values": [ + { + "type": "instance", + "class_path": "autogalaxy.galaxy.galaxy.Galaxy", + "arguments": { + "label": null, + "redshift": 0.5, + "mass": { + "type": "instance", + "class_path": "autogalaxy.profiles.mass.total.isothermal.Isothermal", + "arguments": { + "centre": { + "type": "tuple", + "values": [ + 0.0, + 0.0 + ] + }, + "ell_comps": { + "type": "tuple", + "values": [ + 0.05263157894736841, + 3.2227547345982974e-18 + ] + }, + "einstein_radius": 1.6 + } + } + } + }, + { + "type": "instance", + "class_path": "autogalaxy.galaxy.galaxy.Galaxy", + "arguments": { + "label": null, + "redshift": 1.0, + "light": { + "type": "instance", + "class_path": "autogalaxy.profiles.light.standard.exponential_core.ExponentialCore", + "arguments": { + "alpha": 3.0, + "intensity": 0.1, + "centre": { + "type": "tuple", + "values": [ + 0.07, + 0.07 + ] + }, + "radius_break": 0.025, + "gamma": 0.25, + "ell_comps": { + "type": "tuple", + "values": [ + 0.0, + 0.0 + ] + }, + "effective_radius": 0.02 + } + } + } + } + ] + }, + "cosmology": { + "type": "instance", + "class_path": "autogalaxy.cosmology.model.Planck15", + "arguments": {} + } + } +} \ No newline at end of file diff --git a/likelihood/README.md b/likelihood/README.md index 25bd058..0751281 100644 --- a/likelihood/README.md +++ b/likelihood/README.md @@ -1,7 +1,63 @@ # likelihood -Likelihood JIT profiling scripts and per-section READMEs. +JAX JIT profiling for the PyAutoLens likelihood function across imaging, interferometer, point-source, and datacube datasets, and across the MGE, pixelization, and Delaunay model compositions used in real science cases. -Populated by **Phase 1** of the `autolens_profiling` roadmap. Will mirror `autolens_workspace_developer/jax_profiling/jit/{imaging,interferometer,point_source,datacube}/`, preserving the step-by-step profile narrative each script already prints. +## What "JIT likelihood profiling" means -See the top-level [README](../README.md) for the full phase plan. +For each science case, the likelihood function turns a parameter vector into a single number (log-likelihood) via a chain of array operations: instantiate the model, build the `Tracer`, ray-trace grids through the lens, compute a mapping matrix, blur it with the PSF, solve a linear-algebra reconstruction problem, and finally compute a chi-squared. Under `xp=jnp`, every step is dispatched as a JAX op and can be compiled into a single XLA program with `jax.jit`. + +Profiling the **whole likelihood** as one JIT'd function gives the honest per-call cost a sampler will see in production. Profiling **each step individually** under its own JIT gives the breakdown that tells you where the time is going. Both numbers matter: the whole-function timing is the production cost, and the per-step breakdown is the optimisation target. Each script in this section reports both wherever the underlying pipeline supports per-step JIT-ing (the interferometer and datacube paths intentionally stay at full-pipeline JIT for now — see those subfolders' READMEs for why). + +Every script also reports a **batched (`jax.vmap`) per-likelihood cost** to make explicit how much the JIT amortises across a population of evaluations — the regime an actual sampler operates in. + +## How to read the per-script output + +Each script prints a structured narrative to stdout, ending in: + +- The eager (numpy) baseline log-likelihood for sanity. +- The single-JIT lower / compile / first-call / steady-state per-call timings. +- The vmap per-likelihood cost and speedup vs single-JIT. +- A correctness check: eager ≡ JIT ≡ vmap log-likelihoods at `rtol=1e-4`. +- A `results/likelihood//