Repository navigation
feat: number_of_cores="auto", parallel banner/metadata and factor-graph setups (5D) - #1795
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 honestParallel:banner line, records the resolved parallelism insearch.summaryandfiles/parallel.json, and makesFactorGraphModelforwardmodify_before_fitto every factor's analysis, with a setup-agreement check, sosetup=works inside factor graphs. The default staysnumber_of_cores=1(R6).API Changes
number_of_coresonSettingsSearchand every search accepts an int ≥ 1,None(→ 1) or"auto"; anything else raisesValueError.search.jsonkeeps 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 hasresources_per_eval(). There is no parallel-efficiency cap.Parallel: N workers (requested R; reason) · setup <id>aftermodify_before_fit.log_fit_startno longer logs a core count.files/parallel.json: requested, number_of_cores, reason, detected_cores, available_memory_gb, setup_id.FactorGraphModel.modify_before_fitforwards to each factor (rebinding both analysis references) and callscheck_setup_agreement(), which is also run in preflight.GridSearch/Sensitivityaccept"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 intest_number_of_cores_auto.py, 8 intest_factor_graph_setup.py. Probes are monkeypatched and nothing forks.test_gaussian.py::test__potential_2d_from__zero_at_centre_and_basis_is_fast, which took 59 s; it passes alone. Unrelated to autofit.)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_ROOTFull 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().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.PoolFactoryuses the fit's resolved count.warn_if_threads_unpinnedonly 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]plusSetup = <id>.preflight.check_runtime_gatesalso runscheck_setup_agreement.Migration
number_of_cores=1is unchanged. Tests that assert the exact oldlog_fit_start"with N cores" line need the new banner instead.Notes:
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 shipsruntime_estimates.yamland implementsresources_per_eval().SetupExceptionfor graph fits), and mismatched setups raise aSearchExceptionthat names the factors. EP still never callsmodify_before_fit, so the Lens guard stays for EP.ModelAnalysisdoes not forwardmodify_before_fitto 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.pystays within its 600-line budget: the new helpers live inruntime.py.Generated by the PyAutoLabs agent workflow.
🤖 Generated with Claude Code