Skip to content

feat: add searches_minimal examples for HST MGE likelihood #27

@Jammy2211

Description

@Jammy2211

Overview

Add a searches_minimal/ folder to autolens_workspace_developer that mirrors the equivalent folder in autofit_workspace_developer, but runs each sampler against the real MGE imaging likelihood (HST dataset) instead of the 1D Gaussian toy model. These scripts drive Nautilus, Dynesty, Emcee, scipy.L-BFGS-B, and NSS directly against PyAutoFit's Model / Analysis objects, bypassing the NonLinearSearch wrapper — useful for quickly smoke-testing a search against a realistic likelihood.

Plan

  • Create searches_minimal/ with one script per sampler (nautilus, dynesty, emcee, lbfgs, nss_simple, nss_jit, nss_grad).
  • Share the HST dataset + MGE model + AnalysisImaging setup via a small _setup.py helper.
  • NumPy-path samplers use the standard AnalysisImaging and model.instance_from_vector.
  • nss_simple.py wraps the NumPy analysis in jax.pure_callback.
  • nss_jit.py / nss_grad.py use AnalysisImaging(use_jax=True) + autofit.jax.register_model for the pure-JAX path — exercising the MGE gradient support.
  • Keep run times short (small n_live, short chains) — these are smoke tests, not converged runs.
Detailed implementation plan

Affected Repositories

  • autolens_workspace_developer (primary)

Work Classification

Workspace

Branch Survey

Repository Current Branch Dirty?
./autolens_workspace_developer main clean

Suggested branch: feature/searches-minimal
Worktree root: ~/Code/PyAutoLabs-wt/searches-minimal/ (created later by /start_workspace)

Implementation Steps

  1. Create searches_minimal/_setup.py with build_dataset(instrument=\"hst\"), build_model(mask_radius=3.5), build_analysis(dataset, use_jax=False) helpers. Mirrors the setup block in jax_profiling/imaging/mge.py (mask radius 3.5, radial-bin over-sampling, 20-gaussian MGE bulges for lens + source, Isothermal mass + ExternalShear).
  2. Create searches_minimal/nautilus_simple.py — load setup, run nautilus.Sampler with n_live=50, print best-fit lens / source parameters + log evidence + wall time / likelihood-call count.
  3. Create searches_minimal/dynesty_simple.pydynesty.NestedSampler with small nlive.
  4. Create searches_minimal/emcee_simple.pyemcee.EnsembleSampler, walkers initialised near prior medians with small scatter, short chain (few hundred steps).
  5. Create searches_minimal/lbfgs_simple.pyscipy.optimize.minimize(method=\"L-BFGS-B\") with bounds derived from the model's priors via model.physical_upper_limits_for_parameters / physical_lower_limits_for_parameters, started at model.physical_values_from_prior_medians.
  6. Create searches_minimal/nss_simple.pyrun_nested_sampling using NumPy analysis wrapped in jax.pure_callback (same pattern as autofit reference).
  7. Create searches_minimal/nss_jit.pyAnalysisImaging(use_jax=True) + autofit.jax.register_model(model) + params_tree = jax.tree_util.tree_map(jnp.asarray, instance), then run_nested_sampling with the pure-JAX likelihood.
  8. Create searches_minimal/nss_grad.py — same pure-JAX setup, then run_hmc_sequential_mc to exercise jax.grad through MGE.
  9. Smoke-test each script: NUMBA_CACHE_DIR=/tmp/numba_cache MPLCONFIGDIR=/tmp/matplotlib python searches_minimal/<name>.py, verify a best-fit instance + finite log evidence are printed.

Key Files

  • searches_minimal/_setup.py — shared HST dataset + MGE model + analysis setup.
  • searches_minimal/nautilus_simple.py — direct Nautilus example.
  • searches_minimal/dynesty_simple.py — direct Dynesty example.
  • searches_minimal/emcee_simple.py — direct Emcee example.
  • searches_minimal/lbfgs_simple.py — direct scipy L-BFGS-B example.
  • searches_minimal/nss_simple.py — NSS with NumPy likelihood via jax.pure_callback.
  • searches_minimal/nss_jit.py — NSS with pure-JAX MGE likelihood.
  • searches_minimal/nss_grad.py — NSS HMC-SMC with gradient-accelerated MGE.

Original Prompt

Click to expand starting prompt

The folder autofit_workspace_developer/searches_minimal has examples of how to set up an likelihood function and
have it so a search runs with a minimal interface, for quick testing of lieklihood functions.

Can you set up all of these on autolens_workspacde_developer, using the same hst data used in jax_profiling/imaging
and using the mge model which now supports gradients.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions