Skip to content

refactor(latent): first-class Latent class + engine extraction (Phase 1) - #1315

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/latent-class-phase1
Jun 9, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/latent-class-phase1

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Phase 1 of the latent-variable redesign (PyAutoPrompt/autofit/latent_class_redesign.md). Decouples latent handling from Analysis into a first-class, subclassable Latent class — mirroring how Visualizer/Result are declared on an analysis, and the earlier SearchUpdater extraction. Pure refactor, no behaviour change, with a back-compat shim so PyAutoGalaxy/PyAutoLens/Euclid/workspaces run unchanged.

  • New autofit/non_linear/analysis/latent.py:
    • Latent base — static keys(analysis) / variables(analysis, parameters, model) + BATCH_MODE; declared as Analysis.Latent = MyLatent and subclassed by users.
    • latent_samples_from(analysis, samples, batch_size) — the batched engine (JAX vmap/jit dispatch, global mask + greedy salvage) moved verbatim out of Analysis.
  • analysis.py: Latent = Latent class attr; compute_latent_samples is now a thin delegator; engine removed (585 → 387 lines).
  • af.Latent exported.

API Changes

No signature changes. New extension point af.Latent (declare Analysis.Latent = ..., override keys/variables). The legacy Analysis.LATENT_KEYS / LATENT_BATCH_MODE / compute_latent_variables still work — the default Latent delegates to them (back-compat shim).
See full details below.

Test Plan

  • pytest test_autofit/non_linear test_autofit/analysis — 298 passed, 14 skipped (NSS optional-dep)
  • new-path coverage test_autofit/analysis/test_latent.py + back-compat test_latent_variables.py + quantile — 32 passed
  • cross-library back-compat (live autofit on PYTHONPATH): autofit / autogalaxy / autolens latent_nan_robustness.py PASS; autolens latent_variables_smoke.py (test-mode) PASS — all via the shim, unchanged
Full API Changes (for automation & release notes)

Added

  • autofit.non_linear.analysis.latent.Latent (exported as af.Latent) — latent extension class; override keys/variables, set BATCH_MODE; declare Analysis.Latent = MyLatent.
  • autofit.non_linear.analysis.latent.latent_samples_from(analysis, samples, batch_size=None) — the latent batching/masking engine, usable standalone.

Changed (internal, back-compat preserved)

  • Analysis.compute_latent_samples is now a thin delegator to latent_samples_from. The engine body moved out of analysis.py.
  • Analysis.LATENT_KEYS, Analysis.LATENT_BATCH_MODE, Analysis.compute_latent_variables retained as a back-compat shim (the default Latent reads them). Preferred path is now subclassing Latent.

🤖 Generated with Claude Code

…ysis

Latent handling is decoupled from Analysis, mirroring the Visualizer/Result
class-attribute pattern (and the earlier SearchUpdater extraction):

- New autofit/non_linear/analysis/latent.py: `Latent` base (static keys()/
  variables(), BATCH_MODE) declared as `Analysis.Latent = ...`, plus the
  batched evaluation engine `latent_samples_from` moved verbatim out of
  Analysis.compute_latent_samples (JAX vmap/jit dispatch, global mask + salvage).
- analysis.py: `Latent = Latent` class attr; compute_latent_samples is now a
  thin delegator; engine removed (585 -> 387 lines). LATENT_KEYS /
  LATENT_BATCH_MODE / compute_latent_variables kept as a back-compat shim that
  the default Latent reads, so existing overrides (autolens/autogalaxy/Euclid)
  run unchanged.
- Export `af.Latent`.

Pure refactor, no behaviour change (Phase 1 of the latent redesign). New code
subclasses `af.Latent`; legacy method-override path still works via the shim.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Jun 8, 2026
@Jammy2211
Jammy2211 merged commit ff8ebd6 into main Jun 9, 2026
7 checks passed
@Jammy2211
Jammy2211 deleted the feature/latent-class-phase1 branch June 9, 2026 09:20
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Sep 4, 2026
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