Skip to content

feat: environment probe, PYAUTO_SETUP at import, honour JAX_ENABLE_X64=False #222

Closed

Description

@Jammy2211

Overview

Likelihood-lifecycle epic, phase 5A (PyAutoNerves only). Phase 5 bakes the Pulse-designated optimal compute setup into the source as setup="auto"; 5A lays the environment layer underneath it: a hardware probe, PYAUTO_SETUP honoured at import, and the JAX_ENABLE_X64=False opt-out bug fixed (ruling R4 depends on it). 5A detects and honours overrides only; it chooses nothing (choice is 5B Setup.auto in PyAutoArray).

Plan

  • Add autonerves.environment.Environment.detect(): GPU (present, name, memory), usable cores, RAM, numba / nufftax availability, site hint. Reports only.
  • jax_wrapper honours PYAUTO_SETUP=auto|cpu|gpu|<setup_id> at import: an explicit CPU intent pins JAX to CPU and sets thread variables before JAX initialises; auto/unset/gpu set nothing; invalid values raise a clear error.
  • Fix x64: JAX_ENABLE_X64=False|0 is respected; unset still forces x64 on.
  • Docstrings only (workspace prose is 5F). Ship to an open pending-release PR.
  • Tier + merge mode: effective level: supervised; merge mode: human /prm
Detailed implementation plan

Affected Repositories

  • PyAutoNerves (primary)

Branch Survey

Repository Current Branch Dirty?
./PyAutoNerves main clean

Suggested branch: feature/likelihood-lifecycle-p5a-nerves

Implementation Steps

  1. autonerves/environment.py (new): frozen Environment dataclass (gpu, gpu_name, gpu_memory_gb, cores, ram_gb, numba, nufftax, site) + Environment.detect(). cores = SLURM_CPUS_PER_TASK → os.sched_getaffinity(0) → os.cpu_count(); RAM from /proc/meminfo (fallback os.sysconf); numba/nufftax via importlib.util.find_spec (no import); GPU via jax.devices() only when jax is already in sys.modules, else one nvidia-smi query with a timeout (documented); site = SLURM_CLUSTER_NAME or hostname class, reusing site_config detection.
  2. autonerves/jax_wrapper.py: parse PYAUTO_SETUP before anything can import JAX via a reusable parse_setup_intent() (5B reuses it). cpu, or a <setup_id> (<backend>_<device>_<operator>_<precision>[_<transformer>], report §3.1) whose device token is cpu, sets JAX_PLATFORMS=cpu and OMP/MKL/OPENBLAS/NUMBA_NUM_THREADS to the detected cores, only where unset (never overwriting a user value). auto/unset/gpu are no-ops. Invalid → error naming the allowed forms.
  3. x64 block: explicit False/0 stays False (one log line noting fp32 was requested); unset → forced True as today; explicit True/1 untouched.
  4. Tests: test_autonerves/test_environment.py (monkeypatched env vars, affinity, missing /proc, absent optional packages; one test per branch); subprocess import tests for PYAUTO_SETUP (JAX_PLATFORMS, thread vars, no overwrite, no-op cases, invalid error); subprocess x64 tests (False, 0, unset, True → jax.config.read("jax_enable_x64")). Full suite green.
  5. ship_library → open PR (pending-release); merge is the human's /prm.

Key Files

  • autonerves/environment.py — new probe
  • autonerves/jax_wrapper.py — PYAUTO_SETUP + x64 fix
  • autonerves/site_config.py — existing site detection to reuse
  • test_autonerves/test_environment.py, test_autonerves/test_jax_wrapper.py

Note: CPU-intent thread defaults are the detected cores (right for a single process); Nautilus numba workers pin their own threads, so this never overrides that.

Original Prompt

Click to expand starting prompt

Likelihood lifecycle phase 5A: PyAutoNerves environment probe, PYAUTO_SETUP honoured at import, and the x64 opt-out bug

