Skip to content

Add jax_zero_contour-based critical curve and caustic tracing#312

Merged
Jammy2211 merged 4 commits intomainfrom
feature/jax-zero-contour-critical-curves
Apr 1, 2026
Merged

Add jax_zero_contour-based critical curve and caustic tracing#312
Jammy2211 merged 4 commits intomainfrom
feature/jax-zero-contour-critical-curves

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

Summary

  • Integrates the jax_zero_contour package to trace critical curves and caustics via Newton's method + Euler-Lagrange stepping, eliminating the need for a dense input grid.
  • New LensCalc methods: tangential/radial_critical_curve_list_via_zero_contour_from, tangential/radial_caustic_list_via_zero_contour_from, einstein_radius_via_zero_contour_from.
  • Auto-seeds the zero-contour solver from a cheap 25×25 coarse grid scan; gracefully returns [] when no critical curve is found (e.g. sub-critical mass configurations).
  • Adds a critical_curves_method config key to visualize/general.yaml (zero_contour default, marching_squares fallback) so the visualizer/plotting layer can dispatch between methods without code changes.
  • Fixes a pre-existing filename bug in galaxy_plots.subplot_of_mass_profiles (was saving as subplot_convergence.png, tests expected convergence.png).

Test plan

  • python -m pytest test_autogalaxy/ — 833 passed, 0 failed (confirmed before commit)
  • Integration test at autolens_workspace_test/scripts/critical_curves_zero_contour.py covers return-type checks, cross-comparison with marching squares (mean-radius rtol ≤ 5%, centroid atol ≤ 0.15 arcsec, area rtol ≤ 10%), auto-seed path, and offset-centre lens
  • Config dispatch tested in test_autogalaxy/plot/mat_wrap/test_visuals.py::test__mass_plotter__tangential_critical_curves (geometric consistency check ≤ 5% mean-radius difference)

🤖 Generated with Claude Code

Jammy2211 and others added 4 commits April 1, 2026 11:08
Replaces the dense marching-squares grid evaluation with a JAX contour
tracer that evaluates the eigen-value function only along the curve
itself — far fewer function calls, no input grid required.

New LensCalc methods
- _make_eigen_fn(kind, pixel_scales): unified JAX scalar function factory
  (tangential/radial differ only in sign; hessian_xy is symmetrised)
- _init_guess_from_coarse_grid: 25x25 seed search via marching squares
- _critical_curve_list_via_zero_contour: shared private implementation
- _caustic_list_via_zero_contour: shared private implementation
- tangential/radial_critical_curve_list_via_zero_contour_from
- tangential/radial_caustic_list_via_zero_contour_from
- einstein_radius_list/scalar_via_zero_contour_from

Visualizer config (visualize/general.yaml)
- New key general.critical_curves_method (default: zero_contour)
- plot_utils._critical_curves_method() reads config and dispatches
- Both _critical_curves_from and _caustics_from respect the setting
- Gracefully returns [] when no curve found (no ValueError in plot path)

Also fixes pre-existing bug in galaxy_plots.subplot_of_mass_profiles
where output filenames were prefixed with "subplot_" contrary to the
intended behaviour described in commit 585acb6.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add jax_zero_contour to pyproject.toml [optional] extras and wrap the
import inside _critical_curve_list_via_zero_contour in a try/except so
that the rest of the package imports cleanly on build servers that do
not have the package installed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Appending pts[0] to the end of each path ensures the plotted critical
curve and its derived caustic have no gap between the last and first
point.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Jammy2211 Jammy2211 merged commit 7d6849f into main Apr 1, 2026
8 checks passed
@Jammy2211 Jammy2211 deleted the feature/jax-zero-contour-critical-curves branch April 1, 2026 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant