Repository navigation
Description
Overview
Phase D follow-up of the aggregator profiling task (#1375, phases A+B merged as #1376 + autofit_workspace_test#48). The sqlite results database (autofit/database/) has two paths: build-from-directory (scrape) and direct-write during a fit (session). Neither has been used in a long time and the direct-write path is suspected buggy. Goal: exercise both with the merged mock-results harness, fix the cheap bugs, and produce a written where-it's-at assessment for whatever isn't cheap — explicitly per the original prompt: "If its hard to fix dont bother, but its good to work out where its at."
Plan
- Run the existing
autofit_workspace_test/scripts/database/{directory,scrape,session}scripts against current main — record which still pass, triage what fails. - Exercise the scrape/build path at scale using the merged mock-results generator (
scripts/profiling/aggregator/mock_results.py); fix bugs where cheap. - Extend the profiling grid with database stages (build time, query time) so sqlite loading can be compared against the directory
Aggregator— answering "when is building the database worth it?". - Assess the session/direct-write path: fix if cheap, otherwise a written assessment (what works, what's broken, what a fix would take) posted to this issue.
- Assessment-first: source edits happen only after the failure survey, with the fix plan checkpointed.
Detailed implementation plan
Work Classification
Both (library + workspace) — bug workflow.
Worktree root
~/Code/PyAutoLabs-wt/aggregator-sqlite/
Affected Repositories
- PyAutoFit (primary —
autofit/database/:aggregator/scrape.py,aggregator/aggregator.py,model/,sqlalchemy_.py,migration/) - autofit_workspace_test (
scripts/database/,scripts/profiling/aggregator/)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoFit | main | clean |
| ./autofit_workspace_test | main | clean |
Suggested branch: feature/aggregator-sqlite
Implementation Steps
- Survey: run
scripts/database/directory/*.py,scripts/database/scrape/*.py,scripts/database/session/*.pyunder PYAUTO_TEST_MODE; tabulate pass/fail + tracebacks. - Scale exercise: mock N=100/1000 result sets →
af.Aggregator(database file)scrape/add_directory; catalogue failures. - Cheap fixes in
autofit/database/with unit tests (numpy-only). - Profiling stage: add
database_build+database_querystages toprofile_aggregator.py(or a siblingprofile_database.py). - Session/direct-write assessment; cheap fixes or written verdict on this issue.
Key Files
PyAutoFit/autofit/database/aggregator/scrape.py— build-from-directory pathPyAutoFit/autofit/database/aggregator/aggregator.py— sqlite Aggregator + queriesPyAutoFit/autofit/non_linear/paths/database.py— direct-write (session) pathsautofit_workspace_test/scripts/database/— existing coverageautofit_workspace_test/scripts/profiling/aggregator/— merged harness to reuse
Verification
- Existing database scripts pass (or failures documented with tracebacks and triage).
pytest test_autofit/database/(plus aggregator subtree) green.- Profiling table showing database build/query vs directory-aggregator loading on the same mock sets.
Original Prompt
Click to expand starting prompt
Phase D follow-up of the aggregator profiling task (PyAutoFit#1375; phases A+B merged as PyAutoFit#1376 + autofit_workspace_test#48). Original goal 3 of that prompt, verbatim:
"dont work on sqlite database builds on 1 or 2, but then do a follow up where you use this functionality, inevitably encounter and fix bugs for its use, and assess the code which writes directly to the sqlite database, which has not been used in a long time and I'm sure is buggy. If its hard to fix dont bother, but its good to work out where its at."
Concretely, in PyAutoFit (autofit/database/) driven from autofit_workspace_test:
-
Use the merged mock-results harness (scripts/profiling/aggregator/mock_results.py) to exercise the sqlite build-from-directory path (autofit/database/aggregator/scrape.py, af.Aggregator(database file) + add_directory) at scale; fix the bugs encountered where they are cheap; extend the profiling grid with a database-build + database-query stage so sqlite loading can be compared against the directory Aggregator.
-
Assess the direct-write path (session-based writing during a fit, database.py paths) — long unused and suspected buggy. Fix if cheap; otherwise produce a written where-it's-at assessment (what works, what is broken, what it would take) rather than sinking time.
-
The existing scripts/database/{directory,scrape,session}/ scripts in autofit_workspace_test are the current coverage — run them, note which still pass.
Activity
Jammy2211 commentedon Jul 16, 2026
Phase D assessment — where the sqlite database is at
Survey of existing coverage (8 scripts, PYAUTO_TEST_MODE)
database/directory/generaloutput/…while fits land inoutput/test_mode/…database/directory/multi_analysisdatabase/scrape/generaldatabase/scrape/multi_analysisdatabase/scrape/grid_searchwith_test_mode_segment)database/scrape/sensitivitydatabase/session/generaldatabase/session/multi_analysisThe 4 failures were all one trap: manual output paths missing the test-mode segment — the same fix the two passing scrape scripts already carried. These are very likely the standing "workspace validation not passing" failures Heart has been reporting since 2026-07-09.
Bugs found and fixed (PyAutoFit)
database/aggregator/aggregator.py::__getitem__):agg[:5]on 26 fits returned 21 (len − stopitems instead ofstop − start);agg[3:8]returned 15. The existing unit test passed only by coincidence (2 fits, stop=1, where len−stop == stop). Fixed + regression test with 3 fits.samples_summary:DatabasePathsfell through to the abstract no-op, so summary-based workflows (the lightweight path we just made central in phases A+B, andAggregateCSV) failed withAttributeErroron any session-written database. Implementedsave_samples_summary/load_samples_summaryonDatabasePaths(mirroring the directory filter semantics; missing summary maps to theFileNotFoundErrorthe resume check expects). Verified end-to-end: a session-written fit's database now servesvalues("samples_summary").Not bugs, but traps documented
unique_taginto each copy'ssearch.jsonso database exercise is faithful.open_databasesilently prependsconf.instance.output_path(plus the test-mode segment) to relative sqlite paths — a relative path you pass is not where the file goes, and an empty decoy file can appear at the literal path. Absolute paths bypass both. The new profiler uses absolute paths.save_all_samples=False→samples.minimise()), so session databases legitimately have ~1-row sample lists unless configured otherwise — not a bug, but surprising next to scrape databases that keep the full csv.Performance: database vs directory (mock results, same data)
Quick grid (per-result ms; 5-component model;
values("samples")on identical mock data):values("samples")values("samples")The 1000-result × 1k-sample cell was abandoned mid-run after ~50 min of CPU on that single cell (its 173 MB database did build; the process sat at ~3.4 GB RSS in the sample-loading stages) — the directory Aggregator's entire 9-cell grid including a 3000-result cell completes in ~8 min. Build cost is ~0.4 s/result up front (≈20 min for a 3000-lens catalogue) and is dominated by loading every result's full samples into the ORM.
Verdict: at current state the sqlite path offers no loading-speed advantage — build costs ~0.4s/result up front and
values("samples")from the ORM is several times slower than the (post-#1376) directory Aggregator on identical data. Queries are fast once built, and the single-file property remains the real use case (HPC inode limits). Making the database fast would mean attacking ORM object reconstruction — out of "low-hanging" scope; recorded here instead.Direct-write path — verdict
Contrary to suspicion it is not broken at the smoke level: both session scripts pass, fits/queries/samples round-trip. Its real gaps were the missing
samples_summary(fixed above) and the minimised-samples surprise (documented). It remains less exercised than the scrape path — treat it as working-but-thinly-tested.Jammy2211 commentedon Jul 16, 2026
Shipped and merged (2026-07-16): #1380 + PyAutoLabs/autofit_workspace_test#49 (heart RED acked — 5 pre-existing unrelated reasons, recorded in Mind; this PR pair actually fixes part of the workspace-validation reason). Closing — the assessment above is the Phase D deliverable; making the sqlite path fast (ORM reconstruction) is recorded there as explicitly out of low-hanging scope.