Repository navigation
feat(aggregator): opt-in temporary extraction for zipped search outputs (#1584) - #1592
Merged
Merged
Conversation
…ts (#1584) `Aggregator.from_directory` extracts every `.zip` it meets into a sibling directory beside the zip and leaves it there, so aggregating a results tree that holds only zips (an HPC run, or any run with `output: remove_files`) permanently doubles the disk and file count. On a three-result zip-only tree the scan grew the directory 1.85x in bytes and 10x in files. `unzip_temporary=True` extracts into a temporary directory instead, mirroring the scanned layout so same-named zips in different directories cannot collide. The scanned tree is left byte-identical. Every search output read out of the extraction holds a reference to it, so the files live exactly as long as something can still read them and are removed once the last such object is collected; `close()` and the context manager remove them eagerly. `TemporaryExtraction` uses `weakref.finalize` rather than `tempfile.TemporaryDirectory` because the latter emits a `ResourceWarning` whenever it is cleaned up implicitly, which is the normal path here. The default is unchanged: extraction beside the zip, skipped when the extracted directory already exists. That short-cut still wins in temporary mode, so a tree that is already unpacked is never re-extracted. The cost of the new mode is re-extracting on every call rather than once: 0.33s vs 0.04s for a 200-result tree, against ~45ms per result to parse samples. Reading members straight from the zip was assessed and not taken: ~20 path-based loader and enumeration call sites, plus lazy per-query re-reads that would re-open the archive repeatedly and regress the 2026-07 aggregator speed-up. Full PyAutoFit suite green: 2552 passed, 2 skipped. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EwQS9x9Ls1NBUpbASL7n1s
The grid-search branch of the scan gained the same ownership reference as the search-output branch, and nothing exercised it: the aggregator tests carried no `.is_grid_search` fixture at all. The assertion that matters is `children`. Pairing a grid search with its child searches goes through `is_relative_to` on their directories, which only holds if both were extracted into the same mirrored temporary tree; a flat or per-zip extraction would silently return a grid search with no children. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EwQS9x9Ls1NBUpbASL7n1s
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
Aggregator.from_directoryextracts every.zipit meets into a sibling directory beside the zip and leaves it there. Aggregating a results tree that holds only zips — an HPC run, or any run withoutput: remove_files— therefore doubles the disk and file count permanently, with no opt-out and no automatic cleanup (remove_unzipped()is opt-in and removes the parent of each search directory).On a three-result zip-only tree the default scan grew the directory 1.85x in bytes and 10x in files.
unzip_temporary=Trueextracts into a temporary directory instead, mirroring the scanned layout so that same-named zips in different directories cannot collide. The scanned tree is left byte-identical. Every search output read out of the extraction holds a reference to it, so the files live exactly as long as something can still read them and are removed when the last such object is garbage collected;close()and the context manager remove them eagerly.TemporaryExtractionusesweakref.finalizerather thantempfile.TemporaryDirectory, because the latter emits aResourceWarningwhenever it is cleaned up implicitly, and implicit cleanup is the normal path here.The default is unchanged, including the short-cut that skips a zip whose extracted directory already exists. That short-cut still wins in temporary mode, so a tree that is already unpacked is never re-extracted.
Cost: the new mode re-extracts on every call rather than once — 0.33s vs 0.04s on a repeat call over a 200-result tree, against ~45 ms per result to parse samples. Extraction is not where aggregation time goes.
Not taken: reading members straight from the zip. That is ~20 path-based loader and enumeration call sites across
file_output.py,search_output.pyandaggregator.py, plus lazy per-query re-reads that would re-open the archive repeatedly and regress the 2026-07 aggregator speed-up (#1375 arc). Flipping the default to temporary extraction is left as a one-line follow-up.API Changes
Purely additive.
Aggregator.from_directoryandadd_directorygain an opt-inunzip_temporarykeyword defaulting toFalse;Aggregatorgainsclose()and the context-manager protocol; a newTemporaryExtractionclass owns the extracted files. The search-output constructors gain an optionaltemporary_directorykeyword. No symbol was removed or renamed, and no default changed, so every existing call behaves exactly as before.See full details below.
Test Plan
close()/ context-manager exittest_zip_extracted_and_loaded,test_zip_not_re_extracted) unchanged and greenTo verify by hand, point the aggregator at a tree of
.zipresults and comparedu -sbefore and after with and without the flag.Full API Changes (for automation & release notes)
Added
autofit.aggregator.search_output.TemporaryExtraction— a temporary directory owning extracted zip contents; removed viaweakref.finalizewhen the last referent is collected. Public attributes:path,is_alive,cleanup().Aggregator.close()— remove the temporary extraction eagerly; a no-op when there is none.Aggregator.__enter__/Aggregator.__exit__— context-manager protocol, exiting viaclose().Changed Signature
Aggregator.from_directory(directory, completed_only=False, reference=None, unzip_temporary=False)— new trailing keyword, default preserves existing behaviour.Aggregator.add_directory(directory, unzip_temporary=False)— same.Aggregator.__init__(search_outputs, grid_search_outputs, temporary_directory=None)— new trailing keyword.AbstractSearchOutput.__init__(directory, reference=None, temporary_directory=None)— new trailing keyword.SearchOutput.__init__(directory, reference=None, temporary_directory=None)— new trailing keyword.Changed Behaviour
unzip_temporary=True, extraction targets a temporary directory instead of a sibling of the zip, and that directory is removed automatically.Migration
Aggregator.from_directory(path, unzip_temporary=True), orwith Aggregator.from_directory(path, unzip_temporary=True) as agg:to release the extraction at a known point.Closes #1584
Generated by the PyAutoLabs agent workflow.
🤖 Generated with Claude Code
https://claude.ai/code/session_01EwQS9x9Ls1NBUpbASL7n1s