Repository navigation
Done
Description
Overview
Likelihood-lifecycle epic, phase 5D (PyAutoFit). This adds opt-in number_of_cores="auto", resolved at fit start after the analysis has resolved its compute setup. It replaces the stale fit-start JAX/cores line with one honest parallel banner, records the resolved parallelism and setup in the search metadata, and makes factor graphs forward modify_before_fit to each factor's analysis, so setup= works inside af.FactorGraphModel with an agreement check.
Plan
- Accept
number_of_cores="auto"onSettingsSearchand every search, validating an int ≥ 1 or "auto". The default stays 1 (R6). - Resolve "auto" in
PoolFactory, aftermodify_before_fit, to the detected cores (SLURM_CPUS_PER_TASK→ affinity →cpu_count); 1 for JAX (fork rule) and EP factor searches. Cap it by min(cores / cpus_per_eval, available memory / peak_rss) only when the analysis suppliesresources_per_eval(). - One banner line after
modify_before_fit:Parallel: N workers (requested auto; capped by cores|memory|JAX) · setup <setup_id>. The stalelog_fit_startclaim is removed. - Metadata: the resolved count, cap reason and setup_id go into
search.summaryandfiles/parallel.json;search.jsonkeeps the request. - Factor graphs:
FactorGraphModel.modify_before_fitforwards to each factor's analysis (its own model and sub-paths, rebinding both analysis references), andcheck_setup_agreementsits besidecheck_backend_agreement.
Design calls (human-approved 2026-11-24):
- No η-based cap in 5D: the only measured curve (imaging/rectangular numba) has cores × η rising at every step up to 32, so throughput favours all cores.
- The memory cap is a hook (duck-typed
analysis.resources_per_eval()), live once 5E shipsruntime_estimates.yaml, plus an available-memory read (MemAvailable, falling back to total). - "auto" is validated everywhere; the thread warning is deferred until the count is resolved.
- Factor-graph forwarding lives in PyAutoFit; Galaxy/Lens are untouched. The Lens
SetupExceptionguard stays for EP.
- Tier + merge mode: effective level: supervised; merge mode: human /prm
Detailed implementation plan
Affected Repositories
- PyAutoFit (primary)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoFit | main | clean |
Suggested branch: feature/likelihood-lifecycle-p5d-fit
Implementation Steps
- Validation:
SettingsSearch.__init__(autofit/non_linear/settings.py:16) andNonLinearSearch.__init__(abstract_search.py:98, :168-169) accept an int ≥ 1, None (→ 1) or "auto" (case-insensitive), and raise a clear error otherwise.warn_if_threads_unpinned(runtime.py:97-114) only runs for an int, and runs for the resolved count at fit start.- Searches that pass
number_of_coresthrough (dynesty static/dynamic, nautilus, zeus, blackjax, abstract_mcmc) keep working with "auto".
- Resolution:
- Add
resolve_number_of_cores(requested, analysis, is_jax, where)(parallel/pool.py, next toeffective_number_of_cores). For "auto": detected cores viaautonerves.environment.detect_cores. JAX gives 1; EP factor searches give 1 (check_factor_search_cores). - If
getattr(analysis, "resources_per_eval", None)returns cpus_per_eval / peak_rss_gb, cap by min(cores // cpus_per_eval, floor(available_gb / peak_rss_gb)), never below 1. - Return (n, reason).
PoolFactoryuses it, so.number_of_cores,.summaryand__call__all use the resolved count.
- Add
- Available memory: a small helper (autofit or
autonerves.environmentif appropriate; autofit-local if simpler) reading/proc/meminfoMemAvailable, then cgroup v2memory.maxwhen lower, then total RAM. - Banner: after
modify_before_fit(abstract_search.py_fit_and_output~:317, or instart_resume_fitafterPoolFactory), logParallel: N workers (requested R; <reason>) · setup <setup_id>. The setup_id comes fromgetattr(analysis, "setup", None), duck-typed with no autoarray import. Remove or trim the stale count/JAX claim inlog_fit_start(runtime.py:242-263), keeping anything else it reports. - Metadata:
search._parallel_summary/PoolFactory.summaryincludes the resolved count, request, reason and setup_id, andpaths.save_json("parallel", {...})writesfiles/parallel.json(directory and database paths). - Factor graphs:
FactorGraphModel.modify_before_fit(paths, model)(graphical/declarative/collection.py) loops overmodel_factorswith sub-paths (paths.for_sub_analysis("analyses/analysis_i"), as_for_each_analysisdoes) and each factor's own prior model. It callsfactor.analysis.modify_before_fit(child_paths, factor_model), rebindsfactor.analysisand theFactorCallable.analysis(factor/analysis.py:21, :74) to the returned object, and returns self.check_setup_agreement(collection.py, next to :111-142) comparesgetattr(analysis, "setup", None).setup_idacross factors, ignoring None, and raises a clear error on disagreement. It is called at the end of the forwarding and in preflight (search/preflight.py:345-351).- Confirm
HierarchicalFactor/_flat_factorsare handled.
- Tests:
test_autofit/non_linear/test_fork_rule.pyandtest_parallel.py: auto resolution, JAX → 1, EP → 1, memory cap with a fakeresources_per_eval, a cgroup/MemAvailable helper with fake files, validation errors.search/test_abstract_search.py: "auto" throughSettingsSearchand constructors; the warning is deferred.test_logging.py/test_capabilities.py: banner and summary.- paths tests:
parallel.json. - graphical: forwarding calls each factor's
modify_before_fitonce with its model and sub-paths, rebinds both references, and agreement passes or fails. A dummy analysis withsetup_id-carryingsetupattributes; no autoarray dependency.
- Full suite plus
pyauto-heart smoke --affected-by PyAutoFit.
Key Files
autofit/non_linear/settings.py,autofit/non_linear/search/abstract_search.py,autofit/non_linear/runtime.pyautofit/non_linear/parallel/pool.py,autofit/non_linear/capabilities.py,autofit/non_linear/paths/*autofit/graphical/declarative/collection.py,autofit/graphical/declarative/factor/analysis.py,autofit/non_linear/search/preflight.py
Original Prompt
Click to expand starting prompt
Likelihood lifecycle phase 5D: PyAutoFit number_of_cores="auto", a post-setup parallel banner, parallel metadata, and factor graphs that forward modify_before_fit with a setup-agreement check
Type: feature
Target: PyAutoFit
Repos:
- PyAutoFit
Themes: - hpc-gpu
- profiling
Difficulty: large
Autonomy: supervised
Priority: high
Status: draft
Consequence: judge
Witness: PyAutoFit main acceptsnumber_of_cores="auto"onSettingsSearchand every search constructor, validating an int ≥ 1 or"auto". The default stays 1 (R6). "auto" is resolved inPoolFactory, afteranalysis.modify_before_fit, to the detected cores (SLURM_CPUS_PER_TASK→ CPU affinity →cpu_count), and to 1 for JAX analyses (the existing fork rule) and for EP factor searches. When the analysis suppliesresources_per_eval()(cpus_per_eval, peak_rss_gb), the count is capped at min(cores / cpus_per_eval, available memory / peak_rss); otherwise there is no cap. One banner line aftermodify_before_fitreports the effective workers, the request, any cap reason and the setup_id; the stalelog_fit_startJAX/cores claim is gone. The resolved count, cap reason and setup_id are written tosearch.summaryandfiles/parallel.json.FactorGraphModel.modify_before_fitforwards to each factor's analysis (its own model and sub-paths, rebinding both analysis references), and acheck_setup_agreementbesidecheck_backend_agreementrefuses graphs whose factors resolved different setups. Full test suite green;pyauto-heart smoke --affected-by PyAutoFitpasses.
Review-minutes: 30
Unattended: no
Lane: any
Gate: 5C-3 MERGED (PyAutoGalaxy#753, PyAutoLens#886); 5C setup resolution inmodify_before_fitis on Galaxy/Lens main. Plan and design calls approved by the human 2026-11-24.
Epic: likelihood-lifecycle
Phase: 5
Parent: draft/research/autolens_profiling/likelihood_lifecycle_epic.md
Filed: 2026-11-24
Context
- Report §3.5, PyAutoFit row:
SettingsSearch(number_of_cores="auto")→ setup threads; the fork rule is unchanged; the banner is printed at fit start; the resolved setup is stored in the search metadata. The node-throughput amendment caps workers at min(cores / cpus_per_eval, memory / peak_rss). - Survey 2026-11-24:
number_of_coresis unvalidated (settings.py:16; abstract_search.py:98, :168-169).warn_if_threads_unpinnedcompares<= 1(runtime.py:103), so "auto" would raise in the constructor.- Fork rule:
effective_number_of_cores(parallel/pool.py:60-90).PoolFactory(:137-230) is built instart_resume_fit(abstract_search.py:424) aftermodify_before_fit.log_fit_start(runtime.py:242-263) runs before it (:307 vs :317). - Metadata:
search.jsoncomes fromto_dict(search)(paths/directory.py:382-401);search.summaryfromrun_summary_from→search._parallel_summary(capabilities.py:281-287, abstract_search.py:425). - Factor graphs:
FactorGraphModelinherits the no-opmodify_before_fit(analysis.py:301-309). There are two analysis references,AnalysisFactor.analysis(factor/analysis.py:74) andFactorCallable.analysis(:21). Preflight runscheck_backend_agreement(search/preflight.py:326-356; collection.py:111-142). - Phase 4 measured η only for imaging/rectangular numba (autolens_inference
scripts/misc/wall/model.py:99: 1.0, 0.68, 0.62, 0.55, 0.36, 0.28 at 1–32 cores). Cores × η is monotone increasing, so throughput favours all cores. peak_rss_gbexists only in autolens_profilingruntime_estimates.yaml, which no library reads until 5E. Nerves has totalram_gbbut no available-memory probe.
- Design calls (human-approved 2026-11-24):
- No η-based cap in 5D. The one measured curve favours all cores; record η context in the metadata note.
- The memory cap applies only when the analysis supplies
resources_per_eval(). It goes live when 5E shipsruntime_estimates.yaml. Add an available-memory read:MemAvailable, cgroup-aware if simple, falling back to total. - "auto" is accepted and validated everywhere; the thread warning is deferred to resolution.
- Factor-graph setup forwarding lands in PyAutoFit; Galaxy/Lens are untouched. The PyAutoLens
SetupExceptionguard stays for EP, which never callsmodify_before_fit.
Out of scope
- The runtime estimator and copying
runtime_estimates.yamlinto PyAutoLens (5E). - Workspace prose (5F).
- Flipping the default to auto (R6).
- Slimming the Analysis setup to delegate numpy operators to
sparse_operator_for(at the R6 flip).
Metadata
Metadata
Assignees
Labels
No labels
Activity
Jammy2211 commentedon Nov 24, 2026
5D shipped as #1795 (pending-release):
number_of_cores="auto"(validated; resolved after modify_before_fit),Parallel:banner,files/parallel.json, factor-graphmodify_before_fitforwarding withcheck_setup_agreement. Gate: 4376 passed, Galaxy/Lens compat green, Heart dev GREEN, smoke 8/8.Jammy2211 commentedon Nov 24, 2026
Shipped
#1795 (23b7dfe):
number_of_cores="auto"(validated; resolved after modify_before_fit; JAX/EP → 1; memory cap viaresources_per_eval()), theParallel:banner,files/parallel.json, and factor-graphmodify_before_fitforwarding withcheck_setup_agreement. Pending release. Next: 5E (runtime estimator; PyAutoLens implementsresources_per_eval()so the memory cap goes live).