Skip to content

fix(jax-assertions): run multi_start_gradient_auto_convergence with a real search #83

Closed

Description

@Jammy2211

Overview

scripts/jax_assertions/multi_start_gradient_auto_convergence.py fails in the
workspace-smoke full-profile sweep with KeyError: 'total_steps' (PyAutoHeart run
30858578587,
job smoke / run_scripts (3.12, autofit_test, jax_assertions), 2026-08-03T22:28:40Z,
against released autofit 2026.7.29.2).

This is not a library contract break. The script's __Env__ section declares
ENV: jax, which releases only PYAUTO_DISABLE_JAX, so profile_smoke.yaml's
default PYAUTO_TEST_MODE: "2" still applies and the sampler is bypassed. The
bypass path never writes total_steps into samples_info, so the script's
line 123 read raises. The script asserts on a real fit's outcome and must run
the real search, exactly like its siblings in scripts/searches/.

Plan

  • Change the script's declaration from ENV: jax to ENV: real_search jax, so
    PYAUTO_TEST_MODE is released too and the search runs for real.
  • Move the rationale into the __Env__ section beside the declaration, mirroring
    scripts/searches/MultiStartAdam.py.
  • Fix the stale af.AbstractMultiStartGradient reference in the module docstring
    (that symbol is not exported on af), which currently trips the PyAuto API gate
    on any local run of the script.
  • Re-run the script under the env build_env_for_script resolves post-change and
    confirm all three assertion blocks pass.
Detailed implementation plan

Root cause (reproduced locally 2026-08-04)

  • build_env_for_script(<script>, profile_smoke.yaml) resolves to
    {'PYAUTO_TEST_MODE': '2', 'JAX_ENABLE_X64': 'True', ...} — the jax token
    releases only PYAUTO_DISABLE_JAX (autohands/env_config.py:47).
  • Under PYAUTO_TEST_MODE=2, AbstractSearch._fit_bypass_test_mode
    (autofit/non_linear/search/abstract_search.py:864) skips _fit entirely and
    builds samples_info from {total_iterations, time, log_evidence} plus
    _test_mode_samples_info(). AbstractMultiStartGradient does not override that
    hook (only BlackJAX NUTS does), so total_steps is absent.
  • Script line 123 result.samples.samples_info["total_steps"] → KeyError.
    Reproduced verbatim in ~4.5 s, matching CI's 4.7 s.
  • samples_via_internal_from has written total_steps into samples_info since
    63cd4e222 (the original multi-start commit) and does so in released
    2026.7.29.2 — the library never changed.
  • The bypass can never satisfy this script regardless: it asserts
    normalization ≈ 25, and the bypass returns the prior median, which for
    LogUniformPrior(1e-2, 1e2) is 1.0.

Not a regression

The identical failure is present in the previous workspace-smoke run
(30790463134,
2026-08-03T06:33Z). Pre-migration, profile_smoke.yaml gave jax_assertions/
only unset: [PYAUTO_DISABLE_JAX], so the #187/#189 declaration migration was a
genuine no-op here — the script has been broken under the smoke profile since it
was authored. It is not in smoke_tests.txt, so the per-PR gate is unaffected;
only the full-profile sweep runs it.

Library side considered and rejected

Adding a _test_mode_samples_info() override to AbstractMultiStartGradient
(as BlackJAX NUTS has) would supply a placeholder total_steps, but would only
convert a loud KeyError into a vacuous 0 < 300 pass followed by a confusing
truth-recovery failure. The NUTS-vs-MultiStart asymmetry is worth raising
separately, not as the repair here.

Affected Repositories

  • autofit_workspace_test (primary)

Branch Survey

Repository Current Branch Dirty?
./autofit_workspace_test main clean

active.md shows point-source-defaults-campaign claiming this repo on
feature/jax-pytree-traced-aux-fix — that claim is stale: PR
autofit_workspace_test#81 merged 2026-08-01T12:47:34Z and the checkout was
restored to main. Not a live conflict.

Suggested branch: feature/multi-start-auto-convergence-real-search

Worktree root: ~/Code/PyAutoLabs-wt/multi-start-auto-convergence-real-search/

Work Classification: Workspace

Implementation Steps

  1. scripts/jax_assertions/multi_start_gradient_auto_convergence.py — in the
    __Env__ section, change ENV: jax to ENV: real_search jax and record why
    (the script asserts a real fit's total_steps / truth recovery; the bypass
    returns the prior median and never writes total_steps).
  2. Same file, module docstring — drop the af. prefix from
    af.AbstractMultiStartGradient (the class lives in
    autofit.non_linear.search.mle.multi_start_gradient, not on the af
    namespace).
  3. Verify under the resolved smoke env, then /ship_workspace.

Key Files

  • scripts/jax_assertions/multi_start_gradient_auto_convergence.py — the fix.
  • config/build/profile_smoke.yaml — supplies the PYAUTO_TEST_MODE: "2" default
    (unchanged; the declaration is the sanctioned per-script lever).
  • scripts/searches/MultiStartAdam.py — the sibling to mirror (ENV: real_search jax).

Acceptance

The script passes under the resolved smoke env, running the real search.
Verified pre-fix by running with PYAUTO_TEST_MODE unset (output cleared first):

Auto-convergence stopped after 158 / 300 steps.
Recovered: centre=50.156, normalization=25.197, sigma=9.858
Auto-convergence early-stopped at the truth basin of the 1D Gaussian.
Resume path builds a byte-identical value_and_grad HLO (77848 chars)
Results-DB round-trip OK: converged=True, stop_reason=converged, fom_history trace length 158 (ceiling 300).

Wall time ~60 s (vs 4.7 s bypassed) — acceptable for the full-profile sweep, the
only place this script runs.

Original Prompt

Click to expand starting prompt
  1. multi_start_gradient_auto_convergence.py KeyError

In the PyAutoLabs workspace, this script fails in workspace-smoke:

autofit_workspace_test scripts/jax_assertions/multi_start_gradient_auto_convergence.py
KeyError: 'total_steps' (FAIL after 4.7s)

Evidence: PyAutoHeart workspace-smoke run 30858578587, job
"smoke / run_scripts (3.12, autofit_test, jax_assertions)",
2026-08-03T22:28:40Z. Ran against released autofit 2026.7.29.2.

Fails fast (4.7s), so it looks like a plain contract break between the
script and whatever dict it reads 'total_steps' from — likely a
MultiStartGradient progress/result structure that changed. Find who
writes that key, decide whether the library or the script is wrong, and
fix the owning side. Route through start_dev.

Activity

  1. Jammy2211 commented on Aug 4, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped — 2026-08-04

    PRs

    Summary

    scripts/jax_assertions/multi_start_gradient_auto_convergence.py now declares
    ENV: real_search jax instead of ENV: jax, so PYAUTO_TEST_MODE is released and
    the search actually runs. The KeyError: 'total_steps' was never a library
    contract break — the sampler was being bypassed, and the bypass stub never writes
    total_steps into samples_info. Also dropped the stale af. prefix from
    af.AbstractMultiStartGradient in the module docstring. Docstring-only diff.

    Session Notes

    Latent, not a regression. The identical failure is in the previous sweep
    (PyAutoHeart run 30790463134). Pre-migration, profile_smoke.yaml gave
    jax_assertions/ only unset: [PYAUTO_DISABLE_JAX] — never PYAUTO_TEST_MODE —
    so the #187/#189 declaration migration was a genuine no-op here and the fault
    predates it. The script has been broken under the smoke profile since it was
    authored. It is not in smoke_tests.txt, so the per-PR gate was never affected.

    Library change considered and rejected. AbstractMultiStartGradient has no
    _test_mode_samples_info() override while BlackJAXNUTS does. Adding one would
    have supplied a placeholder total_steps but only converted a loud KeyError
    into a vacuous 0 < 300 pass followed by a confusing truth-recovery failure
    (the bypass returns the prior median, and LogUniformPrior(1e-2, 1e2)'s median
    is 1.0, not the asserted 25). The asymmetry is filed separately as a PyAutoMind
    draft prompt (draft/bug/autofit/multi_start_test_mode_samples_info_gap.md)
    rather than patched over here.

    Gotcha for anyone re-verifying. A second run of this script takes ~3.3 s
    instead of ~10 s because PyAutoFit resumes the completed fit from the existing
    output folder — the search does not re-run. rm -rf output/jax_assertions/ multi_start_gradient_auto_convergence before timing or trusting a pass. The
    directory sweep's 11/11 included one such resume; the fresh-output runs (10.0 s
    and 11.1 s, both EXIT=0) are the real evidence.

    Also cleaned up: the point-source-defaults-campaign active.md entry still
    claimed autofit_workspace_test at "PR #81 OPEN" — that PR merged 2026-08-01 and
    the entry's own status line already said so. The stale claim was firing the
    worktree conflict guard, and has been released.

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