Skip to content

feat: number_of_cores="auto", parallel banner/metadata and factor-graph setups (5D) - #1795

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/likelihood-lifecycle-p5d-fit
Nov 24, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/likelihood-lifecycle-p5d-fit

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Likelihood-lifecycle phase 5D (#1794). This adds opt-in number_of_cores="auto", resolved at fit start once the analysis has resolved its compute setup. It replaces the fit-start core claim with one honest Parallel: banner line, records the resolved parallelism in search.summary and files/parallel.json, and makes FactorGraphModel forward modify_before_fit to every factor's analysis, with a setup-agreement check, so setup= works inside factor graphs. The default stays number_of_cores=1 (R6).

API Changes

  • number_of_cores on SettingsSearch and every search accepts an int ≥ 1, None (→ 1) or "auto"; anything else raises ValueError. search.json keeps the request.
  • "auto" → the detected cores (SLURM_CPUS_PER_TASK → affinity → cpu_count), 1 for JAX analyses and EP factor searches. It is capped by min(cores // cpus_per_eval, available memory // peak_rss_gb) only when the analysis has resources_per_eval(). There is no parallel-efficiency cap.
  • New banner Parallel: N workers (requested R; reason) · setup <id> after modify_before_fit. log_fit_start no longer logs a core count.
  • New files/parallel.json: requested, number_of_cores, reason, detected_cores, available_memory_gb, setup_id.
  • FactorGraphModel.modify_before_fit forwards to each factor (rebinding both analysis references) and calls check_setup_agreement(), which is also run in preflight.
  • GridSearch / Sensitivity accept "auto" for their job count (the detected cores).
    See full details below.

Test Plan

  • pytest test_autofit: 4376 passed, 2 skipped, 1 xfailed. New: 43 tests in test_number_of_cores_auto.py, 8 in test_factor_graph_setup.py. Probes are monkeypatched and nothing forks.
  • PyAutoGalaxy compatibility: 1659 passed. (A rerun under CPU contention, with the Lens suite running at the same time, failed one 30 s wall-clock assert in test_gaussian.py::test__potential_2d_from__zero_at_centre_and_basis_is_fast, which took 59 s; it passes alone. Unrelated to autofit.)
  • PyAutoLens compatibility: 1123 passed, 1 xfailed
  • Heart dev gate (pyauto-heart readiness --dev --repos PyAutoFit): GREEN. Non-blocking shown reasons: manifest drift; test run status unknown; no release rehearsal for current source; release push credential check 53 h old.
  • pyauto-heart smoke --affected-by PyAutoFit --jobs 3: 8/8 workspaces PASS (autofit, autogalaxy, autolens, autolens_test, euclid, howtolens, autocti, autocti_test), run against this branch via PYAUTO_ROOT
Full API Changes (for automation & release notes)

Added

  • autofit.non_linear.parallel.resources: validate_number_of_cores, is_auto, detected_cores, available_memory_gb (MemAvailable, the cgroup v2 headroom when lower, fallback total RAM), resolve_job_cores, AUTO.
  • autofit.non_linear.parallel.pool: resolve_number_of_cores(requested, analysis, is_jax, where, ep_factor_search), ParallelResolution (banner, summary, to_dict), setup_id_of(analysis), JAX_REASON, EP_REASON.
  • FactorGraphModel.modify_before_fit, FactorGraphModel.setup_ids(), FactorGraphModel.check_setup_agreement().
  • AnalysisFactor.modify_before_fit, AnalysisFactor.rebind_analysis().
  • Duck-typed analysis hook resources_per_eval() → {cpus_per_eval, peak_rss_gb} or None. No PyAutoFit analysis defines it yet; PyAutoLens will in 5E.

Changed

  • SettingsSearch(number_of_cores=...) / NonLinearSearch(number_of_cores=...) validate the request.
  • PoolFactory uses the fit's resolved count.
  • warn_if_threads_unpinned only checks an int; "auto" is checked once resolved.
  • log_fit_start: the non-JAX line is now "Starting non-linear search." (the JAX device line is kept).
  • search.summary "Number of cores" line: N (requested R)[: reason] plus Setup = <id>.
  • preflight.check_runtime_gates also runs check_setup_agreement.

Migration

  • None. The default number_of_cores=1 is unchanged. Tests that assert the exact old log_fit_start "with N cores" line need the new banner instead.

Notes:

  • Why no efficiency cap: the one measured curve (imaging/rectangular numba, autolens_inference wall/model.py) has cores × η rising at every step up to 32 cores, so throughput favours all cores (approved design call 1). The memory cap goes live in 5E, when PyAutoLens ships runtime_estimates.yaml and implements resources_per_eval().
  • Factor graphs: forwarding resolves each factor's setup (clearing the PyAutoLens SetupException for graph fits), and mismatched setups raise a SearchException that names the factors. EP still never calls modify_before_fit, so the Lens guard stays for EP.
  • Not changed: ModelAnalysis does not forward modify_before_fit to the analysis it wraps. That predates this PR and is out of the approved scope. An analysis wrapped via .with_model(...) therefore still skips setup resolution; a small follow-up if wanted.
  • abstract_search.py stays within its 600-line budget: the new helpers live in runtime.py.

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

…ph setups (5D)

number_of_cores accepts an int >= 1, None or "auto" (validated). "auto" is
resolved after modify_before_fit to the detected cores, 1 for JAX and EP
factor searches, capped by cores/memory only when the analysis declares
resources_per_eval(). One "Parallel:" banner line replaces the fit-start
core claim; search.summary and files/parallel.json record the resolution.
FactorGraphModel forwards modify_before_fit to every factor (rebinding
both analysis references) and checks setup agreement.

Closes #1794 (likelihood-lifecycle phase 5D).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Nov 24, 2026
@Jammy2211
Jammy2211 merged commit 23b7dfe into main Nov 24, 2026
6 checks passed
@Jammy2211
Jammy2211 deleted the feature/likelihood-lifecycle-p5d-fit branch November 24, 2026 19:05
@pyautolabs-bot pyautolabs-bot Bot removed the pending-release PR queued for the next release build label Nov 25, 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