Refresh cached SearchUpdater when AbstractSearch.paths is reassigned#1252
Merged
Conversation
``AbstractSearch._updater`` lazily caches a ``SearchUpdater`` on first access and previously never invalidated the cache. When the EP loop reuses a single search across factors and iterations, ``AbstractSearch.optimise(factor_approx)`` mutates ``self.paths`` to a fresh ``SubDirectoryPaths`` per factor and per EP iteration — but the updater stayed pinned to the first paths it ever saw, so all subsequent samples / visualizations / profiles wrote under the wrong directory. The user-visible symptom is per-EP-iteration visualisations overwriting each other in the first iteration's image folder. Identity-comparing the cached updater's ``_paths`` against ``self.paths`` makes the property recreate the updater whenever the search has been pointed at a new paths object. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
AbstractSearch._updaterlazy-caches aSearchUpdateron first access and previously never invalidated the cache. When the EP loop reuses one search instance across factors and iterations,AbstractSearch.optimise(factor_approx)reassignsself.pathsto a freshSubDirectoryPathsper factor and per EP iteration — but the updater stayed pinned to the very first paths it ever saw. Result: every per-factor / per-iteration sample, visualisation, and profile output silently wrote under the first iteration's directory, with each later iteration overwriting the earlier one. The user-visible symptom is that anAnalysis.Visualizeronly ever produces output underdataset_<i>/optimization_0/image/, never underoptimization_1/,optimization_2/, etc.The fix is one identity check in the
_updaterproperty: if the cached updater's_pathsis no longer the search's currentself.paths, recreate the updater. Identity (is not) is the right test —AbstractSearch.optimisealways assigns a freshly-constructedSubDirectoryPaths, never an in-place mutation. Plus a unit test that simulates the EP path-mutation pattern (assignsearch.paths = af.DirectoryPaths(...)and check_updater._paths is search.paths).End-to-end verified on the cancer-IC50 EP validation script: 10 datasets × 3 EP iterations now produces 30 per-iteration Hill-curve fit plots correctly distributed across
dataset_0..9 / optimization_0..2. Before the fix the same script produced only 10 plots, all in the iter-1 directory.API Changes
None — internal change only. Existing callers see no behaviour difference unless they were affected by the bug. The
_updaterproperty remains a private cached lazily-initialisedSearchUpdater; the only difference is that it now refreshes when the search'spathsattribute has been reassigned to a new object.Test Plan
pytest test_autofit/non_linear/search/test_abstract_search.py::TestUpdaterPathsRefresh— new testpytest test_autofit/non_linear test_autofit/graphical -q— 426 tests pass (no regressions)hill_curve_fit.pngplots distributed correctly acrossdataset_<i> / optimization_<j>(was 10 plots, all inoptimization_0, before the fix)Full API Changes (for automation & release notes)
Changed Behaviour
autofit.non_linear.search.abstract_search.AbstractSearch._updater— the cachedSearchUpdateris now invalidated and recreated whenself.pathsis reassigned to a different object. Previously it was created once on first access and reused forever, regardless of subsequentself.pathsreassignments. Identity comparison (is not) is used as the cache-invalidation key.Migration
None required — the property is private and the bug fix removes a silent behaviour that no correct caller could have relied on.
🤖 Generated with Claude Code