Type: feature
Target: PyAutoNerves
Repos:

  • PyAutoNerves
    Themes:
  • hpc-gpu
  • profiling
    Difficulty: medium
    Autonomy: supervised
    Priority: high
    Status: draft
    Consequence: judge
    Witness: PyAutoNerves main carries autonerves.environment.Environment.detect() returning gpu, gpu_name, gpu_memory_gb, cores (SLURM_CPUS_PER_TASK, then sched_getaffinity, then cpu_count), ram_gb, numba, nufftax and a site hint, each branch covered by a unit test with the environment monkeypatched; jax_wrapper honours PYAUTO_SETUP=auto|cpu|gpu|<setup_id> at import (explicit cpu/numba intents set JAX_PLATFORMS=cpu and the *_NUM_THREADS variables before JAX initialises; auto and unset set nothing), checked by subprocess import tests; under JAX_ENABLE_X64=False (and 0) importing autonerves leaves jax.config.read("jax_enable_x64") False while unset still forces x64 on, checked by a subprocess test; full test suite green
    Review-minutes: 20
    Unattended: ready
    Lane: any
    Gate: MET 2026-11-16 — human ruled phase 4 closed (gaps listed), approved report §3.4 and R6 = opt-in first (ledger line 2026-11-16). Ran after the wall-estimate bug, per the human — that bug is fixed (complete/2026/11/validation-wall-estimates-miss-eval-count-and-sampler-floor.md, autolens_inference#70, merged 2026-11-16).
    Epic: likelihood-lifecycle
    Phase: 5
    Parent: draft/research/autolens_profiling/likelihood_lifecycle_epic.md
    Filed: 2026-11-16

Context

  • Phase 5 (epic ledger): optimal setup baked into the source, library first: 5A PyAutoNerves → 5B PyAutoArray → 5C PyAutoGalaxy + PyAutoLens → 5D PyAutoFit → 5E estimator → 5F workspace/HowToLens → 5G assistant → 5H science projects. This prompt is 5A only. One issue in PyAutoNerves.
  • Design: report §3.5 (draft/research/autolens_profiling/likelihood_lifecycle_epic_report.md), the PyAutoNerves row:
    • autonerves.environment.Environment.detect() → gpu (bool), gpu_name, gpu_memory_gb, cores (SLURM_CPUS_PER_TASK → sched_getaffinity → cpu_count), ram_gb, numba, nufftax, site hint (SLURM_CLUSTER_NAME, hostname class).
    • jax_wrapper honours PYAUTO_SETUP=auto|cpu|gpu|<setup_id> at import: only explicit cpu/numba intents set JAX_PLATFORMS=cpu and the *_NUM_THREADS variables before JAX initialises; auto sets nothing at import (JAX picks the GPU when present).
  • Boundary (report §3.4): auto decides backend, device, operator, precision, route, threads and default cores; it never touches the model, the sampler or the HPC request, and an explicit override (PYAUTO_SETUP=<setup_id>) always wins. 5A only detects and honours the override; it chooses nothing (choice is 5B Setup.auto).
  • The x64 bug is adopted into 5A (ledger "Adopted": draft/bug/autonerves/jax_enable_x64_env_ignored_and_fp32_leg_runs_fp64.md → 5A). Root cause in @PyAutoNerves/autonerves/jax_wrapper.py (the JAX_ENABLE_X64 block: an explicit False is overwritten with True). 5A fixes the Nerves root cause only; that draft's PyAutoFit preflight.py X64_WARNING text and the autofit_inference fp32 row check stay in that draft (narrow it when 5A merges). Ruling R4 (mixed precision experimental until the x64 bug is fixed) depends on this fix.
  • Existing neighbours, read before designing: @PyAutoNerves/autonerves/site_config.py and autonerves/site/ral.yaml (site layer); the thread-pinning lessons in Brain memory (numba under Nautilus is one process per core; never prange inside multiprocessing workers; OMP does not cap numba).

Plan

  1. autonerves/environment.py: frozen dataclass Environment + detect(); no JAX import inside detect() beyond what is already initialised (GPU facts read lazily or via jax.devices() only when JAX is already imported; document which). Unit tests with monkeypatched env vars, affinity and missing optional packages.
  2. jax_wrapper.py: read PYAUTO_SETUP before JAX initialises; implement the cpu/numba intents (JAX_PLATFORMS=cpu, thread variables set only when absent, never overwriting a user value); auto/unset is a no-op. Invalid values raise a clear error naming the allowed forms.
  3. x64: respect an explicit JAX_ENABLE_X64=False|0; keep forcing x64 on when unset; update the log message to match.
  4. Docs: docstrings only (workspace prose is 5F). Changelog/pending-release note per ship_library.
  5. Ship via ship_library to an open PR (pending-release). Stop at PR-open; merge is the human's /prm.

Out of scope

aa.Setup, Setup.auto, the rule table and apply_setup (5B); setup="auto", banner and setup.json (5C); number_of_cores="auto" (5D); the estimator (5E). No compute; no RAL.

Activity

  1. Jammy2211 commented on Nov 23, 2026

    @Jammy2211
    CollaboratorAuthor

    Library PR created — awaiting human /prm

    PR: #223 (pending-release), commit 32ee087.

    Gate:

    • Tests: test_autonerves 375 passed (80 in test_environment.py / test_jax_wrapper.py, including subprocess import tests for PYAUTO_SETUP and for x64 under False, 0, unset and True).
    • Smoke: pyauto-heart smoke --affected-by PyAutoNerves, run against the task worktree: 8/8 workspaces PASS (autofit, autogalaxy, autolens, autolens_test, euclid, howtolens, autocti, autocti_test).
    • Heart dev readiness (PyAutoNerves): GREEN. Shown but not blocking: manifest drift; no release rehearsal for current source.

    Workspace impact: none needed. PYAUTO_SETUP is new and opt-in. The three callers that set JAX_ENABLE_X64=False|0 (autofit_inference CLI fp32 legs, the autolens_profiling point-source fp32 what-if, and the PyAutoFit preflight warning text) do it because they want fp32, which they now actually get.

    Tier: judge, so the merge is the human's /prm. After the merge, narrow draft/bug/autonerves/jax_enable_x64_env_ignored_and_fp32_leg_runs_fp64.md to its PyAutoFit/autofit_inference remainder, and file 5B (PyAutoArray aa.Setup, Setup.auto).

  2. Jammy2211 commented on Nov 23, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped

    Merged PyAutoNerves#223 → main (db589c2), via human /prm. Pending release.

    • autonerves.environment: Environment.detect() and parse_setup_intent() (which 5B reuses)
    • PYAUTO_SETUP read at import: a CPU intent sets JAX_PLATFORMS and the thread variables only where unset
    • JAX_ENABLE_X64=False|0 is now respected; unset still turns x64 on

    Next in the epic: 5B, PyAutoArray aa.Setup / Setup.auto.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions