Skip to content

fix: load database latent variables in wheel environments #1367

Description

@Jammy2211

Overview

Release-wheel validation fails all six PyAutoFit database scripts with a bare AssertionError, while the same source passes in the development environment. Reproduce the failure in the exact Python 3.12 TestPyPI wheel stack, isolate the dependency that changes behaviour, and fix the latent-variable loading producer in PyAutoFit without masking the warning or weakening workspace assertions.

Plan

  • Reproduce scripts/database/scrape/general.py in an isolated wheel-only Python 3.12 environment and capture the complete traceback and package manifest.
  • Pin SQLAlchemy, NumPy, and dill independently to isolate the dependency that flips the result, then repeat the winning forward/backward transition to establish causality.
  • Trace the failure through latent-sample file loading and database serialization, fixing the producer in PyAutoFit rather than adding a workspace workaround or silent guard.
  • Add focused regression coverage for latent-variable scraping/loading under the triggering dependency behaviour.
  • Validate focused and full PyAutoFit tests, the exact reproduction, and all six database integration scripts.
Detailed implementation plan

Affected Repositories

  • PyAutoFit (primary; source and unit-test changes)
  • autofit_workspace_test (validation only; no script changes expected)

Work Classification

Library

Branch Survey

Repository Current Branch Dirty?
./PyAutoFit main clean
./autofit_workspace_test main clean

No active worktree claims PyAutoFit. The workspace is a read-only reproduction and validation surface.

Suggested branch: feature/database-latent-wheel-load

Worktree root: ~/Code/PyAutoLabs-wt/database-latent-wheel-load/

Implementation Steps

  1. Create an isolated Python 3.12 environment with TestPyPI autolens[optional]==2026.7.13.1.dev65601, jax, jaxnnls, and jax_zero_contour. Record pip freeze, verify the imported autofit location is inside the venv, and ensure no local source checkout is on PYTHONPATH.
  2. Remove prior generated output/database files, run autofit_workspace_test/scripts/database/scrape/general.py under the release profile, and preserve the full Python traceback plus the produced files/latent/ artifacts.
  3. Hold the wheel environment fixed and vary one dependency at a time. Compare SQLAlchemy 2.0.51 with the dev version 2.0.32, NumPy 2.4.6 with the dev version 2.2.6, and dill 0.4.1 with a preceding compatible release as a control. Use --no-deps, pip check, and a clean output directory for every run. Reinstall the triggering version after the passing pin to prove the failure returns.
  4. Trace the actual exception through SearchOutput._load_samples, _add_files_fit, and the database Fit/Object serialization path. Patch the component that produces or reconstructs the invalid latent samples. Do not broaden the warning catch to suppress the exception, silently omit latent data, or change workspace assertions to tolerate corrupt/missing data.
  5. Add a regression fixture that contains real latent samples.csv and samples_info.json output and exercises the scrape-to-database round trip. Assert the latent samples retain their class, parameter values, model, and usable summary/instance after loading.
  6. Run the focused aggregator/database tests, the relevant PyAutoFit test subtrees, then the full test_autofit/ suite. Re-run the exact wheel-stack script and all six scripts/database/{directory,scrape}/ scripts to confirm the release failure is removed.

Key Files

  • autofit/aggregator/search_output.py — latent sample CSV/metadata reconstruction and likely exception origin.
  • autofit/database/aggregator/scrape.py — boundary that assigns latent samples and currently emits the warning.
  • autofit/database/model/fit.py — database representation of latent samples.
  • autofit/database/model/ — object reconstruction if dependency behaviour changes serialization.
  • test_autofit/aggregator/test_scrape.py — focused scraper regression coverage.
  • test_autofit/database/test_serialize.py — database round-trip coverage if the traceback reaches object reconstruction.
  • autofit_workspace_test/scripts/database/scrape/general.py — exact reproduction and validation script; no masking edits expected.

Original Prompt

Click to expand starting prompt

Database scripts fail on release wheels: "Failed to load latent variables" → AssertionError

Type: bug
Target: autofit
Repos:

  • PyAutoFit
  • autofit_workspace_test
    Difficulty: medium
    Autonomy: supervised
    Priority: normal
    Status: formalised

Surfaced burning down the 2026-07-13 release-validation tail (PyAutoHeart#72). On the release
wheels (mode=release), all six autofit_workspace_test/scripts/database/** scripts fail
FAST (4–13 s) with a bare AssertionError:

scripts/database/directory/general.py       ... FAIL (5.4s) AssertionError
scripts/database/directory/multi_analysis.py... FAIL (4.4s) AssertionError
scripts/database/scrape/general.py          ... FAIL (4.3s) AssertionError
scripts/database/scrape/grid_search.py      ... FAIL (8.8s) AssertionError
scripts/database/scrape/multi_analysis.py   ... FAIL (4.4s) AssertionError
scripts/database/scrape/sensitivity.py      ... FAIL (12.7s) AssertionError

with a recurring warning:

autofit.database.aggregator.scrape - WARNING - Failed to load latent variables for <hash>

Not jax, not perf, not the release profile. These PASS on the current dev venv
(jax 0.10.2) even under the release profile (PYAUTO_TEST_MODE=0)
— the latent-variable
load emits only the WARNING there and the assertion passes. The wheel code is identical to
main HEAD, so the delta is the wheel-env dependency set: the release stack resolves
SQLAlchemy 2.0.51, dill 0.4.1, numpy 2.4.6 (full list in the rehearsal install log of
run 29279095224). The most likely culprit is a serialization/deserialization
incompatibility in the latent-variable load path
(autofit.database.aggregator.scrape
whatever loads latent samples from the SQLAlchemy-backed database) under one of those
dependency versions.

Reproduce with the wheel dependency set (the dev venv won't show it): build a venv with
the release stack — pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ "autolens[optional]==2026.7.13.1.dev65601" jax jaxnnls jax_zero_contour
(a scratch rel-venv approximating this already exists from the 2026-07-14 session) — then run
scripts/database/scrape/general.py from autofit_workspace_test/ and capture the full
traceback (the one-line CI summary hides the assertion detail). Isolate which dependency flips
it (SQLAlchemy vs dill vs numpy) by pinning them one at a time.

Fix the producer of the bad load (don't silence the warning — [[feedback_no_silent_guards]]):
if latent variables genuinely fail to deserialize under the newer dep, fix the
load/serialization in autofit.database; if the scripts' assertion is over-strict about a
tolerable-missing latent, fix the assertion. Release run: PyAutoHeart workspace-validation
29279095224, TestPyPI 2026.7.13.1.dev65601. See [[project_release_2026_07_13_blocked_3bugs]].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions