Repository navigation
Description
Overview
A /cli_noise_clean audit of the full PyAutoFit suite (1667 tests, -W all) surfaced five mechanical warning sources, all in PyAutoFit. The largest is an unclosed search.log FileHandler leaking a file descriptor per decorated search call (44 warnings/run); the rest are one deprecation each from SQLAlchemy, nautilus, scipy, and CPython's fork-in-threads check. All five are noise-only fixes with no behaviour change.
Plan
- Close the
search.logFileHandlerinconfigure_handler'sfinallyblock, beside the existingremoveHandler. - Annotate the overlapping
Fit.arrays/Fit.hdusvsHDU.fitSQLAlchemy relationships with theoverlaps=parameters SQLAlchemy suggests, silencing theSAWarningfromconfigure_mappers(). - Swap the deprecated nautilus
search_internal.evidence()call for the.log_zproperty. - Stop forwarding the scipy-deprecated
disp/iprintoptions to the L-BFGS-B solver (constructor keeps accepting them for API stability). - Add a module-local
filterwarningsmark totest_fork_context.pyfor CPython's fork-in-a-multi-threaded-processDeprecationWarning, which pytest's background thread makes unavoidable there.
Detailed implementation plan
Affected Repositories
- PyAutoFit (primary, only)
Work Classification
Library
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| PyAutoFit | main (fresh clone @ 401e666) | clean |
Branch: claude/pyautofit-cli-noise-fixes-vqs7mg (session-designated; remote web session, no local worktree — the ~/Code/PyAutoLabs-wt/ flow is not used)
Note: active.md claims PyAutoFit for stored-sample-reconstruction-guard (autofit/non_linear/samples/) and version-stamp-sync-guards (autofit/__init__.py, files/release.sh). This task is file-disjoint from both.
Implementation Steps
autofit/non_linear/search/abstract_search.py(configure_handler,finallyblock): addhandler.close()afterroot_logger.removeHandler(handler)— the handler holdssearch.logopen otherwise (44ResourceWarnings per suite run).autofit/database/model/array.py:Array.fit,HDU.fit,Fit.arraysandFit.hdusall write the samearray.fit_idcolumn (HDU inherits it via joined-table inheritance), which firesSAWarning: relationship ... will copy column fit.id to column array.fit_id, which conflicts with relationship(s) ...atconfigure_mappers(). Add theoverlaps="..."parameter with exactly the relationship names SQLAlchemy's warning lists (reproduced locally before committing).autofit/non_linear/search/nest/nautilus/search.py(samples_info_from, line 535):search_internal.evidence()→search_internal.log_z(nautilus deprecated the method for the property).autofit/non_linear/search/mle/bfgs/search.py: scipy 1.15 deprecated the L-BFGS-Bdisp/iprintoptions (removal slated for 1.18). OverrideoptionsinLBFGSto drop both keys before the dict reachesoptimize.minimize; constructor keeps accepting them (API stability;dispremains live for plainBFGS). Updatetest_autofit/non_linear/search/optimize/test_lbfgs.pyaccordingly (assert the attributes survive and the options keys are absent).test_autofit/non_linear/test_fork_context.py: addpytestmark = pytest.mark.filterwarnings("ignore:This process:DeprecationWarning")— CPython 3.12+ warns onos.fork()in a multi-threaded process, and pytest's machinery keeps a thread alive; the tests exercise the fork-pinned pool deliberately.
Out of scope (noted lowest-priority in the prompt): edge-case LinAlgWarning/RuntimeWarning from tests that deliberately exercise degenerate inputs (interpolator/covariance.py, messages/normal.py, fitness.py).
Key Files
autofit/non_linear/search/abstract_search.py— handler closeautofit/database/model/array.py— SQLAlchemyoverlaps=autofit/non_linear/search/nest/nautilus/search.py—.log_zautofit/non_linear/search/mle/bfgs/search.py+test_autofit/non_linear/search/optimize/test_lbfgs.py— L-BFGS-B optionstest_autofit/non_linear/test_fork_context.py— fork warning mark
Testing
- Reproduce each warning on
mainfirst (SAWarning viasa.orm.configure_mappers(); scipy deprecation via anaf.LBFGSfit; handler leak via-W error::ResourceWarningon a search-log test), then show it gone after the fix. - Run the affected test files:
test_autofit/non_linear/search/optimize/test_lbfgs.py,test_autofit/non_linear/test_fork_context.py,test_autofit/database/, nautilus search tests, plus thenon_linear/searchtree.
Original Prompt
Click to expand starting prompt
PyAutoFit CLI-noise batch: unclosed search.log handler + four small warning fixes
Type: maintenance
Target: PyAutoFit
Repos:
- PyAutoFit
Difficulty: small
Autonomy: safe
Priority: normal
Status: formalised
Filed 2026-08-06 from a full /cli_noise_clean audit (full PyAutoFit suite,
1667 tests, -W all). Five mechanical fixes, all in PyAutoFit:
- Unclosed
search.logFileHandler (44 warnings/run) —
autofit/non_linear/search/abstract_search.py:123-131(configure_handler)
removes the handler infinallybut never callshandler.close(). Add
handler.close()besideremoveHandlerat line 131. - SQLAlchemy
SAWarningrelationship overlap —Fit.arrays/Fit.hdus
vsHDU.fit("will copy column fit.id ... conflicts"). Add the
overlaps="..."parameters SQLAlchemy suggests, in the DB model
definitions (fires fromconfigure_mappers(), not the test). - Nautilus deprecation —
non_linear/search/nest/nautilus/search.py:535
usessearch_internal.evidence(); swap to the.log_zproperty. - scipy L-BFGS-B deprecation —
non_linear/search/mle/bfgs/search.py:194
passes deprecateddisp/iprintoptions; drop them per scipy's migration
note (or gate on scipy version). - fork() DeprecationWarning in
test_fork_context.py— pytest's thread
pool +os.fork(); add a module-localfilterwarningsmark or use the
spawncontext in that test where feasible.
Edge-case numerical warnings from tests that deliberately exercise degenerate
inputs (LinAlgWarning/RuntimeWarning in interpolator/covariance.py,
messages/normal.py, fitness.py) are lowest priority — silence locally in
the triggering tests with warnings.catch_warnings(), never globally.
Activity
Jammy2211 commentedon Aug 18, 2026
Implementation pushed to
claude/pyautofit-cli-noise-fixes-vqs7mgas 7d1fe19 (6 files, +42/−5). All five fixes landed as planned, each verified against its warning before/after:configure_handlercloses thesearch.loghandler infinally— 50 decorated calls under-W error::ResourceWarningnow run clean with no handlers left on the root logger.Fit.arraysgetsoverlaps="fit",Fit.hdusgetsoverlaps="arrays,fit"(the exact strings SQLAlchemy 2.0.52's two SAWarnings suggest);configure_mappers()now emits zero warnings, with no follow-on overlaps.samples_info_fromreads.log_z; nautilus 1.0.5's deprecatedevidence()is a warn-then-return self.log_zwrapper, so the swap is exactly equivalent.LBFGS.optionsdropsdisp/iprint(scipy 1.17.1 confirmed the DeprecationWarning fires on any L-BFGS-B call passing them); constructor still accepts both anddispstays live for plainBFGS.test_lbfgs.pyupdated to pin the new contract.test_fork_context.pycarries module-local filters for both fork warnings — CPython 3.12+'s DeprecationWarning and JAX's equivalent RuntimeWarning (the latter surfaced during validation; same unavoidable-fork noise, different emitter).Full suite on Python 3.13 / scipy 1.17.1: 1884 passed, 3 skipped. Remaining fork warnings from dynesty pool tests elsewhere in the tree are outside this prompt's scope, as are the deliberately-degenerate-input numerical warnings the prompt marks lowest priority.
No PR opened yet — branch is ready for one when wanted.
Generated by Claude Code
Jammy2211 commentedon Aug 18, 2026
Shipped: #1496 merged as
7d4d931with all checks green (unittest 3.12 + 3.13, docs-build),pending-releaselabel on for the next release build. Workspace impact: none — internal changes only, no migration needed. Completion record:PyAutoMind/complete/2026/08/cli-noise-pyautofit-batch.md(landed on main via PyAutoMind#235).Generated by Claude Code